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 void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
44 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
46 ddraw_null_wined3d_object_destroyed
,
49 static inline IDirectDrawImpl
*impl_from_IDirectDraw(IDirectDraw
*iface
)
51 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw_iface
);
54 static inline IDirectDrawImpl
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
56 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw2_iface
);
59 static inline IDirectDrawImpl
*impl_from_IDirectDraw3(IDirectDraw3
*iface
)
61 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw3_iface
);
64 static inline IDirectDrawImpl
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
66 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw4_iface
);
69 static inline IDirectDrawImpl
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
71 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw7_iface
);
74 static inline IDirectDrawImpl
*impl_from_IDirect3D(IDirect3D
*iface
)
76 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D_iface
);
79 static inline IDirectDrawImpl
*impl_from_IDirect3D2(IDirect3D2
*iface
)
81 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D2_iface
);
84 static inline IDirectDrawImpl
*impl_from_IDirect3D3(IDirect3D3
*iface
)
86 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D3_iface
);
89 static inline IDirectDrawImpl
*impl_from_IDirect3D7(IDirect3D7
*iface
)
91 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D7_iface
);
94 /*****************************************************************************
96 *****************************************************************************/
98 /*****************************************************************************
99 * IDirectDraw7::QueryInterface
101 * Queries different interfaces of the DirectDraw object. It can return
102 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
103 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
105 * The returned interface is AddRef()-ed before it's returned
107 * Used for version 1, 2, 4 and 7
110 * refiid: Interface ID asked for
111 * obj: Used to return the interface pointer
114 * S_OK if an interface was found
115 * E_NOINTERFACE if the requested interface wasn't found
117 *****************************************************************************/
118 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
120 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
122 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
124 /* Can change surface impl type */
125 EnterCriticalSection(&ddraw_cs
);
127 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
132 LeaveCriticalSection(&ddraw_cs
);
133 return DDERR_INVALIDPARAMS
;
136 /* Check DirectDraw Interfaces */
137 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
138 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
141 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
143 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
145 *obj
= &This
->IDirectDraw4_iface
;
146 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
148 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
150 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
151 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
153 LeaveCriticalSection(&ddraw_cs
);
154 return E_NOINTERFACE
;
156 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
158 *obj
= &This
->IDirectDraw2_iface
;
159 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
161 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
163 *obj
= &This
->IDirectDraw_iface
;
164 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
168 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
169 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
170 * who had this idea and why. The older interfaces can query and IDirect3D version
171 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
172 * and messy to implement with the common creation function, so it has been left out here.
174 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
175 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
176 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
177 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
179 /* Check the surface implementation */
180 if(This
->ImplType
== SURFACE_UNKNOWN
)
182 /* Apps may create the IDirect3D Interface before the primary surface.
183 * set the surface implementation */
184 This
->ImplType
= SURFACE_OPENGL
;
185 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
187 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
189 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
190 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
191 /* Should I assert(0) here??? */
193 else if(This
->ImplType
!= SURFACE_OPENGL
)
195 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
196 /* Do not abort here, only reject 3D Device creation */
199 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
201 This
->d3dversion
= 1;
202 *obj
= &This
->IDirect3D_iface
;
203 TRACE(" returning Direct3D interface at %p.\n", *obj
);
205 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
207 This
->d3dversion
= 2;
208 *obj
= &This
->IDirect3D2_iface
;
209 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
211 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
213 This
->d3dversion
= 3;
214 *obj
= &This
->IDirect3D3_iface
;
215 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
217 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
219 This
->d3dversion
= 7;
220 *obj
= &This
->IDirect3D7_iface
;
221 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
224 /* Unknown interface */
227 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
228 LeaveCriticalSection(&ddraw_cs
);
229 return E_NOINTERFACE
;
232 IUnknown_AddRef( (IUnknown
*) *obj
);
233 LeaveCriticalSection(&ddraw_cs
);
237 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
239 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
241 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
243 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
246 static HRESULT WINAPI
ddraw3_QueryInterface(IDirectDraw3
*iface
, REFIID riid
, void **object
)
248 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
250 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
252 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
255 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
257 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
259 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
261 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
264 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
266 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
268 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
270 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
273 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
275 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
277 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
279 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
282 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
284 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
286 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
288 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
291 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
293 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
295 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
297 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
300 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
302 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
304 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
306 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
309 /*****************************************************************************
310 * IDirectDraw7::AddRef
312 * Increases the interfaces refcount, basically
314 * DDraw refcounting is a bit tricky. The different DirectDraw interface
315 * versions have individual refcounts, but the IDirect3D interfaces do not.
316 * All interfaces are from one object, that means calling QueryInterface on an
317 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
318 * IDirectDrawImpl object.
320 * That means all AddRef and Release implementations of IDirectDrawX work
321 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
322 * except of IDirect3D7 which thunks to IDirectDraw7
324 * Returns: The new refcount
326 *****************************************************************************/
327 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
329 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
330 ULONG ref
= InterlockedIncrement(&This
->ref7
);
332 TRACE("%p increasing refcount to %u.\n", This
, ref
);
334 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
339 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
341 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
342 ULONG ref
= InterlockedIncrement(&This
->ref4
);
344 TRACE("%p increasing refcount to %u.\n", This
, ref
);
346 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
351 static ULONG WINAPI
ddraw3_AddRef(IDirectDraw3
*iface
)
353 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
354 ULONG ref
= InterlockedIncrement(&This
->ref3
);
356 TRACE("%p increasing refcount to %u.\n", This
, ref
);
358 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
363 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
365 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
366 ULONG ref
= InterlockedIncrement(&This
->ref2
);
368 TRACE("%p increasing refcount to %u.\n", This
, ref
);
370 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
375 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
377 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
378 ULONG ref
= InterlockedIncrement(&This
->ref1
);
380 TRACE("%p increasing refcount to %u.\n", This
, ref
);
382 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
387 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
389 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
391 TRACE("iface %p.\n", iface
);
393 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
396 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
398 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
400 TRACE("iface %p.\n", iface
);
402 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
405 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
407 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
409 TRACE("iface %p.\n", iface
);
411 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
414 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
416 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
418 TRACE("iface %p.\n", iface
);
420 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
423 /*****************************************************************************
426 * Destroys a ddraw object if all refcounts are 0. This is to share code
427 * between the IDirectDrawX::Release functions
430 * This: DirectDraw object to destroy
432 *****************************************************************************/
433 static void ddraw_destroy(IDirectDrawImpl
*This
)
435 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
436 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
438 /* Destroy the device window if we created one */
439 if(This
->devicewindow
!= 0)
441 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
442 DestroyWindow(This
->devicewindow
);
443 This
->devicewindow
= 0;
446 EnterCriticalSection(&ddraw_cs
);
447 list_remove(&This
->ddraw_list_entry
);
448 LeaveCriticalSection(&ddraw_cs
);
450 /* Release the attached WineD3D stuff */
451 wined3d_device_decref(This
->wined3d_device
);
452 wined3d_decref(This
->wineD3D
);
454 /* Now free the object */
455 HeapFree(GetProcessHeap(), 0, This
);
458 /*****************************************************************************
459 * IDirectDraw7::Release
461 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
463 * Returns: The new refcount
464 *****************************************************************************/
465 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
467 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
468 ULONG ref
= InterlockedDecrement(&This
->ref7
);
470 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
472 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
478 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
480 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
481 ULONG ref
= InterlockedDecrement(&This
->ref4
);
483 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
485 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
491 static ULONG WINAPI
ddraw3_Release(IDirectDraw3
*iface
)
493 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
494 ULONG ref
= InterlockedDecrement(&This
->ref3
);
496 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
498 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
504 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
506 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
507 ULONG ref
= InterlockedDecrement(&This
->ref2
);
509 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
511 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
517 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
519 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
520 ULONG ref
= InterlockedDecrement(&This
->ref1
);
522 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
524 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
530 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
532 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
534 TRACE("iface %p.\n", iface
);
536 return ddraw7_Release(&This
->IDirectDraw7_iface
);
539 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
541 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
543 TRACE("iface %p.\n", iface
);
545 return ddraw1_Release(&This
->IDirectDraw_iface
);
548 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
550 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
552 TRACE("iface %p.\n", iface
);
554 return ddraw1_Release(&This
->IDirectDraw_iface
);
557 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
559 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
561 TRACE("iface %p.\n", iface
);
563 return ddraw1_Release(&This
->IDirectDraw_iface
);
566 /*****************************************************************************
567 * IDirectDraw methods
568 *****************************************************************************/
570 /*****************************************************************************
571 * IDirectDraw7::SetCooperativeLevel
573 * Sets the cooperative level for the DirectDraw object, and the window
574 * assigned to it. The cooperative level determines the general behavior
575 * of the DirectDraw application
577 * Warning: This is quite tricky, as it's not really documented which
578 * cooperative levels can be combined with each other. If a game fails
579 * after this function, try to check the cooperative levels passed on
580 * Windows, and if it returns something different.
582 * If you think that this function caused the failure because it writes a
583 * fixme, be sure to run again with a +ddraw trace.
585 * What is known about cooperative levels (See the ddraw modes test):
586 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
587 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
588 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
589 * DDSCL_FULLSCREEN can be activated
590 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
592 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
593 * DDSCL_SETFOCUSWINDOW (partially),
594 * DDSCL_MULTITHREADED (work in progress)
596 * Unhandled flags, which should be implemented
597 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
598 * expect any difference to a normal window for wine)
599 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
600 * rendering (Possible test case: Half-Life)
602 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
604 * These don't seem very important for wine:
605 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
608 * DD_OK if the cooperative level was set successfully
609 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
610 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
611 * (Probably others too, have to investigate)
613 *****************************************************************************/
614 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
616 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
619 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
620 DDRAW_dump_cooperativelevel(cooplevel
);
622 EnterCriticalSection(&ddraw_cs
);
624 /* Get the old window */
625 window
= This
->dest_window
;
627 /* Tests suggest that we need one of them: */
628 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
632 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
633 LeaveCriticalSection(&ddraw_cs
);
634 return DDERR_INVALIDPARAMS
;
637 /* Handle those levels first which set various hwnds */
638 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
640 /* This isn't compatible with a lot of flags */
641 if(cooplevel
& ( DDSCL_MULTITHREADED
|
642 DDSCL_CREATEDEVICEWINDOW
|
647 DDSCL_SETDEVICEWINDOW
|
652 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
653 LeaveCriticalSection(&ddraw_cs
);
654 return DDERR_INVALIDPARAMS
;
657 if( (This
->cooperative_level
& DDSCL_EXCLUSIVE
) && window
)
659 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
660 LeaveCriticalSection(&ddraw_cs
);
661 return DDERR_HWNDALREADYSET
;
664 This
->focuswindow
= hwnd
;
665 /* Won't use the hwnd param for anything else */
668 /* Use the focus window for drawing too */
669 This
->dest_window
= This
->focuswindow
;
671 /* Destroy the device window, if we have one */
672 if(This
->devicewindow
)
674 DestroyWindow(This
->devicewindow
);
675 This
->devicewindow
= NULL
;
678 LeaveCriticalSection(&ddraw_cs
);
682 if(cooplevel
& DDSCL_EXCLUSIVE
)
684 if( !(cooplevel
& DDSCL_FULLSCREEN
) || !hwnd
)
686 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This
);
687 LeaveCriticalSection(&ddraw_cs
);
688 return DDERR_INVALIDPARAMS
;
691 else if( !(cooplevel
& DDSCL_NORMAL
) )
693 TRACE("(%p) SetCooperativeLevel needs at least SetFocusWindow or Exclusive or Normal mode\n", This
);
694 LeaveCriticalSection(&ddraw_cs
);
695 return DDERR_INVALIDPARAMS
;
698 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
699 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
700 wined3d_device_release_focus_window(This
->wined3d_device
);
702 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
704 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
705 wined3d_device_restore_fullscreen_window(This
->wined3d_device
, window
);
707 if (cooplevel
& DDSCL_FULLSCREEN
)
709 WINED3DDISPLAYMODE display_mode
;
711 wined3d_get_adapter_display_mode(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, &display_mode
);
712 wined3d_device_setup_fullscreen_window(This
->wined3d_device
, hwnd
,
713 display_mode
.Width
, display_mode
.Height
);
717 if ((cooplevel
& DDSCL_EXCLUSIVE
)
718 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
720 HRESULT hr
= wined3d_device_acquire_focus_window(This
->wined3d_device
, hwnd
);
723 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
724 LeaveCriticalSection(&ddraw_cs
);
729 /* Don't override focus windows or private device windows */
730 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
731 This
->dest_window
= hwnd
;
733 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
735 /* Don't create a device window if a focus window is set */
736 if( !(This
->focuswindow
) )
738 HWND devicewindow
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DDraw device window",
739 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
740 NULL
, NULL
, NULL
, NULL
);
743 ERR("Failed to create window, last error %#x.\n", GetLastError());
744 LeaveCriticalSection(&ddraw_cs
);
748 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
749 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
751 This
->devicewindow
= devicewindow
;
752 This
->dest_window
= devicewindow
;
756 if (cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
757 wined3d_device_set_multithreaded(This
->wined3d_device
);
759 /* Unhandled flags */
760 if(cooplevel
& DDSCL_ALLOWREBOOT
)
761 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
762 if(cooplevel
& DDSCL_ALLOWMODEX
)
763 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
764 if(cooplevel
& DDSCL_FPUSETUP
)
765 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
767 /* Store the cooperative_level */
768 This
->cooperative_level
= cooplevel
;
769 TRACE("SetCooperativeLevel retuning DD_OK\n");
770 LeaveCriticalSection(&ddraw_cs
);
774 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
776 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
778 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
780 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
783 static HRESULT WINAPI
ddraw3_SetCooperativeLevel(IDirectDraw3
*iface
, HWND window
, DWORD flags
)
785 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
787 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
789 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
792 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
794 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
796 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
798 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
801 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
803 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
805 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
807 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
810 /*****************************************************************************
812 * Helper function for SetDisplayMode and RestoreDisplayMode
814 * Implements DirectDraw's SetDisplayMode, but ignores the value of
815 * ForceRefreshRate, since it is already handled by
816 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
817 * without worrying that ForceRefreshRate will override the refresh rate. For
818 * argument and return value documentation, see
819 * ddraw7_SetDisplayMode.
821 *****************************************************************************/
822 static HRESULT
ddraw_set_display_mode(IDirectDrawImpl
*ddraw
, DWORD Width
, DWORD Height
,
823 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
825 enum wined3d_format_id format
;
826 WINED3DDISPLAYMODE Mode
;
829 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
830 Height
, BPP
, RefreshRate
, Flags
);
832 EnterCriticalSection(&ddraw_cs
);
833 if( !Width
|| !Height
)
835 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
836 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
837 LeaveCriticalSection(&ddraw_cs
);
843 case 8: format
= WINED3DFMT_P8_UINT
; break;
844 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
845 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
846 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
847 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
848 default: format
= WINED3DFMT_UNKNOWN
; break;
851 if (FAILED(hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &Mode
)))
853 ERR("Failed to get current display mode, hr %#x.\n", hr
);
855 else if (Mode
.Width
== Width
856 && Mode
.Height
== Height
857 && Mode
.Format
== format
858 && Mode
.RefreshRate
== RefreshRate
)
860 TRACE("Skipping redundant mode setting call.\n");
861 LeaveCriticalSection(&ddraw_cs
);
865 /* Check the exclusive mode
866 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
867 return DDERR_NOEXCLUSIVEMODE;
868 * This is WRONG. Don't know if the SDK is completely
869 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
870 * is returned, but Half-Life 1.1.1.1 (Steam version)
875 Mode
.Height
= Height
;
876 Mode
.RefreshRate
= RefreshRate
;
877 Mode
.Format
= format
;
879 /* TODO: The possible return values from msdn suggest that
880 * the screen mode can't be changed if a surface is locked
881 * or some drawing is in progress
884 /* TODO: Lose the primary surface */
885 hr
= wined3d_device_set_display_mode(ddraw
->wined3d_device
, 0, &Mode
);
887 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
889 wined3d_device_restore_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
);
890 wined3d_device_setup_fullscreen_window(ddraw
->wined3d_device
, ddraw
->dest_window
, Width
, Height
);
893 LeaveCriticalSection(&ddraw_cs
);
896 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
901 /*****************************************************************************
902 * IDirectDraw7::SetDisplayMode
904 * Sets the display screen resolution, color depth and refresh frequency
905 * when in fullscreen mode (in theory).
906 * Possible return values listed in the SDK suggest that this method fails
907 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
908 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
909 * It seems to be valid to pass 0 for With and Height, this has to be tested
910 * It could mean that the current video mode should be left as-is. (But why
914 * Height, Width: Screen dimension
915 * BPP: Color depth in Bits per pixel
916 * Refreshrate: Screen refresh rate
922 *****************************************************************************/
923 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
924 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
926 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
928 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
929 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
931 if (force_refresh_rate
!= 0)
933 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
934 RefreshRate
, force_refresh_rate
);
935 RefreshRate
= force_refresh_rate
;
938 return ddraw_set_display_mode(This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
941 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
942 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
944 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
946 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
947 iface
, width
, height
, bpp
, refresh_rate
, flags
);
949 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
952 static HRESULT WINAPI
ddraw3_SetDisplayMode(IDirectDraw3
*iface
, DWORD width
, DWORD height
,
953 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
955 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
957 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
958 iface
, width
, height
, bpp
, refresh_rate
, flags
);
960 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
963 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
964 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
966 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
968 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
969 iface
, width
, height
, bpp
, refresh_rate
, flags
);
971 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
974 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
976 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
978 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
980 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
983 /*****************************************************************************
984 * IDirectDraw7::RestoreDisplayMode
986 * Restores the display mode to what it was at creation time. Basically.
988 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
989 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
990 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
991 * -> DD_1 is released. The screen should be left at 1024x768x32.
992 * -> DD_2 is released. The screen should be set to 1400x1050x32
993 * This case is unhandled right now, but Empire Earth does it this way.
994 * (But perhaps there is something in SetCooperativeLevel to prevent this)
996 * The msdn says that this method resets the display mode to what it was before
997 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
1001 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
1003 *****************************************************************************/
1004 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
1006 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1008 TRACE("iface %p.\n", iface
);
1010 return ddraw_set_display_mode(This
, This
->orig_width
, This
->orig_height
, This
->orig_bpp
, 0, 0);
1013 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
1015 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1017 TRACE("iface %p.\n", iface
);
1019 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1022 static HRESULT WINAPI
ddraw3_RestoreDisplayMode(IDirectDraw3
*iface
)
1024 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1026 TRACE("iface %p.\n", iface
);
1028 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1031 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
1033 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1035 TRACE("iface %p.\n", iface
);
1037 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1040 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
1042 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1044 TRACE("iface %p.\n", iface
);
1046 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1049 /*****************************************************************************
1050 * IDirectDraw7::GetCaps
1052 * Returns the drives capabilities
1054 * Used for version 1, 2, 4 and 7
1057 * DriverCaps: Structure to write the Hardware accelerated caps to
1058 * HelCaps: Structure to write the emulation caps to
1061 * This implementation returns DD_OK only
1063 *****************************************************************************/
1064 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1066 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1068 WINED3DCAPS winecaps
;
1070 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1072 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1074 /* One structure must be != NULL */
1075 if( (!DriverCaps
) && (!HELCaps
) )
1077 ERR("(%p) Invalid params to ddraw7_GetCaps\n", This
);
1078 return DDERR_INVALIDPARAMS
;
1081 memset(&caps
, 0, sizeof(caps
));
1082 memset(&winecaps
, 0, sizeof(winecaps
));
1083 caps
.dwSize
= sizeof(caps
);
1084 EnterCriticalSection(&ddraw_cs
);
1085 hr
= wined3d_device_get_device_caps(This
->wined3d_device
, &winecaps
);
1088 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1089 LeaveCriticalSection(&ddraw_cs
);
1093 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1094 LeaveCriticalSection(&ddraw_cs
);
1096 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1100 caps
.dwCaps
= winecaps
.DirectDrawCaps
.Caps
;
1101 caps
.dwCaps2
= winecaps
.DirectDrawCaps
.Caps2
;
1102 caps
.dwCKeyCaps
= winecaps
.DirectDrawCaps
.CKeyCaps
;
1103 caps
.dwFXCaps
= winecaps
.DirectDrawCaps
.FXCaps
;
1104 caps
.dwPalCaps
= winecaps
.DirectDrawCaps
.PalCaps
;
1105 caps
.ddsCaps
.dwCaps
= winecaps
.DirectDrawCaps
.ddsCaps
;
1106 caps
.dwSVBCaps
= winecaps
.DirectDrawCaps
.SVBCaps
;
1107 caps
.dwSVBCKeyCaps
= winecaps
.DirectDrawCaps
.SVBCKeyCaps
;
1108 caps
.dwSVBFXCaps
= winecaps
.DirectDrawCaps
.SVBFXCaps
;
1109 caps
.dwVSBCaps
= winecaps
.DirectDrawCaps
.VSBCaps
;
1110 caps
.dwVSBCKeyCaps
= winecaps
.DirectDrawCaps
.VSBCKeyCaps
;
1111 caps
.dwVSBFXCaps
= winecaps
.DirectDrawCaps
.VSBFXCaps
;
1112 caps
.dwSSBCaps
= winecaps
.DirectDrawCaps
.SSBCaps
;
1113 caps
.dwSSBCKeyCaps
= winecaps
.DirectDrawCaps
.SSBCKeyCaps
;
1114 caps
.dwSSBFXCaps
= winecaps
.DirectDrawCaps
.SSBFXCaps
;
1116 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1119 if(DefaultSurfaceType
== SURFACE_GDI
) {
1120 caps
.dwCaps
&= ~DDCAPS_3D
;
1121 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1123 if(winecaps
.DirectDrawCaps
.StrideAlign
!= 0) {
1124 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1125 caps
.dwAlignStrideAlign
= winecaps
.DirectDrawCaps
.StrideAlign
;
1130 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1131 if (TRACE_ON(ddraw
))
1133 TRACE("Driver Caps :\n");
1134 DDRAW_dump_DDCAPS(DriverCaps
);
1140 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1141 if (TRACE_ON(ddraw
))
1143 TRACE("HEL Caps :\n");
1144 DDRAW_dump_DDCAPS(HELCaps
);
1151 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1153 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1155 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1157 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1160 static HRESULT WINAPI
ddraw3_GetCaps(IDirectDraw3
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1162 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1164 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1166 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1169 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1171 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1173 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1175 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1178 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1180 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1182 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1184 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1187 /*****************************************************************************
1188 * IDirectDraw7::Compact
1190 * No idea what it does, MSDN says it's not implemented.
1193 * DD_OK, but this is unchecked
1195 *****************************************************************************/
1196 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1198 TRACE("iface %p.\n", iface
);
1203 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1205 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1207 TRACE("iface %p.\n", iface
);
1209 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1212 static HRESULT WINAPI
ddraw3_Compact(IDirectDraw3
*iface
)
1214 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1216 TRACE("iface %p.\n", iface
);
1218 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1221 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1223 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1225 TRACE("iface %p.\n", iface
);
1227 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1230 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1232 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1234 TRACE("iface %p.\n", iface
);
1236 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1239 /*****************************************************************************
1240 * IDirectDraw7::GetDisplayMode
1242 * Returns information about the current display mode
1244 * Exists in Version 1, 2, 4 and 7
1247 * DDSD: Address of a surface description structure to write the info to
1252 *****************************************************************************/
1253 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1255 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1257 WINED3DDISPLAYMODE Mode
;
1260 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1262 EnterCriticalSection(&ddraw_cs
);
1263 /* This seems sane */
1266 LeaveCriticalSection(&ddraw_cs
);
1267 return DDERR_INVALIDPARAMS
;
1270 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1271 * so one method can be used for all versions (Hopefully) */
1272 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &Mode
);
1275 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
1276 LeaveCriticalSection(&ddraw_cs
);
1280 Size
= DDSD
->dwSize
;
1281 memset(DDSD
, 0, Size
);
1283 DDSD
->dwSize
= Size
;
1284 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1285 DDSD
->dwWidth
= Mode
.Width
;
1286 DDSD
->dwHeight
= Mode
.Height
;
1287 DDSD
->u2
.dwRefreshRate
= 60;
1288 DDSD
->ddsCaps
.dwCaps
= 0;
1289 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1290 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
1291 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1295 TRACE("Returning surface desc :\n");
1296 DDRAW_dump_surface_desc(DDSD
);
1299 LeaveCriticalSection(&ddraw_cs
);
1303 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1305 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1307 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1309 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, surface_desc
);
1312 static HRESULT WINAPI
ddraw3_GetDisplayMode(IDirectDraw3
*iface
, DDSURFACEDESC
*surface_desc
)
1314 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1316 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1318 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1321 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1323 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1325 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1327 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1330 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1332 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1334 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1336 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1339 /*****************************************************************************
1340 * IDirectDraw7::GetFourCCCodes
1342 * Returns an array of supported FourCC codes.
1344 * Exists in Version 1, 2, 4 and 7
1347 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1348 * of enumerated codes
1349 * Codes: Pointer to an array of DWORDs where the supported codes are written
1353 * Always returns DD_OK, as it's a stub for now
1355 *****************************************************************************/
1356 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1358 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1359 static const enum wined3d_format_id formats
[] =
1361 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1362 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1363 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1365 DWORD count
= 0, i
, outsize
;
1367 WINED3DDISPLAYMODE d3ddm
;
1368 WINED3DSURFTYPE type
= This
->ImplType
;
1370 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1372 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &d3ddm
);
1374 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1376 if(type
== SURFACE_UNKNOWN
) type
= SURFACE_GDI
;
1378 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1380 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, WINED3DDEVTYPE_HAL
,
1381 d3ddm
.Format
, 0, WINED3DRTYPE_SURFACE
, formats
[i
], type
);
1384 if (count
< outsize
)
1385 Codes
[count
] = formats
[i
];
1390 TRACE("Returning %u FourCC codes\n", count
);
1397 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1399 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1401 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1403 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1406 static HRESULT WINAPI
ddraw3_GetFourCCCodes(IDirectDraw3
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1408 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1410 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1412 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1415 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1417 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1419 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1421 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1424 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1426 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1428 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1430 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1433 /*****************************************************************************
1434 * IDirectDraw7::GetMonitorFrequency
1436 * Returns the monitor's frequency
1438 * Exists in Version 1, 2, 4 and 7
1441 * Freq: Pointer to a DWORD to write the frequency to
1444 * Always returns DD_OK
1446 *****************************************************************************/
1447 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1449 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1451 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1452 * but for now this should make the games happy
1458 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1460 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1462 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1464 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1467 static HRESULT WINAPI
ddraw3_GetMonitorFrequency(IDirectDraw3
*iface
, DWORD
*frequency
)
1469 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1471 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1473 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1476 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1478 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1480 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1482 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1485 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1487 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1489 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1491 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1494 /*****************************************************************************
1495 * IDirectDraw7::GetVerticalBlankStatus
1497 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1498 * too basically, but as it's a semi stub, I didn't create a function there
1501 * status: Pointer to a BOOL to be filled with the vertical blank status
1505 * DDERR_INVALIDPARAMS if status is NULL
1507 *****************************************************************************/
1508 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1510 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1512 TRACE("iface %p, status %p.\n", iface
, status
);
1514 /* This looks sane, the MSDN suggests it too */
1515 EnterCriticalSection(&ddraw_cs
);
1518 LeaveCriticalSection(&ddraw_cs
);
1519 return DDERR_INVALIDPARAMS
;
1522 *status
= This
->fake_vblank
;
1523 This
->fake_vblank
= !This
->fake_vblank
;
1524 LeaveCriticalSection(&ddraw_cs
);
1528 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1530 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1532 TRACE("iface %p, status %p.\n", iface
, status
);
1534 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1537 static HRESULT WINAPI
ddraw3_GetVerticalBlankStatus(IDirectDraw3
*iface
, BOOL
*status
)
1539 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1541 TRACE("iface %p, status %p.\n", iface
, status
);
1543 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1546 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1548 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1550 TRACE("iface %p, status %p.\n", iface
, status
);
1552 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1555 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1557 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1559 TRACE("iface %p, status %p.\n", iface
, status
);
1561 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1564 /*****************************************************************************
1565 * IDirectDraw7::GetAvailableVidMem
1567 * Returns the total and free video memory
1570 * Caps: Specifies the memory type asked for
1571 * total: Pointer to a DWORD to be filled with the total memory
1572 * free: Pointer to a DWORD to be filled with the free memory
1576 * DDERR_INVALIDPARAMS of free and total are NULL
1578 *****************************************************************************/
1579 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1582 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1584 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1588 TRACE("(%p) Asked for memory with description: ", This
);
1589 DDRAW_dump_DDSCAPS2(Caps
);
1591 EnterCriticalSection(&ddraw_cs
);
1593 /* Todo: System memory vs local video memory vs non-local video memory
1594 * The MSDN also mentions differences between texture memory and other
1595 * resources, but that's not important
1598 if( (!total
) && (!free
) )
1600 LeaveCriticalSection(&ddraw_cs
);
1601 return DDERR_INVALIDPARAMS
;
1605 *total
= This
->total_vidmem
;
1607 *free
= wined3d_device_get_available_texture_mem(This
->wined3d_device
);
1609 LeaveCriticalSection(&ddraw_cs
);
1613 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1614 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1616 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1618 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1620 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, caps
, total
, free
);
1623 static HRESULT WINAPI
ddraw3_GetAvailableVidMem(IDirectDraw3
*iface
, DDSCAPS
*caps
, DWORD
*total
,
1626 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1629 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1631 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1632 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1635 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1636 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1638 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1641 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1643 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1644 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1647 /*****************************************************************************
1648 * IDirectDraw7::Initialize
1650 * Initializes a DirectDraw interface.
1653 * GUID: Interface identifier. Well, don't know what this is really good
1657 * Returns DD_OK on the first call,
1658 * DDERR_ALREADYINITIALIZED on repeated calls
1660 *****************************************************************************/
1661 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*Guid
)
1663 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1665 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(Guid
));
1667 if(This
->initialized
)
1669 return DDERR_ALREADYINITIALIZED
;
1677 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1679 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1681 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1683 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1686 static HRESULT WINAPI
ddraw3_Initialize(IDirectDraw3
*iface
, GUID
*guid
)
1688 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1690 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1692 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1695 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1697 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1699 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1701 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1704 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1706 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1708 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1710 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1713 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1715 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1720 /*****************************************************************************
1721 * IDirectDraw7::FlipToGDISurface
1723 * "Makes the surface that the GDI writes to the primary surface"
1724 * Looks like some windows specific thing we don't have to care about.
1725 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1726 * show error boxes ;)
1727 * Well, just return DD_OK.
1730 * Always returns DD_OK
1732 *****************************************************************************/
1733 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1735 FIXME("iface %p stub!\n", iface
);
1740 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1742 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1744 TRACE("iface %p.\n", iface
);
1746 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1749 static HRESULT WINAPI
ddraw3_FlipToGDISurface(IDirectDraw3
*iface
)
1751 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1753 TRACE("iface %p.\n", iface
);
1755 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1758 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1760 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1762 TRACE("iface %p.\n", iface
);
1764 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1767 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1769 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1771 TRACE("iface %p.\n", iface
);
1773 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1776 /*****************************************************************************
1777 * IDirectDraw7::WaitForVerticalBlank
1779 * This method allows applications to get in sync with the vertical blank
1781 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1782 * redraw the screen, most likely because of this stub
1785 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1786 * or DDWAITVB_BLOCKEND
1787 * h: Not used, according to MSDN
1790 * Always returns DD_OK
1792 *****************************************************************************/
1793 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1797 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1799 /* This function is called often, so print the fixme only once */
1802 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1806 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1807 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1808 return DDERR_UNSUPPORTED
; /* unchecked */
1813 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1815 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1817 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1819 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1822 static HRESULT WINAPI
ddraw3_WaitForVerticalBlank(IDirectDraw3
*iface
, DWORD flags
, HANDLE event
)
1824 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1826 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1828 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1831 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1833 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1835 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1837 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1840 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1842 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1844 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1846 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1849 /*****************************************************************************
1850 * IDirectDraw7::GetScanLine
1852 * Returns the scan line that is being drawn on the monitor
1855 * Scanline: Address to write the scan line value to
1858 * Always returns DD_OK
1860 *****************************************************************************/
1861 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1863 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1864 static BOOL hide
= FALSE
;
1865 WINED3DDISPLAYMODE Mode
;
1867 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1869 /* This function is called often, so print the fixme only once */
1870 EnterCriticalSection(&ddraw_cs
);
1873 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1877 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &Mode
);
1879 /* Fake the line sweeping of the monitor */
1880 /* FIXME: We should synchronize with a source to keep the refresh rate */
1881 *Scanline
= This
->cur_scanline
++;
1882 /* Assume 20 scan lines in the vertical blank */
1883 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1884 This
->cur_scanline
= 0;
1886 LeaveCriticalSection(&ddraw_cs
);
1890 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1892 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1894 TRACE("iface %p, line %p.\n", iface
, line
);
1896 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1899 static HRESULT WINAPI
ddraw3_GetScanLine(IDirectDraw3
*iface
, DWORD
*line
)
1901 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1903 TRACE("iface %p, line %p.\n", iface
, line
);
1905 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1908 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1910 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1912 TRACE("iface %p, line %p.\n", iface
, line
);
1914 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1917 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1919 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1921 TRACE("iface %p, line %p.\n", iface
, line
);
1923 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1926 /*****************************************************************************
1927 * IDirectDraw7::TestCooperativeLevel
1929 * Informs the application about the state of the video adapter, depending
1930 * on the cooperative level
1933 * DD_OK if the device is in a sane state
1934 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1935 * if the state is not correct(See below)
1937 *****************************************************************************/
1938 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1940 TRACE("iface %p.\n", iface
);
1945 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1947 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1949 TRACE("iface %p.\n", iface
);
1951 return ddraw7_TestCooperativeLevel(&This
->IDirectDraw7_iface
);
1954 /*****************************************************************************
1955 * IDirectDraw7::GetGDISurface
1957 * Returns the surface that GDI is treating as the primary surface.
1958 * For Wine this is the front buffer
1961 * GDISurface: Address to write the surface pointer to
1964 * DD_OK if the surface was found
1965 * DDERR_NOTFOUND if the GDI surface wasn't found
1967 *****************************************************************************/
1968 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
1970 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1971 struct wined3d_surface
*wined3d_surface
;
1972 IDirectDrawSurface7
*ddsurf
;
1976 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
1978 /* Get the back buffer from the wineD3DDevice and search its
1979 * attached surfaces for the front buffer. */
1980 EnterCriticalSection(&ddraw_cs
);
1981 hr
= wined3d_device_get_back_buffer(This
->wined3d_device
,
1982 0, 0, WINED3DBACKBUFFER_TYPE_MONO
, &wined3d_surface
);
1983 if (FAILED(hr
) || !wined3d_surface
)
1985 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1986 LeaveCriticalSection(&ddraw_cs
);
1987 return DDERR_NOTFOUND
;
1990 ddsurf
= wined3d_surface_get_parent(wined3d_surface
);
1991 wined3d_surface_decref(wined3d_surface
);
1993 /* Find the front buffer */
1994 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1995 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
2000 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
2003 /* The AddRef is OK this time */
2004 LeaveCriticalSection(&ddraw_cs
);
2008 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2010 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2012 TRACE("iface %p, surface %p.\n", iface
, surface
);
2014 return ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, (IDirectDrawSurface7
**)surface
);
2017 static HRESULT WINAPI
ddraw3_GetGDISurface(IDirectDraw3
*iface
, IDirectDrawSurface
**surface
)
2019 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2020 IDirectDrawSurface7
*surface7
;
2023 TRACE("iface %p, surface %p.\n", iface
, surface
);
2025 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2026 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2031 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2033 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2034 IDirectDrawSurface7
*surface7
;
2037 TRACE("iface %p, surface %p.\n", iface
, surface
);
2039 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2040 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2045 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2047 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2048 IDirectDrawSurface7
*surface7
;
2051 TRACE("iface %p, surface %p.\n", iface
, surface
);
2053 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2054 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2059 struct displaymodescallback_context
2061 LPDDENUMMODESCALLBACK func
;
2065 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2067 struct displaymodescallback_context
*cbcontext
= context
;
2070 memcpy(&desc
, surface_desc
, sizeof(desc
));
2071 desc
.dwSize
= sizeof(desc
);
2073 return cbcontext
->func(&desc
, cbcontext
->context
);
2076 /*****************************************************************************
2077 * IDirectDraw7::EnumDisplayModes
2079 * Enumerates the supported Display modes. The modes can be filtered with
2080 * the DDSD parameter.
2083 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
2084 * versions (3 and older?) this is reserved and must be 0.
2085 * DDSD: Surface description to filter the modes
2086 * Context: Pointer passed back to the callback function
2087 * cb: Application-provided callback function
2091 * DDERR_INVALIDPARAMS if the callback wasn't set
2093 *****************************************************************************/
2094 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2095 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2097 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2098 unsigned int modenum
, fmt
;
2099 WINED3DDISPLAYMODE mode
;
2100 DDSURFACEDESC2 callback_sd
;
2101 WINED3DDISPLAYMODE
*enum_modes
= NULL
;
2102 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2103 DDPIXELFORMAT pixelformat
;
2105 static const enum wined3d_format_id checkFormatList
[] =
2107 WINED3DFMT_B8G8R8X8_UNORM
,
2108 WINED3DFMT_B5G6R5_UNORM
,
2112 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2113 iface
, Flags
, DDSD
, Context
, cb
);
2115 EnterCriticalSection(&ddraw_cs
);
2116 /* This looks sane */
2119 LeaveCriticalSection(&ddraw_cs
);
2120 return DDERR_INVALIDPARAMS
;
2123 if(!(Flags
& DDEDM_REFRESHRATES
))
2125 enum_mode_array_size
= 16;
2126 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2129 ERR("Out of memory\n");
2130 LeaveCriticalSection(&ddraw_cs
);
2131 return DDERR_OUTOFMEMORY
;
2135 pixelformat
.dwSize
= sizeof(pixelformat
);
2136 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2139 while (wined3d_enum_adapter_modes(This
->wineD3D
, WINED3DADAPTER_DEFAULT
,
2140 checkFormatList
[fmt
], modenum
++, &mode
) == WINED3D_OK
)
2142 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.Format
);
2145 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
2146 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
2147 if(DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.RefreshRate
!= DDSD
->u2
.dwRefreshRate
) continue;
2148 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
&&
2149 pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
) continue;
2152 if(!(Flags
& DDEDM_REFRESHRATES
))
2154 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2155 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2156 * to be reduced to a single unique result in such case.
2161 for (i
= 0; i
< enum_mode_count
; i
++)
2163 if(enum_modes
[i
].Width
== mode
.Width
&& enum_modes
[i
].Height
== mode
.Height
&&
2164 enum_modes
[i
].Format
== mode
.Format
)
2174 memset(&callback_sd
, 0, sizeof(callback_sd
));
2175 callback_sd
.dwSize
= sizeof(callback_sd
);
2176 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2178 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2179 if(Flags
& DDEDM_REFRESHRATES
)
2181 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
2184 callback_sd
.dwWidth
= mode
.Width
;
2185 callback_sd
.dwHeight
= mode
.Height
;
2187 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2189 /* Calc pitch and DWORD align like MSDN says */
2190 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.Width
;
2191 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2193 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2194 callback_sd
.u2
.dwRefreshRate
);
2196 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2198 TRACE("Application asked to terminate the enumeration\n");
2199 HeapFree(GetProcessHeap(), 0, enum_modes
);
2200 LeaveCriticalSection(&ddraw_cs
);
2204 if(!(Flags
& DDEDM_REFRESHRATES
))
2206 if (enum_mode_count
== enum_mode_array_size
)
2208 WINED3DDISPLAYMODE
*new_enum_modes
;
2210 enum_mode_array_size
*= 2;
2211 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2213 if (!new_enum_modes
)
2215 ERR("Out of memory\n");
2216 HeapFree(GetProcessHeap(), 0, enum_modes
);
2217 LeaveCriticalSection(&ddraw_cs
);
2218 return DDERR_OUTOFMEMORY
;
2221 enum_modes
= new_enum_modes
;
2224 enum_modes
[enum_mode_count
++] = mode
;
2229 TRACE("End of enumeration\n");
2230 HeapFree(GetProcessHeap(), 0, enum_modes
);
2231 LeaveCriticalSection(&ddraw_cs
);
2235 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2236 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2238 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2240 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2241 iface
, flags
, surface_desc
, context
, callback
);
2243 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2246 static HRESULT WINAPI
ddraw3_EnumDisplayModes(IDirectDraw3
*iface
, DWORD flags
,
2247 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2249 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2250 struct displaymodescallback_context cbcontext
;
2252 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2253 iface
, flags
, surface_desc
, context
, callback
);
2255 cbcontext
.func
= callback
;
2256 cbcontext
.context
= context
;
2258 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2259 &cbcontext
, EnumDisplayModesCallbackThunk
);
2262 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2263 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2265 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2266 struct displaymodescallback_context cbcontext
;
2268 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2269 iface
, flags
, surface_desc
, context
, callback
);
2271 cbcontext
.func
= callback
;
2272 cbcontext
.context
= context
;
2274 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2275 &cbcontext
, EnumDisplayModesCallbackThunk
);
2278 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2279 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2281 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2282 struct displaymodescallback_context cbcontext
;
2284 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2285 iface
, flags
, surface_desc
, context
, callback
);
2287 cbcontext
.func
= callback
;
2288 cbcontext
.context
= context
;
2290 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2291 &cbcontext
, EnumDisplayModesCallbackThunk
);
2294 /*****************************************************************************
2295 * IDirectDraw7::EvaluateMode
2297 * Used with IDirectDraw7::StartModeTest to test video modes.
2298 * EvaluateMode is used to pass or fail a mode, and continue with the next
2302 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2303 * Timeout: Returns the amount of seconds left before the mode would have
2304 * been failed automatically
2307 * This implementation always DD_OK, because it's a stub
2309 *****************************************************************************/
2310 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2312 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2314 /* When implementing this, implement it in WineD3D */
2319 /*****************************************************************************
2320 * IDirectDraw7::GetDeviceIdentifier
2322 * Returns the device identifier, which gives information about the driver
2323 * Our device identifier is defined at the beginning of this file.
2326 * DDDI: Address for the returned structure
2327 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2330 * On success it returns DD_OK
2331 * DDERR_INVALIDPARAMS if DDDI is NULL
2333 *****************************************************************************/
2334 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2335 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2337 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2340 return DDERR_INVALIDPARAMS
;
2342 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2343 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2344 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2345 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2346 * bytes too long. So only copy the relevant part of the structure
2349 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2353 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2354 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2356 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2357 DDDEVICEIDENTIFIER2 identifier2
;
2360 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2362 hr
= ddraw7_GetDeviceIdentifier(&This
->IDirectDraw7_iface
, &identifier2
, flags
);
2363 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2368 /*****************************************************************************
2369 * IDirectDraw7::GetSurfaceFromDC
2371 * Returns the Surface for a GDI device context handle.
2372 * Is this related to IDirectDrawSurface::GetDC ???
2375 * hdc: hdc to return the surface for
2376 * Surface: Address to write the surface pointer to
2379 * Always returns DD_OK because it's a stub
2381 *****************************************************************************/
2382 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2383 IDirectDrawSurface7
**Surface
)
2385 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2386 struct wined3d_surface
*wined3d_surface
;
2389 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2391 if (!Surface
) return E_INVALIDARG
;
2393 hr
= wined3d_device_get_surface_from_dc(This
->wined3d_device
, hdc
, &wined3d_surface
);
2396 TRACE("No surface found for dc %p.\n", hdc
);
2398 return DDERR_NOTFOUND
;
2401 *Surface
= wined3d_surface_get_parent(wined3d_surface
);
2402 IDirectDrawSurface7_AddRef(*Surface
);
2403 TRACE("Returning surface %p.\n", Surface
);
2407 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2408 IDirectDrawSurface4
**surface
)
2410 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2411 IDirectDrawSurface7
*surface7
;
2414 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2416 if (!surface
) return E_INVALIDARG
;
2418 hr
= ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, &surface7
);
2419 *surface
= surface7
? (IDirectDrawSurface4
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2424 static HRESULT WINAPI
ddraw3_GetSurfaceFromDC(IDirectDraw3
*iface
, HDC dc
,
2425 IDirectDrawSurface
**surface
)
2427 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2429 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2431 return ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, (IDirectDrawSurface7
**)surface
);
2434 /*****************************************************************************
2435 * IDirectDraw7::RestoreAllSurfaces
2437 * Calls the restore method of all surfaces
2442 * Always returns DD_OK because it's a stub
2444 *****************************************************************************/
2445 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2447 FIXME("iface %p stub!\n", iface
);
2449 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2450 * get their parent and call their restore method. Do not implement
2451 * it in WineD3D, as restoring a surface means re-creating the
2457 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2459 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2461 TRACE("iface %p.\n", iface
);
2463 return ddraw7_RestoreAllSurfaces(&This
->IDirectDraw7_iface
);
2466 /*****************************************************************************
2467 * IDirectDraw7::StartModeTest
2469 * Tests the specified video modes to update the system registry with
2470 * refresh rate information. StartModeTest starts the mode test,
2471 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2472 * isn't called within 15 seconds, the mode is failed automatically
2474 * As refresh rates are handled by the X server, I don't think this
2475 * Method is important
2478 * Modes: An array of mode specifications
2479 * NumModes: The number of modes in Modes
2480 * Flags: Some flags...
2483 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2484 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2487 *****************************************************************************/
2488 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2490 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2491 iface
, Modes
, NumModes
, Flags
);
2493 /* This looks sane */
2494 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2496 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2497 * As it is not, DDERR_TESTFINISHED is returned
2498 * (hopefully that's correct
2500 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2501 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2507 /*****************************************************************************
2508 * ddraw_recreate_surfaces_cb
2510 * Enumeration callback for ddraw_recreate_surface.
2511 * It re-recreates the WineD3DSurface. It's pretty straightforward
2513 *****************************************************************************/
2514 HRESULT WINAPI
ddraw_recreate_surfaces_cb(IDirectDrawSurface7
*surf
, DDSURFACEDESC2
*desc
, void *Context
)
2516 IDirectDrawSurfaceImpl
*surfImpl
= (IDirectDrawSurfaceImpl
*)surf
;
2517 struct wined3d_resource_desc wined3d_desc
;
2518 struct wined3d_resource
*wined3d_resource
;
2519 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
2520 struct wined3d_surface
*wined3d_surface
;
2521 struct wined3d_swapchain
*swapchain
;
2522 struct wined3d_clipper
*clipper
;
2526 TRACE("surface %p, surface_desc %p, context %p.\n",
2527 surf
, desc
, Context
);
2529 /* For the enumeration */
2530 IDirectDrawSurface7_Release(surf
);
2532 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
2534 /* Get the objects */
2535 swapchain
= surfImpl
->wined3d_swapchain
;
2536 surfImpl
->wined3d_swapchain
= NULL
;
2537 wined3d_surface
= surfImpl
->wined3d_surface
;
2539 /* get the clipper */
2540 clipper
= wined3d_surface_get_clipper(wined3d_surface
);
2542 /* Get the surface properties */
2543 wined3d_resource
= wined3d_surface_get_resource(wined3d_surface
);
2544 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
2546 parent
= wined3d_surface_get_parent(wined3d_surface
);
2547 hr
= wined3d_surface_create(This
->wined3d_device
, wined3d_desc
.width
, wined3d_desc
.height
,
2548 wined3d_desc
.format
, TRUE
, FALSE
, surfImpl
->mipmap_level
, wined3d_desc
.usage
, wined3d_desc
.pool
,
2549 wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
, This
->ImplType
,
2550 parent
, &ddraw_surface_wined3d_parent_ops
, &surfImpl
->wined3d_surface
);
2553 surfImpl
->wined3d_surface
= wined3d_surface
;
2557 wined3d_surface_set_clipper(surfImpl
->wined3d_surface
, clipper
);
2559 /* TODO: Copy the surface content, except for render targets */
2561 /* If there's a swapchain, it owns the wined3d surfaces. So Destroy
2566 /* The backbuffers have the swapchain set as well, but the primary
2567 * owns it and destroys it. */
2568 if (surfImpl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2569 wined3d_device_uninit_gdi(This
->wined3d_device
);
2570 surfImpl
->isRenderTarget
= FALSE
;
2574 if (!wined3d_surface_decref(wined3d_surface
))
2575 TRACE("Surface released successful, next surface\n");
2577 ERR("Something's still holding the old WineD3DSurface\n");
2580 surfImpl
->ImplType
= This
->ImplType
;
2582 return DDENUMRET_OK
;
2585 /*****************************************************************************
2586 * ddraw_recreate_surfaces
2588 * A function, that converts all wineD3DSurfaces to the new implementation type
2589 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
2590 * new WineD3DSurface, copies the content and releases the old surface
2592 *****************************************************************************/
2593 static HRESULT
ddraw_recreate_surfaces(IDirectDrawImpl
*This
)
2595 DDSURFACEDESC2 desc
;
2596 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
2598 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
2600 /* Should happen almost never */
2601 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
2603 wined3d_device_uninit_3d(This
->wined3d_device
);
2605 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
2607 memset(&desc
, 0, sizeof(desc
));
2608 desc
.dwSize
= sizeof(desc
);
2610 return IDirectDraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, 0, &desc
, This
,
2611 ddraw_recreate_surfaces_cb
);
2614 /*****************************************************************************
2615 * ddraw_create_surface
2617 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2618 * with the passed parameters.
2621 * DDSD: Description of the surface to create
2622 * Surf: Address to store the interface pointer at
2627 *****************************************************************************/
2628 static HRESULT
ddraw_create_surface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
,
2629 IDirectDrawSurfaceImpl
**ppSurf
, UINT level
)
2631 WINED3DSURFTYPE ImplType
= This
->ImplType
;
2634 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2635 This
, pDDSD
, ppSurf
, level
);
2637 if (TRACE_ON(ddraw
))
2639 TRACE(" (%p) Requesting surface desc :\n", This
);
2640 DDRAW_dump_surface_desc(pDDSD
);
2643 /* Select the surface type, if it wasn't choosen yet */
2644 if(ImplType
== SURFACE_UNKNOWN
)
2646 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
2647 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2649 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
2650 ImplType
= SURFACE_OPENGL
;
2653 /* Otherwise use GDI surfaces for now */
2656 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
2657 ImplType
= SURFACE_GDI
;
2660 /* Policy if all surface implementations are available:
2661 * First, check if a default type was set with winecfg. If not,
2662 * try Xrender surfaces, and use them if they work. Next, check if
2663 * accelerated OpenGL is available, and use GL surfaces in this
2664 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
2665 * was created, always use OpenGL surfaces.
2667 * (Note: Xrender surfaces are not implemented for now, the
2668 * unaccelerated implementation uses GDI to render in Software)
2671 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
2672 * be re-created. This could be done with IDirectDrawSurface7::Restore
2674 This
->ImplType
= ImplType
;
2678 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2679 && (This
->ImplType
!= SURFACE_OPENGL
)
2680 && DefaultSurfaceType
== SURFACE_UNKNOWN
)
2682 /* We have to change to OpenGL,
2683 * and re-create all WineD3DSurfaces
2685 ImplType
= SURFACE_OPENGL
;
2686 This
->ImplType
= ImplType
;
2687 TRACE("(%p) Re-creating all surfaces\n", This
);
2688 ddraw_recreate_surfaces(This
);
2689 TRACE("(%p) Done recreating all surfaces\n", This
);
2691 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2693 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
2694 /* Do not fail surface creation, only fail 3D device creation */
2698 /* Create the Surface object */
2699 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
2702 ERR("(%p) Error allocating memory for a surface\n", This
);
2703 return DDERR_OUTOFVIDEOMEMORY
;
2706 hr
= ddraw_surface_init(*ppSurf
, This
, pDDSD
, level
, ImplType
);
2709 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2710 HeapFree(GetProcessHeap(), 0, *ppSurf
);
2714 /* Increase the surface counter, and attach the surface */
2715 InterlockedIncrement(&This
->surfaces
);
2716 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
2718 TRACE("Created surface %p.\n", *ppSurf
);
2722 /*****************************************************************************
2723 * CreateAdditionalSurfaces
2725 * Creates a new mipmap chain.
2728 * root: Root surface to attach the newly created chain to
2729 * count: number of surfaces to create
2730 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2731 * effects on the caller
2732 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2733 * creates an additional surface without the mipmapping flags
2735 *****************************************************************************/
2737 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2738 IDirectDrawSurfaceImpl
*root
,
2740 DDSURFACEDESC2 DDSD
,
2743 UINT i
, j
, level
= 0;
2745 IDirectDrawSurfaceImpl
*last
= root
;
2747 for(i
= 0; i
< count
; i
++)
2749 IDirectDrawSurfaceImpl
*object2
= NULL
;
2751 /* increase the mipmap level, but only if a mipmap is created
2752 * In this case, also halve the size
2754 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2757 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2758 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2759 /* Set the mipmap sublevel flag according to msdn */
2760 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2764 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2766 CubeFaceRoot
= FALSE
;
2768 hr
= ddraw_create_surface(This
, &DDSD
, &object2
, level
);
2774 /* Add the new surface to the complex attachment array */
2775 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2777 if(last
->complex_array
[j
]) continue;
2778 last
->complex_array
[j
] = object2
;
2783 /* Remove the (possible) back buffer cap from the new surface description,
2784 * because only one surface in the flipping chain is a back buffer, one
2785 * is a front buffer, the others are just primary surfaces.
2787 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2792 /* Must set all attached surfaces (e.g. mipmaps) versions as well */
2793 static void ddraw_set_surface_version(IDirectDrawSurfaceImpl
*surface
, UINT version
)
2797 TRACE("surface %p, version %u -> %u.\n", surface
, surface
->version
, version
);
2799 surface
->version
= version
;
2800 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
2802 if (!surface
->complex_array
[i
]) break;
2803 ddraw_set_surface_version(surface
->complex_array
[i
], version
);
2805 while ((surface
= surface
->next_attached
))
2807 ddraw_set_surface_version(surface
, version
);
2811 /*****************************************************************************
2812 * ddraw_attach_d3d_device
2814 * Initializes the D3D capabilities of WineD3D
2817 * primary: The primary surface for D3D
2823 *****************************************************************************/
2824 static HRESULT
ddraw_attach_d3d_device(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2826 WINED3DPRESENT_PARAMETERS localParameters
;
2827 HWND window
= ddraw
->dest_window
;
2830 TRACE("ddraw %p, primary %p.\n", ddraw
, primary
);
2832 if (!window
|| window
== GetDesktopWindow())
2834 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
2835 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
2836 NULL
, NULL
, NULL
, NULL
);
2839 ERR("Failed to create window, last error %#x.\n", GetLastError());
2843 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2844 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
2848 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
2850 ddraw
->d3d_window
= window
;
2852 /* Store the future Render Target surface */
2853 ddraw
->d3d_target
= primary
;
2855 /* Use the surface description for the device parameters, not the device
2856 * settings. The application might render to an offscreen surface. */
2857 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2858 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2859 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2860 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2861 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2862 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2863 localParameters
.MultiSampleQuality
= 0;
2864 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2865 localParameters
.hDeviceWindow
= window
;
2866 localParameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2867 localParameters
.EnableAutoDepthStencil
= TRUE
;
2868 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16_UNORM
;
2869 localParameters
.Flags
= 0;
2870 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2871 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2872 localParameters
.AutoRestoreDisplayMode
= FALSE
;
2874 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2875 * recursive loop until ram or emulated video memory is full. */
2876 ddraw
->d3d_initialized
= TRUE
;
2877 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, &localParameters
);
2880 ddraw
->d3d_target
= NULL
;
2881 ddraw
->d3d_initialized
= FALSE
;
2885 ddraw
->declArraySize
= 2;
2886 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
2889 ERR("Error allocating an array for the converted vertex decls.\n");
2890 ddraw
->declArraySize
= 0;
2891 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
2892 return E_OUTOFMEMORY
;
2895 TRACE("Successfully initialized 3D.\n");
2900 static HRESULT
ddraw_create_gdi_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2902 WINED3DPRESENT_PARAMETERS presentation_parameters
;
2906 window
= ddraw
->dest_window
;
2908 memset(&presentation_parameters
, 0, sizeof(presentation_parameters
));
2910 /* Use the surface description for the device parameters, not the device
2911 * settings. The application might render to an offscreen surface. */
2912 presentation_parameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2913 presentation_parameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2914 presentation_parameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2915 presentation_parameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2916 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2917 presentation_parameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2918 presentation_parameters
.MultiSampleQuality
= 0;
2919 presentation_parameters
.SwapEffect
= WINED3DSWAPEFFECT_FLIP
;
2920 presentation_parameters
.hDeviceWindow
= window
;
2921 presentation_parameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2922 presentation_parameters
.EnableAutoDepthStencil
= FALSE
; /* Not on GDI swapchains */
2923 presentation_parameters
.AutoDepthStencilFormat
= 0;
2924 presentation_parameters
.Flags
= 0;
2925 presentation_parameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2926 presentation_parameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2927 presentation_parameters
.AutoRestoreDisplayMode
= FALSE
;
2929 ddraw
->d3d_target
= primary
;
2930 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &presentation_parameters
);
2931 ddraw
->d3d_target
= NULL
;
2934 WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr
);
2935 primary
->wined3d_swapchain
= NULL
;
2941 /*****************************************************************************
2942 * IDirectDraw7::CreateSurface
2944 * Creates a new IDirectDrawSurface object and returns its interface.
2946 * The surface connections with wined3d are a bit tricky. Basically it works
2949 * |------------------------| |-----------------|
2950 * | DDraw surface | | WineD3DSurface |
2952 * | WineD3DSurface |-------------->| |
2953 * | Child |<------------->| Parent |
2954 * |------------------------| |-----------------|
2956 * The DDraw surface is the parent of the wined3d surface, and it releases
2957 * the WineD3DSurface when the ddraw surface is destroyed.
2959 * However, for all surfaces which can be in a container in WineD3D,
2960 * we have to do this. These surfaces are usually complex surfaces,
2961 * so this concerns primary surfaces with a front and a back buffer,
2964 * |------------------------| |-----------------|
2965 * | DDraw surface | | Container |
2967 * | Child |<------------->| Parent |
2968 * | Texture |<------------->| |
2969 * | WineD3DSurface |<----| | Levels |<--|
2970 * | Complex connection | | | | |
2971 * |------------------------| | |-----------------| |
2975 * | |------------------| | |-----------------| |
2976 * | | IParent | |-------->| WineD3DSurface | |
2978 * | | Child |<------------->| Parent | |
2979 * | | | | Container |<--|
2980 * | |------------------| |-----------------| |
2982 * | |----------------------| |
2983 * | | DDraw surface 2 | |
2985 * |<->| Complex root Child | |
2987 * | | WineD3DSurface |<----| |
2988 * | |----------------------| | |
2990 * | |---------------------| | |-----------------| |
2991 * | | IParent | |----->| WineD3DSurface | |
2993 * | | Child |<---------->| Parent | |
2994 * | |---------------------| | Container |<--|
2995 * | |-----------------| |
2997 * | ---More surfaces can follow--- |
2999 * The reason is that the IWineD3DSwapchain(render target container)
3000 * and the IWineD3DTexure(Texture container) release the parents
3001 * of their surface's children, but by releasing the complex root
3002 * the surfaces which are complexly attached to it are destroyed
3003 * too. See IDirectDrawSurface::Release for a more detailed
3007 * DDSD: Description of the surface to create
3008 * Surf: Address to store the interface pointer at
3009 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
3010 * aggregation, so it has to be NULL
3014 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3015 * DDERR_* if an error occurs
3017 *****************************************************************************/
3018 static HRESULT
CreateSurface(IDirectDrawImpl
*ddraw
, DDSURFACEDESC2
*DDSD
,
3019 IDirectDrawSurface7
**Surf
, IUnknown
*UnkOuter
)
3021 IDirectDrawSurfaceImpl
*object
= NULL
;
3023 LONG extra_surfaces
= 0;
3024 DDSURFACEDESC2 desc2
;
3025 WINED3DDISPLAYMODE Mode
;
3026 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
3028 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, Surf
, UnkOuter
);
3030 /* Some checks before we start */
3031 if (TRACE_ON(ddraw
))
3033 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
3034 DDRAW_dump_surface_desc(DDSD
);
3036 EnterCriticalSection(&ddraw_cs
);
3038 if (UnkOuter
!= NULL
)
3040 FIXME("(%p) : outer != NULL?\n", ddraw
);
3041 LeaveCriticalSection(&ddraw_cs
);
3042 return CLASS_E_NOAGGREGATION
; /* unchecked */
3047 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
3048 LeaveCriticalSection(&ddraw_cs
);
3049 return E_POINTER
; /* unchecked */
3052 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
3054 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
3055 DDSD
->dwFlags
|= DDSD_CAPS
;
3058 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
3060 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
3061 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
3064 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
3066 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
3067 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
3068 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
3071 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
3072 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
3074 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
3077 LeaveCriticalSection(&ddraw_cs
);
3078 return DDERR_NOEXCLUSIVEMODE
;
3081 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
3083 WARN("Application wanted to create back buffer primary surface\n");
3084 LeaveCriticalSection(&ddraw_cs
);
3085 return DDERR_INVALIDCAPS
;
3088 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
3090 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
3091 WARN("Application tries to put the surface in both system and video memory\n");
3092 LeaveCriticalSection(&ddraw_cs
);
3094 return DDERR_INVALIDCAPS
;
3097 /* Check cube maps but only if the size includes them */
3098 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
3100 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
3101 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
3103 WARN("Cube map faces requested without cube map flag\n");
3104 LeaveCriticalSection(&ddraw_cs
);
3105 return DDERR_INVALIDCAPS
;
3107 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
3108 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
3110 WARN("Cube map without faces requested\n");
3111 LeaveCriticalSection(&ddraw_cs
);
3112 return DDERR_INVALIDPARAMS
;
3115 /* Quick tests confirm those can be created, but we don't do that yet */
3116 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
3117 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
3119 FIXME("Partial cube maps not supported yet\n");
3123 /* According to the msdn this flag is ignored by CreateSurface */
3124 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
3125 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
3127 /* Modify some flags */
3128 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
3129 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
3130 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
3132 /* Get the video mode from WineD3D - we will need it */
3133 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &Mode
);
3136 ERR("Failed to read display mode from wined3d\n");
3137 switch(ddraw
->orig_bpp
)
3140 Mode
.Format
= WINED3DFMT_P8_UINT
;
3144 Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
;
3148 Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
;
3152 Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
;
3156 Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
;
3159 Mode
.Width
= ddraw
->orig_width
;
3160 Mode
.Height
= ddraw
->orig_height
;
3163 /* No pixelformat given? Use the current screen format */
3164 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
3166 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
3167 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
3169 /* Wait: It could be a Z buffer */
3170 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
3172 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
3175 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_S1_UINT_D15_UNORM
);
3178 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16_UNORM
);
3181 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_X8D24_UNORM
);
3184 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32_UNORM
);
3187 ERR("Unknown Z buffer bit depth\n");
3192 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
3196 /* No Width or no Height? Use the original screen size
3198 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
3199 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
3201 /* Invalid for non-render targets */
3202 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
3204 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
3206 LeaveCriticalSection(&ddraw_cs
);
3207 return DDERR_INVALIDPARAMS
;
3210 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
3211 desc2
.dwWidth
= Mode
.Width
;
3212 desc2
.dwHeight
= Mode
.Height
;
3215 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
3217 LeaveCriticalSection(&ddraw_cs
);
3218 return DDERR_INVALIDPARAMS
;
3221 /* Mipmap count fixes */
3222 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3224 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
3226 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
3228 /* Mipmap count is given, should not be 0 */
3229 if( desc2
.u2
.dwMipMapCount
== 0 )
3231 LeaveCriticalSection(&ddraw_cs
);
3232 return DDERR_INVALIDPARAMS
;
3237 /* Undocumented feature: Create sublevels until
3238 * either the width or the height is 1
3240 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
3241 desc2
.dwWidth
: desc2
.dwHeight
;
3242 desc2
.u2
.dwMipMapCount
= 0;
3245 desc2
.u2
.dwMipMapCount
+= 1;
3252 /* Not-complex mipmap -> Mipmapcount = 1 */
3253 desc2
.u2
.dwMipMapCount
= 1;
3255 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
3257 /* There's a mipmap count in the created surface in any case */
3258 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
3260 /* If no mipmap is given, the texture has only one level */
3262 /* The first surface is a front buffer, the back buffer is created afterwards */
3263 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
3265 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
3268 /* The root surface in a cube map is positive x */
3269 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3271 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3272 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3275 /* Create the first surface */
3276 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0);
3279 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3280 LeaveCriticalSection(&ddraw_cs
);
3283 object
->is_complex_root
= TRUE
;
3285 *Surf
= (IDirectDrawSurface7
*)object
;
3287 /* Create Additional surfaces if necessary
3288 * This applies to Primary surfaces which have a back buffer count
3289 * set, but not to mipmap textures. In case of Mipmap textures,
3290 * wineD3D takes care of the creation of additional surfaces
3292 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3294 extra_surfaces
= DDSD
->dwBackBufferCount
;
3295 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3296 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3297 desc2
.dwBackBufferCount
= 0;
3301 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3303 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3304 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3305 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3306 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3307 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
3308 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3309 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
3310 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
3311 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3312 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
3313 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
3314 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3315 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
3316 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
3317 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3318 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
3319 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3322 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
);
3325 /* This destroys and possibly created surfaces too */
3326 IDirectDrawSurface_Release((IDirectDrawSurface7
*)object
);
3327 LeaveCriticalSection(&ddraw_cs
);
3331 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
3332 * But attach the d3ddevice only if the currently created surface was
3333 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
3334 * The only case I can think of where this doesn't apply is when a
3335 * 2D app was configured by the user to run with OpenGL and it didn't create
3336 * the render target as first surface. In this case the render target creation
3337 * will cause the 3D init.
3339 if( (ddraw
->ImplType
== SURFACE_OPENGL
) && !(ddraw
->d3d_initialized
) &&
3340 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
3342 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
3345 /* Search for the primary to use as render target */
3346 LIST_FOR_EACH(entry
, &ddraw
->surface_list
)
3348 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3349 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
3350 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
3354 TRACE("Using primary %p as render target\n", target
);
3359 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", ddraw
, target
);
3360 hr
= ddraw_attach_d3d_device(ddraw
, target
);
3363 IDirectDrawSurfaceImpl
*release_surf
;
3364 ERR("ddraw_attach_d3d_device failed, hr %#x\n", hr
);
3367 /* The before created surface structures are in an incomplete state here.
3368 * WineD3D holds the reference on the IParents, and it released them on the failure
3369 * already. So the regular release method implementation would fail on the attempt
3370 * to destroy either the IParents or the swapchain. So free the surface here.
3371 * The surface structure here is a list, not a tree, because onscreen targets
3372 * cannot be cube textures
3376 release_surf
= object
;
3377 object
= object
->complex_array
[0];
3378 ddraw_surface_destroy(release_surf
);
3380 LeaveCriticalSection(&ddraw_cs
);
3384 else if(!(ddraw
->d3d_initialized
) && desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3386 ddraw_create_gdi_swapchain(ddraw
, object
);
3389 /* Addref the ddraw interface to keep an reference for each surface */
3390 IDirectDraw7_AddRef(&ddraw
->IDirectDraw7_iface
);
3391 object
->ifaceToRelease
= (IUnknown
*)&ddraw
->IDirectDraw7_iface
;
3393 /* Create a WineD3DTexture if a texture was requested */
3394 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3396 ddraw
->tex_root
= object
;
3397 ddraw_surface_create_texture(object
);
3398 ddraw
->tex_root
= NULL
;
3401 LeaveCriticalSection(&ddraw_cs
);
3405 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3406 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3408 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3410 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3411 iface
, surface_desc
, surface
, outer_unknown
);
3413 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3415 WARN("Application supplied invalid surface descriptor\n");
3416 return DDERR_INVALIDPARAMS
;
3419 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3421 if (TRACE_ON(ddraw
))
3423 TRACE(" (%p) Requesting surface desc :\n", iface
);
3424 DDRAW_dump_surface_desc(surface_desc
);
3427 WARN("Application tried to create an explicit front or back buffer\n");
3428 return DDERR_INVALIDCAPS
;
3431 return CreateSurface(This
, surface_desc
, surface
, outer_unknown
);
3434 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3435 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3437 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3438 IDirectDrawSurfaceImpl
*impl
;
3441 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3442 iface
, surface_desc
, surface
, outer_unknown
);
3444 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3446 WARN("Application supplied invalid surface descriptor\n");
3447 return DDERR_INVALIDPARAMS
;
3450 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3452 if (TRACE_ON(ddraw
))
3454 TRACE(" (%p) Requesting surface desc :\n", iface
);
3455 DDRAW_dump_surface_desc(surface_desc
);
3458 WARN("Application tried to create an explicit front or back buffer\n");
3459 return DDERR_INVALIDCAPS
;
3462 hr
= CreateSurface(This
, surface_desc
, (IDirectDrawSurface7
**)surface
, outer_unknown
);
3463 impl
= (IDirectDrawSurfaceImpl
*)*surface
;
3464 if (SUCCEEDED(hr
) && impl
)
3466 ddraw_set_surface_version(impl
, 4);
3467 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3468 IDirectDraw4_AddRef(iface
);
3469 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3475 static HRESULT WINAPI
ddraw3_CreateSurface(IDirectDraw3
*iface
, DDSURFACEDESC
*surface_desc
,
3476 IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3478 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3479 IDirectDrawSurface7
*surface7
;
3480 IDirectDrawSurfaceImpl
*impl
;
3483 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3484 iface
, surface_desc
, surface
, outer_unknown
);
3486 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3488 WARN("Application supplied invalid surface descriptor\n");
3489 return DDERR_INVALIDPARAMS
;
3492 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3494 if (TRACE_ON(ddraw
))
3496 TRACE(" (%p) Requesting surface desc :\n", iface
);
3497 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3500 WARN("Application tried to create an explicit front or back buffer\n");
3501 return DDERR_INVALIDCAPS
;
3504 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3511 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3512 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3513 ddraw_set_surface_version(impl
, 3);
3514 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3515 IDirectDraw3_AddRef(iface
);
3516 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3521 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3522 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3524 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3525 IDirectDrawSurface7
*surface7
;
3526 IDirectDrawSurfaceImpl
*impl
;
3529 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3530 iface
, surface_desc
, surface
, outer_unknown
);
3532 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3534 WARN("Application supplied invalid surface descriptor\n");
3535 return DDERR_INVALIDPARAMS
;
3538 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3540 if (TRACE_ON(ddraw
))
3542 TRACE(" (%p) Requesting surface desc :\n", iface
);
3543 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3546 WARN("Application tried to create an explicit front or back buffer\n");
3547 return DDERR_INVALIDCAPS
;
3550 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3557 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3558 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3559 ddraw_set_surface_version(impl
, 2);
3560 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3561 impl
->ifaceToRelease
= NULL
;
3566 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3567 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3569 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3570 IDirectDrawSurface7
*surface7
;
3571 IDirectDrawSurfaceImpl
*impl
;
3574 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3575 iface
, surface_desc
, surface
, outer_unknown
);
3577 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3579 WARN("Application supplied invalid surface descriptor\n");
3580 return DDERR_INVALIDPARAMS
;
3583 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3584 * primaries anyway. */
3585 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3586 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3593 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3594 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3595 ddraw_set_surface_version(impl
, 1);
3596 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3597 impl
->ifaceToRelease
= NULL
;
3602 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3603 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3606 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3607 const DDPIXELFORMAT
*provided
)
3609 /* Some flags must be present in both or neither for a match. */
3610 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3611 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3612 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3614 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3617 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3620 if (requested
->dwFlags
& DDPF_FOURCC
)
3621 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3624 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3625 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3626 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3629 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3630 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3631 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3634 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3635 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3638 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3639 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3641 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3644 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3645 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3651 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3660 #define CMP(FLAG, FIELD) \
3661 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3662 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3664 static const struct compare_info compare
[] =
3666 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3667 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3669 CMP(CKDESTBLT
, ddckCKDestBlt
),
3670 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3671 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3672 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3673 CMP(HEIGHT
, dwHeight
),
3674 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3675 CMP(LPSURFACE
, lpSurface
),
3676 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3677 CMP(PITCH
, u1
/* lPitch */),
3678 /* PIXELFORMAT: manual */
3679 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3680 CMP(TEXTURESTAGE
, dwTextureStage
),
3681 CMP(WIDTH
, dwWidth
),
3682 /* ZBUFFERBITDEPTH: "obsolete" */
3689 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3692 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3694 if (requested
->dwFlags
& compare
[i
].flag
3695 && memcmp((const char *)provided
+ compare
[i
].offset
,
3696 (const char *)requested
+ compare
[i
].offset
,
3697 compare
[i
].size
) != 0)
3701 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3703 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3704 &provided
->u4
.ddpfPixelFormat
))
3711 #undef DDENUMSURFACES_SEARCHTYPE
3712 #undef DDENUMSURFACES_MATCHTYPE
3714 struct surfacescallback_context
3716 LPDDENUMSURFACESCALLBACK func
;
3720 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3721 DDSURFACEDESC2
*surface_desc
, void *context
)
3723 struct surfacescallback_context
*cbcontext
= context
;
3725 return cbcontext
->func((IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface
)->IDirectDrawSurface3_vtbl
,
3726 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3729 /*****************************************************************************
3730 * IDirectDraw7::EnumSurfaces
3732 * Loops through all surfaces attached to this device and calls the
3733 * application callback. This can't be relayed to WineD3DDevice,
3734 * because some WineD3DSurfaces' parents are IParent objects
3737 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3738 * DDSD: Description to filter for
3739 * Context: Application-provided pointer, it's passed unmodified to the
3741 * Callback: Address to call for each surface
3744 * DDERR_INVALIDPARAMS if the callback is NULL
3747 *****************************************************************************/
3748 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3749 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3751 /* The surface enumeration is handled by WineDDraw,
3752 * because it keeps track of all surfaces attached to
3753 * it. The filtering is done by our callback function,
3754 * because WineDDraw doesn't handle ddraw-like surface
3757 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3758 IDirectDrawSurfaceImpl
*surf
;
3760 DDSURFACEDESC2 desc
;
3761 struct list
*entry
, *entry2
;
3763 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3764 iface
, Flags
, DDSD
, Context
, Callback
);
3766 all
= Flags
& DDENUMSURFACES_ALL
;
3767 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3769 EnterCriticalSection(&ddraw_cs
);
3773 LeaveCriticalSection(&ddraw_cs
);
3774 return DDERR_INVALIDPARAMS
;
3777 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3778 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3780 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3781 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3783 desc
= surf
->surface_desc
;
3784 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)surf
);
3785 if (Callback((IDirectDrawSurface7
*)surf
, &desc
, Context
) != DDENUMRET_OK
)
3787 LeaveCriticalSection(&ddraw_cs
);
3792 LeaveCriticalSection(&ddraw_cs
);
3796 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3797 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3799 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3801 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3802 iface
, flags
, surface_desc
, context
, callback
);
3804 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
,
3805 (LPDDENUMSURFACESCALLBACK7
)callback
);
3808 static HRESULT WINAPI
ddraw3_EnumSurfaces(IDirectDraw3
*iface
, DWORD flags
,
3809 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3811 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3812 struct surfacescallback_context cbcontext
;
3814 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3815 iface
, flags
, surface_desc
, context
, callback
);
3817 cbcontext
.func
= callback
;
3818 cbcontext
.context
= context
;
3820 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3821 &cbcontext
, EnumSurfacesCallbackThunk
);
3824 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3825 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3827 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3828 struct surfacescallback_context cbcontext
;
3830 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3831 iface
, flags
, surface_desc
, context
, callback
);
3833 cbcontext
.func
= callback
;
3834 cbcontext
.context
= context
;
3836 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3837 &cbcontext
, EnumSurfacesCallbackThunk
);
3840 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3841 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3843 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3844 struct surfacescallback_context cbcontext
;
3846 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3847 iface
, flags
, surface_desc
, context
, callback
);
3849 cbcontext
.func
= callback
;
3850 cbcontext
.context
= context
;
3852 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3853 &cbcontext
, EnumSurfacesCallbackThunk
);
3856 /*****************************************************************************
3857 * DirectDrawCreateClipper (DDRAW.@)
3859 * Creates a new IDirectDrawClipper object.
3862 * Clipper: Address to write the interface pointer to
3863 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3867 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3868 * E_OUTOFMEMORY if allocating the object failed
3870 *****************************************************************************/
3872 DirectDrawCreateClipper(DWORD Flags
,
3873 LPDIRECTDRAWCLIPPER
*Clipper
,
3876 IDirectDrawClipperImpl
* object
;
3879 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3880 Flags
, Clipper
, UnkOuter
);
3882 EnterCriticalSection(&ddraw_cs
);
3883 if (UnkOuter
!= NULL
)
3885 LeaveCriticalSection(&ddraw_cs
);
3886 return CLASS_E_NOAGGREGATION
;
3889 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3890 sizeof(IDirectDrawClipperImpl
));
3893 LeaveCriticalSection(&ddraw_cs
);
3894 return E_OUTOFMEMORY
;
3897 hr
= ddraw_clipper_init(object
);
3900 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3901 HeapFree(GetProcessHeap(), 0, object
);
3902 LeaveCriticalSection(&ddraw_cs
);
3906 TRACE("Created clipper %p.\n", object
);
3907 *Clipper
= (IDirectDrawClipper
*) object
;
3908 LeaveCriticalSection(&ddraw_cs
);
3912 /*****************************************************************************
3913 * IDirectDraw7::CreateClipper
3915 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3917 *****************************************************************************/
3918 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3919 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3921 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3922 iface
, Flags
, Clipper
, UnkOuter
);
3924 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3927 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3928 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3930 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3932 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3933 iface
, flags
, clipper
, outer_unknown
);
3935 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3938 static HRESULT WINAPI
ddraw3_CreateClipper(IDirectDraw3
*iface
, DWORD flags
,
3939 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3941 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3943 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3944 iface
, flags
, clipper
, outer_unknown
);
3946 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3949 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3950 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3952 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3954 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3955 iface
, flags
, clipper
, outer_unknown
);
3957 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3960 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3961 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3963 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3965 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3966 iface
, flags
, clipper
, outer_unknown
);
3968 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3971 /*****************************************************************************
3972 * IDirectDraw7::CreatePalette
3974 * Creates a new IDirectDrawPalette object
3977 * Flags: The flags for the new clipper
3978 * ColorTable: Color table to assign to the new clipper
3979 * Palette: Address to write the interface pointer to
3980 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3984 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3985 * E_OUTOFMEMORY if allocating the object failed
3987 *****************************************************************************/
3988 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3989 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3991 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3992 IDirectDrawPaletteImpl
*object
;
3995 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3996 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3998 EnterCriticalSection(&ddraw_cs
);
3999 if(pUnkOuter
!= NULL
)
4001 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
4002 LeaveCriticalSection(&ddraw_cs
);
4003 return CLASS_E_NOAGGREGATION
;
4006 /* The refcount test shows that a cooplevel is required for this */
4007 if(!This
->cooperative_level
)
4009 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
4010 LeaveCriticalSection(&ddraw_cs
);
4011 return DDERR_NOCOOPERATIVELEVELSET
;
4014 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
4017 ERR("Out of memory when allocating memory for a palette implementation\n");
4018 LeaveCriticalSection(&ddraw_cs
);
4019 return E_OUTOFMEMORY
;
4022 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
4025 WARN("Failed to initialize palette, hr %#x.\n", hr
);
4026 HeapFree(GetProcessHeap(), 0, object
);
4027 LeaveCriticalSection(&ddraw_cs
);
4031 TRACE("Created palette %p.\n", object
);
4032 *Palette
= (IDirectDrawPalette
*)object
;
4033 LeaveCriticalSection(&ddraw_cs
);
4037 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
4038 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4040 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
4043 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4044 iface
, flags
, entries
, palette
, outer_unknown
);
4046 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4047 if (SUCCEEDED(hr
) && *palette
)
4049 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4050 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4051 IDirectDraw4_AddRef(iface
);
4052 impl
->ifaceToRelease
= (IUnknown
*)iface
;
4057 static HRESULT WINAPI
ddraw3_CreatePalette(IDirectDraw3
*iface
, DWORD flags
,
4058 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4060 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
4063 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4064 iface
, flags
, entries
, palette
, outer_unknown
);
4066 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4067 if (SUCCEEDED(hr
) && *palette
)
4069 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4070 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4071 IDirectDraw4_AddRef(iface
);
4072 impl
->ifaceToRelease
= (IUnknown
*)iface
;
4078 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
4079 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4081 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
4084 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4085 iface
, flags
, entries
, palette
, outer_unknown
);
4087 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4088 if (SUCCEEDED(hr
) && *palette
)
4090 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4091 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4092 impl
->ifaceToRelease
= NULL
;
4098 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
4099 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4101 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
4104 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4105 iface
, flags
, entries
, palette
, outer_unknown
);
4107 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4108 if (SUCCEEDED(hr
) && *palette
)
4110 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4111 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4112 impl
->ifaceToRelease
= NULL
;
4118 /*****************************************************************************
4119 * IDirectDraw7::DuplicateSurface
4121 * Duplicates a surface. The surface memory points to the same memory as
4122 * the original surface, and it's released when the last surface referencing
4123 * it is released. I guess that's beyond Wine's surface management right now
4124 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
4125 * test application to implement this)
4128 * Src: Address of the source surface
4129 * Dest: Address to write the new surface pointer to
4132 * See IDirectDraw7::CreateSurface
4134 *****************************************************************************/
4135 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
4136 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
4138 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Src
;
4140 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
4142 /* For now, simply create a new, independent surface */
4143 return IDirectDraw7_CreateSurface(iface
,
4144 &Surf
->surface_desc
,
4149 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
4150 IDirectDrawSurface4
**dst
)
4152 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
4154 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4156 return ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, (IDirectDrawSurface7
*)src
,
4157 (IDirectDrawSurface7
**)dst
);
4160 static HRESULT WINAPI
ddraw3_DuplicateSurface(IDirectDraw3
*iface
, IDirectDrawSurface
*src
,
4161 IDirectDrawSurface
**dst
)
4163 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
4164 IDirectDrawSurface7
*src7
, *dst7
;
4167 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4168 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4169 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4172 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4176 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
4177 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
4179 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
4180 IDirectDrawSurface7
*src7
, *dst7
;
4183 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4184 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4185 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4188 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4192 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
4193 IDirectDrawSurface
**dst
)
4195 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
4196 IDirectDrawSurface7
*src7
, *dst7
;
4199 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4200 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4201 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4204 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4208 /*****************************************************************************
4209 * IDirect3D7::EnumDevices
4211 * The EnumDevices method for IDirect3D7. It enumerates all supported
4212 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
4215 * callback: Function to call for each enumerated device
4216 * context: Pointer to pass back to the app
4219 * D3D_OK, or the return value of the GetCaps call
4221 *****************************************************************************/
4222 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
4224 char interface_name_tnl
[] = "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D";
4225 char device_name_tnl
[] = "Wine D3D7 T&L HAL";
4226 char interface_name_hal
[] = "WINE Direct3D7 Hardware acceleration using WineD3D";
4227 char device_name_hal
[] = "Wine D3D7 HAL";
4228 char interface_name_rgb
[] = "WINE Direct3D7 RGB Software Emulation using WineD3D";
4229 char device_name_rgb
[] = "Wine D3D7 RGB";
4231 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4232 D3DDEVICEDESC7 device_desc7
;
4233 D3DDEVICEDESC device_desc1
;
4236 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4238 EnterCriticalSection(&ddraw_cs
);
4240 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
4243 LeaveCriticalSection(&ddraw_cs
);
4246 callback(interface_name_tnl
, device_name_tnl
, &device_desc7
, context
);
4248 device_desc7
.deviceGUID
= IID_IDirect3DHALDevice
;
4249 callback(interface_name_hal
, device_name_hal
, &device_desc7
, context
);
4251 device_desc7
.deviceGUID
= IID_IDirect3DRGBDevice
;
4252 callback(interface_name_rgb
, device_name_rgb
, &device_desc7
, context
);
4254 TRACE("End of enumeration.\n");
4256 LeaveCriticalSection(&ddraw_cs
);
4261 /*****************************************************************************
4262 * IDirect3D3::EnumDevices
4264 * Enumerates all supported Direct3DDevice interfaces. This is the
4265 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
4267 * Version 1, 2 and 3
4270 * callback: Application-provided routine to call for each enumerated device
4271 * Context: Pointer to pass to the callback
4274 * D3D_OK on success,
4275 * The result of IDirect3DImpl_GetCaps if it failed
4277 *****************************************************************************/
4278 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4280 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
4282 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4283 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
4284 D3DDEVICEDESC7 device_desc7
;
4287 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
4288 * name string. Let's put the string in a sufficiently sized array in
4289 * writable memory. */
4290 char device_name
[50];
4291 strcpy(device_name
,"Direct3D HEL");
4293 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4295 EnterCriticalSection(&ddraw_cs
);
4297 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
4300 LeaveCriticalSection(&ddraw_cs
);
4304 /* Do I have to enumerate the reference id? Note from old d3d7:
4305 * "It seems that enumerating the reference IID on Direct3D 1 games
4306 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4308 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4309 * EnumReference which enables / disables enumerating the reference
4310 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4311 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4312 * demo directory suggest this.
4314 * Some games(GTA 2) seem to use the second enumerated device, so I have
4315 * to enumerate at least 2 devices. So enumerate the reference device to
4318 * Other games (Rollcage) tell emulation and hal device apart by certain
4319 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4320 * limitation flag), and it refuses all devices that have the perspective
4321 * flag set. This way it refuses the emulation device, and HAL devices
4322 * never have POW2 unset in d3d7 on windows. */
4323 if (This
->d3dversion
!= 1)
4325 static CHAR reference_description
[] = "RGB Direct3D emulation";
4327 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4328 hal_desc
= device_desc1
;
4329 hel_desc
= device_desc1
;
4330 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4331 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4332 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4333 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4334 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4335 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4336 device_name
, &hal_desc
, &hel_desc
, context
);
4337 if (hr
!= D3DENUMRET_OK
)
4339 TRACE("Application cancelled the enumeration.\n");
4340 LeaveCriticalSection(&ddraw_cs
);
4345 strcpy(device_name
,"Direct3D HAL");
4347 TRACE("Enumerating HAL Direct3D device.\n");
4348 hal_desc
= device_desc1
;
4349 hel_desc
= device_desc1
;
4350 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4351 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4352 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4353 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4354 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4355 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4356 device_name
, &hal_desc
, &hel_desc
, context
);
4357 if (hr
!= D3DENUMRET_OK
)
4359 TRACE("Application cancelled the enumeration.\n");
4360 LeaveCriticalSection(&ddraw_cs
);
4364 TRACE("End of enumeration.\n");
4366 LeaveCriticalSection(&ddraw_cs
);
4370 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4372 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4374 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4376 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4379 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4381 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4383 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4385 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4388 /*****************************************************************************
4389 * IDirect3D3::CreateLight
4391 * Creates an IDirect3DLight interface. This interface is used in
4392 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4393 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4394 * uses the IDirect3DDevice7 interface with D3D7 lights.
4396 * Version 1, 2 and 3
4399 * light: Address to store the new interface pointer
4400 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4405 * DDERR_OUTOFMEMORY if memory allocation failed
4406 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4408 *****************************************************************************/
4409 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4410 IUnknown
*outer_unknown
)
4412 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4413 IDirect3DLightImpl
*object
;
4415 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4417 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4419 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4422 ERR("Failed to allocate light memory.\n");
4423 return DDERR_OUTOFMEMORY
;
4426 d3d_light_init(object
, This
);
4428 TRACE("Created light %p.\n", object
);
4429 *light
= (IDirect3DLight
*)object
;
4434 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4436 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4438 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4440 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4443 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4445 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4447 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4449 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4452 /*****************************************************************************
4453 * IDirect3D3::CreateMaterial
4455 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4456 * and older versions. The IDirect3DMaterial implementation wraps its
4457 * functionality to IDirect3DDevice7::SetMaterial and friends.
4459 * Version 1, 2 and 3
4462 * material: Address to store the new interface's pointer to
4463 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4468 * DDERR_OUTOFMEMORY if memory allocation failed
4469 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4471 *****************************************************************************/
4472 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4473 IUnknown
*outer_unknown
)
4475 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4476 IDirect3DMaterialImpl
*object
;
4478 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4480 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4482 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4485 ERR("Failed to allocate material memory.\n");
4486 return DDERR_OUTOFMEMORY
;
4489 d3d_material_init(object
, This
);
4491 TRACE("Created material %p.\n", object
);
4492 *material
= (IDirect3DMaterial3
*)object
;
4497 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
, IUnknown
*outer_unknown
)
4499 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4500 IDirect3DMaterial3
*material3
;
4503 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4505 hr
= d3d3_CreateMaterial(&This
->IDirect3D3_iface
, &material3
, outer_unknown
);
4506 *material
= material3
? (IDirect3DMaterial2
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial2_vtbl
: NULL
;
4508 TRACE("Returning material %p.\n", *material
);
4513 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
, IUnknown
*outer_unknown
)
4515 IDirect3DMaterial3
*material3
;
4518 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4520 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4522 hr
= d3d3_CreateMaterial(&This
->IDirect3D3_iface
, &material3
, outer_unknown
);
4523 *material
= material3
? (IDirect3DMaterial
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial_vtbl
: NULL
;
4525 TRACE("Returning material %p.\n", *material
);
4530 /*****************************************************************************
4531 * IDirect3D3::CreateViewport
4533 * Creates an IDirect3DViewport interface. This interface is used
4534 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4535 * it has been replaced by a viewport structure and
4536 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4537 * uses the IDirect3DDevice7 methods for its functionality
4540 * Viewport: Address to store the new interface pointer
4541 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4546 * DDERR_OUTOFMEMORY if memory allocation failed
4547 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4549 *****************************************************************************/
4550 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4551 IUnknown
*outer_unknown
)
4553 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4554 IDirect3DViewportImpl
*object
;
4556 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4558 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4560 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4563 ERR("Failed to allocate viewport memory.\n");
4564 return DDERR_OUTOFMEMORY
;
4567 d3d_viewport_init(object
, This
);
4569 TRACE("Created viewport %p.\n", object
);
4570 *viewport
= (IDirect3DViewport3
*)object
;
4575 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4577 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4579 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4581 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4585 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4587 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4589 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4591 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4595 /*****************************************************************************
4596 * IDirect3D3::FindDevice
4598 * This method finds a device with the requested properties and returns a
4599 * device description
4603 * fds: Describes the requested device characteristics
4604 * fdr: Returns the device description
4608 * DDERR_INVALIDPARAMS if no device was found
4610 *****************************************************************************/
4611 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4613 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4614 D3DDEVICEDESC7 desc7
;
4615 D3DDEVICEDESC desc1
;
4618 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4620 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4622 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4623 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4624 return DDERR_INVALIDPARAMS
;
4626 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4627 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4629 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4630 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4633 if (fds
->dwFlags
& D3DFDS_GUID
)
4635 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4636 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4637 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4638 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4640 WARN("No match for this GUID.\n");
4641 return DDERR_NOTFOUND
;
4646 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &desc1
, &desc7
);
4647 if (hr
!= D3D_OK
) return hr
;
4649 /* Now return our own GUID */
4650 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4651 fdr
->ddHwDesc
= desc1
;
4652 fdr
->ddSwDesc
= desc1
;
4654 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4659 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4661 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4663 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4665 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4668 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4670 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4672 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4674 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4677 /*****************************************************************************
4678 * IDirect3D7::CreateDevice
4680 * Creates an IDirect3DDevice7 interface.
4682 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4683 * DirectDraw surfaces and are created with
4684 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4685 * create the device object and QueryInterfaces for IDirect3DDevice
4688 * refiid: IID of the device to create
4689 * Surface: Initial rendertarget
4690 * Device: Address to return the interface pointer
4694 * DDERR_OUTOFMEMORY if memory allocation failed
4695 * DDERR_INVALIDPARAMS if a device exists already
4697 *****************************************************************************/
4698 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4699 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4701 IDirectDrawSurfaceImpl
*target
= (IDirectDrawSurfaceImpl
*)surface
;
4702 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4703 IDirect3DDeviceImpl
*object
;
4706 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4708 EnterCriticalSection(&ddraw_cs
);
4711 /* Fail device creation if non-opengl surfaces are used. */
4712 if (This
->ImplType
!= SURFACE_OPENGL
)
4714 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4715 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4717 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4718 * is caught in CreateSurface or QueryInterface. */
4719 LeaveCriticalSection(&ddraw_cs
);
4723 if (This
->d3ddevice
)
4725 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4726 LeaveCriticalSection(&ddraw_cs
);
4727 return DDERR_INVALIDPARAMS
;
4730 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4733 ERR("Failed to allocate device memory.\n");
4734 LeaveCriticalSection(&ddraw_cs
);
4735 return DDERR_OUTOFMEMORY
;
4738 hr
= d3d_device_init(object
, This
, target
);
4741 WARN("Failed to initialize device, hr %#x.\n", hr
);
4742 HeapFree(GetProcessHeap(), 0, object
);
4743 LeaveCriticalSection(&ddraw_cs
);
4747 TRACE("Created device %p.\n", object
);
4748 *device
= (IDirect3DDevice7
*)object
;
4750 LeaveCriticalSection(&ddraw_cs
);
4754 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4755 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4757 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4760 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4761 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4763 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4765 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
, (IDirectDrawSurface7
*)surface
,
4766 (IDirect3DDevice7
**)device
);
4767 if (*device
) *device
= (IDirect3DDevice3
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice3_vtbl
;
4772 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4773 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4775 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4778 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4779 iface
, debugstr_guid(riid
), surface
, device
);
4781 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4782 surface
? (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)surface
) : NULL
,
4783 (IDirect3DDevice7
**)device
);
4784 if (*device
) *device
= (IDirect3DDevice2
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice2_vtbl
;
4789 /*****************************************************************************
4790 * IDirect3D7::CreateVertexBuffer
4792 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4798 * desc: Requested Vertex buffer properties
4799 * vertex_buffer: Address to return the interface pointer at
4800 * flags: Some flags, should be 0
4804 * DDERR_OUTOFMEMORY if memory allocation failed
4805 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4806 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4808 *****************************************************************************/
4809 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4810 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4812 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4813 IDirect3DVertexBufferImpl
*object
;
4816 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4817 iface
, desc
, vertex_buffer
, flags
);
4819 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4821 TRACE("Vertex buffer description:\n");
4822 TRACE(" dwSize %u\n", desc
->dwSize
);
4823 TRACE(" dwCaps %#x\n", desc
->dwCaps
);
4824 TRACE(" FVF %#x\n", desc
->dwFVF
);
4825 TRACE(" dwNumVertices %u\n", desc
->dwNumVertices
);
4827 /* Now create the vertex buffer */
4828 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4831 ERR("Failed to allocate vertex buffer memory.\n");
4832 return DDERR_OUTOFMEMORY
;
4835 hr
= d3d_vertex_buffer_init(object
, This
, desc
);
4838 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
4839 HeapFree(GetProcessHeap(), 0, object
);
4843 TRACE("Created vertex buffer %p.\n", object
);
4844 *vertex_buffer
= (IDirect3DVertexBuffer7
*)object
;
4849 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4850 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4852 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4855 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4856 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4858 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4860 hr
= d3d7_CreateVertexBuffer(&This
->IDirect3D7_iface
, desc
,
4861 (IDirect3DVertexBuffer7
**)vertex_buffer
, flags
);
4863 *vertex_buffer
= (IDirect3DVertexBuffer
*)&((IDirect3DVertexBufferImpl
*)*vertex_buffer
)->IDirect3DVertexBuffer_vtbl
;
4868 /*****************************************************************************
4869 * IDirect3D7::EnumZBufferFormats
4871 * Enumerates all supported Z buffer pixel formats
4877 * callback: callback to call for each pixel format
4878 * context: Pointer to pass back to the callback
4882 * DDERR_INVALIDPARAMS if callback is NULL
4883 * For details, see IWineD3DDevice::EnumZBufferFormats
4885 *****************************************************************************/
4886 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4887 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4889 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4890 WINED3DDISPLAYMODE d3ddm
;
4891 WINED3DDEVTYPE type
;
4895 /* Order matters. Specifically, BattleZone II (full version) expects the
4896 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4897 static const enum wined3d_format_id formats
[] =
4899 WINED3DFMT_S1_UINT_D15_UNORM
,
4900 WINED3DFMT_D16_UNORM
,
4901 WINED3DFMT_X8D24_UNORM
,
4902 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4903 WINED3DFMT_D24_UNORM_S8_UINT
,
4904 WINED3DFMT_D32_UNORM
,
4907 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4908 iface
, debugstr_guid(device_iid
), callback
, context
);
4910 if (!callback
) return DDERR_INVALIDPARAMS
;
4912 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4913 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4914 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4916 TRACE("Asked for HAL device.\n");
4917 type
= WINED3DDEVTYPE_HAL
;
4919 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4920 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4922 TRACE("Asked for SW device.\n");
4923 type
= WINED3DDEVTYPE_SW
;
4925 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4927 TRACE("Asked for REF device.\n");
4928 type
= WINED3DDEVTYPE_REF
;
4930 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4932 TRACE("Asked for NULLREF device.\n");
4933 type
= WINED3DDEVTYPE_NULLREF
;
4937 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4938 type
= WINED3DDEVTYPE_HAL
;
4941 EnterCriticalSection(&ddraw_cs
);
4942 /* We need an adapter format from somewhere to please wined3d and WGL.
4943 * Use the current display mode. So far all cards offer the same depth
4944 * stencil format for all modes, but if some do not and applications do
4945 * not like that we'll have to find some workaround, like iterating over
4946 * all imaginable formats and collecting all the depth stencil formats we
4948 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &d3ddm
);
4950 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4952 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4953 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, formats
[i
], SURFACE_OPENGL
);
4956 DDPIXELFORMAT pformat
;
4958 memset(&pformat
, 0, sizeof(pformat
));
4959 pformat
.dwSize
= sizeof(pformat
);
4960 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4962 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4963 hr
= callback(&pformat
, context
);
4964 if (hr
!= DDENUMRET_OK
)
4966 TRACE("Format enumeration cancelled by application.\n");
4967 LeaveCriticalSection(&ddraw_cs
);
4972 TRACE("End of enumeration.\n");
4974 LeaveCriticalSection(&ddraw_cs
);
4978 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4979 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4981 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4983 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4984 iface
, debugstr_guid(device_iid
), callback
, context
);
4986 return d3d7_EnumZBufferFormats(&This
->IDirect3D7_iface
, device_iid
, callback
, context
);
4989 /*****************************************************************************
4990 * IDirect3D7::EvictManagedTextures
4992 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4993 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4998 * D3D_OK, because it's a stub
5000 *****************************************************************************/
5001 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
5003 FIXME("iface %p stub!\n", iface
);
5005 /* TODO: Just enumerate resources using IWineD3DDevice_EnumResources(),
5006 * then unload surfaces / textures. */
5011 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
5013 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
5015 TRACE("iface %p.\n", iface
);
5017 return d3d7_EvictManagedTextures(&This
->IDirect3D7_iface
);
5020 /*****************************************************************************
5021 * IDirect3DImpl_GetCaps
5023 * This function retrieves the device caps from wined3d
5024 * and converts it into a D3D7 and D3D - D3D3 structure
5025 * This is a helper function called from various places in ddraw
5028 * wined3d: The interface to get the caps from
5029 * desc1: Old D3D <3 structure to fill (needed)
5030 * desc7: D3D7 device desc structure to fill (needed)
5033 * D3D_OK on success, or the return value of IWineD3D::GetCaps
5035 *****************************************************************************/
5036 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
5038 WINED3DCAPS wined3d_caps
;
5041 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
5043 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
5045 EnterCriticalSection(&ddraw_cs
);
5046 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3DDEVTYPE_HAL
, &wined3d_caps
);
5047 LeaveCriticalSection(&ddraw_cs
);
5050 WARN("Failed to get device caps, hr %#x.\n", hr
);
5054 /* Copy the results into the d3d7 and d3d3 structures */
5055 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
5056 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
5057 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
5058 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
5059 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
5060 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
5061 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
5062 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
5063 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
5064 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
5065 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
5067 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
5068 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
5070 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
5071 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
5072 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
5073 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
5075 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
5076 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
5077 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
5078 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
5080 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
5081 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
5083 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
5084 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
5086 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
5087 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
5089 /* Remove all non-d3d7 caps */
5090 desc7
->dwDevCaps
&= (
5091 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
5092 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
5093 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
5094 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
5095 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
5096 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
5097 D3DDEVCAPS_HWRASTERIZATION
);
5099 desc7
->dwStencilCaps
&= (
5100 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
5101 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
5102 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
5106 desc7
->dwTextureOpCaps
&= (
5107 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
5108 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
5109 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
5110 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
5111 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
5112 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
5113 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
5114 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
5116 desc7
->dwVertexProcessingCaps
&= (
5117 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
5118 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
5120 desc7
->dpcLineCaps
.dwMiscCaps
&= (
5121 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
5122 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
5123 D3DPMISCCAPS_CULLCCW
);
5125 desc7
->dpcLineCaps
.dwRasterCaps
&= (
5126 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
5127 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
5128 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
5129 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
5130 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
5131 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
5132 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
5133 D3DPRASTERCAPS_ZFOG
);
5135 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
5136 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
5137 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
5138 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
5140 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
5141 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
5142 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
5143 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
5144 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
5145 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
5147 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
5148 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
5149 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
5150 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
5151 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
5152 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
5154 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
5155 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
5156 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
5157 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
5159 desc7
->dpcLineCaps
.dwShadeCaps
&= (
5160 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
5161 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
5162 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
5163 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
5164 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
5165 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
5166 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
5168 desc7
->dpcLineCaps
.dwTextureCaps
&= (
5169 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
5170 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
5171 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
5172 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
5174 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
5175 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
5176 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
5177 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
5178 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
5179 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
5180 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
5182 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
5183 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
5184 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
5185 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
5187 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
5188 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
5189 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
5191 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
5193 /* DirectX7 always has the np2 flag set, no matter what the card
5194 * supports. Some old games (Rollcage) check the caps incorrectly.
5195 * If wined3d supports nonpow2 textures it also has np2 conditional
5197 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
5200 /* Fill the missing members, and do some fixup */
5201 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
5202 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
5203 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
5204 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
5205 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
5206 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
5207 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
5208 /* Use the same for the TriCaps */
5209 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
5211 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
5212 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
5213 desc7
->dwMinTextureWidth
= 1;
5214 desc7
->dwMinTextureHeight
= 1;
5216 /* Convert DWORDs safely to WORDs */
5217 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
5218 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
5219 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
5220 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
5222 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
5223 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
5224 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
5225 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
5227 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
5229 desc7
->dwReserved1
= 0;
5230 desc7
->dwReserved2
= 0;
5231 desc7
->dwReserved3
= 0;
5232 desc7
->dwReserved4
= 0;
5234 /* Fill the old structure */
5235 memset(desc1
, 0, sizeof(*desc1
));
5236 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
5237 desc1
->dwFlags
= D3DDD_COLORMODEL
5239 | D3DDD_TRANSFORMCAPS
5241 | D3DDD_LIGHTINGCAPS
5244 | D3DDD_DEVICERENDERBITDEPTH
5245 | D3DDD_DEVICEZBUFFERBITDEPTH
5246 | D3DDD_MAXBUFFERSIZE
5247 | D3DDD_MAXVERTEXCOUNT
;
5249 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
5250 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
5251 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
5252 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
5253 desc1
->bClipping
= TRUE
;
5254 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
5255 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
5256 | D3DLIGHTCAPS_PARALLELPOINT
5257 | D3DLIGHTCAPS_POINT
5258 | D3DLIGHTCAPS_SPOT
;
5260 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
5261 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
5263 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5264 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
5265 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
5266 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
5267 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
5268 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
5269 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
5270 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
5271 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
5272 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
5273 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
5274 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
5275 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
5277 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5278 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
5279 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
5280 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
5281 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
5282 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
5283 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
5284 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
5285 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
5286 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
5287 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
5288 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
5289 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
5291 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
5292 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
5293 desc1
->dwMaxBufferSize
= 0;
5294 desc1
->dwMaxVertexCount
= 65536;
5295 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
5296 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
5297 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
5298 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
5299 desc1
->dwMinStippleWidth
= 1;
5300 desc1
->dwMinStippleHeight
= 1;
5301 desc1
->dwMaxStippleWidth
= 32;
5302 desc1
->dwMaxStippleHeight
= 32;
5303 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
5304 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
5305 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
5306 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
5307 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
5308 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
5309 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
5310 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
5311 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
5312 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
5313 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
5314 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
5315 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
5320 /*****************************************************************************
5321 * IDirectDraw7 VTable
5322 *****************************************************************************/
5323 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
5326 ddraw7_QueryInterface
,
5331 ddraw7_CreateClipper
,
5332 ddraw7_CreatePalette
,
5333 ddraw7_CreateSurface
,
5334 ddraw7_DuplicateSurface
,
5335 ddraw7_EnumDisplayModes
,
5336 ddraw7_EnumSurfaces
,
5337 ddraw7_FlipToGDISurface
,
5339 ddraw7_GetDisplayMode
,
5340 ddraw7_GetFourCCCodes
,
5341 ddraw7_GetGDISurface
,
5342 ddraw7_GetMonitorFrequency
,
5344 ddraw7_GetVerticalBlankStatus
,
5346 ddraw7_RestoreDisplayMode
,
5347 ddraw7_SetCooperativeLevel
,
5348 ddraw7_SetDisplayMode
,
5349 ddraw7_WaitForVerticalBlank
,
5351 ddraw7_GetAvailableVidMem
,
5353 ddraw7_GetSurfaceFromDC
,
5355 ddraw7_RestoreAllSurfaces
,
5356 ddraw7_TestCooperativeLevel
,
5357 ddraw7_GetDeviceIdentifier
,
5359 ddraw7_StartModeTest
,
5363 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
5366 ddraw4_QueryInterface
,
5371 ddraw4_CreateClipper
,
5372 ddraw4_CreatePalette
,
5373 ddraw4_CreateSurface
,
5374 ddraw4_DuplicateSurface
,
5375 ddraw4_EnumDisplayModes
,
5376 ddraw4_EnumSurfaces
,
5377 ddraw4_FlipToGDISurface
,
5379 ddraw4_GetDisplayMode
,
5380 ddraw4_GetFourCCCodes
,
5381 ddraw4_GetGDISurface
,
5382 ddraw4_GetMonitorFrequency
,
5384 ddraw4_GetVerticalBlankStatus
,
5386 ddraw4_RestoreDisplayMode
,
5387 ddraw4_SetCooperativeLevel
,
5388 ddraw4_SetDisplayMode
,
5389 ddraw4_WaitForVerticalBlank
,
5391 ddraw4_GetAvailableVidMem
,
5393 ddraw4_GetSurfaceFromDC
,
5395 ddraw4_RestoreAllSurfaces
,
5396 ddraw4_TestCooperativeLevel
,
5397 ddraw4_GetDeviceIdentifier
,
5400 static const struct IDirectDraw3Vtbl ddraw3_vtbl
=
5403 ddraw3_QueryInterface
,
5408 ddraw3_CreateClipper
,
5409 ddraw3_CreatePalette
,
5410 ddraw3_CreateSurface
,
5411 ddraw3_DuplicateSurface
,
5412 ddraw3_EnumDisplayModes
,
5413 ddraw3_EnumSurfaces
,
5414 ddraw3_FlipToGDISurface
,
5416 ddraw3_GetDisplayMode
,
5417 ddraw3_GetFourCCCodes
,
5418 ddraw3_GetGDISurface
,
5419 ddraw3_GetMonitorFrequency
,
5421 ddraw3_GetVerticalBlankStatus
,
5423 ddraw3_RestoreDisplayMode
,
5424 ddraw3_SetCooperativeLevel
,
5425 ddraw3_SetDisplayMode
,
5426 ddraw3_WaitForVerticalBlank
,
5428 ddraw3_GetAvailableVidMem
,
5430 ddraw3_GetSurfaceFromDC
,
5433 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5436 ddraw2_QueryInterface
,
5441 ddraw2_CreateClipper
,
5442 ddraw2_CreatePalette
,
5443 ddraw2_CreateSurface
,
5444 ddraw2_DuplicateSurface
,
5445 ddraw2_EnumDisplayModes
,
5446 ddraw2_EnumSurfaces
,
5447 ddraw2_FlipToGDISurface
,
5449 ddraw2_GetDisplayMode
,
5450 ddraw2_GetFourCCCodes
,
5451 ddraw2_GetGDISurface
,
5452 ddraw2_GetMonitorFrequency
,
5454 ddraw2_GetVerticalBlankStatus
,
5456 ddraw2_RestoreDisplayMode
,
5457 ddraw2_SetCooperativeLevel
,
5458 ddraw2_SetDisplayMode
,
5459 ddraw2_WaitForVerticalBlank
,
5461 ddraw2_GetAvailableVidMem
,
5464 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5467 ddraw1_QueryInterface
,
5472 ddraw1_CreateClipper
,
5473 ddraw1_CreatePalette
,
5474 ddraw1_CreateSurface
,
5475 ddraw1_DuplicateSurface
,
5476 ddraw1_EnumDisplayModes
,
5477 ddraw1_EnumSurfaces
,
5478 ddraw1_FlipToGDISurface
,
5480 ddraw1_GetDisplayMode
,
5481 ddraw1_GetFourCCCodes
,
5482 ddraw1_GetGDISurface
,
5483 ddraw1_GetMonitorFrequency
,
5485 ddraw1_GetVerticalBlankStatus
,
5487 ddraw1_RestoreDisplayMode
,
5488 ddraw1_SetCooperativeLevel
,
5489 ddraw1_SetDisplayMode
,
5490 ddraw1_WaitForVerticalBlank
,
5493 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5495 /* IUnknown methods */
5496 d3d7_QueryInterface
,
5499 /* IDirect3D7 methods */
5502 d3d7_CreateVertexBuffer
,
5503 d3d7_EnumZBufferFormats
,
5504 d3d7_EvictManagedTextures
5507 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5509 /* IUnknown methods */
5510 d3d3_QueryInterface
,
5513 /* IDirect3D3 methods */
5516 d3d3_CreateMaterial
,
5517 d3d3_CreateViewport
,
5520 d3d3_CreateVertexBuffer
,
5521 d3d3_EnumZBufferFormats
,
5522 d3d3_EvictManagedTextures
5525 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5527 /* IUnknown methods */
5528 d3d2_QueryInterface
,
5531 /* IDirect3D2 methods */
5534 d3d2_CreateMaterial
,
5535 d3d2_CreateViewport
,
5540 static const struct IDirect3DVtbl d3d1_vtbl
=
5542 /* IUnknown methods */
5543 d3d1_QueryInterface
,
5546 /* IDirect3D methods */
5550 d3d1_CreateMaterial
,
5551 d3d1_CreateViewport
,
5555 /*****************************************************************************
5558 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5559 * if none was found.
5561 * This function is in ddraw.c and the DDraw object space because D3D7
5562 * vertex buffers are created using the IDirect3D interface to the ddraw
5563 * object, so they can be valid across D3D devices(theoretically. The ddraw
5564 * object also owns the wined3d device
5568 * fvf: Fvf to find the decl for
5571 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5573 *****************************************************************************/
5574 struct wined3d_vertex_declaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5576 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5578 int p
, low
, high
; /* deliberately signed */
5579 struct FvfToDecl
*convertedDecls
= This
->decls
;
5581 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5584 high
= This
->numConvertedDecls
- 1;
5585 while(low
<= high
) {
5586 p
= (low
+ high
) >> 1;
5588 if(convertedDecls
[p
].fvf
== fvf
) {
5589 TRACE("found %p\n", convertedDecls
[p
].decl
);
5590 return convertedDecls
[p
].decl
;
5591 } else if(convertedDecls
[p
].fvf
< fvf
) {
5597 TRACE("not found. Creating and inserting at position %d.\n", low
);
5599 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5600 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5601 if (hr
!= S_OK
) return NULL
;
5603 if(This
->declArraySize
== This
->numConvertedDecls
) {
5604 int grow
= max(This
->declArraySize
/ 2, 8);
5605 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5606 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5607 if (!convertedDecls
)
5609 wined3d_vertex_declaration_decref(pDecl
);
5612 This
->decls
= convertedDecls
;
5613 This
->declArraySize
+= grow
;
5616 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5617 convertedDecls
[low
].decl
= pDecl
;
5618 convertedDecls
[low
].fvf
= fvf
;
5619 This
->numConvertedDecls
++;
5621 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5625 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5627 return CONTAINING_RECORD(device_parent
, struct IDirectDrawImpl
, device_parent
);
5630 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5631 struct wined3d_device
*device
)
5633 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5636 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
5637 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5638 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, struct wined3d_surface
**surface
)
5640 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5641 IDirectDrawSurfaceImpl
*surf
= NULL
;
5643 DDSCAPS2 searchcaps
= ddraw
->tex_root
->surface_desc
.ddsCaps
;
5645 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5646 "\tpool %#x, level %u, face %u, surface %p.\n",
5647 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5649 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5652 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
5653 TRACE("Asked for positive x\n");
5654 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5656 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5658 surf
= ddraw
->tex_root
; break;
5659 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
5660 TRACE("Asked for negative x\n");
5661 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5662 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
5663 TRACE("Asked for positive y\n");
5664 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5665 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
5666 TRACE("Asked for negative y\n");
5667 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5668 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
5669 TRACE("Asked for positive z\n");
5670 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5671 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
5672 TRACE("Asked for negative z\n");
5673 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5674 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
5679 IDirectDrawSurface7
*attached
;
5680 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)ddraw
->tex_root
, &searchcaps
, &attached
);
5681 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5682 IDirectDrawSurface7_Release(attached
);
5684 if (!surf
) ERR("root search surface not found\n");
5686 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5689 IDirectDrawSurface7
*attached
;
5690 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &searchcaps
, &attached
);
5691 if(!attached
) ERR("Surface not found\n");
5692 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5693 IDirectDrawSurface7_Release(attached
);
5697 /* Return the surface */
5698 *surface
= surf
->wined3d_surface
;
5699 wined3d_surface_incref(*surface
);
5701 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5706 static HRESULT WINAPI
findRenderTarget(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *ctx
)
5708 IDirectDrawSurfaceImpl
*s
= (IDirectDrawSurfaceImpl
*)surface
;
5709 IDirectDrawSurfaceImpl
**target
= ctx
;
5711 if (!s
->isRenderTarget
)
5714 IDirectDrawSurface7_Release(surface
);
5715 return DDENUMRET_CANCEL
;
5718 /* Recurse into the surface tree */
5719 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
5721 IDirectDrawSurface7_Release(surface
);
5722 if (*target
) return DDENUMRET_CANCEL
;
5724 return DDENUMRET_OK
;
5727 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
5728 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5729 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5730 struct wined3d_surface
**surface
)
5732 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5733 IDirectDrawSurfaceImpl
*d3d_surface
= ddraw
->d3d_target
;
5734 IDirectDrawSurfaceImpl
*target
= NULL
;
5736 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5737 "\tmultisample_quality %u, lockable %u, surface %p.\n",
5738 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
5739 multisample_quality
, lockable
, surface
);
5741 if (d3d_surface
->isRenderTarget
)
5743 IDirectDrawSurface7_EnumAttachedSurfaces((IDirectDrawSurface7
*)d3d_surface
, &target
, findRenderTarget
);
5747 target
= d3d_surface
;
5752 target
= ddraw
->d3d_target
;
5753 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", ddraw
);
5756 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
5758 *surface
= target
->wined3d_surface
;
5759 wined3d_surface_incref(*surface
);
5760 target
->isRenderTarget
= TRUE
;
5762 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, d3d_surface
);
5767 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
5768 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
5769 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
5771 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5772 IDirectDrawSurfaceImpl
*ddraw_surface
;
5773 DDSURFACEDESC2 ddsd
;
5776 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5777 "\tmultisample_quality %u, discard %u, surface %p.\n",
5778 device_parent
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
5782 /* Create a DirectDraw surface */
5783 memset(&ddsd
, 0, sizeof(ddsd
));
5784 ddsd
.dwSize
= sizeof(ddsd
);
5785 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
5786 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
5787 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5788 ddsd
.dwHeight
= height
;
5789 ddsd
.dwWidth
= width
;
5792 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, format
);
5796 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
5799 ddraw
->depthstencil
= TRUE
;
5800 hr
= IDirectDraw7_CreateSurface(&ddraw
->IDirectDraw7_iface
, &ddsd
,
5801 (IDirectDrawSurface7
**)&ddraw_surface
, NULL
);
5802 ddraw
->depthstencil
= FALSE
;
5805 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr
);
5809 *surface
= ddraw_surface
->wined3d_surface
;
5810 wined3d_surface_incref(*surface
);
5811 IDirectDrawSurface7_Release((IDirectDrawSurface7
*)ddraw_surface
);
5816 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5817 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5818 WINED3DPOOL pool
, DWORD usage
, struct wined3d_volume
**volume
)
5820 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5821 "format %#x, pool %#x, usage %#x, volume %p.\n",
5822 device_parent
, container_parent
, width
, height
, depth
,
5823 format
, pool
, usage
, volume
);
5825 ERR("Not implemented!\n");
5830 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5831 WINED3DPRESENT_PARAMETERS
*present_parameters
, struct wined3d_swapchain
**swapchain
)
5833 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5834 IDirectDrawSurfaceImpl
*iterator
;
5837 TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent
, present_parameters
, swapchain
);
5839 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, present_parameters
,
5840 ddraw
->ImplType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5843 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5848 ddraw
->d3d_target
->wined3d_swapchain
= *swapchain
;
5849 iterator
= ddraw
->d3d_target
->complex_array
[0];
5852 iterator
->wined3d_swapchain
= *swapchain
;
5853 iterator
= iterator
->complex_array
[0];
5859 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5861 device_parent_wined3d_device_created
,
5862 device_parent_create_surface
,
5863 device_parent_create_rendertarget
,
5864 device_parent_create_depth_stencil
,
5865 device_parent_create_volume
,
5866 device_parent_create_swapchain
,
5869 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, WINED3DDEVTYPE device_type
)
5874 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5875 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5876 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5877 ddraw
->IDirectDraw3_iface
.lpVtbl
= &ddraw3_vtbl
;
5878 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5879 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5880 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5881 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5882 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5883 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5884 ddraw
->numIfaces
= 1;
5887 /* See comments in IDirectDrawImpl_CreateNewSurface for a description of
5889 ddraw
->ImplType
= DefaultSurfaceType
;
5891 /* Get the current screen settings. */
5893 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5895 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5896 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5898 ddraw
->wineD3D
= wined3d_create(7, &ddraw
->IDirectDraw7_iface
);
5899 if (!ddraw
->wineD3D
)
5901 WARN("Failed to create a wined3d object.\n");
5902 return E_OUTOFMEMORY
;
5905 hr
= wined3d_device_create(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, device_type
,
5906 NULL
, 0, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5909 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5910 wined3d_decref(ddraw
->wineD3D
);
5914 /* Get the amount of video memory */
5915 ddraw
->total_vidmem
= wined3d_device_get_available_texture_mem(ddraw
->wined3d_device
);
5917 list_init(&ddraw
->surface_list
);