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
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 /* Device identifier. Don't relay it to WineD3D */
31 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
35 { { 0x00010001, 0x00010001 } },
37 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
38 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
42 static struct enum_device_entry
44 char interface_name
[100];
45 char device_name
[100];
46 const GUID
*device_guid
;
51 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
53 &IID_IDirect3DTnLHalDevice
,
58 "WINE Direct3D7 Hardware acceleration using WineD3D",
60 &IID_IDirect3DHALDevice
,
65 "WINE Direct3D7 RGB Software Emulation using WineD3D",
67 &IID_IDirect3DRGBDevice
,
71 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
73 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
75 ddraw_null_wined3d_object_destroyed
,
78 static inline IDirectDrawImpl
*impl_from_IDirectDraw(IDirectDraw
*iface
)
80 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw_iface
);
83 static inline IDirectDrawImpl
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
85 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw2_iface
);
88 static inline IDirectDrawImpl
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
90 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw4_iface
);
93 static inline IDirectDrawImpl
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
95 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw7_iface
);
98 static inline IDirectDrawImpl
*impl_from_IDirect3D(IDirect3D
*iface
)
100 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D_iface
);
103 static inline IDirectDrawImpl
*impl_from_IDirect3D2(IDirect3D2
*iface
)
105 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D2_iface
);
108 static inline IDirectDrawImpl
*impl_from_IDirect3D3(IDirect3D3
*iface
)
110 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D3_iface
);
113 static inline IDirectDrawImpl
*impl_from_IDirect3D7(IDirect3D7
*iface
)
115 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D7_iface
);
118 /*****************************************************************************
120 *****************************************************************************/
122 /*****************************************************************************
123 * IDirectDraw7::QueryInterface
125 * Queries different interfaces of the DirectDraw object. It can return
126 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
127 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
129 * The returned interface is AddRef()-ed before it's returned
131 * Used for version 1, 2, 4 and 7
134 * refiid: Interface ID asked for
135 * obj: Used to return the interface pointer
138 * S_OK if an interface was found
139 * E_NOINTERFACE if the requested interface wasn't found
141 *****************************************************************************/
142 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
144 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
146 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
148 /* Can change surface impl type */
149 wined3d_mutex_lock();
151 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
156 wined3d_mutex_unlock();
157 return DDERR_INVALIDPARAMS
;
160 /* Check DirectDraw Interfaces */
161 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
162 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
165 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
167 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
169 *obj
= &This
->IDirectDraw4_iface
;
170 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
172 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
174 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
175 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
177 wined3d_mutex_unlock();
178 return E_NOINTERFACE
;
180 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
182 *obj
= &This
->IDirectDraw2_iface
;
183 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
185 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
187 *obj
= &This
->IDirectDraw_iface
;
188 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
192 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
193 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
194 * who had this idea and why. The older interfaces can query and IDirect3D version
195 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
196 * and messy to implement with the common creation function, so it has been left out here.
198 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
199 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
200 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
201 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
203 /* Check the surface implementation */
204 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
206 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
207 /* Do not abort here, only reject 3D Device creation */
210 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
212 This
->d3dversion
= 1;
213 *obj
= &This
->IDirect3D_iface
;
214 TRACE(" returning Direct3D interface at %p.\n", *obj
);
216 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
218 This
->d3dversion
= 2;
219 *obj
= &This
->IDirect3D2_iface
;
220 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
222 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
224 This
->d3dversion
= 3;
225 *obj
= &This
->IDirect3D3_iface
;
226 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
228 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
230 This
->d3dversion
= 7;
231 *obj
= &This
->IDirect3D7_iface
;
232 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
235 /* Unknown interface */
238 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
239 wined3d_mutex_unlock();
240 return E_NOINTERFACE
;
243 IUnknown_AddRef( (IUnknown
*) *obj
);
244 wined3d_mutex_unlock();
249 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
251 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
253 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
255 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
258 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
260 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
262 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
264 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
267 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
269 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
271 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
273 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
276 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
278 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
280 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
282 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
285 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
287 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
289 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
291 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
294 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
296 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
298 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
300 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
303 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
305 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
307 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
309 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
312 /*****************************************************************************
313 * IDirectDraw7::AddRef
315 * Increases the interfaces refcount, basically
317 * DDraw refcounting is a bit tricky. The different DirectDraw interface
318 * versions have individual refcounts, but the IDirect3D interfaces do not.
319 * All interfaces are from one object, that means calling QueryInterface on an
320 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
321 * IDirectDrawImpl object.
323 * That means all AddRef and Release implementations of IDirectDrawX work
324 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
325 * except of IDirect3D7 which thunks to IDirectDraw7
327 * Returns: The new refcount
329 *****************************************************************************/
330 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
332 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
333 ULONG ref
= InterlockedIncrement(&This
->ref7
);
335 TRACE("%p increasing refcount to %u.\n", This
, ref
);
337 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
342 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
344 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
345 ULONG ref
= InterlockedIncrement(&This
->ref4
);
347 TRACE("%p increasing refcount to %u.\n", This
, ref
);
349 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
354 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
356 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
357 ULONG ref
= InterlockedIncrement(&This
->ref2
);
359 TRACE("%p increasing refcount to %u.\n", This
, ref
);
361 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
366 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
368 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
369 ULONG ref
= InterlockedIncrement(&This
->ref1
);
371 TRACE("%p increasing refcount to %u.\n", This
, ref
);
373 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
378 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
380 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
382 TRACE("iface %p.\n", iface
);
384 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
387 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
389 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
391 TRACE("iface %p.\n", iface
);
393 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
396 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
398 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
400 TRACE("iface %p.\n", iface
);
402 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
405 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
407 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
409 TRACE("iface %p.\n", iface
);
411 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
414 void ddraw_destroy_swapchain(IDirectDrawImpl
*ddraw
)
416 TRACE("Destroying the swapchain.\n");
418 wined3d_swapchain_decref(ddraw
->wined3d_swapchain
);
419 ddraw
->wined3d_swapchain
= NULL
;
421 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
425 for (i
= 0; i
< ddraw
->numConvertedDecls
; ++i
)
427 wined3d_vertex_declaration_decref(ddraw
->decls
[i
].decl
);
429 HeapFree(GetProcessHeap(), 0, ddraw
->decls
);
430 ddraw
->numConvertedDecls
= 0;
432 if (FAILED(wined3d_device_uninit_3d(ddraw
->wined3d_device
)))
434 ERR("Failed to uninit 3D.\n");
438 /* Free the d3d window if one was created. */
439 if (ddraw
->d3d_window
&& ddraw
->d3d_window
!= ddraw
->dest_window
)
441 TRACE("Destroying the hidden render window %p.\n", ddraw
->d3d_window
);
442 DestroyWindow(ddraw
->d3d_window
);
443 ddraw
->d3d_window
= 0;
447 ddraw
->d3d_initialized
= FALSE
;
451 wined3d_device_uninit_gdi(ddraw
->wined3d_device
);
454 ddraw_set_swapchain_window(ddraw
, NULL
);
456 TRACE("Swapchain destroyed.\n");
459 /*****************************************************************************
462 * Destroys a ddraw object if all refcounts are 0. This is to share code
463 * between the IDirectDrawX::Release functions
466 * This: DirectDraw object to destroy
468 *****************************************************************************/
469 static void ddraw_destroy(IDirectDrawImpl
*This
)
471 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
472 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
474 /* Destroy the device window if we created one */
475 if(This
->devicewindow
!= 0)
477 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
478 DestroyWindow(This
->devicewindow
);
479 This
->devicewindow
= 0;
482 wined3d_mutex_lock();
483 list_remove(&This
->ddraw_list_entry
);
484 wined3d_mutex_unlock();
486 if (This
->wined3d_swapchain
)
487 ddraw_destroy_swapchain(This
);
488 wined3d_device_decref(This
->wined3d_device
);
489 wined3d_decref(This
->wined3d
);
491 /* Now free the object */
492 HeapFree(GetProcessHeap(), 0, This
);
495 /*****************************************************************************
496 * IDirectDraw7::Release
498 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
500 * Returns: The new refcount
501 *****************************************************************************/
502 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
504 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
505 ULONG ref
= InterlockedDecrement(&This
->ref7
);
507 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
509 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
515 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
517 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
518 ULONG ref
= InterlockedDecrement(&This
->ref4
);
520 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
522 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
528 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
530 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
531 ULONG ref
= InterlockedDecrement(&This
->ref2
);
533 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
535 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
541 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
543 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
544 ULONG ref
= InterlockedDecrement(&This
->ref1
);
546 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
548 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
554 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
556 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
558 TRACE("iface %p.\n", iface
);
560 return ddraw7_Release(&This
->IDirectDraw7_iface
);
563 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
565 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
567 TRACE("iface %p.\n", iface
);
569 return ddraw1_Release(&This
->IDirectDraw_iface
);
572 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
574 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
576 TRACE("iface %p.\n", iface
);
578 return ddraw1_Release(&This
->IDirectDraw_iface
);
581 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
583 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
585 TRACE("iface %p.\n", iface
);
587 return ddraw1_Release(&This
->IDirectDraw_iface
);
590 /*****************************************************************************
591 * IDirectDraw methods
592 *****************************************************************************/
594 static HRESULT
ddraw_set_focus_window(IDirectDrawImpl
*ddraw
, HWND window
)
596 /* FIXME: This looks wrong, exclusive mode should imply a destination
598 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
600 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
601 return DDERR_HWNDALREADYSET
;
604 ddraw
->focuswindow
= window
;
606 /* Use the focus window for drawing too. */
607 ddraw
->dest_window
= ddraw
->focuswindow
;
612 static HRESULT
ddraw_attach_d3d_device(IDirectDrawImpl
*ddraw
,
613 struct wined3d_swapchain_desc
*swapchain_desc
)
615 HWND window
= swapchain_desc
->device_window
;
618 TRACE("ddraw %p.\n", ddraw
);
620 if (!window
|| window
== GetDesktopWindow())
622 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
623 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
624 NULL
, NULL
, NULL
, NULL
);
627 ERR("Failed to create window, last error %#x.\n", GetLastError());
631 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
632 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
634 swapchain_desc
->device_window
= window
;
638 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
640 ddraw
->d3d_window
= window
;
642 /* Set this NOW, otherwise creating the depth stencil surface will cause a
643 * recursive loop until ram or emulated video memory is full. */
644 ddraw
->d3d_initialized
= TRUE
;
645 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, swapchain_desc
);
648 ddraw
->d3d_initialized
= FALSE
;
652 ddraw
->declArraySize
= 2;
653 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
656 ERR("Error allocating an array for the converted vertex decls.\n");
657 ddraw
->declArraySize
= 0;
658 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
659 return E_OUTOFMEMORY
;
662 TRACE("Successfully initialized 3D.\n");
667 static HRESULT
ddraw_create_swapchain(IDirectDrawImpl
*ddraw
, HWND window
, BOOL windowed
)
669 struct wined3d_swapchain_desc swapchain_desc
;
670 struct wined3d_display_mode mode
;
671 HRESULT hr
= WINED3D_OK
;
673 /* FIXME: wined3d_get_adapter_display_mode() would be more appropriate
674 * here, since we don't actually have a swapchain yet, but
675 * wined3d_device_get_display_mode() has some special handling for color
677 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
680 ERR("Failed to get display mode.\n");
684 memset(&swapchain_desc
, 0, sizeof(swapchain_desc
));
685 swapchain_desc
.backbuffer_width
= mode
.width
;
686 swapchain_desc
.backbuffer_height
= mode
.height
;
687 swapchain_desc
.backbuffer_format
= mode
.format_id
;
688 swapchain_desc
.swap_effect
= WINED3D_SWAP_EFFECT_COPY
;
689 swapchain_desc
.device_window
= window
;
690 swapchain_desc
.windowed
= windowed
;
692 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_OPENGL
)
693 hr
= ddraw_attach_d3d_device(ddraw
, &swapchain_desc
);
695 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &swapchain_desc
);
699 ERR("Failed to create swapchain, hr %#x.\n", hr
);
703 if (FAILED(hr
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0, &ddraw
->wined3d_swapchain
)))
705 ERR("Failed to get swapchain, hr %#x.\n", hr
);
706 ddraw
->wined3d_swapchain
= NULL
;
710 ddraw_set_swapchain_window(ddraw
, window
);
715 /*****************************************************************************
716 * IDirectDraw7::SetCooperativeLevel
718 * Sets the cooperative level for the DirectDraw object, and the window
719 * assigned to it. The cooperative level determines the general behavior
720 * of the DirectDraw application
722 * Warning: This is quite tricky, as it's not really documented which
723 * cooperative levels can be combined with each other. If a game fails
724 * after this function, try to check the cooperative levels passed on
725 * Windows, and if it returns something different.
727 * If you think that this function caused the failure because it writes a
728 * fixme, be sure to run again with a +ddraw trace.
730 * What is known about cooperative levels (See the ddraw modes test):
731 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
732 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
733 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
734 * DDSCL_FULLSCREEN can be activated
735 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
737 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
738 * DDSCL_SETFOCUSWINDOW (partially),
739 * DDSCL_MULTITHREADED (work in progress)
741 * Unhandled flags, which should be implemented
742 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
743 * expect any difference to a normal window for wine)
744 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
745 * rendering (Possible test case: Half-Life)
747 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
749 * These don't seem very important for wine:
750 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
753 * DD_OK if the cooperative level was set successfully
754 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
755 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
756 * (Probably others too, have to investigate)
758 *****************************************************************************/
759 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
761 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
762 struct wined3d_stateblock
*stateblock
;
763 struct wined3d_surface
*rt
, *ds
;
764 BOOL restore_state
= FALSE
;
768 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
769 DDRAW_dump_cooperativelevel(cooplevel
);
771 wined3d_mutex_lock();
773 /* Get the old window */
774 window
= This
->dest_window
;
776 /* Tests suggest that we need one of them: */
777 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
781 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
782 wined3d_mutex_unlock();
783 return DDERR_INVALIDPARAMS
;
786 if ((cooplevel
& DDSCL_CREATEDEVICEWINDOW
) && !(cooplevel
& DDSCL_EXCLUSIVE
))
788 WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
789 wined3d_mutex_unlock();
790 return DDERR_INVALIDPARAMS
;
793 /* Handle those levels first which set various hwnds */
794 if ((cooplevel
& DDSCL_SETFOCUSWINDOW
) && !(cooplevel
& DDSCL_CREATEDEVICEWINDOW
))
796 /* This isn't compatible with a lot of flags */
797 if (cooplevel
& (DDSCL_MULTITHREADED
802 | DDSCL_SETDEVICEWINDOW
807 WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
808 wined3d_mutex_unlock();
809 return DDERR_INVALIDPARAMS
;
812 hr
= ddraw_set_focus_window(This
, hwnd
);
813 wined3d_mutex_unlock();
817 if (cooplevel
& DDSCL_EXCLUSIVE
)
819 if (!(cooplevel
& DDSCL_FULLSCREEN
) || !(hwnd
|| (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)))
821 WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
822 wined3d_mutex_unlock();
823 return DDERR_INVALIDPARAMS
;
826 if (cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
830 if (!This
->focuswindow
&& !(cooplevel
& DDSCL_SETFOCUSWINDOW
))
832 WARN("No focus window set.\n");
833 wined3d_mutex_unlock();
834 return DDERR_NOFOCUSWINDOW
;
837 device_window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DirectDrawDeviceWnd",
838 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
839 NULL
, NULL
, NULL
, NULL
);
842 ERR("Failed to create window, last error %#x.\n", GetLastError());
843 wined3d_mutex_unlock();
847 ShowWindow(device_window
, SW_SHOW
);
848 TRACE("Created a device window %p.\n", device_window
);
850 /* Native apparently leaks the created device window if setting the
851 * focus window below fails. */
852 This
->cooperative_level
|= DDSCL_CREATEDEVICEWINDOW
;
853 This
->devicewindow
= device_window
;
855 if (cooplevel
& DDSCL_SETFOCUSWINDOW
)
859 wined3d_mutex_unlock();
863 if (FAILED(hr
= ddraw_set_focus_window(This
, hwnd
)))
865 wined3d_mutex_unlock();
870 hwnd
= device_window
;
875 if (This
->cooperative_level
& DDSCL_CREATEDEVICEWINDOW
)
876 DestroyWindow(This
->devicewindow
);
877 This
->devicewindow
= NULL
;
878 This
->focuswindow
= NULL
;
881 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
882 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
883 wined3d_device_release_focus_window(This
->wined3d_device
);
885 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
887 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
888 wined3d_device_restore_fullscreen_window(This
->wined3d_device
, window
);
890 if (cooplevel
& DDSCL_FULLSCREEN
)
892 struct wined3d_display_mode display_mode
;
894 wined3d_get_adapter_display_mode(This
->wined3d
, WINED3DADAPTER_DEFAULT
, &display_mode
);
895 wined3d_device_setup_fullscreen_window(This
->wined3d_device
, hwnd
,
896 display_mode
.width
, display_mode
.height
);
900 if ((cooplevel
& DDSCL_EXCLUSIVE
)
901 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
903 hr
= wined3d_device_acquire_focus_window(This
->wined3d_device
, hwnd
);
906 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
907 wined3d_mutex_unlock();
912 /* Don't override focus windows or private device windows */
913 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
914 This
->dest_window
= hwnd
;
916 if (cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
917 wined3d_device_set_multithreaded(This
->wined3d_device
);
919 if (This
->wined3d_swapchain
)
921 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_GDI
)
923 restore_state
= TRUE
;
925 if (FAILED(hr
= wined3d_stateblock_create(This
->wined3d_device
, WINED3D_SBT_ALL
, &stateblock
)))
927 ERR("Failed to create stateblock, hr %#x.\n", hr
);
928 wined3d_mutex_unlock();
932 if (FAILED(hr
= wined3d_stateblock_capture(stateblock
)))
934 ERR("Failed to capture stateblock, hr %#x.\n", hr
);
935 wined3d_stateblock_decref(stateblock
);
936 wined3d_mutex_unlock();
940 wined3d_device_get_render_target(This
->wined3d_device
, 0, &rt
);
941 if (rt
== This
->wined3d_frontbuffer
)
943 wined3d_surface_decref(rt
);
947 wined3d_device_get_depth_stencil(This
->wined3d_device
, &ds
);
950 ddraw_destroy_swapchain(This
);
953 if (FAILED(hr
= ddraw_create_swapchain(This
, This
->dest_window
, !(cooplevel
& DDSCL_FULLSCREEN
))))
954 ERR("Failed to create swapchain, hr %#x.\n", hr
);
960 wined3d_device_set_depth_stencil(This
->wined3d_device
, ds
);
961 wined3d_surface_decref(ds
);
966 wined3d_device_set_render_target(This
->wined3d_device
, 0, rt
, FALSE
);
967 wined3d_surface_decref(rt
);
970 hr
= wined3d_stateblock_apply(stateblock
);
971 wined3d_stateblock_decref(stateblock
);
974 ERR("Failed to apply stateblock, hr %#x.\n", hr
);
975 wined3d_mutex_unlock();
980 /* Unhandled flags */
981 if(cooplevel
& DDSCL_ALLOWREBOOT
)
982 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
983 if(cooplevel
& DDSCL_ALLOWMODEX
)
984 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
985 if(cooplevel
& DDSCL_FPUSETUP
)
986 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
988 /* Store the cooperative_level */
989 This
->cooperative_level
= cooplevel
;
990 TRACE("SetCooperativeLevel retuning DD_OK\n");
991 wined3d_mutex_unlock();
996 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
998 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1000 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1002 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
1005 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
1007 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1009 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1011 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
1014 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
1016 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1018 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
1020 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
1023 /*****************************************************************************
1025 * Helper function for SetDisplayMode and RestoreDisplayMode
1027 * Implements DirectDraw's SetDisplayMode, but ignores the value of
1028 * ForceRefreshRate, since it is already handled by
1029 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
1030 * without worrying that ForceRefreshRate will override the refresh rate. For
1031 * argument and return value documentation, see
1032 * ddraw7_SetDisplayMode.
1034 *****************************************************************************/
1035 static HRESULT
ddraw_set_display_mode(IDirectDrawImpl
*ddraw
, DWORD Width
, DWORD Height
,
1036 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
1038 struct wined3d_display_mode mode
;
1039 enum wined3d_format_id format
;
1042 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
1043 Height
, BPP
, RefreshRate
, Flags
);
1045 wined3d_mutex_lock();
1046 if( !Width
|| !Height
)
1048 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
1049 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
1050 wined3d_mutex_unlock();
1056 case 8: format
= WINED3DFMT_P8_UINT
; break;
1057 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
1058 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
1059 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
1060 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
1061 default: format
= WINED3DFMT_UNKNOWN
; break;
1064 if (FAILED(hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
)))
1066 ERR("Failed to get current display mode, hr %#x.\n", hr
);
1068 else if (mode
.width
== Width
1069 && mode
.height
== Height
1070 && mode
.format_id
== format
1071 && mode
.refresh_rate
== RefreshRate
)
1073 TRACE("Skipping redundant mode setting call.\n");
1074 wined3d_mutex_unlock();
1078 /* Check the exclusive mode
1079 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
1080 return DDERR_NOEXCLUSIVEMODE;
1081 * This is WRONG. Don't know if the SDK is completely
1082 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
1083 * is returned, but Half-Life 1.1.1.1 (Steam version)
1088 mode
.height
= Height
;
1089 mode
.refresh_rate
= RefreshRate
;
1090 mode
.format_id
= format
;
1092 /* TODO: The possible return values from msdn suggest that
1093 * the screen mode can't be changed if a surface is locked
1094 * or some drawing is in progress
1097 /* TODO: Lose the primary surface */
1098 hr
= wined3d_device_set_display_mode(ddraw
->wined3d_device
, 0, &mode
);
1100 wined3d_mutex_unlock();
1104 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
1109 /*****************************************************************************
1110 * IDirectDraw7::SetDisplayMode
1112 * Sets the display screen resolution, color depth and refresh frequency
1113 * when in fullscreen mode (in theory).
1114 * Possible return values listed in the SDK suggest that this method fails
1115 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
1116 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
1117 * It seems to be valid to pass 0 for With and Height, this has to be tested
1118 * It could mean that the current video mode should be left as-is. (But why
1122 * Height, Width: Screen dimension
1123 * BPP: Color depth in Bits per pixel
1124 * Refreshrate: Screen refresh rate
1125 * Flags: Other stuff
1130 *****************************************************************************/
1131 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
1132 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
1134 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1136 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1137 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
1139 if (force_refresh_rate
!= 0)
1141 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
1142 RefreshRate
, force_refresh_rate
);
1143 RefreshRate
= force_refresh_rate
;
1146 return ddraw_set_display_mode(This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
1149 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
1150 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1152 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1154 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1155 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1157 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1160 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
1161 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
1163 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1165 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
1166 iface
, width
, height
, bpp
, refresh_rate
, flags
);
1168 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
1171 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
1173 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1175 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
1177 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
1180 /*****************************************************************************
1181 * IDirectDraw7::RestoreDisplayMode
1183 * Restores the display mode to what it was at creation time. Basically.
1185 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
1186 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
1187 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
1188 * -> DD_1 is released. The screen should be left at 1024x768x32.
1189 * -> DD_2 is released. The screen should be set to 1400x1050x32
1190 * This case is unhandled right now, but Empire Earth does it this way.
1191 * (But perhaps there is something in SetCooperativeLevel to prevent this)
1193 * The msdn says that this method resets the display mode to what it was before
1194 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
1198 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
1200 *****************************************************************************/
1201 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
1203 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1205 TRACE("iface %p.\n", iface
);
1207 return ddraw_set_display_mode(This
, This
->orig_width
, This
->orig_height
, This
->orig_bpp
, 0, 0);
1210 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
1212 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1214 TRACE("iface %p.\n", iface
);
1216 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1219 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
1221 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1223 TRACE("iface %p.\n", iface
);
1225 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1228 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
1230 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1232 TRACE("iface %p.\n", iface
);
1234 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1237 /*****************************************************************************
1238 * IDirectDraw7::GetCaps
1240 * Returns the drives capabilities
1242 * Used for version 1, 2, 4 and 7
1245 * DriverCaps: Structure to write the Hardware accelerated caps to
1246 * HelCaps: Structure to write the emulation caps to
1249 * This implementation returns DD_OK only
1251 *****************************************************************************/
1252 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1254 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1256 WINED3DCAPS winecaps
;
1258 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1260 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1262 /* One structure must be != NULL */
1263 if( (!DriverCaps
) && (!HELCaps
) )
1265 ERR("(%p) Invalid params to ddraw7_GetCaps\n", This
);
1266 return DDERR_INVALIDPARAMS
;
1269 memset(&caps
, 0, sizeof(caps
));
1270 memset(&winecaps
, 0, sizeof(winecaps
));
1271 caps
.dwSize
= sizeof(caps
);
1273 wined3d_mutex_lock();
1274 hr
= wined3d_device_get_device_caps(This
->wined3d_device
, &winecaps
);
1277 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1278 wined3d_mutex_unlock();
1282 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1283 wined3d_mutex_unlock();
1285 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1289 caps
.dwCaps
= winecaps
.ddraw_caps
.caps
;
1290 caps
.dwCaps2
= winecaps
.ddraw_caps
.caps2
;
1291 caps
.dwCKeyCaps
= winecaps
.ddraw_caps
.color_key_caps
;
1292 caps
.dwFXCaps
= winecaps
.ddraw_caps
.fx_caps
;
1293 caps
.dwPalCaps
= winecaps
.ddraw_caps
.pal_caps
;
1294 caps
.ddsCaps
.dwCaps
= winecaps
.ddraw_caps
.dds_caps
;
1295 caps
.dwSVBCaps
= winecaps
.ddraw_caps
.svb_caps
;
1296 caps
.dwSVBCKeyCaps
= winecaps
.ddraw_caps
.svb_color_key_caps
;
1297 caps
.dwSVBFXCaps
= winecaps
.ddraw_caps
.svb_fx_caps
;
1298 caps
.dwVSBCaps
= winecaps
.ddraw_caps
.vsb_caps
;
1299 caps
.dwVSBCKeyCaps
= winecaps
.ddraw_caps
.vsb_color_key_caps
;
1300 caps
.dwVSBFXCaps
= winecaps
.ddraw_caps
.vsb_fx_caps
;
1301 caps
.dwSSBCaps
= winecaps
.ddraw_caps
.ssb_caps
;
1302 caps
.dwSSBCKeyCaps
= winecaps
.ddraw_caps
.ssb_color_key_caps
;
1303 caps
.dwSSBFXCaps
= winecaps
.ddraw_caps
.ssb_fx_caps
;
1305 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1308 if (DefaultSurfaceType
== WINED3D_SURFACE_TYPE_GDI
)
1310 caps
.dwCaps
&= ~DDCAPS_3D
;
1311 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1313 if (winecaps
.ddraw_caps
.stride_align
)
1315 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1316 caps
.dwAlignStrideAlign
= winecaps
.ddraw_caps
.stride_align
;
1321 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1322 if (TRACE_ON(ddraw
))
1324 TRACE("Driver Caps :\n");
1325 DDRAW_dump_DDCAPS(DriverCaps
);
1331 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1332 if (TRACE_ON(ddraw
))
1334 TRACE("HEL Caps :\n");
1335 DDRAW_dump_DDCAPS(HELCaps
);
1342 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1344 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1346 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1348 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1351 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1353 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1355 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1357 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1360 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1362 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1364 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1366 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1369 /*****************************************************************************
1370 * IDirectDraw7::Compact
1372 * No idea what it does, MSDN says it's not implemented.
1375 * DD_OK, but this is unchecked
1377 *****************************************************************************/
1378 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1380 TRACE("iface %p.\n", iface
);
1385 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1387 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1389 TRACE("iface %p.\n", iface
);
1391 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1394 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1396 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1398 TRACE("iface %p.\n", iface
);
1400 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1403 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1405 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1407 TRACE("iface %p.\n", iface
);
1409 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1412 /*****************************************************************************
1413 * IDirectDraw7::GetDisplayMode
1415 * Returns information about the current display mode
1417 * Exists in Version 1, 2, 4 and 7
1420 * DDSD: Address of a surface description structure to write the info to
1425 *****************************************************************************/
1426 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1428 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1429 struct wined3d_display_mode mode
;
1433 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1435 wined3d_mutex_lock();
1436 /* This seems sane */
1439 wined3d_mutex_unlock();
1440 return DDERR_INVALIDPARAMS
;
1443 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1444 * so one method can be used for all versions (Hopefully) */
1445 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &mode
);
1448 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
1449 wined3d_mutex_unlock();
1453 Size
= DDSD
->dwSize
;
1454 memset(DDSD
, 0, Size
);
1456 DDSD
->dwSize
= Size
;
1457 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1458 DDSD
->dwWidth
= mode
.width
;
1459 DDSD
->dwHeight
= mode
.height
;
1460 DDSD
->u2
.dwRefreshRate
= 60;
1461 DDSD
->ddsCaps
.dwCaps
= 0;
1462 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1463 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, mode
.format_id
);
1464 DDSD
->u1
.lPitch
= mode
.width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1468 TRACE("Returning surface desc :\n");
1469 DDRAW_dump_surface_desc(DDSD
);
1472 wined3d_mutex_unlock();
1477 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1479 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1481 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1483 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, surface_desc
);
1486 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1488 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1490 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1492 /* FIXME: Test sizes, properly convert surface_desc */
1493 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1496 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1498 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1500 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1502 /* FIXME: Test sizes, properly convert surface_desc */
1503 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1506 /*****************************************************************************
1507 * IDirectDraw7::GetFourCCCodes
1509 * Returns an array of supported FourCC codes.
1511 * Exists in Version 1, 2, 4 and 7
1514 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1515 * of enumerated codes
1516 * Codes: Pointer to an array of DWORDs where the supported codes are written
1520 * Always returns DD_OK, as it's a stub for now
1522 *****************************************************************************/
1523 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1525 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1526 static const enum wined3d_format_id formats
[] =
1528 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1529 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1530 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1532 struct wined3d_display_mode mode
;
1533 DWORD count
= 0, i
, outsize
;
1536 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1538 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &mode
);
1540 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1542 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1544 hr
= wined3d_check_device_format(This
->wined3d
, WINED3DADAPTER_DEFAULT
, WINED3D_DEVICE_TYPE_HAL
,
1545 mode
.format_id
, 0, WINED3D_RTYPE_SURFACE
, formats
[i
], DefaultSurfaceType
);
1548 if (count
< outsize
)
1549 Codes
[count
] = formats
[i
];
1554 TRACE("Returning %u FourCC codes\n", count
);
1561 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1563 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1565 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1567 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1570 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1572 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1574 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1576 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1579 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1581 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1583 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1585 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1588 /*****************************************************************************
1589 * IDirectDraw7::GetMonitorFrequency
1591 * Returns the monitor's frequency
1593 * Exists in Version 1, 2, 4 and 7
1596 * Freq: Pointer to a DWORD to write the frequency to
1599 * Always returns DD_OK
1601 *****************************************************************************/
1602 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1604 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1606 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1607 * but for now this should make the games happy
1613 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1615 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1617 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1619 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1622 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1624 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1626 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1628 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1631 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1633 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1635 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1637 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1640 /*****************************************************************************
1641 * IDirectDraw7::GetVerticalBlankStatus
1643 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1644 * too basically, but as it's a semi stub, I didn't create a function there
1647 * status: Pointer to a BOOL to be filled with the vertical blank status
1651 * DDERR_INVALIDPARAMS if status is NULL
1653 *****************************************************************************/
1654 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1656 static BOOL fake_vblank
;
1658 TRACE("iface %p, status %p.\n", iface
, status
);
1661 return DDERR_INVALIDPARAMS
;
1663 *status
= fake_vblank
;
1664 fake_vblank
= !fake_vblank
;
1669 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1671 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1673 TRACE("iface %p, status %p.\n", iface
, status
);
1675 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1678 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1680 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1682 TRACE("iface %p, status %p.\n", iface
, status
);
1684 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1687 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1689 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1691 TRACE("iface %p, status %p.\n", iface
, status
);
1693 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1696 /*****************************************************************************
1697 * IDirectDraw7::GetAvailableVidMem
1699 * Returns the total and free video memory
1702 * Caps: Specifies the memory type asked for
1703 * total: Pointer to a DWORD to be filled with the total memory
1704 * free: Pointer to a DWORD to be filled with the free memory
1708 * DDERR_INVALIDPARAMS of free and total are NULL
1710 *****************************************************************************/
1711 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1714 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1717 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1721 TRACE("(%p) Asked for memory with description: ", This
);
1722 DDRAW_dump_DDSCAPS2(Caps
);
1724 wined3d_mutex_lock();
1726 /* Todo: System memory vs local video memory vs non-local video memory
1727 * The MSDN also mentions differences between texture memory and other
1728 * resources, but that's not important
1731 if( (!total
) && (!free
) )
1733 wined3d_mutex_unlock();
1734 return DDERR_INVALIDPARAMS
;
1738 *free
= wined3d_device_get_available_texture_mem(This
->wined3d_device
);
1741 struct wined3d_adapter_identifier desc
= {0};
1743 hr
= wined3d_get_adapter_identifier(This
->wined3d
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1744 *total
= desc
.video_memory
;
1747 wined3d_mutex_unlock();
1752 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1753 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1755 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1757 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1759 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, caps
, total
, free
);
1762 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1763 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1765 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1768 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1770 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1771 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1774 /*****************************************************************************
1775 * IDirectDraw7::Initialize
1777 * Initializes a DirectDraw interface.
1780 * GUID: Interface identifier. Well, don't know what this is really good
1784 * Returns DD_OK on the first call,
1785 * DDERR_ALREADYINITIALIZED on repeated calls
1787 *****************************************************************************/
1788 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1790 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1792 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1794 if (This
->initialized
)
1795 return DDERR_ALREADYINITIALIZED
;
1797 /* FIXME: To properly take the GUID into account we should call
1798 * ddraw_init() here instead of in DDRAW_Create(). */
1800 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1802 This
->initialized
= TRUE
;
1806 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1808 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1810 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1812 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1815 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1817 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1819 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1821 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1824 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1826 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1828 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1830 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1833 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1835 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1837 return DDERR_ALREADYINITIALIZED
;
1840 /*****************************************************************************
1841 * IDirectDraw7::FlipToGDISurface
1843 * "Makes the surface that the GDI writes to the primary surface"
1844 * Looks like some windows specific thing we don't have to care about.
1845 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1846 * show error boxes ;)
1847 * Well, just return DD_OK.
1850 * Always returns DD_OK
1852 *****************************************************************************/
1853 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1855 FIXME("iface %p stub!\n", iface
);
1860 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1862 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1864 TRACE("iface %p.\n", iface
);
1866 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1869 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1871 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1873 TRACE("iface %p.\n", iface
);
1875 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1878 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1880 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1882 TRACE("iface %p.\n", iface
);
1884 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1887 /*****************************************************************************
1888 * IDirectDraw7::WaitForVerticalBlank
1890 * This method allows applications to get in sync with the vertical blank
1892 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1893 * redraw the screen, most likely because of this stub
1896 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1897 * or DDWAITVB_BLOCKEND
1898 * h: Not used, according to MSDN
1901 * Always returns DD_OK
1903 *****************************************************************************/
1904 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1908 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1910 /* This function is called often, so print the fixme only once */
1913 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1917 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1918 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1919 return DDERR_UNSUPPORTED
; /* unchecked */
1924 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1926 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1928 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1930 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1933 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1935 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1937 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1939 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1942 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1944 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1946 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1948 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1951 /*****************************************************************************
1952 * IDirectDraw7::GetScanLine
1954 * Returns the scan line that is being drawn on the monitor
1957 * Scanline: Address to write the scan line value to
1960 * Always returns DD_OK
1962 *****************************************************************************/
1963 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1965 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1966 struct wined3d_display_mode mode
;
1967 static DWORD cur_scanline
;
1968 static BOOL hide
= FALSE
;
1970 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1972 /* This function is called often, so print the fixme only once */
1975 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1979 wined3d_mutex_lock();
1980 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &mode
);
1981 wined3d_mutex_unlock();
1983 /* Fake the line sweeping of the monitor */
1984 /* FIXME: We should synchronize with a source to keep the refresh rate */
1985 *Scanline
= cur_scanline
++;
1986 /* Assume 20 scan lines in the vertical blank */
1987 if (cur_scanline
>= mode
.height
+ 20)
1993 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1995 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1997 TRACE("iface %p, line %p.\n", iface
, line
);
1999 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
2002 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
2004 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2006 TRACE("iface %p, line %p.\n", iface
, line
);
2008 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
2011 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
2013 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2015 TRACE("iface %p, line %p.\n", iface
, line
);
2017 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
2020 /*****************************************************************************
2021 * IDirectDraw7::TestCooperativeLevel
2023 * Informs the application about the state of the video adapter, depending
2024 * on the cooperative level
2027 * DD_OK if the device is in a sane state
2028 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
2029 * if the state is not correct(See below)
2031 *****************************************************************************/
2032 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
2034 TRACE("iface %p.\n", iface
);
2039 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
2041 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2043 TRACE("iface %p.\n", iface
);
2045 return ddraw7_TestCooperativeLevel(&This
->IDirectDraw7_iface
);
2048 /*****************************************************************************
2049 * IDirectDraw7::GetGDISurface
2051 * Returns the surface that GDI is treating as the primary surface.
2052 * For Wine this is the front buffer
2055 * GDISurface: Address to write the surface pointer to
2058 * DD_OK if the surface was found
2059 * DDERR_NOTFOUND if the GDI surface wasn't found
2061 *****************************************************************************/
2062 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
2064 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2066 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
2068 wined3d_mutex_lock();
2070 if (!(*GDISurface
= &This
->primary
->IDirectDrawSurface7_iface
))
2072 WARN("Primary not created yet.\n");
2073 wined3d_mutex_unlock();
2074 return DDERR_NOTFOUND
;
2076 IDirectDrawSurface7_AddRef(*GDISurface
);
2078 wined3d_mutex_unlock();
2083 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2085 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2086 IDirectDrawSurface7
*surface7
;
2087 IDirectDrawSurfaceImpl
*surface_impl
;
2090 TRACE("iface %p, surface %p.\n", iface
, surface
);
2092 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2098 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2099 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
2100 IDirectDrawSurface4_AddRef(*surface
);
2101 IDirectDrawSurface7_Release(surface7
);
2106 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2108 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2109 IDirectDrawSurface7
*surface7
;
2110 IDirectDrawSurfaceImpl
*surface_impl
;
2113 TRACE("iface %p, surface %p.\n", iface
, surface
);
2115 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2121 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2122 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2123 IDirectDrawSurface_AddRef(*surface
);
2124 IDirectDrawSurface7_Release(surface7
);
2129 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2131 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2132 IDirectDrawSurface7
*surface7
;
2133 IDirectDrawSurfaceImpl
*surface_impl
;
2136 TRACE("iface %p, surface %p.\n", iface
, surface
);
2138 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2144 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2145 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
2146 IDirectDrawSurface_AddRef(*surface
);
2147 IDirectDrawSurface7_Release(surface7
);
2152 struct displaymodescallback_context
2154 LPDDENUMMODESCALLBACK func
;
2158 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2160 struct displaymodescallback_context
*cbcontext
= context
;
2163 DDSD2_to_DDSD(surface_desc
, &desc
);
2164 return cbcontext
->func(&desc
, cbcontext
->context
);
2167 /*****************************************************************************
2168 * IDirectDraw7::EnumDisplayModes
2170 * Enumerates the supported Display modes. The modes can be filtered with
2171 * the DDSD parameter.
2174 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2175 * versions (3 and older?) this is reserved and must be 0.
2176 * DDSD: Surface description to filter the modes
2177 * Context: Pointer passed back to the callback function
2178 * cb: Application-provided callback function
2182 * DDERR_INVALIDPARAMS if the callback wasn't set
2184 *****************************************************************************/
2185 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2186 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2188 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2189 struct wined3d_display_mode
*enum_modes
= NULL
;
2190 struct wined3d_display_mode mode
;
2191 unsigned int modenum
, fmt
;
2192 DDSURFACEDESC2 callback_sd
;
2193 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2194 DDPIXELFORMAT pixelformat
;
2196 static const enum wined3d_format_id checkFormatList
[] =
2198 WINED3DFMT_B8G8R8X8_UNORM
,
2199 WINED3DFMT_B5G6R5_UNORM
,
2203 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2204 iface
, Flags
, DDSD
, Context
, cb
);
2207 return DDERR_INVALIDPARAMS
;
2209 wined3d_mutex_lock();
2210 if(!(Flags
& DDEDM_REFRESHRATES
))
2212 enum_mode_array_size
= 16;
2213 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(*enum_modes
) * enum_mode_array_size
);
2216 ERR("Out of memory\n");
2217 wined3d_mutex_unlock();
2218 return DDERR_OUTOFMEMORY
;
2222 pixelformat
.dwSize
= sizeof(pixelformat
);
2223 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2226 while (wined3d_enum_adapter_modes(This
->wined3d
, WINED3DADAPTER_DEFAULT
,
2227 checkFormatList
[fmt
], modenum
++, &mode
) == WINED3D_OK
)
2229 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.format_id
);
2232 if (DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.width
!= DDSD
->dwWidth
)
2234 if (DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.height
!= DDSD
->dwHeight
)
2236 if (DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.refresh_rate
!= DDSD
->u2
.dwRefreshRate
)
2238 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
2239 && pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
)
2243 if(!(Flags
& DDEDM_REFRESHRATES
))
2245 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2246 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2247 * to be reduced to a single unique result in such case.
2252 for (i
= 0; i
< enum_mode_count
; i
++)
2254 if (enum_modes
[i
].width
== mode
.width
&& enum_modes
[i
].height
== mode
.height
2255 && enum_modes
[i
].format_id
== mode
.format_id
)
2265 memset(&callback_sd
, 0, sizeof(callback_sd
));
2266 callback_sd
.dwSize
= sizeof(callback_sd
);
2267 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2269 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2270 if (Flags
& DDEDM_REFRESHRATES
)
2271 callback_sd
.u2
.dwRefreshRate
= mode
.refresh_rate
;
2273 callback_sd
.dwWidth
= mode
.width
;
2274 callback_sd
.dwHeight
= mode
.height
;
2276 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2278 /* Calc pitch and DWORD align like MSDN says */
2279 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.width
;
2280 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2282 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2283 callback_sd
.u2
.dwRefreshRate
);
2285 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2287 TRACE("Application asked to terminate the enumeration\n");
2288 HeapFree(GetProcessHeap(), 0, enum_modes
);
2289 wined3d_mutex_unlock();
2293 if(!(Flags
& DDEDM_REFRESHRATES
))
2295 if (enum_mode_count
== enum_mode_array_size
)
2297 struct wined3d_display_mode
*new_enum_modes
;
2299 enum_mode_array_size
*= 2;
2300 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
,
2301 sizeof(*new_enum_modes
) * enum_mode_array_size
);
2302 if (!new_enum_modes
)
2304 ERR("Out of memory\n");
2305 HeapFree(GetProcessHeap(), 0, enum_modes
);
2306 wined3d_mutex_unlock();
2307 return DDERR_OUTOFMEMORY
;
2310 enum_modes
= new_enum_modes
;
2313 enum_modes
[enum_mode_count
++] = mode
;
2318 TRACE("End of enumeration\n");
2319 HeapFree(GetProcessHeap(), 0, enum_modes
);
2320 wined3d_mutex_unlock();
2325 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2326 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2328 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2330 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2331 iface
, flags
, surface_desc
, context
, callback
);
2333 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2336 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2337 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2339 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2340 struct displaymodescallback_context cbcontext
;
2341 DDSURFACEDESC2 surface_desc2
;
2343 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2344 iface
, flags
, surface_desc
, context
, callback
);
2346 cbcontext
.func
= callback
;
2347 cbcontext
.context
= context
;
2349 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2350 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
,
2351 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2354 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2355 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2357 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2358 struct displaymodescallback_context cbcontext
;
2359 DDSURFACEDESC2 surface_desc2
;
2361 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2362 iface
, flags
, surface_desc
, context
, callback
);
2364 cbcontext
.func
= callback
;
2365 cbcontext
.context
= context
;
2367 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2368 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
,
2369 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2372 /*****************************************************************************
2373 * IDirectDraw7::EvaluateMode
2375 * Used with IDirectDraw7::StartModeTest to test video modes.
2376 * EvaluateMode is used to pass or fail a mode, and continue with the next
2380 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2381 * Timeout: Returns the amount of seconds left before the mode would have
2382 * been failed automatically
2385 * This implementation always DD_OK, because it's a stub
2387 *****************************************************************************/
2388 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2390 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2392 /* When implementing this, implement it in WineD3D */
2397 /*****************************************************************************
2398 * IDirectDraw7::GetDeviceIdentifier
2400 * Returns the device identifier, which gives information about the driver
2401 * Our device identifier is defined at the beginning of this file.
2404 * DDDI: Address for the returned structure
2405 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2408 * On success it returns DD_OK
2409 * DDERR_INVALIDPARAMS if DDDI is NULL
2411 *****************************************************************************/
2412 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2413 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2415 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2418 return DDERR_INVALIDPARAMS
;
2420 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2421 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2422 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2423 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2424 * bytes too long. So only copy the relevant part of the structure
2427 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2431 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2432 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2434 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2435 DDDEVICEIDENTIFIER2 identifier2
;
2438 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2440 hr
= ddraw7_GetDeviceIdentifier(&This
->IDirectDraw7_iface
, &identifier2
, flags
);
2441 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2446 /*****************************************************************************
2447 * IDirectDraw7::GetSurfaceFromDC
2449 * Returns the Surface for a GDI device context handle.
2450 * Is this related to IDirectDrawSurface::GetDC ???
2453 * hdc: hdc to return the surface for
2454 * Surface: Address to write the surface pointer to
2457 * Always returns DD_OK because it's a stub
2459 *****************************************************************************/
2460 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2461 IDirectDrawSurface7
**Surface
)
2463 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2464 struct wined3d_surface
*wined3d_surface
;
2467 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2469 if (!Surface
) return E_INVALIDARG
;
2471 hr
= wined3d_device_get_surface_from_dc(This
->wined3d_device
, hdc
, &wined3d_surface
);
2474 TRACE("No surface found for dc %p.\n", hdc
);
2476 return DDERR_NOTFOUND
;
2479 *Surface
= wined3d_surface_get_parent(wined3d_surface
);
2480 IDirectDrawSurface7_AddRef(*Surface
);
2481 TRACE("Returning surface %p.\n", Surface
);
2485 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2486 IDirectDrawSurface4
**surface
)
2488 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2489 IDirectDrawSurface7
*surface7
;
2490 IDirectDrawSurfaceImpl
*surface_impl
;
2493 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2495 if (!surface
) return E_INVALIDARG
;
2497 hr
= ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, &surface7
);
2503 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2504 /* Tests say this is true */
2505 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2506 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2507 IDirectDrawSurface7_Release(surface7
);
2512 /*****************************************************************************
2513 * IDirectDraw7::RestoreAllSurfaces
2515 * Calls the restore method of all surfaces
2520 * Always returns DD_OK because it's a stub
2522 *****************************************************************************/
2523 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2525 FIXME("iface %p stub!\n", iface
);
2527 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2528 * get their parent and call their restore method. Do not implement
2529 * it in WineD3D, as restoring a surface means re-creating the
2535 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2537 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2539 TRACE("iface %p.\n", iface
);
2541 return ddraw7_RestoreAllSurfaces(&This
->IDirectDraw7_iface
);
2544 /*****************************************************************************
2545 * IDirectDraw7::StartModeTest
2547 * Tests the specified video modes to update the system registry with
2548 * refresh rate information. StartModeTest starts the mode test,
2549 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2550 * isn't called within 15 seconds, the mode is failed automatically
2552 * As refresh rates are handled by the X server, I don't think this
2553 * Method is important
2556 * Modes: An array of mode specifications
2557 * NumModes: The number of modes in Modes
2558 * Flags: Some flags...
2561 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2562 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2565 *****************************************************************************/
2566 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2568 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2569 iface
, Modes
, NumModes
, Flags
);
2571 /* This looks sane */
2572 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2574 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2575 * As it is not, DDERR_TESTFINISHED is returned
2576 * (hopefully that's correct
2578 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2579 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2585 /*****************************************************************************
2586 * ddraw_create_surface
2588 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2589 * with the passed parameters.
2592 * DDSD: Description of the surface to create
2593 * Surf: Address to store the interface pointer at
2598 *****************************************************************************/
2599 static HRESULT
ddraw_create_surface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
,
2600 IDirectDrawSurfaceImpl
**ppSurf
, UINT level
, UINT version
)
2604 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2605 This
, pDDSD
, ppSurf
, level
);
2607 if (TRACE_ON(ddraw
))
2609 TRACE(" (%p) Requesting surface desc :\n", This
);
2610 DDRAW_dump_surface_desc(pDDSD
);
2613 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
2615 WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n");
2616 /* Do not fail surface creation, only fail 3D device creation. */
2619 /* Create the Surface object */
2620 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
2623 ERR("(%p) Error allocating memory for a surface\n", This
);
2624 return DDERR_OUTOFVIDEOMEMORY
;
2627 hr
= ddraw_surface_init(*ppSurf
, This
, pDDSD
, level
, version
);
2630 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2631 HeapFree(GetProcessHeap(), 0, *ppSurf
);
2635 /* Increase the surface counter, and attach the surface */
2636 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
2638 TRACE("Created surface %p.\n", *ppSurf
);
2642 /*****************************************************************************
2643 * CreateAdditionalSurfaces
2645 * Creates a new mipmap chain.
2648 * root: Root surface to attach the newly created chain to
2649 * count: number of surfaces to create
2650 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2651 * effects on the caller
2652 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2653 * creates an additional surface without the mipmapping flags
2655 *****************************************************************************/
2657 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2658 IDirectDrawSurfaceImpl
*root
,
2660 DDSURFACEDESC2 DDSD
,
2661 BOOL CubeFaceRoot
, UINT version
)
2663 UINT i
, j
, level
= 0;
2665 IDirectDrawSurfaceImpl
*last
= root
;
2667 for(i
= 0; i
< count
; i
++)
2669 IDirectDrawSurfaceImpl
*object2
= NULL
;
2671 /* increase the mipmap level, but only if a mipmap is created
2672 * In this case, also halve the size
2674 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2677 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2678 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2679 /* Set the mipmap sublevel flag according to msdn */
2680 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2684 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2686 CubeFaceRoot
= FALSE
;
2688 hr
= ddraw_create_surface(This
, &DDSD
, &object2
, level
, version
);
2694 /* Add the new surface to the complex attachment array */
2695 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2697 if(last
->complex_array
[j
]) continue;
2698 last
->complex_array
[j
] = object2
;
2703 /* Remove the (possible) back buffer cap from the new surface description,
2704 * because only one surface in the flipping chain is a back buffer, one
2705 * is a front buffer, the others are just primary surfaces.
2707 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2712 static HRESULT CDECL
ddraw_reset_enum_callback(struct wined3d_resource
*resource
)
2717 /*****************************************************************************
2718 * IDirectDraw7::CreateSurface
2720 * Creates a new IDirectDrawSurface object and returns its interface.
2722 * The surface connections with wined3d are a bit tricky. Basically it works
2725 * |------------------------| |-----------------|
2726 * | DDraw surface | | WineD3DSurface |
2728 * | WineD3DSurface |-------------->| |
2729 * | Child |<------------->| Parent |
2730 * |------------------------| |-----------------|
2732 * The DDraw surface is the parent of the wined3d surface, and it releases
2733 * the WineD3DSurface when the ddraw surface is destroyed.
2735 * However, for all surfaces which can be in a container in WineD3D,
2736 * we have to do this. These surfaces are usually complex surfaces,
2737 * so this concerns primary surfaces with a front and a back buffer,
2740 * |------------------------| |-----------------|
2741 * | DDraw surface | | Container |
2743 * | Child |<------------->| Parent |
2744 * | Texture |<------------->| |
2745 * | WineD3DSurface |<----| | Levels |<--|
2746 * | Complex connection | | | | |
2747 * |------------------------| | |-----------------| |
2751 * | |------------------| | |-----------------| |
2752 * | | IParent | |-------->| WineD3DSurface | |
2754 * | | Child |<------------->| Parent | |
2755 * | | | | Container |<--|
2756 * | |------------------| |-----------------| |
2758 * | |----------------------| |
2759 * | | DDraw surface 2 | |
2761 * |<->| Complex root Child | |
2763 * | | WineD3DSurface |<----| |
2764 * | |----------------------| | |
2766 * | |---------------------| | |-----------------| |
2767 * | | IParent | |----->| WineD3DSurface | |
2769 * | | Child |<---------->| Parent | |
2770 * | |---------------------| | Container |<--|
2771 * | |-----------------| |
2773 * | ---More surfaces can follow--- |
2775 * The reason is that the IWineD3DSwapchain(render target container)
2776 * and the IWineD3DTexure(Texture container) release the parents
2777 * of their surface's children, but by releasing the complex root
2778 * the surfaces which are complexly attached to it are destroyed
2779 * too. See IDirectDrawSurface::Release for a more detailed
2783 * DDSD: Description of the surface to create
2784 * Surf: Address to store the interface pointer at
2785 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2786 * aggregation, so it has to be NULL
2790 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2791 * DDERR_* if an error occurs
2793 *****************************************************************************/
2794 static HRESULT
CreateSurface(IDirectDrawImpl
*ddraw
, DDSURFACEDESC2
*DDSD
,
2795 IDirectDrawSurfaceImpl
**Surf
, IUnknown
*UnkOuter
, UINT version
)
2797 IDirectDrawSurfaceImpl
*object
= NULL
;
2798 struct wined3d_display_mode mode
;
2800 LONG extra_surfaces
= 0;
2801 DDSURFACEDESC2 desc2
;
2802 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2804 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, Surf
, UnkOuter
);
2806 /* Some checks before we start */
2807 if (TRACE_ON(ddraw
))
2809 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2810 DDRAW_dump_surface_desc(DDSD
);
2813 if (UnkOuter
!= NULL
)
2815 FIXME("(%p) : outer != NULL?\n", ddraw
);
2816 return CLASS_E_NOAGGREGATION
; /* unchecked */
2821 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2822 return E_POINTER
; /* unchecked */
2825 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2827 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2828 DDSD
->dwFlags
|= DDSD_CAPS
;
2831 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2833 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2834 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2837 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2839 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2840 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2841 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2844 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2845 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2847 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2850 return DDERR_NOEXCLUSIVEMODE
;
2853 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2855 WARN("Application wanted to create back buffer primary surface\n");
2856 return DDERR_INVALIDCAPS
;
2859 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2861 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2862 WARN("Application tries to put the surface in both system and video memory\n");
2864 return DDERR_INVALIDCAPS
;
2867 /* Check cube maps but only if the size includes them */
2868 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2870 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2871 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2873 WARN("Cube map faces requested without cube map flag\n");
2874 return DDERR_INVALIDCAPS
;
2876 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2877 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2879 WARN("Cube map without faces requested\n");
2880 return DDERR_INVALIDPARAMS
;
2883 /* Quick tests confirm those can be created, but we don't do that yet */
2884 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2885 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2887 FIXME("Partial cube maps not supported yet\n");
2891 /* According to the msdn this flag is ignored by CreateSurface */
2892 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2893 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2895 /* Modify some flags */
2896 copy_to_surfacedesc2(&desc2
, DDSD
);
2897 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2899 /* Get the video mode from WineD3D - we will need it */
2900 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
2903 ERR("Failed to read display mode from wined3d\n");
2904 switch(ddraw
->orig_bpp
)
2907 mode
.format_id
= WINED3DFMT_P8_UINT
;
2911 mode
.format_id
= WINED3DFMT_B5G5R5X1_UNORM
;
2915 mode
.format_id
= WINED3DFMT_B5G6R5_UNORM
;
2919 mode
.format_id
= WINED3DFMT_B8G8R8_UNORM
;
2923 mode
.format_id
= WINED3DFMT_B8G8R8X8_UNORM
;
2926 mode
.width
= ddraw
->orig_width
;
2927 mode
.height
= ddraw
->orig_height
;
2930 /* No pixelformat given? Use the current screen format */
2931 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2933 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2934 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2936 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, mode
.format_id
);
2939 /* No Width or no Height? Use the original screen size
2941 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2942 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2944 /* Invalid for non-render targets */
2945 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2947 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2949 return DDERR_INVALIDPARAMS
;
2952 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2953 desc2
.dwWidth
= mode
.width
;
2954 desc2
.dwHeight
= mode
.height
;
2957 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2958 return DDERR_INVALIDPARAMS
;
2960 /* Mipmap count fixes */
2961 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2963 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2965 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2967 /* Mipmap count is given, should not be 0 */
2968 if( desc2
.u2
.dwMipMapCount
== 0 )
2969 return DDERR_INVALIDPARAMS
;
2973 /* Undocumented feature: Create sublevels until
2974 * either the width or the height is 1
2976 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2977 desc2
.dwWidth
: desc2
.dwHeight
;
2978 desc2
.u2
.dwMipMapCount
= 0;
2981 desc2
.u2
.dwMipMapCount
+= 1;
2988 /* Not-complex mipmap -> Mipmapcount = 1 */
2989 desc2
.u2
.dwMipMapCount
= 1;
2991 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2993 /* There's a mipmap count in the created surface in any case */
2994 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2996 /* If no mipmap is given, the texture has only one level */
2998 /* The first surface is a front buffer, the back buffer is created afterwards */
2999 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
3001 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
3004 /* The root surface in a cube map is positive x */
3005 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3007 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3008 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3011 if ((desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) && (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
3013 struct wined3d_swapchain_desc swapchain_desc
;
3015 hr
= wined3d_swapchain_get_desc(ddraw
->wined3d_swapchain
, &swapchain_desc
);
3018 ERR("Failed to get present parameters.\n");
3022 swapchain_desc
.backbuffer_width
= mode
.width
;
3023 swapchain_desc
.backbuffer_height
= mode
.height
;
3024 swapchain_desc
.backbuffer_format
= mode
.format_id
;
3026 hr
= wined3d_device_reset(ddraw
->wined3d_device
,
3027 &swapchain_desc
, ddraw_reset_enum_callback
);
3030 ERR("Failed to reset device.\n");
3035 /* Create the first surface */
3036 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0, version
);
3039 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3042 object
->is_complex_root
= TRUE
;
3046 /* Create Additional surfaces if necessary
3047 * This applies to Primary surfaces which have a back buffer count
3048 * set, but not to mipmap textures. In case of Mipmap textures,
3049 * wineD3D takes care of the creation of additional surfaces
3051 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3053 extra_surfaces
= DDSD
->dwBackBufferCount
;
3054 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3055 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3056 desc2
.dwBackBufferCount
= 0;
3060 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3062 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3063 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3064 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3065 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3066 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
3067 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3068 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
3069 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
3070 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3071 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
3072 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
3073 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3074 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
3075 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
3076 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
3077 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
3078 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3081 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
, version
);
3084 /* This destroys and possibly created surfaces too */
3086 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
3087 else if (version
== 4)
3088 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
3090 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
3095 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3096 ddraw
->primary
= object
;
3098 /* Create a WineD3DTexture if a texture was requested */
3099 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3101 ddraw
->tex_root
= object
;
3102 ddraw_surface_create_texture(object
);
3103 ddraw
->tex_root
= NULL
;
3109 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3110 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3112 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3113 IDirectDrawSurfaceImpl
*impl
;
3116 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3117 iface
, surface_desc
, surface
, outer_unknown
);
3119 wined3d_mutex_lock();
3121 if (!(This
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3123 WARN("Cooperative level not set.\n");
3124 wined3d_mutex_unlock();
3125 return DDERR_NOCOOPERATIVELEVELSET
;
3128 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3130 WARN("Application supplied invalid surface descriptor\n");
3131 wined3d_mutex_unlock();
3132 return DDERR_INVALIDPARAMS
;
3135 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3137 if (TRACE_ON(ddraw
))
3139 TRACE(" (%p) Requesting surface desc :\n", iface
);
3140 DDRAW_dump_surface_desc(surface_desc
);
3143 WARN("Application tried to create an explicit front or back buffer\n");
3144 wined3d_mutex_unlock();
3145 return DDERR_INVALIDCAPS
;
3148 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 7);
3149 wined3d_mutex_unlock();
3156 *surface
= &impl
->IDirectDrawSurface7_iface
;
3157 IDirectDraw7_AddRef(iface
);
3158 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3163 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3164 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3166 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3167 IDirectDrawSurfaceImpl
*impl
;
3170 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3171 iface
, surface_desc
, surface
, outer_unknown
);
3173 wined3d_mutex_lock();
3175 if (!(This
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3177 WARN("Cooperative level not set.\n");
3178 wined3d_mutex_unlock();
3179 return DDERR_NOCOOPERATIVELEVELSET
;
3182 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3184 WARN("Application supplied invalid surface descriptor\n");
3185 wined3d_mutex_unlock();
3186 return DDERR_INVALIDPARAMS
;
3189 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3191 if (TRACE_ON(ddraw
))
3193 TRACE(" (%p) Requesting surface desc :\n", iface
);
3194 DDRAW_dump_surface_desc(surface_desc
);
3197 WARN("Application tried to create an explicit front or back buffer\n");
3198 wined3d_mutex_unlock();
3199 return DDERR_INVALIDCAPS
;
3202 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 4);
3203 wined3d_mutex_unlock();
3210 *surface
= &impl
->IDirectDrawSurface4_iface
;
3211 IDirectDraw4_AddRef(iface
);
3212 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3217 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3218 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3220 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3221 IDirectDrawSurfaceImpl
*impl
;
3223 DDSURFACEDESC2 surface_desc2
;
3225 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3226 iface
, surface_desc
, surface
, outer_unknown
);
3228 wined3d_mutex_lock();
3230 if (!(This
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3232 WARN("Cooperative level not set.\n");
3233 wined3d_mutex_unlock();
3234 return DDERR_NOCOOPERATIVELEVELSET
;
3237 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3239 WARN("Application supplied invalid surface descriptor\n");
3240 wined3d_mutex_unlock();
3241 return DDERR_INVALIDPARAMS
;
3244 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3245 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3247 if (TRACE_ON(ddraw
))
3249 TRACE(" (%p) Requesting surface desc :\n", iface
);
3250 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3253 WARN("Application tried to create an explicit front or back buffer\n");
3254 wined3d_mutex_unlock();
3255 return DDERR_INVALIDCAPS
;
3258 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 2);
3259 wined3d_mutex_unlock();
3266 *surface
= &impl
->IDirectDrawSurface_iface
;
3267 impl
->ifaceToRelease
= NULL
;
3272 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3273 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3275 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3276 IDirectDrawSurfaceImpl
*impl
;
3278 DDSURFACEDESC2 surface_desc2
;
3280 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3281 iface
, surface_desc
, surface
, outer_unknown
);
3283 wined3d_mutex_lock();
3285 if (!(This
->cooperative_level
& (DDSCL_NORMAL
| DDSCL_EXCLUSIVE
)))
3287 WARN("Cooperative level not set.\n");
3288 wined3d_mutex_unlock();
3289 return DDERR_NOCOOPERATIVELEVELSET
;
3292 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3294 WARN("Application supplied invalid surface descriptor\n");
3295 wined3d_mutex_unlock();
3296 return DDERR_INVALIDPARAMS
;
3299 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3300 * primaries anyway. */
3301 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3302 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3303 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 1);
3304 wined3d_mutex_unlock();
3311 *surface
= &impl
->IDirectDrawSurface_iface
;
3312 impl
->ifaceToRelease
= NULL
;
3317 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3318 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3321 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3322 const DDPIXELFORMAT
*provided
)
3324 /* Some flags must be present in both or neither for a match. */
3325 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3326 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3327 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3329 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3332 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3335 if (requested
->dwFlags
& DDPF_FOURCC
)
3336 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3339 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3340 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3341 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3344 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3345 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3346 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3349 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3350 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3353 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3354 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3356 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3359 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3360 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3366 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3375 #define CMP(FLAG, FIELD) \
3376 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3377 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3379 static const struct compare_info compare
[] =
3381 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3382 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3384 CMP(CKDESTBLT
, ddckCKDestBlt
),
3385 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3386 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3387 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3388 CMP(HEIGHT
, dwHeight
),
3389 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3390 CMP(LPSURFACE
, lpSurface
),
3391 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3392 CMP(PITCH
, u1
/* lPitch */),
3393 /* PIXELFORMAT: manual */
3394 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3395 CMP(TEXTURESTAGE
, dwTextureStage
),
3396 CMP(WIDTH
, dwWidth
),
3397 /* ZBUFFERBITDEPTH: "obsolete" */
3404 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3407 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3409 if (requested
->dwFlags
& compare
[i
].flag
3410 && memcmp((const char *)provided
+ compare
[i
].offset
,
3411 (const char *)requested
+ compare
[i
].offset
,
3412 compare
[i
].size
) != 0)
3416 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3418 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3419 &provided
->u4
.ddpfPixelFormat
))
3426 #undef DDENUMSURFACES_SEARCHTYPE
3427 #undef DDENUMSURFACES_MATCHTYPE
3429 struct surfacescallback2_context
3431 LPDDENUMSURFACESCALLBACK2 func
;
3435 struct surfacescallback_context
3437 LPDDENUMSURFACESCALLBACK func
;
3441 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3442 DDSURFACEDESC2
*surface_desc
, void *context
)
3444 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3445 struct surfacescallback2_context
*cbcontext
= context
;
3447 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3448 IDirectDrawSurface7_Release(surface
);
3450 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3451 surface_desc
, cbcontext
->context
);
3454 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3455 DDSURFACEDESC2
*surface_desc
, void *context
)
3457 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3458 struct surfacescallback_context
*cbcontext
= context
;
3460 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3461 IDirectDrawSurface7_Release(surface
);
3463 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3464 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3467 /*****************************************************************************
3468 * IDirectDraw7::EnumSurfaces
3470 * Loops through all surfaces attached to this device and calls the
3471 * application callback. This can't be relayed to WineD3DDevice,
3472 * because some WineD3DSurfaces' parents are IParent objects
3475 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3476 * DDSD: Description to filter for
3477 * Context: Application-provided pointer, it's passed unmodified to the
3479 * Callback: Address to call for each surface
3482 * DDERR_INVALIDPARAMS if the callback is NULL
3485 *****************************************************************************/
3486 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3487 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3489 /* The surface enumeration is handled by WineDDraw,
3490 * because it keeps track of all surfaces attached to
3491 * it. The filtering is done by our callback function,
3492 * because WineDDraw doesn't handle ddraw-like surface
3495 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3496 IDirectDrawSurfaceImpl
*surf
;
3498 DDSURFACEDESC2 desc
;
3499 struct list
*entry
, *entry2
;
3501 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3502 iface
, Flags
, DDSD
, Context
, Callback
);
3504 all
= Flags
& DDENUMSURFACES_ALL
;
3505 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3508 return DDERR_INVALIDPARAMS
;
3510 wined3d_mutex_lock();
3512 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3513 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3515 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3517 if (!surf
->iface_count
)
3519 WARN("Not enumerating surface %p because it doesn't have any references.\n", surf
);
3523 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3525 TRACE("Enumerating surface %p.\n", surf
);
3526 desc
= surf
->surface_desc
;
3527 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3528 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3530 wined3d_mutex_unlock();
3536 wined3d_mutex_unlock();
3541 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3542 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3544 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3545 struct surfacescallback2_context cbcontext
;
3547 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3548 iface
, flags
, surface_desc
, context
, callback
);
3550 cbcontext
.func
= callback
;
3551 cbcontext
.context
= context
;
3553 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, surface_desc
,
3554 &cbcontext
, EnumSurfacesCallback2Thunk
);
3557 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3558 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3560 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3561 struct surfacescallback_context cbcontext
;
3562 DDSURFACEDESC2 surface_desc2
;
3564 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3565 iface
, flags
, surface_desc
, context
, callback
);
3567 cbcontext
.func
= callback
;
3568 cbcontext
.context
= context
;
3570 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3571 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3572 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3575 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3576 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3578 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3579 struct surfacescallback_context cbcontext
;
3580 DDSURFACEDESC2 surface_desc2
;
3582 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3583 iface
, flags
, surface_desc
, context
, callback
);
3585 cbcontext
.func
= callback
;
3586 cbcontext
.context
= context
;
3588 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3589 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3590 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3593 /*****************************************************************************
3594 * DirectDrawCreateClipper (DDRAW.@)
3596 * Creates a new IDirectDrawClipper object.
3599 * Clipper: Address to write the interface pointer to
3600 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3604 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3605 * E_OUTOFMEMORY if allocating the object failed
3607 *****************************************************************************/
3608 HRESULT WINAPI
DirectDrawCreateClipper(DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3610 struct ddraw_clipper
*object
;
3613 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3614 flags
, clipper
, outer_unknown
);
3617 return CLASS_E_NOAGGREGATION
;
3619 wined3d_mutex_lock();
3621 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3624 wined3d_mutex_unlock();
3625 return E_OUTOFMEMORY
;
3628 hr
= ddraw_clipper_init(object
);
3631 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3632 HeapFree(GetProcessHeap(), 0, object
);
3633 wined3d_mutex_unlock();
3637 TRACE("Created clipper %p.\n", object
);
3638 *clipper
= &object
->IDirectDrawClipper_iface
;
3639 wined3d_mutex_unlock();
3644 /*****************************************************************************
3645 * IDirectDraw7::CreateClipper
3647 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3649 *****************************************************************************/
3650 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3651 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3653 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3654 iface
, Flags
, Clipper
, UnkOuter
);
3656 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3659 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3660 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3662 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3664 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3665 iface
, flags
, clipper
, outer_unknown
);
3667 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3670 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3671 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3673 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3675 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3676 iface
, flags
, clipper
, outer_unknown
);
3678 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3681 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3682 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3684 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3686 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3687 iface
, flags
, clipper
, outer_unknown
);
3689 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3692 /*****************************************************************************
3693 * IDirectDraw7::CreatePalette
3695 * Creates a new IDirectDrawPalette object
3698 * Flags: The flags for the new clipper
3699 * ColorTable: Color table to assign to the new clipper
3700 * Palette: Address to write the interface pointer to
3701 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3705 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3706 * E_OUTOFMEMORY if allocating the object failed
3708 *****************************************************************************/
3709 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3710 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3712 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3713 IDirectDrawPaletteImpl
*object
;
3716 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3717 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3720 return CLASS_E_NOAGGREGATION
;
3722 wined3d_mutex_lock();
3724 /* The refcount test shows that a cooplevel is required for this */
3725 if(!This
->cooperative_level
)
3727 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3728 wined3d_mutex_unlock();
3729 return DDERR_NOCOOPERATIVELEVELSET
;
3732 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3735 ERR("Out of memory when allocating memory for a palette implementation\n");
3736 wined3d_mutex_unlock();
3737 return E_OUTOFMEMORY
;
3740 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
3743 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3744 HeapFree(GetProcessHeap(), 0, object
);
3745 wined3d_mutex_unlock();
3749 TRACE("Created palette %p.\n", object
);
3750 *Palette
= &object
->IDirectDrawPalette_iface
;
3751 wined3d_mutex_unlock();
3756 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3757 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3759 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3762 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3763 iface
, flags
, entries
, palette
, outer_unknown
);
3765 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3766 if (SUCCEEDED(hr
) && *palette
)
3768 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3769 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3770 IDirectDraw4_AddRef(iface
);
3771 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3776 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3777 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3779 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3782 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3783 iface
, flags
, entries
, palette
, outer_unknown
);
3785 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3786 if (SUCCEEDED(hr
) && *palette
)
3788 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3789 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3790 impl
->ifaceToRelease
= NULL
;
3796 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3797 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3799 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3802 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3803 iface
, flags
, entries
, palette
, outer_unknown
);
3805 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3806 if (SUCCEEDED(hr
) && *palette
)
3808 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3809 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3810 impl
->ifaceToRelease
= NULL
;
3816 /*****************************************************************************
3817 * IDirectDraw7::DuplicateSurface
3819 * Duplicates a surface. The surface memory points to the same memory as
3820 * the original surface, and it's released when the last surface referencing
3821 * it is released. I guess that's beyond Wine's surface management right now
3822 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3823 * test application to implement this)
3826 * Src: Address of the source surface
3827 * Dest: Address to write the new surface pointer to
3830 * See IDirectDraw7::CreateSurface
3832 *****************************************************************************/
3833 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3834 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3836 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3838 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3840 /* For now, simply create a new, independent surface */
3841 return IDirectDraw7_CreateSurface(iface
,
3842 &Surf
->surface_desc
,
3847 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3848 IDirectDrawSurface4
**dst
)
3850 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3851 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3852 IDirectDrawSurface7
*dst7
;
3853 IDirectDrawSurfaceImpl
*dst_impl
;
3856 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3857 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3858 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3864 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3865 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3866 IDirectDrawSurface4_AddRef(*dst
);
3867 IDirectDrawSurface7_Release(dst7
);
3872 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3873 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3875 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3876 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3877 IDirectDrawSurface7
*dst7
;
3878 IDirectDrawSurfaceImpl
*dst_impl
;
3881 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3882 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3883 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3886 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3887 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3888 IDirectDrawSurface_AddRef(*dst
);
3889 IDirectDrawSurface7_Release(dst7
);
3894 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3895 IDirectDrawSurface
**dst
)
3897 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3898 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3899 IDirectDrawSurface7
*dst7
;
3900 IDirectDrawSurfaceImpl
*dst_impl
;
3903 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3904 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3905 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3908 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3909 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3910 IDirectDrawSurface_AddRef(*dst
);
3911 IDirectDrawSurface7_Release(dst7
);
3916 /*****************************************************************************
3917 * IDirect3D7::EnumDevices
3919 * The EnumDevices method for IDirect3D7. It enumerates all supported
3920 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3923 * callback: Function to call for each enumerated device
3924 * context: Pointer to pass back to the app
3927 * D3D_OK, or the return value of the GetCaps call
3929 *****************************************************************************/
3930 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3932 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
3933 D3DDEVICEDESC7 device_desc7
;
3934 D3DDEVICEDESC device_desc1
;
3938 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3941 return DDERR_INVALIDPARAMS
;
3943 wined3d_mutex_lock();
3945 hr
= IDirect3DImpl_GetCaps(This
->wined3d
, &device_desc1
, &device_desc7
);
3948 wined3d_mutex_unlock();
3952 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3956 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3957 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3958 if (ret
!= DDENUMRET_OK
)
3960 TRACE("Application cancelled the enumeration.\n");
3961 wined3d_mutex_unlock();
3966 TRACE("End of enumeration.\n");
3968 wined3d_mutex_unlock();
3973 /*****************************************************************************
3974 * IDirect3D3::EnumDevices
3976 * Enumerates all supported Direct3DDevice interfaces. This is the
3977 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3979 * Version 1, 2 and 3
3982 * callback: Application-provided routine to call for each enumerated device
3983 * Context: Pointer to pass to the callback
3986 * D3D_OK on success,
3987 * The result of IDirect3DImpl_GetCaps if it failed
3989 *****************************************************************************/
3990 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3992 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3994 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
3995 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3996 D3DDEVICEDESC7 device_desc7
;
3999 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
4000 * name string. Let's put the string in a sufficiently sized array in
4001 * writable memory. */
4002 char device_name
[50];
4003 strcpy(device_name
,"Direct3D HEL");
4005 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4008 return DDERR_INVALIDPARAMS
;
4010 wined3d_mutex_lock();
4012 hr
= IDirect3DImpl_GetCaps(This
->wined3d
, &device_desc1
, &device_desc7
);
4015 wined3d_mutex_unlock();
4019 /* Do I have to enumerate the reference id? Note from old d3d7:
4020 * "It seems that enumerating the reference IID on Direct3D 1 games
4021 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4023 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4024 * EnumReference which enables / disables enumerating the reference
4025 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4026 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4027 * demo directory suggest this.
4029 * Some games(GTA 2) seem to use the second enumerated device, so I have
4030 * to enumerate at least 2 devices. So enumerate the reference device to
4033 * Other games (Rollcage) tell emulation and hal device apart by certain
4034 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4035 * limitation flag), and it refuses all devices that have the perspective
4036 * flag set. This way it refuses the emulation device, and HAL devices
4037 * never have POW2 unset in d3d7 on windows. */
4038 if (This
->d3dversion
!= 1)
4040 static CHAR reference_description
[] = "RGB Direct3D emulation";
4042 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4043 hal_desc
= device_desc1
;
4044 hel_desc
= device_desc1
;
4045 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4046 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4047 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4048 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4049 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4050 /* RGB, RAMP and MMX devices have a HAL dcmColorModel of 0 */
4051 hal_desc
.dcmColorModel
= 0;
4053 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4054 device_name
, &hal_desc
, &hel_desc
, context
);
4055 if (hr
!= D3DENUMRET_OK
)
4057 TRACE("Application cancelled the enumeration.\n");
4058 wined3d_mutex_unlock();
4063 strcpy(device_name
,"Direct3D HAL");
4065 TRACE("Enumerating HAL Direct3D device.\n");
4066 hal_desc
= device_desc1
;
4067 hel_desc
= device_desc1
;
4069 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4070 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4071 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4072 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4073 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4074 /* HAL devices have a HEL dcmColorModel of 0 */
4075 hel_desc
.dcmColorModel
= 0;
4077 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4078 device_name
, &hal_desc
, &hel_desc
, context
);
4079 if (hr
!= D3DENUMRET_OK
)
4081 TRACE("Application cancelled the enumeration.\n");
4082 wined3d_mutex_unlock();
4086 TRACE("End of enumeration.\n");
4088 wined3d_mutex_unlock();
4093 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4095 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4097 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4099 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4102 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4104 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4106 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4108 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4111 /*****************************************************************************
4112 * IDirect3D3::CreateLight
4114 * Creates an IDirect3DLight interface. This interface is used in
4115 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4116 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4117 * uses the IDirect3DDevice7 interface with D3D7 lights.
4119 * Version 1, 2 and 3
4122 * light: Address to store the new interface pointer
4123 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4128 * DDERR_OUTOFMEMORY if memory allocation failed
4129 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4131 *****************************************************************************/
4132 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4133 IUnknown
*outer_unknown
)
4135 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4136 IDirect3DLightImpl
*object
;
4138 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4140 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4142 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4145 ERR("Failed to allocate light memory.\n");
4146 return DDERR_OUTOFMEMORY
;
4149 d3d_light_init(object
, This
);
4151 TRACE("Created light %p.\n", object
);
4152 *light
= &object
->IDirect3DLight_iface
;
4157 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4159 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4161 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4163 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4166 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4168 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4170 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4172 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4175 /*****************************************************************************
4176 * IDirect3D3::CreateMaterial
4178 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4179 * and older versions. The IDirect3DMaterial implementation wraps its
4180 * functionality to IDirect3DDevice7::SetMaterial and friends.
4182 * Version 1, 2 and 3
4185 * material: Address to store the new interface's pointer to
4186 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4191 * DDERR_OUTOFMEMORY if memory allocation failed
4192 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4194 *****************************************************************************/
4195 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4196 IUnknown
*outer_unknown
)
4198 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4199 IDirect3DMaterialImpl
*object
;
4201 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4203 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4205 object
= d3d_material_create(This
);
4208 ERR("Failed to allocate material memory.\n");
4209 return DDERR_OUTOFMEMORY
;
4212 TRACE("Created material %p.\n", object
);
4213 *material
= &object
->IDirect3DMaterial3_iface
;
4218 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4219 IUnknown
*outer_unknown
)
4221 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4222 IDirect3DMaterialImpl
*object
;
4224 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4226 object
= d3d_material_create(This
);
4229 ERR("Failed to allocate material memory.\n");
4230 return DDERR_OUTOFMEMORY
;
4233 TRACE("Created material %p.\n", object
);
4234 *material
= &object
->IDirect3DMaterial2_iface
;
4239 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4240 IUnknown
*outer_unknown
)
4242 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4243 IDirect3DMaterialImpl
*object
;
4245 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4247 object
= d3d_material_create(This
);
4250 ERR("Failed to allocate material memory.\n");
4251 return DDERR_OUTOFMEMORY
;
4254 TRACE("Created material %p.\n", object
);
4255 *material
= &object
->IDirect3DMaterial_iface
;
4260 /*****************************************************************************
4261 * IDirect3D3::CreateViewport
4263 * Creates an IDirect3DViewport interface. This interface is used
4264 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4265 * it has been replaced by a viewport structure and
4266 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4267 * uses the IDirect3DDevice7 methods for its functionality
4270 * Viewport: Address to store the new interface pointer
4271 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4276 * DDERR_OUTOFMEMORY if memory allocation failed
4277 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4279 *****************************************************************************/
4280 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4281 IUnknown
*outer_unknown
)
4283 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4284 IDirect3DViewportImpl
*object
;
4286 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4288 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4290 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4293 ERR("Failed to allocate viewport memory.\n");
4294 return DDERR_OUTOFMEMORY
;
4297 d3d_viewport_init(object
, This
);
4299 TRACE("Created viewport %p.\n", object
);
4300 *viewport
= &object
->IDirect3DViewport3_iface
;
4305 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4307 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4309 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4311 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4315 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4317 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4319 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4321 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4325 /*****************************************************************************
4326 * IDirect3D3::FindDevice
4328 * This method finds a device with the requested properties and returns a
4329 * device description
4333 * fds: Describes the requested device characteristics
4334 * fdr: Returns the device description
4338 * DDERR_INVALIDPARAMS if no device was found
4340 *****************************************************************************/
4341 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4343 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4344 D3DDEVICEDESC7 desc7
;
4345 D3DDEVICEDESC desc1
;
4348 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4350 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4352 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4353 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4354 return DDERR_INVALIDPARAMS
;
4356 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4357 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4359 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4360 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4363 if (fds
->dwFlags
& D3DFDS_GUID
)
4365 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4366 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4367 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4368 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4370 WARN("No match for this GUID.\n");
4371 return DDERR_NOTFOUND
;
4376 hr
= IDirect3DImpl_GetCaps(This
->wined3d
, &desc1
, &desc7
);
4377 if (hr
!= D3D_OK
) return hr
;
4379 /* Now return our own GUID */
4380 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4381 fdr
->ddHwDesc
= desc1
;
4382 fdr
->ddSwDesc
= desc1
;
4384 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4389 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4391 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4393 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4395 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4398 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4400 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4402 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4404 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4407 /*****************************************************************************
4408 * IDirect3D7::CreateDevice
4410 * Creates an IDirect3DDevice7 interface.
4412 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4413 * DirectDraw surfaces and are created with
4414 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4415 * create the device object and QueryInterfaces for IDirect3DDevice
4418 * refiid: IID of the device to create
4419 * Surface: Initial rendertarget
4420 * Device: Address to return the interface pointer
4424 * DDERR_OUTOFMEMORY if memory allocation failed
4425 * DDERR_INVALIDPARAMS if a device exists already
4427 *****************************************************************************/
4428 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4429 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4431 IDirectDrawSurfaceImpl
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4432 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4433 IDirect3DDeviceImpl
*object
;
4436 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4438 wined3d_mutex_lock();
4441 /* Fail device creation if non-opengl surfaces are used. */
4442 if (DefaultSurfaceType
!= WINED3D_SURFACE_TYPE_OPENGL
)
4444 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4445 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4447 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4448 * is caught in CreateSurface or QueryInterface. */
4449 wined3d_mutex_unlock();
4453 if (This
->d3ddevice
)
4455 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4456 wined3d_mutex_unlock();
4457 return DDERR_INVALIDPARAMS
;
4460 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4463 ERR("Failed to allocate device memory.\n");
4464 wined3d_mutex_unlock();
4465 return DDERR_OUTOFMEMORY
;
4468 hr
= d3d_device_init(object
, This
, target
);
4471 WARN("Failed to initialize device, hr %#x.\n", hr
);
4472 HeapFree(GetProcessHeap(), 0, object
);
4473 wined3d_mutex_unlock();
4477 TRACE("Created device %p.\n", object
);
4478 *device
= &object
->IDirect3DDevice7_iface
;
4480 wined3d_mutex_unlock();
4485 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4486 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4488 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4489 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4490 IDirect3DDevice7
*device7
;
4491 IDirect3DDeviceImpl
*device_impl
;
4494 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4495 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4497 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4499 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4500 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
, device
? &device7
: NULL
);
4503 device_impl
= impl_from_IDirect3DDevice7(device7
);
4504 *device
= &device_impl
->IDirect3DDevice3_iface
;
4510 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4511 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4513 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4514 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4515 IDirect3DDevice7
*device7
;
4516 IDirect3DDeviceImpl
*device_impl
;
4519 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4520 iface
, debugstr_guid(riid
), surface
, device
);
4522 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4523 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
, device
? &device7
: NULL
);
4526 device_impl
= impl_from_IDirect3DDevice7(device7
);
4527 *device
= &device_impl
->IDirect3DDevice2_iface
;
4533 /*****************************************************************************
4534 * IDirect3D7::CreateVertexBuffer
4536 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4542 * desc: Requested Vertex buffer properties
4543 * vertex_buffer: Address to return the interface pointer at
4544 * flags: Some flags, should be 0
4548 * DDERR_OUTOFMEMORY if memory allocation failed
4549 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4550 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4552 *****************************************************************************/
4553 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4554 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4556 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4557 IDirect3DVertexBufferImpl
*object
;
4560 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4561 iface
, desc
, vertex_buffer
, flags
);
4563 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4565 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4568 TRACE("Created vertex buffer %p.\n", object
);
4569 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4572 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4577 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4578 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4580 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4581 IDirect3DVertexBufferImpl
*object
;
4584 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4585 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4588 return CLASS_E_NOAGGREGATION
;
4589 if (!vertex_buffer
|| !desc
)
4590 return DDERR_INVALIDPARAMS
;
4592 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4595 TRACE("Created vertex buffer %p.\n", object
);
4596 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4599 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4604 /*****************************************************************************
4605 * IDirect3D7::EnumZBufferFormats
4607 * Enumerates all supported Z buffer pixel formats
4613 * callback: callback to call for each pixel format
4614 * context: Pointer to pass back to the callback
4618 * DDERR_INVALIDPARAMS if callback is NULL
4619 * For details, see IWineD3DDevice::EnumZBufferFormats
4621 *****************************************************************************/
4622 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4623 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4625 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4626 struct wined3d_display_mode mode
;
4627 enum wined3d_device_type type
;
4631 /* Order matters. Specifically, BattleZone II (full version) expects the
4632 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4633 static const enum wined3d_format_id formats
[] =
4635 WINED3DFMT_S1_UINT_D15_UNORM
,
4636 WINED3DFMT_D16_UNORM
,
4637 WINED3DFMT_X8D24_UNORM
,
4638 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4639 WINED3DFMT_D24_UNORM_S8_UINT
,
4640 WINED3DFMT_D32_UNORM
,
4643 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4644 iface
, debugstr_guid(device_iid
), callback
, context
);
4646 if (!callback
) return DDERR_INVALIDPARAMS
;
4648 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4649 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4650 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4652 TRACE("Asked for HAL device.\n");
4653 type
= WINED3D_DEVICE_TYPE_HAL
;
4655 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4656 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4658 TRACE("Asked for SW device.\n");
4659 type
= WINED3D_DEVICE_TYPE_SW
;
4661 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4663 TRACE("Asked for REF device.\n");
4664 type
= WINED3D_DEVICE_TYPE_REF
;
4666 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4668 TRACE("Asked for NULLREF device.\n");
4669 type
= WINED3D_DEVICE_TYPE_NULLREF
;
4673 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4674 type
= WINED3D_DEVICE_TYPE_HAL
;
4677 wined3d_mutex_lock();
4678 /* We need an adapter format from somewhere to please wined3d and WGL.
4679 * Use the current display mode. So far all cards offer the same depth
4680 * stencil format for all modes, but if some do not and applications do
4681 * not like that we'll have to find some workaround, like iterating over
4682 * all imaginable formats and collecting all the depth stencil formats we
4684 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &mode
);
4686 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4688 hr
= wined3d_check_device_format(This
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4689 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, formats
[i
], WINED3D_SURFACE_TYPE_OPENGL
);
4692 DDPIXELFORMAT pformat
;
4694 memset(&pformat
, 0, sizeof(pformat
));
4695 pformat
.dwSize
= sizeof(pformat
);
4696 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4698 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4699 hr
= callback(&pformat
, context
);
4700 if (hr
!= DDENUMRET_OK
)
4702 TRACE("Format enumeration cancelled by application.\n");
4703 wined3d_mutex_unlock();
4709 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4710 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4711 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4712 * newer enumerate both versions, so we do the same(bug 22434) */
4713 hr
= wined3d_check_device_format(This
->wined3d
, WINED3DADAPTER_DEFAULT
, type
, mode
.format_id
,
4714 WINED3DUSAGE_DEPTHSTENCIL
, WINED3D_RTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, WINED3D_SURFACE_TYPE_OPENGL
);
4717 DDPIXELFORMAT x8d24
=
4719 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4720 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4722 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4723 callback(&x8d24
, context
);
4726 TRACE("End of enumeration.\n");
4728 wined3d_mutex_unlock();
4733 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4734 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4736 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4738 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4739 iface
, debugstr_guid(device_iid
), callback
, context
);
4741 return d3d7_EnumZBufferFormats(&This
->IDirect3D7_iface
, device_iid
, callback
, context
);
4744 /*****************************************************************************
4745 * IDirect3D7::EvictManagedTextures
4747 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4748 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4753 * D3D_OK, because it's a stub
4755 *****************************************************************************/
4756 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4758 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4760 TRACE("iface %p!\n", iface
);
4762 wined3d_mutex_lock();
4763 if (This
->d3d_initialized
)
4764 wined3d_device_evict_managed_resources(This
->wined3d_device
);
4765 wined3d_mutex_unlock();
4770 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4772 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4774 TRACE("iface %p.\n", iface
);
4776 return d3d7_EvictManagedTextures(&This
->IDirect3D7_iface
);
4779 /*****************************************************************************
4780 * IDirect3DImpl_GetCaps
4782 * This function retrieves the device caps from wined3d
4783 * and converts it into a D3D7 and D3D - D3D3 structure
4784 * This is a helper function called from various places in ddraw
4787 * wined3d: The interface to get the caps from
4788 * desc1: Old D3D <3 structure to fill (needed)
4789 * desc7: D3D7 device desc structure to fill (needed)
4792 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4794 *****************************************************************************/
4795 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4797 WINED3DCAPS wined3d_caps
;
4800 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4802 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4804 wined3d_mutex_lock();
4805 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3D_DEVICE_TYPE_HAL
, &wined3d_caps
);
4806 wined3d_mutex_unlock();
4809 WARN("Failed to get device caps, hr %#x.\n", hr
);
4813 /* Copy the results into the d3d7 and d3d3 structures */
4814 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4815 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4816 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4817 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4818 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4819 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4820 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4821 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4822 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4823 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4824 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4826 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4827 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4829 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4830 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4831 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4832 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4834 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4835 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4836 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4837 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4839 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4840 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4842 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4843 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4845 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4846 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4848 /* Remove all non-d3d7 caps */
4849 desc7
->dwDevCaps
&= (
4850 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4851 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4852 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4853 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4854 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4855 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4856 D3DDEVCAPS_HWRASTERIZATION
);
4858 desc7
->dwStencilCaps
&= (
4859 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4860 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4861 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4865 desc7
->dwTextureOpCaps
&= (
4866 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4867 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4868 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4869 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4870 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4871 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4872 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4873 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4875 desc7
->dwVertexProcessingCaps
&= (
4876 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4877 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4879 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4880 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4881 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4882 D3DPMISCCAPS_CULLCCW
);
4884 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4885 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4886 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4887 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4888 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4889 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4890 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4891 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4892 D3DPRASTERCAPS_ZFOG
);
4894 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4895 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4896 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4897 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4899 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4900 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4901 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4902 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4903 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4904 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4906 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4907 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4908 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4909 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4910 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4911 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4913 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4914 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4915 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4916 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4918 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4919 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4920 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4921 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4922 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4923 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4924 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4925 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4927 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4928 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4929 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4930 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4931 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4933 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4934 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4935 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4936 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4937 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4938 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4939 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4941 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4942 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4943 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4944 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4946 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4947 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4948 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4950 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4952 /* DirectX7 always has the np2 flag set, no matter what the card
4953 * supports. Some old games (Rollcage) check the caps incorrectly.
4954 * If wined3d supports nonpow2 textures it also has np2 conditional
4956 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4959 /* Fill the missing members, and do some fixup */
4960 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4961 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4962 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4963 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4964 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4965 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4966 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4967 /* Use the same for the TriCaps */
4968 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4970 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4971 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4972 desc7
->dwMinTextureWidth
= 1;
4973 desc7
->dwMinTextureHeight
= 1;
4975 /* Convert DWORDs safely to WORDs */
4976 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4977 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4978 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4979 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4981 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4982 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4983 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4984 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4986 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4988 desc7
->dwReserved1
= 0;
4989 desc7
->dwReserved2
= 0;
4990 desc7
->dwReserved3
= 0;
4991 desc7
->dwReserved4
= 0;
4993 /* Fill the old structure */
4994 memset(desc1
, 0, sizeof(*desc1
));
4995 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4996 desc1
->dwFlags
= D3DDD_COLORMODEL
4998 | D3DDD_TRANSFORMCAPS
5000 | D3DDD_LIGHTINGCAPS
5003 | D3DDD_DEVICERENDERBITDEPTH
5004 | D3DDD_DEVICEZBUFFERBITDEPTH
5005 | D3DDD_MAXBUFFERSIZE
5006 | D3DDD_MAXVERTEXCOUNT
;
5008 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
5009 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
5010 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
5011 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
5012 desc1
->bClipping
= TRUE
;
5013 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
5014 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
5015 | D3DLIGHTCAPS_PARALLELPOINT
5016 | D3DLIGHTCAPS_POINT
5017 | D3DLIGHTCAPS_SPOT
;
5019 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
5020 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
5022 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5023 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
5024 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
5025 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
5026 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
5027 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
5028 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
5029 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
5030 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
5031 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
5032 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
5033 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
5034 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
5036 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5037 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
5038 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
5039 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
5040 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
5041 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
5042 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
5043 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
5044 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
5045 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
5046 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
5047 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
5048 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
5050 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
5051 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
5052 desc1
->dwMaxBufferSize
= 0;
5053 desc1
->dwMaxVertexCount
= 65536;
5054 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
5055 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
5056 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
5057 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
5058 desc1
->dwMinStippleWidth
= 1;
5059 desc1
->dwMinStippleHeight
= 1;
5060 desc1
->dwMaxStippleWidth
= 32;
5061 desc1
->dwMaxStippleHeight
= 32;
5062 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
5063 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
5064 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
5065 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
5066 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
5067 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
5068 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
5069 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
5070 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
5071 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
5072 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
5073 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
5074 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
5079 /*****************************************************************************
5080 * IDirectDraw7 VTable
5081 *****************************************************************************/
5082 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
5085 ddraw7_QueryInterface
,
5090 ddraw7_CreateClipper
,
5091 ddraw7_CreatePalette
,
5092 ddraw7_CreateSurface
,
5093 ddraw7_DuplicateSurface
,
5094 ddraw7_EnumDisplayModes
,
5095 ddraw7_EnumSurfaces
,
5096 ddraw7_FlipToGDISurface
,
5098 ddraw7_GetDisplayMode
,
5099 ddraw7_GetFourCCCodes
,
5100 ddraw7_GetGDISurface
,
5101 ddraw7_GetMonitorFrequency
,
5103 ddraw7_GetVerticalBlankStatus
,
5105 ddraw7_RestoreDisplayMode
,
5106 ddraw7_SetCooperativeLevel
,
5107 ddraw7_SetDisplayMode
,
5108 ddraw7_WaitForVerticalBlank
,
5110 ddraw7_GetAvailableVidMem
,
5112 ddraw7_GetSurfaceFromDC
,
5114 ddraw7_RestoreAllSurfaces
,
5115 ddraw7_TestCooperativeLevel
,
5116 ddraw7_GetDeviceIdentifier
,
5118 ddraw7_StartModeTest
,
5122 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
5125 ddraw4_QueryInterface
,
5130 ddraw4_CreateClipper
,
5131 ddraw4_CreatePalette
,
5132 ddraw4_CreateSurface
,
5133 ddraw4_DuplicateSurface
,
5134 ddraw4_EnumDisplayModes
,
5135 ddraw4_EnumSurfaces
,
5136 ddraw4_FlipToGDISurface
,
5138 ddraw4_GetDisplayMode
,
5139 ddraw4_GetFourCCCodes
,
5140 ddraw4_GetGDISurface
,
5141 ddraw4_GetMonitorFrequency
,
5143 ddraw4_GetVerticalBlankStatus
,
5145 ddraw4_RestoreDisplayMode
,
5146 ddraw4_SetCooperativeLevel
,
5147 ddraw4_SetDisplayMode
,
5148 ddraw4_WaitForVerticalBlank
,
5150 ddraw4_GetAvailableVidMem
,
5152 ddraw4_GetSurfaceFromDC
,
5154 ddraw4_RestoreAllSurfaces
,
5155 ddraw4_TestCooperativeLevel
,
5156 ddraw4_GetDeviceIdentifier
,
5159 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5162 ddraw2_QueryInterface
,
5167 ddraw2_CreateClipper
,
5168 ddraw2_CreatePalette
,
5169 ddraw2_CreateSurface
,
5170 ddraw2_DuplicateSurface
,
5171 ddraw2_EnumDisplayModes
,
5172 ddraw2_EnumSurfaces
,
5173 ddraw2_FlipToGDISurface
,
5175 ddraw2_GetDisplayMode
,
5176 ddraw2_GetFourCCCodes
,
5177 ddraw2_GetGDISurface
,
5178 ddraw2_GetMonitorFrequency
,
5180 ddraw2_GetVerticalBlankStatus
,
5182 ddraw2_RestoreDisplayMode
,
5183 ddraw2_SetCooperativeLevel
,
5184 ddraw2_SetDisplayMode
,
5185 ddraw2_WaitForVerticalBlank
,
5187 ddraw2_GetAvailableVidMem
,
5190 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5193 ddraw1_QueryInterface
,
5198 ddraw1_CreateClipper
,
5199 ddraw1_CreatePalette
,
5200 ddraw1_CreateSurface
,
5201 ddraw1_DuplicateSurface
,
5202 ddraw1_EnumDisplayModes
,
5203 ddraw1_EnumSurfaces
,
5204 ddraw1_FlipToGDISurface
,
5206 ddraw1_GetDisplayMode
,
5207 ddraw1_GetFourCCCodes
,
5208 ddraw1_GetGDISurface
,
5209 ddraw1_GetMonitorFrequency
,
5211 ddraw1_GetVerticalBlankStatus
,
5213 ddraw1_RestoreDisplayMode
,
5214 ddraw1_SetCooperativeLevel
,
5215 ddraw1_SetDisplayMode
,
5216 ddraw1_WaitForVerticalBlank
,
5219 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5221 /* IUnknown methods */
5222 d3d7_QueryInterface
,
5225 /* IDirect3D7 methods */
5228 d3d7_CreateVertexBuffer
,
5229 d3d7_EnumZBufferFormats
,
5230 d3d7_EvictManagedTextures
5233 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5235 /* IUnknown methods */
5236 d3d3_QueryInterface
,
5239 /* IDirect3D3 methods */
5242 d3d3_CreateMaterial
,
5243 d3d3_CreateViewport
,
5246 d3d3_CreateVertexBuffer
,
5247 d3d3_EnumZBufferFormats
,
5248 d3d3_EvictManagedTextures
5251 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5253 /* IUnknown methods */
5254 d3d2_QueryInterface
,
5257 /* IDirect3D2 methods */
5260 d3d2_CreateMaterial
,
5261 d3d2_CreateViewport
,
5266 static const struct IDirect3DVtbl d3d1_vtbl
=
5268 /* IUnknown methods */
5269 d3d1_QueryInterface
,
5272 /* IDirect3D methods */
5276 d3d1_CreateMaterial
,
5277 d3d1_CreateViewport
,
5281 /*****************************************************************************
5284 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5285 * if none was found.
5287 * This function is in ddraw.c and the DDraw object space because D3D7
5288 * vertex buffers are created using the IDirect3D interface to the ddraw
5289 * object, so they can be valid across D3D devices(theoretically. The ddraw
5290 * object also owns the wined3d device
5294 * fvf: Fvf to find the decl for
5297 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5299 *****************************************************************************/
5300 struct wined3d_vertex_declaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5302 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5304 int p
, low
, high
; /* deliberately signed */
5305 struct FvfToDecl
*convertedDecls
= This
->decls
;
5307 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5310 high
= This
->numConvertedDecls
- 1;
5311 while(low
<= high
) {
5312 p
= (low
+ high
) >> 1;
5314 if(convertedDecls
[p
].fvf
== fvf
) {
5315 TRACE("found %p\n", convertedDecls
[p
].decl
);
5316 return convertedDecls
[p
].decl
;
5317 } else if(convertedDecls
[p
].fvf
< fvf
) {
5323 TRACE("not found. Creating and inserting at position %d.\n", low
);
5325 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5326 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5327 if (hr
!= S_OK
) return NULL
;
5329 if(This
->declArraySize
== This
->numConvertedDecls
) {
5330 int grow
= max(This
->declArraySize
/ 2, 8);
5331 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5332 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5333 if (!convertedDecls
)
5335 wined3d_vertex_declaration_decref(pDecl
);
5338 This
->decls
= convertedDecls
;
5339 This
->declArraySize
+= grow
;
5342 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5343 convertedDecls
[low
].decl
= pDecl
;
5344 convertedDecls
[low
].fvf
= fvf
;
5345 This
->numConvertedDecls
++;
5347 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5351 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5353 return CONTAINING_RECORD(device_parent
, struct IDirectDrawImpl
, device_parent
);
5356 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5357 struct wined3d_device
*device
)
5359 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5362 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
5364 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5365 MONITORINFO monitor_info
;
5370 TRACE("device_parent %p.\n", device_parent
);
5372 if (!(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) || !ddraw
->swapchain_window
)
5374 TRACE("Nothing to resize.\n");
5378 monitor
= MonitorFromWindow(ddraw
->swapchain_window
, MONITOR_DEFAULTTOPRIMARY
);
5379 monitor_info
.cbSize
= sizeof(monitor_info
);
5380 if (!(ret
= GetMonitorInfoW(monitor
, &monitor_info
)))
5382 ERR("Failed to get monitor info.\n");
5386 r
= &monitor_info
.rcMonitor
;
5387 TRACE("Resizing window %p to %s.\n", ddraw
->swapchain_window
, wine_dbgstr_rect(r
));
5389 if (!(ret
= SetWindowPos(ddraw
->swapchain_window
, HWND_TOP
, r
->left
, r
->top
,
5390 r
->right
- r
->left
, r
->bottom
- r
->top
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
)))
5391 ERR("Failed to resize window.\n");
5394 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
5395 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5396 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
5398 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5399 IDirectDrawSurfaceImpl
*surf
= NULL
;
5401 DDSCAPS2 searchcaps
= ddraw
->tex_root
->surface_desc
.ddsCaps
;
5403 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5404 "\tpool %#x, level %u, face %u, surface %p.\n",
5405 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5407 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5410 case WINED3D_CUBEMAP_FACE_POSITIVE_X
:
5411 TRACE("Asked for positive x\n");
5412 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5414 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5416 surf
= ddraw
->tex_root
; break;
5417 case WINED3D_CUBEMAP_FACE_NEGATIVE_X
:
5418 TRACE("Asked for negative x\n");
5419 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5420 case WINED3D_CUBEMAP_FACE_POSITIVE_Y
:
5421 TRACE("Asked for positive y\n");
5422 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5423 case WINED3D_CUBEMAP_FACE_NEGATIVE_Y
:
5424 TRACE("Asked for negative y\n");
5425 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5426 case WINED3D_CUBEMAP_FACE_POSITIVE_Z
:
5427 TRACE("Asked for positive z\n");
5428 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5429 case WINED3D_CUBEMAP_FACE_NEGATIVE_Z
:
5430 TRACE("Asked for negative z\n");
5431 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5433 ERR("Unexpected cube face.\n");
5438 IDirectDrawSurface7
*attached
;
5439 IDirectDrawSurface7_GetAttachedSurface(&ddraw
->tex_root
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5440 surf
= unsafe_impl_from_IDirectDrawSurface7(attached
);
5441 IDirectDrawSurface7_Release(attached
);
5443 if (!surf
) ERR("root search surface not found\n");
5445 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5448 IDirectDrawSurface7
*attached
;
5449 IDirectDrawSurface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5450 if(!attached
) ERR("Surface not found\n");
5451 surf
= impl_from_IDirectDrawSurface7(attached
);
5452 IDirectDrawSurface7_Release(attached
);
5456 /* Return the surface */
5457 *surface
= surf
->wined3d_surface
;
5458 wined3d_surface_incref(*surface
);
5460 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5465 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5467 struct IDirectDrawImpl
*ddraw
= parent
;
5468 ddraw
->wined3d_frontbuffer
= NULL
;
5471 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5473 ddraw_frontbuffer_destroyed
,
5476 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
5477 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5478 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5479 struct wined3d_surface
**surface
)
5481 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5485 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5486 "\tmultisample_quality %u, lockable %u, surface %p.\n",
5487 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
5488 multisample_quality
, lockable
, surface
);
5490 if (ddraw
->wined3d_frontbuffer
)
5492 ERR("Frontbuffer already created.\n");
5497 flags
|= WINED3D_SURFACE_MAPPABLE
;
5499 hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format
, 0,
5500 WINED3DUSAGE_RENDERTARGET
, WINED3D_POOL_DEFAULT
, multisample_type
, multisample_quality
,
5501 DefaultSurfaceType
, flags
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
);
5503 ddraw
->wined3d_frontbuffer
= *surface
;
5508 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
5509 UINT width
, UINT height
, enum wined3d_format_id format
, enum wined3d_multisample_type multisample_type
,
5510 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
5512 ERR("DirectDraw doesn't have and shouldn't try creating implicit depth buffers.\n");
5516 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5517 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5518 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
5520 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5521 "format %#x, pool %#x, usage %#x, volume %p.\n",
5522 device_parent
, container_parent
, width
, height
, depth
,
5523 format
, pool
, usage
, volume
);
5525 ERR("Not implemented!\n");
5530 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5531 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
5533 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5536 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent
, desc
, swapchain
);
5538 if (ddraw
->wined3d_swapchain
)
5540 ERR("Swapchain already created.\n");
5544 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, desc
,
5545 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5547 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5552 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5554 device_parent_wined3d_device_created
,
5555 device_parent_mode_changed
,
5556 device_parent_create_surface
,
5557 device_parent_create_rendertarget
,
5558 device_parent_create_depth_stencil
,
5559 device_parent_create_volume
,
5560 device_parent_create_swapchain
,
5563 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, enum wined3d_device_type device_type
)
5568 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5569 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5570 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5571 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5572 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5573 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5574 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5575 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5576 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5577 ddraw
->numIfaces
= 1;
5580 /* Get the current screen settings. */
5582 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5584 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5585 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5587 ddraw
->wined3d
= wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS
,
5588 &ddraw
->IDirectDraw7_iface
);
5589 if (!ddraw
->wined3d
)
5591 WARN("Failed to create a wined3d object.\n");
5592 return E_OUTOFMEMORY
;
5595 hr
= wined3d_device_create(ddraw
->wined3d
, WINED3DADAPTER_DEFAULT
, device_type
,
5596 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5599 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5600 wined3d_decref(ddraw
->wined3d
);
5604 list_init(&ddraw
->surface_list
);