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
*ddraw_from_ddraw1(IDirectDraw
*iface
)
51 return (IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(IDirectDrawImpl
, IDirectDraw_vtbl
));
54 static inline IDirectDrawImpl
*ddraw_from_ddraw2(IDirectDraw2
*iface
)
56 return (IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(IDirectDrawImpl
, IDirectDraw2_vtbl
));
59 static inline IDirectDrawImpl
*ddraw_from_ddraw3(IDirectDraw3
*iface
)
61 return (IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(IDirectDrawImpl
, IDirectDraw3_vtbl
));
64 static inline IDirectDrawImpl
*ddraw_from_ddraw4(IDirectDraw4
*iface
)
66 return (IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(IDirectDrawImpl
, IDirectDraw4_vtbl
));
69 /*****************************************************************************
71 *****************************************************************************/
73 /*****************************************************************************
74 * IDirectDraw7::QueryInterface
76 * Queries different interfaces of the DirectDraw object. It can return
77 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
78 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
80 * The returned interface is AddRef()-ed before it's returned
82 * Used for version 1, 2, 4 and 7
85 * refiid: Interface ID asked for
86 * obj: Used to return the interface pointer
89 * S_OK if an interface was found
90 * E_NOINTERFACE if the requested interface wasn't found
92 *****************************************************************************/
93 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
95 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
97 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
99 /* Can change surface impl type */
100 EnterCriticalSection(&ddraw_cs
);
102 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
107 LeaveCriticalSection(&ddraw_cs
);
108 return DDERR_INVALIDPARAMS
;
111 /* Check DirectDraw Interfaces */
112 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
113 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
116 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
118 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
120 *obj
= &This
->IDirectDraw4_vtbl
;
121 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
123 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
125 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
126 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
128 LeaveCriticalSection(&ddraw_cs
);
129 return E_NOINTERFACE
;
131 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
133 *obj
= &This
->IDirectDraw2_vtbl
;
134 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
136 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
138 *obj
= &This
->IDirectDraw_vtbl
;
139 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
143 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
144 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
145 * who had this idea and why. The older interfaces can query and IDirect3D version
146 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
147 * and messy to implement with the common creation function, so it has been left out here.
149 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
150 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
151 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
152 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
154 /* Check the surface implementation */
155 if(This
->ImplType
== SURFACE_UNKNOWN
)
157 /* Apps may create the IDirect3D Interface before the primary surface.
158 * set the surface implementation */
159 This
->ImplType
= SURFACE_OPENGL
;
160 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
162 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
164 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
165 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
166 /* Should I assert(0) here??? */
168 else if(This
->ImplType
!= SURFACE_OPENGL
)
170 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
171 /* Do not abort here, only reject 3D Device creation */
174 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
176 This
->d3dversion
= 1;
177 *obj
= &This
->IDirect3D_vtbl
;
178 TRACE(" returning Direct3D interface at %p.\n", *obj
);
180 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
182 This
->d3dversion
= 2;
183 *obj
= &This
->IDirect3D2_vtbl
;
184 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
186 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
188 This
->d3dversion
= 3;
189 *obj
= &This
->IDirect3D3_vtbl
;
190 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
192 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
194 This
->d3dversion
= 7;
195 *obj
= &This
->IDirect3D7_vtbl
;
196 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
199 else if (IsEqualGUID(refiid
, &IID_IWineD3DDeviceParent
))
201 *obj
= &This
->device_parent_vtbl
;
204 /* Unknown interface */
207 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
208 LeaveCriticalSection(&ddraw_cs
);
209 return E_NOINTERFACE
;
212 IUnknown_AddRef( (IUnknown
*) *obj
);
213 LeaveCriticalSection(&ddraw_cs
);
217 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
219 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
221 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_ddraw4(iface
), riid
, object
);
224 static HRESULT WINAPI
ddraw3_QueryInterface(IDirectDraw3
*iface
, REFIID riid
, void **object
)
226 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
228 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_ddraw3(iface
), riid
, object
);
231 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
233 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
235 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_ddraw2(iface
), riid
, object
);
238 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
240 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
242 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_ddraw1(iface
), riid
, object
);
245 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
247 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
249 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_d3d7(iface
), riid
, object
);
252 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
254 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
256 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_d3d3(iface
), riid
, object
);
259 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
261 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
263 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_d3d2(iface
), riid
, object
);
266 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
268 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
270 return ddraw7_QueryInterface((IDirectDraw7
*)ddraw_from_d3d1(iface
), riid
, object
);
273 /*****************************************************************************
274 * IDirectDraw7::AddRef
276 * Increases the interfaces refcount, basically
278 * DDraw refcounting is a bit tricky. The different DirectDraw interface
279 * versions have individual refcounts, but the IDirect3D interfaces do not.
280 * All interfaces are from one object, that means calling QueryInterface on an
281 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
282 * IDirectDrawImpl object.
284 * That means all AddRef and Release implementations of IDirectDrawX work
285 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
286 * except of IDirect3D7 which thunks to IDirectDraw7
288 * Returns: The new refcount
290 *****************************************************************************/
291 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
293 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
294 ULONG ref
= InterlockedIncrement(&This
->ref7
);
296 TRACE("%p increasing refcount to %u.\n", This
, ref
);
298 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
303 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
305 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw4(iface
);
306 ULONG ref
= InterlockedIncrement(&ddraw
->ref4
);
308 TRACE("%p increasing refcount to %u.\n", ddraw
, ref
);
310 if (ref
== 1) InterlockedIncrement(&ddraw
->numIfaces
);
315 static ULONG WINAPI
ddraw3_AddRef(IDirectDraw3
*iface
)
317 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw3(iface
);
318 ULONG ref
= InterlockedIncrement(&ddraw
->ref3
);
320 TRACE("%p increasing refcount to %u.\n", ddraw
, ref
);
322 if (ref
== 1) InterlockedIncrement(&ddraw
->numIfaces
);
327 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
329 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw2(iface
);
330 ULONG ref
= InterlockedIncrement(&ddraw
->ref2
);
332 TRACE("%p increasing refcount to %u.\n", ddraw
, ref
);
334 if (ref
== 1) InterlockedIncrement(&ddraw
->numIfaces
);
339 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
341 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw1(iface
);
342 ULONG ref
= InterlockedIncrement(&ddraw
->ref1
);
344 TRACE("%p increasing refcount to %u.\n", ddraw
, ref
);
346 if (ref
== 1) InterlockedIncrement(&ddraw
->numIfaces
);
351 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
353 TRACE("iface %p.\n", iface
);
355 return ddraw7_AddRef((IDirectDraw7
*)ddraw_from_d3d7(iface
));
358 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
360 TRACE("iface %p.\n", iface
);
362 return ddraw1_AddRef((IDirectDraw
*)&ddraw_from_d3d3(iface
)->IDirectDraw_vtbl
);
365 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
367 TRACE("iface %p.\n", iface
);
369 return ddraw1_AddRef((IDirectDraw
*)&ddraw_from_d3d2(iface
)->IDirectDraw_vtbl
);
372 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
374 TRACE("iface %p.\n", iface
);
376 return ddraw1_AddRef((IDirectDraw
*)&ddraw_from_d3d1(iface
)->IDirectDraw_vtbl
);
379 /*****************************************************************************
382 * Destroys a ddraw object if all refcounts are 0. This is to share code
383 * between the IDirectDrawX::Release functions
386 * This: DirectDraw object to destroy
388 *****************************************************************************/
389 static void ddraw_destroy(IDirectDrawImpl
*This
)
391 IDirectDraw7_SetCooperativeLevel((IDirectDraw7
*)This
, NULL
, DDSCL_NORMAL
);
392 IDirectDraw7_RestoreDisplayMode((IDirectDraw7
*)This
);
394 /* Destroy the device window if we created one */
395 if(This
->devicewindow
!= 0)
397 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
398 DestroyWindow(This
->devicewindow
);
399 This
->devicewindow
= 0;
402 EnterCriticalSection(&ddraw_cs
);
403 list_remove(&This
->ddraw_list_entry
);
404 LeaveCriticalSection(&ddraw_cs
);
406 /* Release the attached WineD3D stuff */
407 IWineD3DDevice_Release(This
->wineD3DDevice
);
408 IWineD3D_Release(This
->wineD3D
);
410 /* Now free the object */
411 HeapFree(GetProcessHeap(), 0, This
);
414 /*****************************************************************************
415 * IDirectDraw7::Release
417 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
419 * Returns: The new refcount
420 *****************************************************************************/
421 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
423 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
424 ULONG ref
= InterlockedDecrement(&This
->ref7
);
426 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
428 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
434 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
436 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw4(iface
);
437 ULONG ref
= InterlockedDecrement(&ddraw
->ref4
);
439 TRACE("%p decreasing refcount to %u.\n", ddraw
, ref
);
441 if (!ref
&& !InterlockedDecrement(&ddraw
->numIfaces
))
442 ddraw_destroy(ddraw
);
447 static ULONG WINAPI
ddraw3_Release(IDirectDraw3
*iface
)
449 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw3(iface
);
450 ULONG ref
= InterlockedDecrement(&ddraw
->ref3
);
452 TRACE("%p decreasing refcount to %u.\n", ddraw
, ref
);
454 if (!ref
&& !InterlockedDecrement(&ddraw
->numIfaces
))
455 ddraw_destroy(ddraw
);
460 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
462 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw2(iface
);
463 ULONG ref
= InterlockedDecrement(&ddraw
->ref2
);
465 TRACE("%p decreasing refcount to %u.\n", ddraw
, ref
);
467 if (!ref
&& !InterlockedDecrement(&ddraw
->numIfaces
))
468 ddraw_destroy(ddraw
);
473 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
475 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw1(iface
);
476 ULONG ref
= InterlockedDecrement(&ddraw
->ref1
);
478 TRACE("%p decreasing refcount to %u.\n", ddraw
, ref
);
480 if (!ref
&& !InterlockedDecrement(&ddraw
->numIfaces
))
481 ddraw_destroy(ddraw
);
486 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
488 TRACE("iface %p.\n", iface
);
490 return ddraw7_Release((IDirectDraw7
*)ddraw_from_d3d7(iface
));
493 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
495 TRACE("iface %p.\n", iface
);
497 return ddraw1_Release((IDirectDraw
*)&ddraw_from_d3d3(iface
)->IDirectDraw_vtbl
);
500 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
502 TRACE("iface %p.\n", iface
);
504 return ddraw1_Release((IDirectDraw
*)&ddraw_from_d3d2(iface
)->IDirectDraw_vtbl
);
507 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
509 TRACE("iface %p.\n", iface
);
511 return ddraw1_Release((IDirectDraw
*)&ddraw_from_d3d1(iface
)->IDirectDraw_vtbl
);
514 /*****************************************************************************
515 * IDirectDraw methods
516 *****************************************************************************/
518 /*****************************************************************************
519 * IDirectDraw7::SetCooperativeLevel
521 * Sets the cooperative level for the DirectDraw object, and the window
522 * assigned to it. The cooperative level determines the general behavior
523 * of the DirectDraw application
525 * Warning: This is quite tricky, as it's not really documented which
526 * cooperative levels can be combined with each other. If a game fails
527 * after this function, try to check the cooperative levels passed on
528 * Windows, and if it returns something different.
530 * If you think that this function caused the failure because it writes a
531 * fixme, be sure to run again with a +ddraw trace.
533 * What is known about cooperative levels (See the ddraw modes test):
534 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
535 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
536 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
537 * DDSCL_FULLSCREEN can be activated
538 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
540 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
541 * DDSCL_SETFOCUSWINDOW (partially),
542 * DDSCL_MULTITHREADED (work in progress)
544 * Unhandled flags, which should be implemented
545 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
546 * expect any difference to a normal window for wine)
547 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
548 * rendering (Possible test case: Half-Life)
550 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
552 * These don't seem very important for wine:
553 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
556 * DD_OK if the cooperative level was set successfully
557 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
558 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
559 * (Probably others too, have to investigate)
561 *****************************************************************************/
562 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
564 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
567 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
568 DDRAW_dump_cooperativelevel(cooplevel
);
570 EnterCriticalSection(&ddraw_cs
);
572 /* Get the old window */
573 window
= This
->dest_window
;
575 /* Tests suggest that we need one of them: */
576 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
580 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
581 LeaveCriticalSection(&ddraw_cs
);
582 return DDERR_INVALIDPARAMS
;
585 /* Handle those levels first which set various hwnds */
586 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
588 /* This isn't compatible with a lot of flags */
589 if(cooplevel
& ( DDSCL_MULTITHREADED
|
590 DDSCL_CREATEDEVICEWINDOW
|
595 DDSCL_SETDEVICEWINDOW
|
600 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
601 LeaveCriticalSection(&ddraw_cs
);
602 return DDERR_INVALIDPARAMS
;
605 if( (This
->cooperative_level
& DDSCL_EXCLUSIVE
) && window
)
607 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
608 LeaveCriticalSection(&ddraw_cs
);
609 return DDERR_HWNDALREADYSET
;
612 This
->focuswindow
= hwnd
;
613 /* Won't use the hwnd param for anything else */
616 /* Use the focus window for drawing too */
617 This
->dest_window
= This
->focuswindow
;
619 /* Destroy the device window, if we have one */
620 if(This
->devicewindow
)
622 DestroyWindow(This
->devicewindow
);
623 This
->devicewindow
= NULL
;
626 LeaveCriticalSection(&ddraw_cs
);
630 if(cooplevel
& DDSCL_EXCLUSIVE
)
632 if( !(cooplevel
& DDSCL_FULLSCREEN
) || !hwnd
)
634 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This
);
635 LeaveCriticalSection(&ddraw_cs
);
636 return DDERR_INVALIDPARAMS
;
639 else if( !(cooplevel
& DDSCL_NORMAL
) )
641 TRACE("(%p) SetCooperativeLevel needs at least SetFocusWindow or Exclusive or Normal mode\n", This
);
642 LeaveCriticalSection(&ddraw_cs
);
643 return DDERR_INVALIDPARAMS
;
646 /* Do we switch from fullscreen to non-fullscreen ? */
648 if( !(cooplevel
& DDSCL_FULLSCREEN
) && (This
->cooperative_level
& DDSCL_FULLSCREEN
) )
649 IWineD3DDevice_ReleaseFocusWindow(This
->wineD3DDevice
);
651 /* Don't override focus windows or private device windows */
652 if( hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
654 if( cooplevel
& DDSCL_FULLSCREEN
)
656 HRESULT hr
= IWineD3DDevice_AcquireFocusWindow(This
->wineD3DDevice
, hwnd
);
659 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
660 LeaveCriticalSection(&ddraw_cs
);
664 This
->dest_window
= hwnd
;
667 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
669 /* Don't create a device window if a focus window is set */
670 if( !(This
->focuswindow
) )
672 HWND devicewindow
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DDraw device window",
673 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
674 NULL
, NULL
, NULL
, NULL
);
677 ERR("Failed to create window, last error %#x.\n", GetLastError());
678 LeaveCriticalSection(&ddraw_cs
);
682 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
683 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
685 This
->devicewindow
= devicewindow
;
686 This
->dest_window
= devicewindow
;
690 if(cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
692 /* Enable thread safety in wined3d */
693 IWineD3DDevice_SetMultithreaded(This
->wineD3DDevice
);
696 /* Unhandled flags */
697 if(cooplevel
& DDSCL_ALLOWREBOOT
)
698 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
699 if(cooplevel
& DDSCL_ALLOWMODEX
)
700 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
701 if(cooplevel
& DDSCL_FPUSETUP
)
702 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
704 /* Store the cooperative_level */
705 This
->cooperative_level
= cooplevel
;
706 TRACE("SetCooperativeLevel retuning DD_OK\n");
707 LeaveCriticalSection(&ddraw_cs
);
711 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
713 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
715 return ddraw7_SetCooperativeLevel((IDirectDraw7
*)ddraw_from_ddraw4(iface
), window
, flags
);
718 static HRESULT WINAPI
ddraw3_SetCooperativeLevel(IDirectDraw3
*iface
, HWND window
, DWORD flags
)
720 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
722 return ddraw7_SetCooperativeLevel((IDirectDraw7
*)ddraw_from_ddraw3(iface
), window
, flags
);
725 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
727 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
729 return ddraw7_SetCooperativeLevel((IDirectDraw7
*)ddraw_from_ddraw2(iface
), window
, flags
);
732 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
734 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
736 return ddraw7_SetCooperativeLevel((IDirectDraw7
*)ddraw_from_ddraw1(iface
), window
, flags
);
739 /*****************************************************************************
741 * Helper function for SetDisplayMode and RestoreDisplayMode
743 * Implements DirectDraw's SetDisplayMode, but ignores the value of
744 * ForceRefreshRate, since it is already handled by
745 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
746 * without worrying that ForceRefreshRate will override the refresh rate. For
747 * argument and return value documentation, see
748 * ddraw7_SetDisplayMode.
750 *****************************************************************************/
751 static HRESULT
ddraw_set_display_mode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
752 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
754 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
755 WINED3DDISPLAYMODE Mode
;
758 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
759 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
761 EnterCriticalSection(&ddraw_cs
);
762 if( !Width
|| !Height
)
764 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
765 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
766 LeaveCriticalSection(&ddraw_cs
);
770 /* Check the exclusive mode
771 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
772 return DDERR_NOEXCLUSIVEMODE;
773 * This is WRONG. Don't know if the SDK is completely
774 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
775 * is returned, but Half-Life 1.1.1.1 (Steam version)
780 Mode
.Height
= Height
;
781 Mode
.RefreshRate
= RefreshRate
;
784 case 8: Mode
.Format
= WINED3DFMT_P8_UINT
; break;
785 case 15: Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
786 case 16: Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
; break;
787 case 24: Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
; break;
788 case 32: Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
791 /* TODO: The possible return values from msdn suggest that
792 * the screen mode can't be changed if a surface is locked
793 * or some drawing is in progress
796 /* TODO: Lose the primary surface */
797 hr
= IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
798 0, /* First swapchain */
800 LeaveCriticalSection(&ddraw_cs
);
803 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
808 /*****************************************************************************
809 * IDirectDraw7::SetDisplayMode
811 * Sets the display screen resolution, color depth and refresh frequency
812 * when in fullscreen mode (in theory).
813 * Possible return values listed in the SDK suggest that this method fails
814 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
815 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
816 * It seems to be valid to pass 0 for With and Height, this has to be tested
817 * It could mean that the current video mode should be left as-is. (But why
821 * Height, Width: Screen dimension
822 * BPP: Color depth in Bits per pixel
823 * Refreshrate: Screen refresh rate
829 *****************************************************************************/
830 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
831 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
833 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
834 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
836 if (force_refresh_rate
!= 0)
838 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
839 RefreshRate
, force_refresh_rate
);
840 RefreshRate
= force_refresh_rate
;
843 return ddraw_set_display_mode(iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
846 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
,
847 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
849 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
850 iface
, width
, height
, bpp
, refresh_rate
, flags
);
852 return ddraw7_SetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw4(iface
),
853 width
, height
, bpp
, refresh_rate
, flags
);
856 static HRESULT WINAPI
ddraw3_SetDisplayMode(IDirectDraw3
*iface
,
857 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
859 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
860 iface
, width
, height
, bpp
, refresh_rate
, flags
);
862 return ddraw7_SetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw3(iface
),
863 width
, height
, bpp
, refresh_rate
, flags
);
866 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
867 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
869 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
870 iface
, width
, height
, bpp
, refresh_rate
, flags
);
872 return ddraw7_SetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw2(iface
),
873 width
, height
, bpp
, refresh_rate
, flags
);
876 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
878 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
880 return ddraw7_SetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw1(iface
), width
, height
, bpp
, 0, 0);
883 /*****************************************************************************
884 * IDirectDraw7::RestoreDisplayMode
886 * Restores the display mode to what it was at creation time. Basically.
888 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
889 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
890 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
891 * -> DD_1 is released. The screen should be left at 1024x768x32.
892 * -> DD_2 is released. The screen should be set to 1400x1050x32
893 * This case is unhandled right now, but Empire Earth does it this way.
894 * (But perhaps there is something in SetCooperativeLevel to prevent this)
896 * The msdn says that this method resets the display mode to what it was before
897 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
901 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
903 *****************************************************************************/
904 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
906 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
908 TRACE("iface %p.\n", iface
);
910 return ddraw_set_display_mode(iface
, This
->orig_width
, This
->orig_height
, This
->orig_bpp
, 0, 0);
913 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
915 TRACE("iface %p.\n", iface
);
917 return ddraw7_RestoreDisplayMode((IDirectDraw7
*)ddraw_from_ddraw4(iface
));
920 static HRESULT WINAPI
ddraw3_RestoreDisplayMode(IDirectDraw3
*iface
)
922 TRACE("iface %p.\n", iface
);
924 return ddraw7_RestoreDisplayMode((IDirectDraw7
*)ddraw_from_ddraw3(iface
));
927 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
929 TRACE("iface %p.\n", iface
);
931 return ddraw7_RestoreDisplayMode((IDirectDraw7
*)ddraw_from_ddraw2(iface
));
934 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
936 TRACE("iface %p.\n", iface
);
938 return ddraw7_RestoreDisplayMode((IDirectDraw7
*)ddraw_from_ddraw1(iface
));
941 /*****************************************************************************
942 * IDirectDraw7::GetCaps
944 * Returns the drives capabilities
946 * Used for version 1, 2, 4 and 7
949 * DriverCaps: Structure to write the Hardware accelerated caps to
950 * HelCaps: Structure to write the emulation caps to
953 * This implementation returns DD_OK only
955 *****************************************************************************/
956 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
958 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
960 WINED3DCAPS winecaps
;
962 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
964 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
966 /* One structure must be != NULL */
967 if( (!DriverCaps
) && (!HELCaps
) )
969 ERR("(%p) Invalid params to ddraw7_GetCaps\n", This
);
970 return DDERR_INVALIDPARAMS
;
973 memset(&caps
, 0, sizeof(caps
));
974 memset(&winecaps
, 0, sizeof(winecaps
));
975 caps
.dwSize
= sizeof(caps
);
976 EnterCriticalSection(&ddraw_cs
);
977 hr
= IWineD3DDevice_GetDeviceCaps(This
->wineD3DDevice
, &winecaps
);
979 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
980 LeaveCriticalSection(&ddraw_cs
);
984 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
985 LeaveCriticalSection(&ddraw_cs
);
987 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
991 caps
.dwCaps
= winecaps
.DirectDrawCaps
.Caps
;
992 caps
.dwCaps2
= winecaps
.DirectDrawCaps
.Caps2
;
993 caps
.dwCKeyCaps
= winecaps
.DirectDrawCaps
.CKeyCaps
;
994 caps
.dwFXCaps
= winecaps
.DirectDrawCaps
.FXCaps
;
995 caps
.dwPalCaps
= winecaps
.DirectDrawCaps
.PalCaps
;
996 caps
.ddsCaps
.dwCaps
= winecaps
.DirectDrawCaps
.ddsCaps
;
997 caps
.dwSVBCaps
= winecaps
.DirectDrawCaps
.SVBCaps
;
998 caps
.dwSVBCKeyCaps
= winecaps
.DirectDrawCaps
.SVBCKeyCaps
;
999 caps
.dwSVBFXCaps
= winecaps
.DirectDrawCaps
.SVBFXCaps
;
1000 caps
.dwVSBCaps
= winecaps
.DirectDrawCaps
.VSBCaps
;
1001 caps
.dwVSBCKeyCaps
= winecaps
.DirectDrawCaps
.VSBCKeyCaps
;
1002 caps
.dwVSBFXCaps
= winecaps
.DirectDrawCaps
.VSBFXCaps
;
1003 caps
.dwSSBCaps
= winecaps
.DirectDrawCaps
.SSBCaps
;
1004 caps
.dwSSBCKeyCaps
= winecaps
.DirectDrawCaps
.SSBCKeyCaps
;
1005 caps
.dwSSBFXCaps
= winecaps
.DirectDrawCaps
.SSBFXCaps
;
1007 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1010 if(DefaultSurfaceType
== SURFACE_GDI
) {
1011 caps
.dwCaps
&= ~DDCAPS_3D
;
1012 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1014 if(winecaps
.DirectDrawCaps
.StrideAlign
!= 0) {
1015 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1016 caps
.dwAlignStrideAlign
= winecaps
.DirectDrawCaps
.StrideAlign
;
1021 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1022 if (TRACE_ON(ddraw
))
1024 TRACE("Driver Caps :\n");
1025 DDRAW_dump_DDCAPS(DriverCaps
);
1031 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1032 if (TRACE_ON(ddraw
))
1034 TRACE("HEL Caps :\n");
1035 DDRAW_dump_DDCAPS(HELCaps
);
1042 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1044 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1046 return ddraw7_GetCaps((IDirectDraw7
*)ddraw_from_ddraw4(iface
), driver_caps
, hel_caps
);
1049 static HRESULT WINAPI
ddraw3_GetCaps(IDirectDraw3
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1051 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1053 return ddraw7_GetCaps((IDirectDraw7
*)ddraw_from_ddraw3(iface
), driver_caps
, hel_caps
);
1056 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1058 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1060 return ddraw7_GetCaps((IDirectDraw7
*)ddraw_from_ddraw2(iface
), driver_caps
, hel_caps
);
1063 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1065 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1067 return ddraw7_GetCaps((IDirectDraw7
*)ddraw_from_ddraw1(iface
), driver_caps
, hel_caps
);
1070 /*****************************************************************************
1071 * IDirectDraw7::Compact
1073 * No idea what it does, MSDN says it's not implemented.
1076 * DD_OK, but this is unchecked
1078 *****************************************************************************/
1079 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1081 TRACE("iface %p.\n", iface
);
1086 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1088 TRACE("iface %p.\n", iface
);
1090 return ddraw7_Compact((IDirectDraw7
*)ddraw_from_ddraw4(iface
));
1093 static HRESULT WINAPI
ddraw3_Compact(IDirectDraw3
*iface
)
1095 TRACE("iface %p.\n", iface
);
1097 return ddraw7_Compact((IDirectDraw7
*)ddraw_from_ddraw3(iface
));
1100 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1102 TRACE("iface %p.\n", iface
);
1104 return ddraw7_Compact((IDirectDraw7
*)ddraw_from_ddraw2(iface
));
1107 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1109 TRACE("iface %p.\n", iface
);
1111 return ddraw7_Compact((IDirectDraw7
*)ddraw_from_ddraw1(iface
));
1114 /*****************************************************************************
1115 * IDirectDraw7::GetDisplayMode
1117 * Returns information about the current display mode
1119 * Exists in Version 1, 2, 4 and 7
1122 * DDSD: Address of a surface description structure to write the info to
1127 *****************************************************************************/
1128 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1130 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1132 WINED3DDISPLAYMODE Mode
;
1135 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1137 EnterCriticalSection(&ddraw_cs
);
1138 /* This seems sane */
1141 LeaveCriticalSection(&ddraw_cs
);
1142 return DDERR_INVALIDPARAMS
;
1145 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1146 * so one method can be used for all versions (Hopefully)
1148 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1149 0 /* swapchain 0 */,
1153 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
1154 LeaveCriticalSection(&ddraw_cs
);
1158 Size
= DDSD
->dwSize
;
1159 memset(DDSD
, 0, Size
);
1161 DDSD
->dwSize
= Size
;
1162 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1163 DDSD
->dwWidth
= Mode
.Width
;
1164 DDSD
->dwHeight
= Mode
.Height
;
1165 DDSD
->u2
.dwRefreshRate
= 60;
1166 DDSD
->ddsCaps
.dwCaps
= 0;
1167 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1168 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
1169 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1173 TRACE("Returning surface desc :\n");
1174 DDRAW_dump_surface_desc(DDSD
);
1177 LeaveCriticalSection(&ddraw_cs
);
1181 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1183 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1185 return ddraw7_GetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw4(iface
), surface_desc
);
1188 static HRESULT WINAPI
ddraw3_GetDisplayMode(IDirectDraw3
*iface
, DDSURFACEDESC
*surface_desc
)
1190 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1192 return ddraw7_GetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw3(iface
), (DDSURFACEDESC2
*)surface_desc
);
1195 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1197 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1199 return ddraw7_GetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw2(iface
), (DDSURFACEDESC2
*)surface_desc
);
1202 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1204 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1206 return ddraw7_GetDisplayMode((IDirectDraw7
*)ddraw_from_ddraw1(iface
), (DDSURFACEDESC2
*)surface_desc
);
1209 /*****************************************************************************
1210 * IDirectDraw7::GetFourCCCodes
1212 * Returns an array of supported FourCC codes.
1214 * Exists in Version 1, 2, 4 and 7
1217 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1218 * of enumerated codes
1219 * Codes: Pointer to an array of DWORDs where the supported codes are written
1223 * Always returns DD_OK, as it's a stub for now
1225 *****************************************************************************/
1226 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1228 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1229 static const enum wined3d_format_id formats
[] =
1231 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1232 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1233 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1235 DWORD count
= 0, i
, outsize
;
1237 WINED3DDISPLAYMODE d3ddm
;
1238 WINED3DSURFTYPE type
= This
->ImplType
;
1240 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1242 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1243 0 /* swapchain 0 */,
1246 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1248 if(type
== SURFACE_UNKNOWN
) type
= SURFACE_GDI
;
1250 for(i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); i
++) {
1251 hr
= IWineD3D_CheckDeviceFormat(This
->wineD3D
,
1252 WINED3DADAPTER_DEFAULT
,
1254 d3ddm
.Format
/* AdapterFormat */,
1256 WINED3DRTYPE_SURFACE
,
1260 if(count
< outsize
) {
1261 Codes
[count
] = formats
[i
];
1267 TRACE("Returning %u FourCC codes\n", count
);
1274 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1276 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1278 return ddraw7_GetFourCCCodes((IDirectDraw7
*)ddraw_from_ddraw4(iface
), codes_count
, codes
);
1281 static HRESULT WINAPI
ddraw3_GetFourCCCodes(IDirectDraw3
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1283 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1285 return ddraw7_GetFourCCCodes((IDirectDraw7
*)ddraw_from_ddraw3(iface
), codes_count
, codes
);
1288 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1290 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1292 return ddraw7_GetFourCCCodes((IDirectDraw7
*)ddraw_from_ddraw2(iface
), codes_count
, codes
);
1295 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1297 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1299 return ddraw7_GetFourCCCodes((IDirectDraw7
*)ddraw_from_ddraw1(iface
), codes_count
, codes
);
1302 /*****************************************************************************
1303 * IDirectDraw7::GetMonitorFrequency
1305 * Returns the monitor's frequency
1307 * Exists in Version 1, 2, 4 and 7
1310 * Freq: Pointer to a DWORD to write the frequency to
1313 * Always returns DD_OK
1315 *****************************************************************************/
1316 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1318 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1320 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1321 * but for now this should make the games happy
1327 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1329 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1331 return ddraw7_GetMonitorFrequency((IDirectDraw7
*)ddraw_from_ddraw4(iface
), frequency
);
1334 static HRESULT WINAPI
ddraw3_GetMonitorFrequency(IDirectDraw3
*iface
, DWORD
*frequency
)
1336 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1338 return ddraw7_GetMonitorFrequency((IDirectDraw7
*)ddraw_from_ddraw3(iface
), frequency
);
1341 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1343 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1345 return ddraw7_GetMonitorFrequency((IDirectDraw7
*)ddraw_from_ddraw2(iface
), frequency
);
1348 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1350 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1352 return ddraw7_GetMonitorFrequency((IDirectDraw7
*)ddraw_from_ddraw1(iface
), frequency
);
1355 /*****************************************************************************
1356 * IDirectDraw7::GetVerticalBlankStatus
1358 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1359 * too basically, but as it's a semi stub, I didn't create a function there
1362 * status: Pointer to a BOOL to be filled with the vertical blank status
1366 * DDERR_INVALIDPARAMS if status is NULL
1368 *****************************************************************************/
1369 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1371 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1373 TRACE("iface %p, status %p.\n", iface
, status
);
1375 /* This looks sane, the MSDN suggests it too */
1376 EnterCriticalSection(&ddraw_cs
);
1379 LeaveCriticalSection(&ddraw_cs
);
1380 return DDERR_INVALIDPARAMS
;
1383 *status
= This
->fake_vblank
;
1384 This
->fake_vblank
= !This
->fake_vblank
;
1385 LeaveCriticalSection(&ddraw_cs
);
1389 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1391 TRACE("iface %p, status %p.\n", iface
, status
);
1393 return ddraw7_GetVerticalBlankStatus((IDirectDraw7
*)ddraw_from_ddraw4(iface
), status
);
1396 static HRESULT WINAPI
ddraw3_GetVerticalBlankStatus(IDirectDraw3
*iface
, BOOL
*status
)
1398 TRACE("iface %p, status %p.\n", iface
, status
);
1400 return ddraw7_GetVerticalBlankStatus((IDirectDraw7
*)ddraw_from_ddraw3(iface
), status
);
1403 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1405 TRACE("iface %p, status %p.\n", iface
, status
);
1407 return ddraw7_GetVerticalBlankStatus((IDirectDraw7
*)ddraw_from_ddraw2(iface
), status
);
1410 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1412 TRACE("iface %p, status %p.\n", iface
, status
);
1414 return ddraw7_GetVerticalBlankStatus((IDirectDraw7
*)ddraw_from_ddraw1(iface
), status
);
1417 /*****************************************************************************
1418 * IDirectDraw7::GetAvailableVidMem
1420 * Returns the total and free video memory
1423 * Caps: Specifies the memory type asked for
1424 * total: Pointer to a DWORD to be filled with the total memory
1425 * free: Pointer to a DWORD to be filled with the free memory
1429 * DDERR_INVALIDPARAMS of free and total are NULL
1431 *****************************************************************************/
1432 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
1434 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1436 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1440 TRACE("(%p) Asked for memory with description: ", This
);
1441 DDRAW_dump_DDSCAPS2(Caps
);
1443 EnterCriticalSection(&ddraw_cs
);
1445 /* Todo: System memory vs local video memory vs non-local video memory
1446 * The MSDN also mentions differences between texture memory and other
1447 * resources, but that's not important
1450 if( (!total
) && (!free
) )
1452 LeaveCriticalSection(&ddraw_cs
);
1453 return DDERR_INVALIDPARAMS
;
1456 if(total
) *total
= This
->total_vidmem
;
1457 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
1459 LeaveCriticalSection(&ddraw_cs
);
1463 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1464 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1466 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1468 return ddraw7_GetAvailableVidMem((IDirectDraw7
*)ddraw_from_ddraw4(iface
), caps
, total
, free
);
1471 static HRESULT WINAPI
ddraw3_GetAvailableVidMem(IDirectDraw3
*iface
,
1472 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1476 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1478 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1479 return ddraw7_GetAvailableVidMem((IDirectDraw7
*)ddraw_from_ddraw3(iface
), &caps2
, total
, free
);
1482 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1483 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1487 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1489 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1490 return ddraw7_GetAvailableVidMem((IDirectDraw7
*)ddraw_from_ddraw2(iface
), &caps2
, total
, free
);
1493 /*****************************************************************************
1494 * IDirectDraw7::Initialize
1496 * Initializes a DirectDraw interface.
1499 * GUID: Interface identifier. Well, don't know what this is really good
1503 * Returns DD_OK on the first call,
1504 * DDERR_ALREADYINITIALIZED on repeated calls
1506 *****************************************************************************/
1507 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*Guid
)
1509 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1511 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(Guid
));
1513 if(This
->initialized
)
1515 return DDERR_ALREADYINITIALIZED
;
1523 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1525 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1527 return ddraw7_Initialize((IDirectDraw7
*)ddraw_from_ddraw4(iface
), guid
);
1530 static HRESULT WINAPI
ddraw3_Initialize(IDirectDraw3
*iface
, GUID
*guid
)
1532 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1534 return ddraw7_Initialize((IDirectDraw7
*)ddraw_from_ddraw3(iface
), guid
);
1537 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1539 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1541 return ddraw7_Initialize((IDirectDraw7
*)ddraw_from_ddraw2(iface
), guid
);
1544 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1546 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1548 return ddraw7_Initialize((IDirectDraw7
*)ddraw_from_ddraw1(iface
), guid
);
1551 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1553 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1558 /*****************************************************************************
1559 * IDirectDraw7::FlipToGDISurface
1561 * "Makes the surface that the GDI writes to the primary surface"
1562 * Looks like some windows specific thing we don't have to care about.
1563 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1564 * show error boxes ;)
1565 * Well, just return DD_OK.
1568 * Always returns DD_OK
1570 *****************************************************************************/
1571 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1573 FIXME("iface %p stub!\n", iface
);
1578 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1580 TRACE("iface %p.\n", iface
);
1582 return ddraw7_FlipToGDISurface((IDirectDraw7
*)ddraw_from_ddraw4(iface
));
1585 static HRESULT WINAPI
ddraw3_FlipToGDISurface(IDirectDraw3
*iface
)
1587 TRACE("iface %p.\n", iface
);
1589 return ddraw7_FlipToGDISurface((IDirectDraw7
*)ddraw_from_ddraw3(iface
));
1592 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1594 TRACE("iface %p.\n", iface
);
1596 return ddraw7_FlipToGDISurface((IDirectDraw7
*)ddraw_from_ddraw2(iface
));
1599 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1601 TRACE("iface %p.\n", iface
);
1603 return ddraw7_FlipToGDISurface((IDirectDraw7
*)ddraw_from_ddraw1(iface
));
1606 /*****************************************************************************
1607 * IDirectDraw7::WaitForVerticalBlank
1609 * This method allows applications to get in sync with the vertical blank
1611 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1612 * redraw the screen, most likely because of this stub
1615 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1616 * or DDWAITVB_BLOCKEND
1617 * h: Not used, according to MSDN
1620 * Always returns DD_OK
1622 *****************************************************************************/
1623 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1627 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1629 /* This function is called often, so print the fixme only once */
1632 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1636 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1637 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1638 return DDERR_UNSUPPORTED
; /* unchecked */
1643 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1645 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1647 return ddraw7_WaitForVerticalBlank((IDirectDraw7
*)ddraw_from_ddraw4(iface
), flags
, event
);
1650 static HRESULT WINAPI
ddraw3_WaitForVerticalBlank(IDirectDraw3
*iface
, DWORD flags
, HANDLE event
)
1652 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1654 return ddraw7_WaitForVerticalBlank((IDirectDraw7
*)ddraw_from_ddraw3(iface
), flags
, event
);
1657 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1659 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1661 return ddraw7_WaitForVerticalBlank((IDirectDraw7
*)ddraw_from_ddraw2(iface
), flags
, event
);
1664 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1666 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1668 return ddraw7_WaitForVerticalBlank((IDirectDraw7
*)ddraw_from_ddraw1(iface
), flags
, event
);
1671 /*****************************************************************************
1672 * IDirectDraw7::GetScanLine
1674 * Returns the scan line that is being drawn on the monitor
1677 * Scanline: Address to write the scan line value to
1680 * Always returns DD_OK
1682 *****************************************************************************/
1683 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1685 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1686 static BOOL hide
= FALSE
;
1687 WINED3DDISPLAYMODE Mode
;
1689 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1691 /* This function is called often, so print the fixme only once */
1692 EnterCriticalSection(&ddraw_cs
);
1695 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1699 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1703 /* Fake the line sweeping of the monitor */
1704 /* FIXME: We should synchronize with a source to keep the refresh rate */
1705 *Scanline
= This
->cur_scanline
++;
1706 /* Assume 20 scan lines in the vertical blank */
1707 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1708 This
->cur_scanline
= 0;
1710 LeaveCriticalSection(&ddraw_cs
);
1714 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1716 TRACE("iface %p, line %p.\n", iface
, line
);
1718 return ddraw7_GetScanLine((IDirectDraw7
*)ddraw_from_ddraw4(iface
), line
);
1721 static HRESULT WINAPI
ddraw3_GetScanLine(IDirectDraw3
*iface
, DWORD
*line
)
1723 TRACE("iface %p, line %p.\n", iface
, line
);
1725 return ddraw7_GetScanLine((IDirectDraw7
*)ddraw_from_ddraw3(iface
), line
);
1728 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1730 TRACE("iface %p, line %p.\n", iface
, line
);
1732 return ddraw7_GetScanLine((IDirectDraw7
*)ddraw_from_ddraw2(iface
), line
);
1735 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1737 TRACE("iface %p, line %p.\n", iface
, line
);
1739 return ddraw7_GetScanLine((IDirectDraw7
*)ddraw_from_ddraw1(iface
), line
);
1742 /*****************************************************************************
1743 * IDirectDraw7::TestCooperativeLevel
1745 * Informs the application about the state of the video adapter, depending
1746 * on the cooperative level
1749 * DD_OK if the device is in a sane state
1750 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1751 * if the state is not correct(See below)
1753 *****************************************************************************/
1754 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1756 TRACE("iface %p.\n", iface
);
1761 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1763 TRACE("iface %p.\n", iface
);
1765 return ddraw7_TestCooperativeLevel((IDirectDraw7
*)ddraw_from_ddraw4(iface
));
1768 /*****************************************************************************
1769 * IDirectDraw7::GetGDISurface
1771 * Returns the surface that GDI is treating as the primary surface.
1772 * For Wine this is the front buffer
1775 * GDISurface: Address to write the surface pointer to
1778 * DD_OK if the surface was found
1779 * DDERR_NOTFOUND if the GDI surface wasn't found
1781 *****************************************************************************/
1782 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
1784 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1785 IWineD3DSurface
*Surf
;
1786 IDirectDrawSurface7
*ddsurf
;
1790 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
1792 /* Get the back buffer from the wineD3DDevice and search its
1793 * attached surfaces for the front buffer
1795 EnterCriticalSection(&ddraw_cs
);
1796 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1798 0, /* first back buffer*/
1799 WINED3DBACKBUFFER_TYPE_MONO
,
1802 if( (hr
!= D3D_OK
) ||
1805 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1806 LeaveCriticalSection(&ddraw_cs
);
1807 return DDERR_NOTFOUND
;
1810 ddsurf
= IWineD3DSurface_GetParent(Surf
);
1811 IWineD3DSurface_Release(Surf
);
1813 /* Find the front buffer */
1814 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1815 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1820 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1823 /* The AddRef is OK this time */
1824 LeaveCriticalSection(&ddraw_cs
);
1828 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
1830 TRACE("iface %p, surface %p.\n", iface
, surface
);
1832 return ddraw7_GetGDISurface((IDirectDraw7
*)ddraw_from_ddraw4(iface
), (IDirectDrawSurface7
**)surface
);
1835 static HRESULT WINAPI
ddraw3_GetGDISurface(IDirectDraw3
*iface
, IDirectDrawSurface
**surface
)
1837 IDirectDrawSurface7
*surface7
;
1840 TRACE("iface %p, surface %p.\n", iface
, surface
);
1842 hr
= ddraw7_GetGDISurface((IDirectDraw7
*)ddraw_from_ddraw3(iface
), &surface7
);
1843 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
1848 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
1850 IDirectDrawSurface7
*surface7
;
1853 TRACE("iface %p, surface %p.\n", iface
, surface
);
1855 hr
= ddraw7_GetGDISurface((IDirectDraw7
*)ddraw_from_ddraw2(iface
), &surface7
);
1856 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
1861 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
1863 IDirectDrawSurface7
*surface7
;
1866 TRACE("iface %p, surface %p.\n", iface
, surface
);
1868 hr
= ddraw7_GetGDISurface((IDirectDraw7
*)ddraw_from_ddraw1(iface
), &surface7
);
1869 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
1874 struct displaymodescallback_context
1876 LPDDENUMMODESCALLBACK func
;
1880 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
1882 struct displaymodescallback_context
*cbcontext
= context
;
1885 memcpy(&desc
, surface_desc
, sizeof(desc
));
1886 desc
.dwSize
= sizeof(desc
);
1888 return cbcontext
->func(&desc
, cbcontext
->context
);
1891 /*****************************************************************************
1892 * IDirectDraw7::EnumDisplayModes
1894 * Enumerates the supported Display modes. The modes can be filtered with
1895 * the DDSD parameter.
1898 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1899 * DDSD: Surface description to filter the modes
1900 * Context: Pointer passed back to the callback function
1901 * cb: Application-provided callback function
1905 * DDERR_INVALIDPARAMS if the callback wasn't set
1907 *****************************************************************************/
1908 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
1909 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
1911 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
1912 unsigned int modenum
, fmt
;
1913 enum wined3d_format_id pixelformat
= WINED3DFMT_UNKNOWN
;
1914 WINED3DDISPLAYMODE mode
;
1915 DDSURFACEDESC2 callback_sd
;
1916 WINED3DDISPLAYMODE
*enum_modes
= NULL
;
1917 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
1919 static const enum wined3d_format_id checkFormatList
[] =
1921 WINED3DFMT_B8G8R8X8_UNORM
,
1922 WINED3DFMT_B5G6R5_UNORM
,
1926 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
1927 iface
, Flags
, DDSD
, Context
, cb
);
1929 EnterCriticalSection(&ddraw_cs
);
1930 /* This looks sane */
1933 LeaveCriticalSection(&ddraw_cs
);
1934 return DDERR_INVALIDPARAMS
;
1939 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1940 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1943 if(!(Flags
& DDEDM_REFRESHRATES
))
1945 enum_mode_array_size
= 16;
1946 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
1949 ERR("Out of memory\n");
1950 LeaveCriticalSection(&ddraw_cs
);
1951 return DDERR_OUTOFMEMORY
;
1955 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
1957 if(pixelformat
!= WINED3DFMT_UNKNOWN
&& checkFormatList
[fmt
] != pixelformat
)
1963 while(IWineD3D_EnumAdapterModes(This
->wineD3D
,
1964 WINED3DADAPTER_DEFAULT
,
1965 checkFormatList
[fmt
],
1967 &mode
) == WINED3D_OK
)
1971 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
1972 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
1975 if(!(Flags
& DDEDM_REFRESHRATES
))
1977 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
1978 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
1979 * to be reduced to a single unique result in such case.
1984 for (i
= 0; i
< enum_mode_count
; i
++)
1986 if(enum_modes
[i
].Width
== mode
.Width
&& enum_modes
[i
].Height
== mode
.Height
&&
1987 enum_modes
[i
].Format
== mode
.Format
)
1997 memset(&callback_sd
, 0, sizeof(callback_sd
));
1998 callback_sd
.dwSize
= sizeof(callback_sd
);
1999 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2001 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
2002 if(Flags
& DDEDM_REFRESHRATES
)
2004 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
2005 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
2008 callback_sd
.dwWidth
= mode
.Width
;
2009 callback_sd
.dwHeight
= mode
.Height
;
2011 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, mode
.Format
);
2013 /* Calc pitch and DWORD align like MSDN says */
2014 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.Width
;
2015 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2017 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2018 callback_sd
.u2
.dwRefreshRate
);
2020 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2022 TRACE("Application asked to terminate the enumeration\n");
2023 HeapFree(GetProcessHeap(), 0, enum_modes
);
2024 LeaveCriticalSection(&ddraw_cs
);
2028 if(!(Flags
& DDEDM_REFRESHRATES
))
2030 if (enum_mode_count
== enum_mode_array_size
)
2032 WINED3DDISPLAYMODE
*new_enum_modes
;
2034 enum_mode_array_size
*= 2;
2035 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2037 if (!new_enum_modes
)
2039 ERR("Out of memory\n");
2040 HeapFree(GetProcessHeap(), 0, enum_modes
);
2041 LeaveCriticalSection(&ddraw_cs
);
2042 return DDERR_OUTOFMEMORY
;
2045 enum_modes
= new_enum_modes
;
2048 enum_modes
[enum_mode_count
++] = mode
;
2053 TRACE("End of enumeration\n");
2054 HeapFree(GetProcessHeap(), 0, enum_modes
);
2055 LeaveCriticalSection(&ddraw_cs
);
2059 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2060 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2062 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2063 iface
, flags
, surface_desc
, context
, callback
);
2065 return ddraw7_EnumDisplayModes((IDirectDraw7
*)ddraw_from_ddraw4(iface
), flags
,
2066 surface_desc
, context
, callback
);
2069 static HRESULT WINAPI
ddraw3_EnumDisplayModes(IDirectDraw3
*iface
, DWORD flags
,
2070 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2072 struct displaymodescallback_context cbcontext
;
2074 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2075 iface
, flags
, surface_desc
, context
, callback
);
2077 cbcontext
.func
= callback
;
2078 cbcontext
.context
= context
;
2080 return ddraw7_EnumDisplayModes((IDirectDraw7
*)ddraw_from_ddraw3(iface
), flags
,
2081 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2084 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2085 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2087 struct displaymodescallback_context cbcontext
;
2089 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2090 iface
, flags
, surface_desc
, context
, callback
);
2092 cbcontext
.func
= callback
;
2093 cbcontext
.context
= context
;
2095 return ddraw7_EnumDisplayModes((IDirectDraw7
*)ddraw_from_ddraw2(iface
), flags
,
2096 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2099 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2100 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2102 struct displaymodescallback_context cbcontext
;
2104 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2105 iface
, flags
, surface_desc
, context
, callback
);
2107 cbcontext
.func
= callback
;
2108 cbcontext
.context
= context
;
2110 return ddraw7_EnumDisplayModes((IDirectDraw7
*)ddraw_from_ddraw1(iface
), flags
,
2111 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2114 /*****************************************************************************
2115 * IDirectDraw7::EvaluateMode
2117 * Used with IDirectDraw7::StartModeTest to test video modes.
2118 * EvaluateMode is used to pass or fail a mode, and continue with the next
2122 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2123 * Timeout: Returns the amount of seconds left before the mode would have
2124 * been failed automatically
2127 * This implementation always DD_OK, because it's a stub
2129 *****************************************************************************/
2130 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2132 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2134 /* When implementing this, implement it in WineD3D */
2139 /*****************************************************************************
2140 * IDirectDraw7::GetDeviceIdentifier
2142 * Returns the device identifier, which gives information about the driver
2143 * Our device identifier is defined at the beginning of this file.
2146 * DDDI: Address for the returned structure
2147 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2150 * On success it returns DD_OK
2151 * DDERR_INVALIDPARAMS if DDDI is NULL
2153 *****************************************************************************/
2154 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2155 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2157 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2160 return DDERR_INVALIDPARAMS
;
2162 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2163 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2164 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2165 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2166 * bytes too long. So only copy the relevant part of the structure
2169 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2173 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2174 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2176 DDDEVICEIDENTIFIER2 identifier2
;
2179 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2181 hr
= ddraw7_GetDeviceIdentifier((IDirectDraw7
*)ddraw_from_ddraw4(iface
), &identifier2
, flags
);
2182 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2187 /*****************************************************************************
2188 * IDirectDraw7::GetSurfaceFromDC
2190 * Returns the Surface for a GDI device context handle.
2191 * Is this related to IDirectDrawSurface::GetDC ???
2194 * hdc: hdc to return the surface for
2195 * Surface: Address to write the surface pointer to
2198 * Always returns DD_OK because it's a stub
2200 *****************************************************************************/
2201 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
, IDirectDrawSurface7
**Surface
)
2203 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
2204 IWineD3DSurface
*wined3d_surface
;
2207 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2209 if (!Surface
) return E_INVALIDARG
;
2211 hr
= IWineD3DDevice_GetSurfaceFromDC(This
->wineD3DDevice
, hdc
, &wined3d_surface
);
2214 TRACE("No surface found for dc %p.\n", hdc
);
2216 return DDERR_NOTFOUND
;
2219 *Surface
= IWineD3DSurface_GetParent(wined3d_surface
);
2220 IDirectDrawSurface7_AddRef(*Surface
);
2221 TRACE("Returning surface %p.\n", Surface
);
2225 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
, IDirectDrawSurface4
**surface
)
2227 IDirectDrawSurface7
*surface7
;
2230 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2232 if (!surface
) return E_INVALIDARG
;
2234 hr
= ddraw7_GetSurfaceFromDC((IDirectDraw7
*)ddraw_from_ddraw4(iface
), dc
, &surface7
);
2235 *surface
= surface7
? (IDirectDrawSurface4
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2240 static HRESULT WINAPI
ddraw3_GetSurfaceFromDC(IDirectDraw3
*iface
, HDC dc
, IDirectDrawSurface
**surface
)
2242 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2244 return ddraw7_GetSurfaceFromDC((IDirectDraw7
*)ddraw_from_ddraw3(iface
),
2245 dc
, (IDirectDrawSurface7
**)surface
);
2248 /*****************************************************************************
2249 * IDirectDraw7::RestoreAllSurfaces
2251 * Calls the restore method of all surfaces
2256 * Always returns DD_OK because it's a stub
2258 *****************************************************************************/
2259 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2261 FIXME("iface %p stub!\n", iface
);
2263 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2264 * get their parent and call their restore method. Do not implement
2265 * it in WineD3D, as restoring a surface means re-creating the
2271 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2273 TRACE("iface %p.\n", iface
);
2275 return ddraw7_RestoreAllSurfaces((IDirectDraw7
*)ddraw_from_ddraw4(iface
));
2278 /*****************************************************************************
2279 * IDirectDraw7::StartModeTest
2281 * Tests the specified video modes to update the system registry with
2282 * refresh rate information. StartModeTest starts the mode test,
2283 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2284 * isn't called within 15 seconds, the mode is failed automatically
2286 * As refresh rates are handled by the X server, I don't think this
2287 * Method is important
2290 * Modes: An array of mode specifications
2291 * NumModes: The number of modes in Modes
2292 * Flags: Some flags...
2295 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2296 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2299 *****************************************************************************/
2300 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2302 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2303 iface
, Modes
, NumModes
, Flags
);
2305 /* This looks sane */
2306 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2308 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2309 * As it is not, DDERR_TESTFINISHED is returned
2310 * (hopefully that's correct
2312 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2313 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2319 /*****************************************************************************
2320 * ddraw_recreate_surfaces_cb
2322 * Enumeration callback for ddraw_recreate_surface.
2323 * It re-recreates the WineD3DSurface. It's pretty straightforward
2325 *****************************************************************************/
2326 HRESULT WINAPI
ddraw_recreate_surfaces_cb(IDirectDrawSurface7
*surf
, DDSURFACEDESC2
*desc
, void *Context
)
2328 IDirectDrawSurfaceImpl
*surfImpl
= (IDirectDrawSurfaceImpl
*)surf
;
2329 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
2330 IWineD3DSurface
*wineD3DSurface
;
2331 IWineD3DSwapChain
*swapchain
;
2334 IWineD3DClipper
*clipper
= NULL
;
2336 WINED3DSURFACE_DESC Desc
;
2337 enum wined3d_format_id Format
;
2341 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
2342 DWORD MultiSampleQuality
;
2346 TRACE("surface %p, surface_desc %p, context %p.\n",
2347 surf
, desc
, Context
);
2349 /* For the enumeration */
2350 IDirectDrawSurface7_Release(surf
);
2352 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
2354 /* Get the objects */
2355 swapchain
= surfImpl
->wineD3DSwapChain
;
2356 surfImpl
->wineD3DSwapChain
= NULL
;
2357 wineD3DSurface
= surfImpl
->WineD3DSurface
;
2359 /* get the clipper */
2360 IWineD3DSurface_GetClipper(wineD3DSurface
, &clipper
);
2362 /* Get the surface properties */
2363 IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
2365 Format
= Desc
.format
;
2368 MultiSampleType
= Desc
.multisample_type
;
2369 MultiSampleQuality
= Desc
.multisample_quality
;
2371 Height
= Desc
.height
;
2373 parent
= IWineD3DSurface_GetParent(wineD3DSurface
);
2374 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
, Width
, Height
, Format
, TRUE
/* Lockable */,
2375 FALSE
/* Discard */, surfImpl
->mipmap_level
, Usage
, Pool
, MultiSampleType
, MultiSampleQuality
,
2376 This
->ImplType
, parent
, &ddraw_null_wined3d_parent_ops
, &surfImpl
->WineD3DSurface
);
2379 surfImpl
->WineD3DSurface
= wineD3DSurface
;
2383 IWineD3DSurface_SetClipper(surfImpl
->WineD3DSurface
, clipper
);
2385 /* TODO: Copy the surface content, except for render targets */
2387 /* If there's a swapchain, it owns the wined3d surfaces. So Destroy
2391 /* The backbuffers have the swapchain set as well, but the primary
2392 * owns it and destroys it
2394 if(surfImpl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) {
2395 IWineD3DDevice_UninitGDI(This
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2397 surfImpl
->isRenderTarget
= FALSE
;
2399 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
2400 TRACE("Surface released successful, next surface\n");
2402 ERR("Something's still holding the old WineD3DSurface\n");
2405 surfImpl
->ImplType
= This
->ImplType
;
2409 IWineD3DClipper_Release(clipper
);
2411 return DDENUMRET_OK
;
2414 /*****************************************************************************
2415 * ddraw_recreate_surfaces
2417 * A function, that converts all wineD3DSurfaces to the new implementation type
2418 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
2419 * new WineD3DSurface, copies the content and releases the old surface
2421 *****************************************************************************/
2422 static HRESULT
ddraw_recreate_surfaces(IDirectDrawImpl
*This
)
2424 DDSURFACEDESC2 desc
;
2425 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
2427 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
2429 /* Should happen almost never */
2430 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
2432 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2434 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
2436 memset(&desc
, 0, sizeof(desc
));
2437 desc
.dwSize
= sizeof(desc
);
2439 return IDirectDraw7_EnumSurfaces((IDirectDraw7
*)This
, 0, &desc
, This
, ddraw_recreate_surfaces_cb
);
2442 ULONG WINAPI
D3D7CB_DestroySwapChain(IWineD3DSwapChain
*pSwapChain
)
2444 IUnknown
*swapChainParent
;
2446 TRACE("swapchain %p.\n", pSwapChain
);
2448 swapChainParent
= IWineD3DSwapChain_GetParent(pSwapChain
);
2449 return IUnknown_Release(swapChainParent
);
2452 /*****************************************************************************
2453 * ddraw_create_surface
2455 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2456 * with the passed parameters.
2459 * DDSD: Description of the surface to create
2460 * Surf: Address to store the interface pointer at
2465 *****************************************************************************/
2466 static HRESULT
ddraw_create_surface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
,
2467 IDirectDrawSurfaceImpl
**ppSurf
, UINT level
)
2469 WINED3DSURFTYPE ImplType
= This
->ImplType
;
2472 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2473 This
, pDDSD
, ppSurf
, level
);
2475 if (TRACE_ON(ddraw
))
2477 TRACE(" (%p) Requesting surface desc :\n", This
);
2478 DDRAW_dump_surface_desc(pDDSD
);
2481 /* Select the surface type, if it wasn't choosen yet */
2482 if(ImplType
== SURFACE_UNKNOWN
)
2484 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
2485 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2487 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
2488 ImplType
= SURFACE_OPENGL
;
2491 /* Otherwise use GDI surfaces for now */
2494 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
2495 ImplType
= SURFACE_GDI
;
2498 /* Policy if all surface implementations are available:
2499 * First, check if a default type was set with winecfg. If not,
2500 * try Xrender surfaces, and use them if they work. Next, check if
2501 * accelerated OpenGL is available, and use GL surfaces in this
2502 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
2503 * was created, always use OpenGL surfaces.
2505 * (Note: Xrender surfaces are not implemented for now, the
2506 * unaccelerated implementation uses GDI to render in Software)
2509 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
2510 * be re-created. This could be done with IDirectDrawSurface7::Restore
2512 This
->ImplType
= ImplType
;
2516 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2517 && (This
->ImplType
!= SURFACE_OPENGL
)
2518 && DefaultSurfaceType
== SURFACE_UNKNOWN
)
2520 /* We have to change to OpenGL,
2521 * and re-create all WineD3DSurfaces
2523 ImplType
= SURFACE_OPENGL
;
2524 This
->ImplType
= ImplType
;
2525 TRACE("(%p) Re-creating all surfaces\n", This
);
2526 ddraw_recreate_surfaces(This
);
2527 TRACE("(%p) Done recreating all surfaces\n", This
);
2529 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2531 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
2532 /* Do not fail surface creation, only fail 3D device creation */
2536 /* Create the Surface object */
2537 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
2540 ERR("(%p) Error allocating memory for a surface\n", This
);
2541 return DDERR_OUTOFVIDEOMEMORY
;
2544 hr
= ddraw_surface_init(*ppSurf
, This
, pDDSD
, level
, ImplType
);
2547 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2548 HeapFree(GetProcessHeap(), 0, *ppSurf
);
2552 /* Increase the surface counter, and attach the surface */
2553 InterlockedIncrement(&This
->surfaces
);
2554 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
2556 TRACE("Created surface %p.\n", *ppSurf
);
2560 /*****************************************************************************
2561 * CreateAdditionalSurfaces
2563 * Creates a new mipmap chain.
2566 * root: Root surface to attach the newly created chain to
2567 * count: number of surfaces to create
2568 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2569 * effects on the caller
2570 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2571 * creates an additional surface without the mipmapping flags
2573 *****************************************************************************/
2575 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2576 IDirectDrawSurfaceImpl
*root
,
2578 DDSURFACEDESC2 DDSD
,
2581 UINT i
, j
, level
= 0;
2583 IDirectDrawSurfaceImpl
*last
= root
;
2585 for(i
= 0; i
< count
; i
++)
2587 IDirectDrawSurfaceImpl
*object2
= NULL
;
2589 /* increase the mipmap level, but only if a mipmap is created
2590 * In this case, also halve the size
2592 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2595 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2596 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2597 /* Set the mipmap sublevel flag according to msdn */
2598 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2602 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2604 CubeFaceRoot
= FALSE
;
2606 hr
= ddraw_create_surface(This
, &DDSD
, &object2
, level
);
2612 /* Add the new surface to the complex attachment array */
2613 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2615 if(last
->complex_array
[j
]) continue;
2616 last
->complex_array
[j
] = object2
;
2621 /* Remove the (possible) back buffer cap from the new surface description,
2622 * because only one surface in the flipping chain is a back buffer, one
2623 * is a front buffer, the others are just primary surfaces.
2625 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2630 /* Must set all attached surfaces (e.g. mipmaps) versions as well */
2631 static void ddraw_set_surface_version(IDirectDrawSurfaceImpl
*surface
, UINT version
)
2635 TRACE("surface %p, version %u -> %u.\n", surface
, surface
->version
, version
);
2637 surface
->version
= version
;
2638 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
2640 if (!surface
->complex_array
[i
]) break;
2641 ddraw_set_surface_version(surface
->complex_array
[i
], version
);
2643 while ((surface
= surface
->next_attached
))
2645 ddraw_set_surface_version(surface
, version
);
2649 /*****************************************************************************
2650 * ddraw_attach_d3d_device
2652 * Initializes the D3D capabilities of WineD3D
2655 * primary: The primary surface for D3D
2661 *****************************************************************************/
2662 static HRESULT
ddraw_attach_d3d_device(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2664 WINED3DPRESENT_PARAMETERS localParameters
;
2665 HWND window
= ddraw
->dest_window
;
2668 TRACE("ddraw %p, primary %p.\n", ddraw
, primary
);
2670 if (!window
|| window
== GetDesktopWindow())
2672 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
2673 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
2674 NULL
, NULL
, NULL
, NULL
);
2677 ERR("Failed to create window, last error %#x.\n", GetLastError());
2681 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2682 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
2686 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
2688 ddraw
->d3d_window
= window
;
2690 /* Store the future Render Target surface */
2691 ddraw
->d3d_target
= primary
;
2693 /* Use the surface description for the device parameters, not the device
2694 * settings. The application might render to an offscreen surface. */
2695 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2696 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2697 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2698 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2699 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2700 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2701 localParameters
.MultiSampleQuality
= 0;
2702 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2703 localParameters
.hDeviceWindow
= window
;
2704 localParameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2705 localParameters
.EnableAutoDepthStencil
= TRUE
;
2706 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16_UNORM
;
2707 localParameters
.Flags
= 0;
2708 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2709 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2711 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2712 * recursive loop until ram or emulated video memory is full. */
2713 ddraw
->d3d_initialized
= TRUE
;
2714 hr
= IWineD3DDevice_Init3D(ddraw
->wineD3DDevice
, &localParameters
);
2717 ddraw
->d3d_target
= NULL
;
2718 ddraw
->d3d_initialized
= FALSE
;
2722 ddraw
->declArraySize
= 2;
2723 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
2726 ERR("Error allocating an array for the converted vertex decls.\n");
2727 ddraw
->declArraySize
= 0;
2728 hr
= IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2729 return E_OUTOFMEMORY
;
2732 TRACE("Successfully initialized 3D.\n");
2737 static HRESULT
ddraw_create_gdi_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2739 WINED3DPRESENT_PARAMETERS presentation_parameters
;
2743 window
= ddraw
->dest_window
;
2745 memset(&presentation_parameters
, 0, sizeof(presentation_parameters
));
2747 /* Use the surface description for the device parameters, not the device
2748 * settings. The application might render to an offscreen surface. */
2749 presentation_parameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2750 presentation_parameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2751 presentation_parameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2752 presentation_parameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2753 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2754 presentation_parameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2755 presentation_parameters
.MultiSampleQuality
= 0;
2756 presentation_parameters
.SwapEffect
= WINED3DSWAPEFFECT_FLIP
;
2757 presentation_parameters
.hDeviceWindow
= window
;
2758 presentation_parameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2759 presentation_parameters
.EnableAutoDepthStencil
= FALSE
; /* Not on GDI swapchains */
2760 presentation_parameters
.AutoDepthStencilFormat
= 0;
2761 presentation_parameters
.Flags
= 0;
2762 presentation_parameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2763 presentation_parameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2765 ddraw
->d3d_target
= primary
;
2766 hr
= IWineD3DDevice_InitGDI(ddraw
->wineD3DDevice
, &presentation_parameters
);
2767 ddraw
->d3d_target
= NULL
;
2770 WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr
);
2771 primary
->wineD3DSwapChain
= NULL
;
2777 /*****************************************************************************
2778 * IDirectDraw7::CreateSurface
2780 * Creates a new IDirectDrawSurface object and returns its interface.
2782 * The surface connections with wined3d are a bit tricky. Basically it works
2785 * |------------------------| |-----------------|
2786 * | DDraw surface | | WineD3DSurface |
2788 * | WineD3DSurface |-------------->| |
2789 * | Child |<------------->| Parent |
2790 * |------------------------| |-----------------|
2792 * The DDraw surface is the parent of the wined3d surface, and it releases
2793 * the WineD3DSurface when the ddraw surface is destroyed.
2795 * However, for all surfaces which can be in a container in WineD3D,
2796 * we have to do this. These surfaces are usually complex surfaces,
2797 * so this concerns primary surfaces with a front and a back buffer,
2800 * |------------------------| |-----------------|
2801 * | DDraw surface | | Container |
2803 * | Child |<------------->| Parent |
2804 * | Texture |<------------->| |
2805 * | WineD3DSurface |<----| | Levels |<--|
2806 * | Complex connection | | | | |
2807 * |------------------------| | |-----------------| |
2811 * | |------------------| | |-----------------| |
2812 * | | IParent | |-------->| WineD3DSurface | |
2814 * | | Child |<------------->| Parent | |
2815 * | | | | Container |<--|
2816 * | |------------------| |-----------------| |
2818 * | |----------------------| |
2819 * | | DDraw surface 2 | |
2821 * |<->| Complex root Child | |
2823 * | | WineD3DSurface |<----| |
2824 * | |----------------------| | |
2826 * | |---------------------| | |-----------------| |
2827 * | | IParent | |----->| WineD3DSurface | |
2829 * | | Child |<---------->| Parent | |
2830 * | |---------------------| | Container |<--|
2831 * | |-----------------| |
2833 * | ---More surfaces can follow--- |
2835 * The reason is that the IWineD3DSwapchain(render target container)
2836 * and the IWineD3DTexure(Texture container) release the parents
2837 * of their surface's children, but by releasing the complex root
2838 * the surfaces which are complexly attached to it are destroyed
2839 * too. See IDirectDrawSurface::Release for a more detailed
2843 * DDSD: Description of the surface to create
2844 * Surf: Address to store the interface pointer at
2845 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2846 * aggregation, so it has to be NULL
2850 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2851 * DDERR_* if an error occurs
2853 *****************************************************************************/
2854 static HRESULT
CreateSurface(IDirectDraw7
*iface
,
2855 DDSURFACEDESC2
*DDSD
, IDirectDrawSurface7
**Surf
, IUnknown
*UnkOuter
)
2857 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
2858 IDirectDrawSurfaceImpl
*object
= NULL
;
2860 LONG extra_surfaces
= 0;
2861 DDSURFACEDESC2 desc2
;
2862 WINED3DDISPLAYMODE Mode
;
2863 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2865 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
2866 iface
, DDSD
, Surf
, UnkOuter
);
2868 /* Some checks before we start */
2869 if (TRACE_ON(ddraw
))
2871 TRACE(" (%p) Requesting surface desc :\n", This
);
2872 DDRAW_dump_surface_desc(DDSD
);
2874 EnterCriticalSection(&ddraw_cs
);
2876 if (UnkOuter
!= NULL
)
2878 FIXME("(%p) : outer != NULL?\n", This
);
2879 LeaveCriticalSection(&ddraw_cs
);
2880 return CLASS_E_NOAGGREGATION
; /* unchecked */
2885 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2886 LeaveCriticalSection(&ddraw_cs
);
2887 return E_POINTER
; /* unchecked */
2890 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2892 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2893 DDSD
->dwFlags
|= DDSD_CAPS
;
2896 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2898 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2899 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2902 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2904 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2905 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2906 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2909 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2910 !(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
2912 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This
);
2914 LeaveCriticalSection(&ddraw_cs
);
2915 return DDERR_NOEXCLUSIVEMODE
;
2918 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2920 WARN("Application wanted to create back buffer primary surface\n");
2921 LeaveCriticalSection(&ddraw_cs
);
2922 return DDERR_INVALIDCAPS
;
2925 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2927 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2928 WARN("Application tries to put the surface in both system and video memory\n");
2929 LeaveCriticalSection(&ddraw_cs
);
2931 return DDERR_INVALIDCAPS
;
2934 /* Check cube maps but only if the size includes them */
2935 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2937 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2938 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2940 WARN("Cube map faces requested without cube map flag\n");
2941 LeaveCriticalSection(&ddraw_cs
);
2942 return DDERR_INVALIDCAPS
;
2944 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2945 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2947 WARN("Cube map without faces requested\n");
2948 LeaveCriticalSection(&ddraw_cs
);
2949 return DDERR_INVALIDPARAMS
;
2952 /* Quick tests confirm those can be created, but we don't do that yet */
2953 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2954 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2956 FIXME("Partial cube maps not supported yet\n");
2960 /* According to the msdn this flag is ignored by CreateSurface */
2961 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2962 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2964 /* Modify some flags */
2965 memset(&desc2
, 0, sizeof(desc2
));
2966 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
2967 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2968 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2969 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2971 /* Get the video mode from WineD3D - we will need it */
2972 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2973 0, /* Swapchain 0 */
2977 ERR("Failed to read display mode from wined3d\n");
2978 switch(This
->orig_bpp
)
2981 Mode
.Format
= WINED3DFMT_P8_UINT
;
2985 Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
;
2989 Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
;
2993 Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
;
2997 Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
;
3000 Mode
.Width
= This
->orig_width
;
3001 Mode
.Height
= This
->orig_height
;
3004 /* No pixelformat given? Use the current screen format */
3005 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
3007 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
3008 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
3010 /* Wait: It could be a Z buffer */
3011 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
3013 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
3016 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_S1_UINT_D15_UNORM
);
3019 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16_UNORM
);
3022 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_X8D24_UNORM
);
3025 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32_UNORM
);
3028 ERR("Unknown Z buffer bit depth\n");
3033 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
3037 /* No Width or no Height? Use the original screen size
3039 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
3040 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
3042 /* Invalid for non-render targets */
3043 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
3045 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
3047 LeaveCriticalSection(&ddraw_cs
);
3048 return DDERR_INVALIDPARAMS
;
3051 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
3052 desc2
.dwWidth
= Mode
.Width
;
3053 desc2
.dwHeight
= Mode
.Height
;
3056 /* Mipmap count fixes */
3057 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3059 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
3061 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
3063 /* Mipmap count is given, should not be 0 */
3064 if( desc2
.u2
.dwMipMapCount
== 0 )
3066 LeaveCriticalSection(&ddraw_cs
);
3067 return DDERR_INVALIDPARAMS
;
3072 /* Undocumented feature: Create sublevels until
3073 * either the width or the height is 1
3075 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
3076 desc2
.dwWidth
: desc2
.dwHeight
;
3077 desc2
.u2
.dwMipMapCount
= 0;
3080 desc2
.u2
.dwMipMapCount
+= 1;
3087 /* Not-complex mipmap -> Mipmapcount = 1 */
3088 desc2
.u2
.dwMipMapCount
= 1;
3090 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
3092 /* There's a mipmap count in the created surface in any case */
3093 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
3095 /* If no mipmap is given, the texture has only one level */
3097 /* The first surface is a front buffer, the back buffer is created afterwards */
3098 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
3100 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
3103 /* The root surface in a cube map is positive x */
3104 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3106 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3107 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3110 /* Create the first surface */
3111 hr
= ddraw_create_surface(This
, &desc2
, &object
, 0);
3114 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3115 LeaveCriticalSection(&ddraw_cs
);
3118 object
->is_complex_root
= TRUE
;
3120 *Surf
= (IDirectDrawSurface7
*)object
;
3122 /* Create Additional surfaces if necessary
3123 * This applies to Primary surfaces which have a back buffer count
3124 * set, but not to mipmap textures. In case of Mipmap textures,
3125 * wineD3D takes care of the creation of additional surfaces
3127 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3129 extra_surfaces
= DDSD
->dwBackBufferCount
;
3130 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3131 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3132 desc2
.dwBackBufferCount
= 0;
3136 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3138 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3139 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3140 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3141 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3142 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
3143 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3144 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
3145 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
3146 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3147 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
3148 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
3149 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3150 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
3151 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
3152 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3153 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
3154 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3157 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
, desc2
, FALSE
);
3160 /* This destroys and possibly created surfaces too */
3161 IDirectDrawSurface_Release((IDirectDrawSurface7
*)object
);
3162 LeaveCriticalSection(&ddraw_cs
);
3166 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
3167 * But attach the d3ddevice only if the currently created surface was
3168 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
3169 * The only case I can think of where this doesn't apply is when a
3170 * 2D app was configured by the user to run with OpenGL and it didn't create
3171 * the render target as first surface. In this case the render target creation
3172 * will cause the 3D init.
3174 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
3175 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
3177 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
3180 /* Search for the primary to use as render target */
3181 LIST_FOR_EACH(entry
, &This
->surface_list
)
3183 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3184 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
3185 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
3189 TRACE("Using primary %p as render target\n", target
);
3194 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
3195 hr
= ddraw_attach_d3d_device(This
, target
);
3198 IDirectDrawSurfaceImpl
*release_surf
;
3199 ERR("ddraw_attach_d3d_device failed, hr %#x\n", hr
);
3202 /* The before created surface structures are in an incomplete state here.
3203 * WineD3D holds the reference on the IParents, and it released them on the failure
3204 * already. So the regular release method implementation would fail on the attempt
3205 * to destroy either the IParents or the swapchain. So free the surface here.
3206 * The surface structure here is a list, not a tree, because onscreen targets
3207 * cannot be cube textures
3211 release_surf
= object
;
3212 object
= object
->complex_array
[0];
3213 ddraw_surface_destroy(release_surf
);
3215 LeaveCriticalSection(&ddraw_cs
);
3219 else if(!(This
->d3d_initialized
) && desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3221 ddraw_create_gdi_swapchain(This
, object
);
3224 /* Addref the ddraw interface to keep an reference for each surface */
3225 IDirectDraw7_AddRef(iface
);
3226 object
->ifaceToRelease
= (IUnknown
*) iface
;
3228 /* Create a WineD3DTexture if a texture was requested */
3229 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3231 enum wined3d_format_id Format
;
3233 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
3235 This
->tex_root
= object
;
3237 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3239 /* a mipmap is created, create enough levels */
3240 levels
= desc2
.u2
.dwMipMapCount
;
3244 /* No mipmap is created, create one level */
3248 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
3249 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
3251 Pool
= WINED3DPOOL_SYSTEMMEM
;
3253 /* Should I forward the MANAGED cap to the managed pool ? */
3255 /* Get the format. It's set already by CreateNewSurface */
3256 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
3258 /* The surfaces are already created, the callback only
3259 * passes the IWineD3DSurface to WineD3D
3261 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3263 hr
= IWineD3DDevice_CreateCubeTexture(This
->wineD3DDevice
, DDSD
->dwWidth
/* Edgelength */, levels
,
3264 0 /* usage */, Format
, Pool
, object
, &ddraw_null_wined3d_parent_ops
,
3265 (IWineD3DCubeTexture
**)&object
->wineD3DTexture
);
3269 hr
= IWineD3DDevice_CreateTexture(This
->wineD3DDevice
, DDSD
->dwWidth
, DDSD
->dwHeight
, levels
,
3270 0 /* usage */, Format
, Pool
, object
, &ddraw_null_wined3d_parent_ops
,
3271 (IWineD3DTexture
**)&object
->wineD3DTexture
);
3273 This
->tex_root
= NULL
;
3276 LeaveCriticalSection(&ddraw_cs
);
3280 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
,
3281 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3283 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3284 iface
, surface_desc
, surface
, outer_unknown
);
3286 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3288 WARN("Application supplied invalid surface descriptor\n");
3289 return DDERR_INVALIDPARAMS
;
3292 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3294 if (TRACE_ON(ddraw
))
3296 TRACE(" (%p) Requesting surface desc :\n", iface
);
3297 DDRAW_dump_surface_desc(surface_desc
);
3300 WARN("Application tried to create an explicit front or back buffer\n");
3301 return DDERR_INVALIDCAPS
;
3304 return CreateSurface(iface
, surface_desc
, surface
, outer_unknown
);
3307 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3308 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3310 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw4(iface
);
3311 IDirectDrawSurfaceImpl
*impl
;
3314 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3315 iface
, surface_desc
, surface
, outer_unknown
);
3317 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3319 WARN("Application supplied invalid surface descriptor\n");
3320 return DDERR_INVALIDPARAMS
;
3323 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3325 if (TRACE_ON(ddraw
))
3327 TRACE(" (%p) Requesting surface desc :\n", iface
);
3328 DDRAW_dump_surface_desc(surface_desc
);
3331 WARN("Application tried to create an explicit front or back buffer\n");
3332 return DDERR_INVALIDCAPS
;
3335 hr
= CreateSurface((IDirectDraw7
*)ddraw
, surface_desc
, (IDirectDrawSurface7
**)surface
, outer_unknown
);
3336 impl
= (IDirectDrawSurfaceImpl
*)*surface
;
3337 if (SUCCEEDED(hr
) && impl
)
3339 ddraw_set_surface_version(impl
, 4);
3340 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3341 IDirectDraw4_AddRef(iface
);
3342 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3348 static HRESULT WINAPI
ddraw3_CreateSurface(IDirectDraw3
*iface
,
3349 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3351 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw3(iface
);
3352 IDirectDrawSurface7
*surface7
;
3353 IDirectDrawSurfaceImpl
*impl
;
3356 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3357 iface
, surface_desc
, surface
, outer_unknown
);
3359 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3361 WARN("Application supplied invalid surface descriptor\n");
3362 return DDERR_INVALIDPARAMS
;
3365 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3367 if (TRACE_ON(ddraw
))
3369 TRACE(" (%p) Requesting surface desc :\n", iface
);
3370 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3373 WARN("Application tried to create an explicit front or back buffer\n");
3374 return DDERR_INVALIDCAPS
;
3377 hr
= CreateSurface((IDirectDraw7
*)ddraw
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3384 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3385 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3386 ddraw_set_surface_version(impl
, 3);
3387 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3388 IDirectDraw3_AddRef(iface
);
3389 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3394 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3395 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3397 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw2(iface
);
3398 IDirectDrawSurface7
*surface7
;
3399 IDirectDrawSurfaceImpl
*impl
;
3402 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3403 iface
, surface_desc
, surface
, outer_unknown
);
3405 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3407 WARN("Application supplied invalid surface descriptor\n");
3408 return DDERR_INVALIDPARAMS
;
3411 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3413 if (TRACE_ON(ddraw
))
3415 TRACE(" (%p) Requesting surface desc :\n", iface
);
3416 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3419 WARN("Application tried to create an explicit front or back buffer\n");
3420 return DDERR_INVALIDCAPS
;
3423 hr
= CreateSurface((IDirectDraw7
*)ddraw
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3430 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3431 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3432 ddraw_set_surface_version(impl
, 2);
3433 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3434 impl
->ifaceToRelease
= NULL
;
3439 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3440 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3442 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw1(iface
);
3443 IDirectDrawSurface7
*surface7
;
3444 IDirectDrawSurfaceImpl
*impl
;
3447 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3448 iface
, surface_desc
, surface
, outer_unknown
);
3450 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3452 WARN("Application supplied invalid surface descriptor\n");
3453 return DDERR_INVALIDPARAMS
;
3456 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3457 * primaries anyway. */
3458 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3459 hr
= CreateSurface((IDirectDraw7
*)ddraw
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3466 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3467 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3468 ddraw_set_surface_version(impl
, 1);
3469 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3470 impl
->ifaceToRelease
= NULL
;
3475 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3476 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3479 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3480 const DDPIXELFORMAT
*provided
)
3482 /* Some flags must be present in both or neither for a match. */
3483 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3484 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3485 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3487 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3490 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3493 if (requested
->dwFlags
& DDPF_FOURCC
)
3494 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3497 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3498 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3499 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3502 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3503 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3504 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3507 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3508 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3511 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3512 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3514 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3517 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3518 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3524 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3533 #define CMP(FLAG, FIELD) \
3534 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3535 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3537 static const struct compare_info compare
[] =
3539 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3540 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3542 CMP(CKDESTBLT
, ddckCKDestBlt
),
3543 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3544 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3545 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3546 CMP(HEIGHT
, dwHeight
),
3547 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3548 CMP(LPSURFACE
, lpSurface
),
3549 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3550 CMP(PITCH
, u1
/* lPitch */),
3551 /* PIXELFORMAT: manual */
3552 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3553 CMP(TEXTURESTAGE
, dwTextureStage
),
3554 CMP(WIDTH
, dwWidth
),
3555 /* ZBUFFERBITDEPTH: "obsolete" */
3562 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3565 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3567 if (requested
->dwFlags
& compare
[i
].flag
3568 && memcmp((const char *)provided
+ compare
[i
].offset
,
3569 (const char *)requested
+ compare
[i
].offset
,
3570 compare
[i
].size
) != 0)
3574 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3576 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3577 &provided
->u4
.ddpfPixelFormat
))
3584 #undef DDENUMSURFACES_SEARCHTYPE
3585 #undef DDENUMSURFACES_MATCHTYPE
3587 struct surfacescallback_context
3589 LPDDENUMSURFACESCALLBACK func
;
3593 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3594 DDSURFACEDESC2
*surface_desc
, void *context
)
3596 struct surfacescallback_context
*cbcontext
= context
;
3598 return cbcontext
->func((IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface
)->IDirectDrawSurface3_vtbl
,
3599 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3602 /*****************************************************************************
3603 * IDirectDraw7::EnumSurfaces
3605 * Loops through all surfaces attached to this device and calls the
3606 * application callback. This can't be relayed to WineD3DDevice,
3607 * because some WineD3DSurfaces' parents are IParent objects
3610 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3611 * DDSD: Description to filter for
3612 * Context: Application-provided pointer, it's passed unmodified to the
3614 * Callback: Address to call for each surface
3617 * DDERR_INVALIDPARAMS if the callback is NULL
3620 *****************************************************************************/
3621 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3622 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3624 /* The surface enumeration is handled by WineDDraw,
3625 * because it keeps track of all surfaces attached to
3626 * it. The filtering is done by our callback function,
3627 * because WineDDraw doesn't handle ddraw-like surface
3630 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
3631 IDirectDrawSurfaceImpl
*surf
;
3633 DDSURFACEDESC2 desc
;
3634 struct list
*entry
, *entry2
;
3636 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3637 iface
, Flags
, DDSD
, Context
, Callback
);
3639 all
= Flags
& DDENUMSURFACES_ALL
;
3640 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3642 EnterCriticalSection(&ddraw_cs
);
3646 LeaveCriticalSection(&ddraw_cs
);
3647 return DDERR_INVALIDPARAMS
;
3650 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3651 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3653 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3654 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3656 desc
= surf
->surface_desc
;
3657 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)surf
);
3658 if (Callback((IDirectDrawSurface7
*)surf
, &desc
, Context
) != DDENUMRET_OK
)
3660 LeaveCriticalSection(&ddraw_cs
);
3665 LeaveCriticalSection(&ddraw_cs
);
3669 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3670 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3672 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3673 iface
, flags
, surface_desc
, context
, callback
);
3675 return ddraw7_EnumSurfaces((IDirectDraw7
*)ddraw_from_ddraw4(iface
),
3676 flags
, surface_desc
, context
, (LPDDENUMSURFACESCALLBACK7
)callback
);
3679 static HRESULT WINAPI
ddraw3_EnumSurfaces(IDirectDraw3
*iface
, DWORD flags
,
3680 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3682 struct surfacescallback_context cbcontext
;
3684 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3685 iface
, flags
, surface_desc
, context
, callback
);
3687 cbcontext
.func
= callback
;
3688 cbcontext
.context
= context
;
3690 return ddraw7_EnumSurfaces((IDirectDraw7
*)ddraw_from_ddraw3(iface
), flags
,
3691 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumSurfacesCallbackThunk
);
3694 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3695 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3697 struct surfacescallback_context cbcontext
;
3699 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3700 iface
, flags
, surface_desc
, context
, callback
);
3702 cbcontext
.func
= callback
;
3703 cbcontext
.context
= context
;
3705 return ddraw7_EnumSurfaces((IDirectDraw7
*)ddraw_from_ddraw2(iface
), flags
,
3706 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumSurfacesCallbackThunk
);
3709 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3710 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3712 struct surfacescallback_context cbcontext
;
3714 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3715 iface
, flags
, surface_desc
, context
, callback
);
3717 cbcontext
.func
= callback
;
3718 cbcontext
.context
= context
;
3720 return ddraw7_EnumSurfaces((IDirectDraw7
*)ddraw_from_ddraw1(iface
), flags
,
3721 (DDSURFACEDESC2
*)surface_desc
, &cbcontext
, EnumSurfacesCallbackThunk
);
3724 /*****************************************************************************
3725 * DirectDrawCreateClipper (DDRAW.@)
3727 * Creates a new IDirectDrawClipper object.
3730 * Clipper: Address to write the interface pointer to
3731 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3735 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3736 * E_OUTOFMEMORY if allocating the object failed
3738 *****************************************************************************/
3740 DirectDrawCreateClipper(DWORD Flags
,
3741 LPDIRECTDRAWCLIPPER
*Clipper
,
3744 IDirectDrawClipperImpl
* object
;
3747 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3748 Flags
, Clipper
, UnkOuter
);
3750 EnterCriticalSection(&ddraw_cs
);
3751 if (UnkOuter
!= NULL
)
3753 LeaveCriticalSection(&ddraw_cs
);
3754 return CLASS_E_NOAGGREGATION
;
3759 LeaveCriticalSection(&ddraw_cs
);
3760 return DDERR_NODIRECTDRAWSUPPORT
;
3763 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3764 sizeof(IDirectDrawClipperImpl
));
3767 LeaveCriticalSection(&ddraw_cs
);
3768 return E_OUTOFMEMORY
;
3771 hr
= ddraw_clipper_init(object
);
3774 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3775 HeapFree(GetProcessHeap(), 0, object
);
3776 LeaveCriticalSection(&ddraw_cs
);
3780 TRACE("Created clipper %p.\n", object
);
3781 *Clipper
= (IDirectDrawClipper
*) object
;
3782 LeaveCriticalSection(&ddraw_cs
);
3786 /*****************************************************************************
3787 * IDirectDraw7::CreateClipper
3789 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3791 *****************************************************************************/
3792 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3793 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3795 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3796 iface
, Flags
, Clipper
, UnkOuter
);
3798 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3801 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
,
3802 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3804 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3805 iface
, flags
, clipper
, outer_unknown
);
3807 return ddraw7_CreateClipper((IDirectDraw7
*)ddraw_from_ddraw4(iface
), flags
, clipper
, outer_unknown
);
3810 static HRESULT WINAPI
ddraw3_CreateClipper(IDirectDraw3
*iface
,
3811 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3813 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3814 iface
, flags
, clipper
, outer_unknown
);
3816 return ddraw7_CreateClipper((IDirectDraw7
*)ddraw_from_ddraw3(iface
), flags
, clipper
, outer_unknown
);
3819 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3820 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3822 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3823 iface
, flags
, clipper
, outer_unknown
);
3825 return ddraw7_CreateClipper((IDirectDraw7
*)ddraw_from_ddraw2(iface
), flags
, clipper
, outer_unknown
);
3828 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3829 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3831 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3832 iface
, flags
, clipper
, outer_unknown
);
3834 return ddraw7_CreateClipper((IDirectDraw7
*)ddraw_from_ddraw1(iface
), flags
, clipper
, outer_unknown
);
3837 /*****************************************************************************
3838 * IDirectDraw7::CreatePalette
3840 * Creates a new IDirectDrawPalette object
3843 * Flags: The flags for the new clipper
3844 * ColorTable: Color table to assign to the new clipper
3845 * Palette: Address to write the interface pointer to
3846 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3850 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3851 * E_OUTOFMEMORY if allocating the object failed
3853 *****************************************************************************/
3854 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3855 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3857 IDirectDrawImpl
*This
= (IDirectDrawImpl
*)iface
;
3858 IDirectDrawPaletteImpl
*object
;
3861 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3862 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3864 EnterCriticalSection(&ddraw_cs
);
3865 if(pUnkOuter
!= NULL
)
3867 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3868 LeaveCriticalSection(&ddraw_cs
);
3869 return CLASS_E_NOAGGREGATION
;
3872 /* The refcount test shows that a cooplevel is required for this */
3873 if(!This
->cooperative_level
)
3875 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3876 LeaveCriticalSection(&ddraw_cs
);
3877 return DDERR_NOCOOPERATIVELEVELSET
;
3880 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3883 ERR("Out of memory when allocating memory for a palette implementation\n");
3884 LeaveCriticalSection(&ddraw_cs
);
3885 return E_OUTOFMEMORY
;
3888 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
3891 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3892 HeapFree(GetProcessHeap(), 0, object
);
3893 LeaveCriticalSection(&ddraw_cs
);
3897 TRACE("Created palette %p.\n", object
);
3898 *Palette
= (IDirectDrawPalette
*)object
;
3899 LeaveCriticalSection(&ddraw_cs
);
3903 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
,
3904 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3906 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw4(iface
);
3909 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3910 iface
, flags
, entries
, palette
, outer_unknown
);
3912 hr
= ddraw7_CreatePalette((IDirectDraw7
*)ddraw
, flags
, entries
, palette
, outer_unknown
);
3913 if (SUCCEEDED(hr
) && *palette
)
3915 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3916 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3917 IDirectDraw4_AddRef(iface
);
3918 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3923 static HRESULT WINAPI
ddraw3_CreatePalette(IDirectDraw3
*iface
, DWORD flags
,
3924 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3926 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw3(iface
);
3929 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3930 iface
, flags
, entries
, palette
, outer_unknown
);
3932 hr
= ddraw7_CreatePalette((IDirectDraw7
*)ddraw
, flags
, entries
, palette
, outer_unknown
);
3933 if (SUCCEEDED(hr
) && *palette
)
3935 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3936 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3937 IDirectDraw4_AddRef(iface
);
3938 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3944 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3945 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3947 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw2(iface
);
3950 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3951 iface
, flags
, entries
, palette
, outer_unknown
);
3953 hr
= ddraw7_CreatePalette((IDirectDraw7
*)ddraw
, flags
, entries
, palette
, outer_unknown
);
3954 if (SUCCEEDED(hr
) && *palette
)
3956 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3957 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3958 impl
->ifaceToRelease
= NULL
;
3964 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3965 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3967 IDirectDrawImpl
*ddraw
= ddraw_from_ddraw1(iface
);
3970 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3971 iface
, flags
, entries
, palette
, outer_unknown
);
3973 hr
= ddraw7_CreatePalette((IDirectDraw7
*)ddraw
, flags
, entries
, palette
, outer_unknown
);
3974 if (SUCCEEDED(hr
) && *palette
)
3976 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3977 IDirectDraw7_Release((IDirectDraw7
*)ddraw
);
3978 impl
->ifaceToRelease
= NULL
;
3984 /*****************************************************************************
3985 * IDirectDraw7::DuplicateSurface
3987 * Duplicates a surface. The surface memory points to the same memory as
3988 * the original surface, and it's released when the last surface referencing
3989 * it is released. I guess that's beyond Wine's surface management right now
3990 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3991 * test application to implement this)
3994 * Src: Address of the source surface
3995 * Dest: Address to write the new surface pointer to
3998 * See IDirectDraw7::CreateSurface
4000 *****************************************************************************/
4001 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
4002 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
4004 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Src
;
4006 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
4008 /* For now, simply create a new, independent surface */
4009 return IDirectDraw7_CreateSurface(iface
,
4010 &Surf
->surface_desc
,
4015 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
,
4016 IDirectDrawSurface4
*src
, IDirectDrawSurface4
**dst
)
4018 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4020 return ddraw7_DuplicateSurface((IDirectDraw7
*)ddraw_from_ddraw4(iface
),
4021 (IDirectDrawSurface7
*)src
, (IDirectDrawSurface7
**)dst
);
4024 static HRESULT WINAPI
ddraw3_DuplicateSurface(IDirectDraw3
*iface
,
4025 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
4027 IDirectDrawSurface7
*src7
, *dst7
;
4030 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4031 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4032 hr
= ddraw7_DuplicateSurface((IDirectDraw7
*)ddraw_from_ddraw3(iface
), src7
, &dst7
);
4035 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4039 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
4040 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
4042 IDirectDrawSurface7
*src7
, *dst7
;
4045 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4046 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4047 hr
= ddraw7_DuplicateSurface((IDirectDraw7
*)ddraw_from_ddraw2(iface
), src7
, &dst7
);
4050 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4054 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
,
4055 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
4057 IDirectDrawSurface7
*src7
, *dst7
;
4060 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4061 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4062 hr
= ddraw7_DuplicateSurface((IDirectDraw7
*)ddraw_from_ddraw1(iface
), src7
, &dst7
);
4065 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4069 /*****************************************************************************
4070 * IDirect3D7::EnumDevices
4072 * The EnumDevices method for IDirect3D7. It enumerates all supported
4073 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
4076 * callback: Function to call for each enumerated device
4077 * context: Pointer to pass back to the app
4080 * D3D_OK, or the return value of the GetCaps call
4082 *****************************************************************************/
4083 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
4085 char interface_name_tnl
[] = "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D";
4086 char device_name_tnl
[] = "Wine D3D7 T&L HAL";
4087 char interface_name_hal
[] = "WINE Direct3D7 Hardware acceleration using WineD3D";
4088 char device_name_hal
[] = "Wine D3D7 HAL";
4089 char interface_name_rgb
[] = "WINE Direct3D7 RGB Software Emulation using WineD3D";
4090 char device_name_rgb
[] = "Wine D3D7 RGB";
4092 IDirectDrawImpl
*ddraw
= ddraw_from_d3d7(iface
);
4093 D3DDEVICEDESC7 device_desc7
;
4094 D3DDEVICEDESC device_desc1
;
4097 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4099 EnterCriticalSection(&ddraw_cs
);
4101 hr
= IDirect3DImpl_GetCaps(ddraw
->wineD3D
, &device_desc1
, &device_desc7
);
4104 LeaveCriticalSection(&ddraw_cs
);
4107 callback(interface_name_tnl
, device_name_tnl
, &device_desc7
, context
);
4109 device_desc7
.deviceGUID
= IID_IDirect3DHALDevice
;
4110 callback(interface_name_hal
, device_name_hal
, &device_desc7
, context
);
4112 device_desc7
.deviceGUID
= IID_IDirect3DRGBDevice
;
4113 callback(interface_name_rgb
, device_name_rgb
, &device_desc7
, context
);
4115 TRACE("End of enumeration.\n");
4117 LeaveCriticalSection(&ddraw_cs
);
4122 /*****************************************************************************
4123 * IDirect3D3::EnumDevices
4125 * Enumerates all supported Direct3DDevice interfaces. This is the
4126 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
4128 * Version 1, 2 and 3
4131 * callback: Application-provided routine to call for each enumerated device
4132 * Context: Pointer to pass to the callback
4135 * D3D_OK on success,
4136 * The result of IDirect3DImpl_GetCaps if it failed
4138 *****************************************************************************/
4139 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4141 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
4143 IDirectDrawImpl
*ddraw
= ddraw_from_d3d3(iface
);
4144 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
4145 D3DDEVICEDESC7 device_desc7
;
4148 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
4149 * name string. Let's put the string in a sufficiently sized array in
4150 * writable memory. */
4151 char device_name
[50];
4152 strcpy(device_name
,"Direct3D HEL");
4154 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4156 EnterCriticalSection(&ddraw_cs
);
4158 hr
= IDirect3DImpl_GetCaps(ddraw
->wineD3D
, &device_desc1
, &device_desc7
);
4161 LeaveCriticalSection(&ddraw_cs
);
4165 /* Do I have to enumerate the reference id? Note from old d3d7:
4166 * "It seems that enumerating the reference IID on Direct3D 1 games
4167 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4169 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4170 * EnumReference which enables / disables enumerating the reference
4171 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4172 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4173 * demo directory suggest this.
4175 * Some games(GTA 2) seem to use the second enumerated device, so I have
4176 * to enumerate at least 2 devices. So enumerate the reference device to
4179 * Other games (Rollcage) tell emulation and hal device apart by certain
4180 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4181 * limitation flag), and it refuses all devices that have the perspective
4182 * flag set. This way it refuses the emulation device, and HAL devices
4183 * never have POW2 unset in d3d7 on windows. */
4184 if (ddraw
->d3dversion
!= 1)
4186 static CHAR reference_description
[] = "RGB Direct3D emulation";
4188 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4189 hal_desc
= device_desc1
;
4190 hel_desc
= device_desc1
;
4191 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4192 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4193 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4194 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4195 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4196 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4197 device_name
, &hal_desc
, &hel_desc
, context
);
4198 if (hr
!= D3DENUMRET_OK
)
4200 TRACE("Application cancelled the enumeration.\n");
4201 LeaveCriticalSection(&ddraw_cs
);
4206 strcpy(device_name
,"Direct3D HAL");
4208 TRACE("Enumerating HAL Direct3D device.\n");
4209 hal_desc
= device_desc1
;
4210 hel_desc
= device_desc1
;
4211 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4212 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4213 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4214 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4215 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4216 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4217 device_name
, &hal_desc
, &hel_desc
, context
);
4218 if (hr
!= D3DENUMRET_OK
)
4220 TRACE("Application cancelled the enumeration.\n");
4221 LeaveCriticalSection(&ddraw_cs
);
4225 TRACE("End of enumeration.\n");
4227 LeaveCriticalSection(&ddraw_cs
);
4231 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4233 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4235 return d3d3_EnumDevices((IDirect3D3
*)&ddraw_from_d3d2(iface
)->IDirect3D3_vtbl
, callback
, context
);
4238 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4240 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4242 return d3d3_EnumDevices((IDirect3D3
*)&ddraw_from_d3d1(iface
)->IDirect3D3_vtbl
, callback
, context
);
4245 /*****************************************************************************
4246 * IDirect3D3::CreateLight
4248 * Creates an IDirect3DLight interface. This interface is used in
4249 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4250 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4251 * uses the IDirect3DDevice7 interface with D3D7 lights.
4253 * Version 1, 2 and 3
4256 * light: Address to store the new interface pointer
4257 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4262 * DDERR_OUTOFMEMORY if memory allocation failed
4263 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4265 *****************************************************************************/
4266 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4268 IDirect3DLightImpl
*object
;
4270 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4272 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4274 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4277 ERR("Failed to allocate light memory.\n");
4278 return DDERR_OUTOFMEMORY
;
4281 d3d_light_init(object
, ddraw_from_d3d3(iface
));
4283 TRACE("Created light %p.\n", object
);
4284 *light
= (IDirect3DLight
*)object
;
4289 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4291 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4293 return d3d3_CreateLight((IDirect3D3
*)&ddraw_from_d3d2(iface
)->IDirect3D3_vtbl
, light
, outer_unknown
);
4296 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4298 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4300 return d3d3_CreateLight((IDirect3D3
*)&ddraw_from_d3d1(iface
)->IDirect3D3_vtbl
, light
, outer_unknown
);
4303 /*****************************************************************************
4304 * IDirect3D3::CreateMaterial
4306 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4307 * and older versions. The IDirect3DMaterial implementation wraps its
4308 * functionality to IDirect3DDevice7::SetMaterial and friends.
4310 * Version 1, 2 and 3
4313 * material: Address to store the new interface's pointer to
4314 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4319 * DDERR_OUTOFMEMORY if memory allocation failed
4320 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4322 *****************************************************************************/
4323 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
, IUnknown
*outer_unknown
)
4325 IDirect3DMaterialImpl
*object
;
4327 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4329 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4331 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4334 ERR("Failed to allocate material memory.\n");
4335 return DDERR_OUTOFMEMORY
;
4338 d3d_material_init(object
, ddraw_from_d3d3(iface
));
4340 TRACE("Created material %p.\n", object
);
4341 *material
= (IDirect3DMaterial3
*)object
;
4346 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
, IUnknown
*outer_unknown
)
4348 IDirect3DMaterial3
*material3
;
4351 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4353 hr
= d3d3_CreateMaterial((IDirect3D3
*)&ddraw_from_d3d2(iface
)->IDirect3D3_vtbl
, &material3
, outer_unknown
);
4354 *material
= material3
? (IDirect3DMaterial2
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial2_vtbl
: NULL
;
4356 TRACE("Returning material %p.\n", *material
);
4361 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
, IUnknown
*outer_unknown
)
4363 IDirect3DMaterial3
*material3
;
4366 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4368 hr
= d3d3_CreateMaterial((IDirect3D3
*)&ddraw_from_d3d1(iface
)->IDirect3D3_vtbl
, &material3
, outer_unknown
);
4369 *material
= material3
? (IDirect3DMaterial
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial_vtbl
: NULL
;
4371 TRACE("Returning material %p.\n", *material
);
4376 /*****************************************************************************
4377 * IDirect3D3::CreateViewport
4379 * Creates an IDirect3DViewport interface. This interface is used
4380 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4381 * it has been replaced by a viewport structure and
4382 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4383 * uses the IDirect3DDevice7 methods for its functionality
4386 * Viewport: Address to store the new interface pointer
4387 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4392 * DDERR_OUTOFMEMORY if memory allocation failed
4393 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4395 *****************************************************************************/
4396 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
, IUnknown
*outer_unknown
)
4398 IDirect3DViewportImpl
*object
;
4400 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4402 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4404 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4407 ERR("Failed to allocate viewport memory.\n");
4408 return DDERR_OUTOFMEMORY
;
4411 d3d_viewport_init(object
, ddraw_from_d3d3(iface
));
4413 TRACE("Created viewport %p.\n", object
);
4414 *viewport
= (IDirect3DViewport3
*)object
;
4419 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4421 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4423 return d3d3_CreateViewport((IDirect3D3
*)&ddraw_from_d3d2(iface
)->IDirect3D3_vtbl
,
4424 (IDirect3DViewport3
**)viewport
, outer_unknown
);
4427 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4429 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4431 return d3d3_CreateViewport((IDirect3D3
*)&ddraw_from_d3d1(iface
)->IDirect3D3_vtbl
,
4432 (IDirect3DViewport3
**)viewport
, outer_unknown
);
4435 /*****************************************************************************
4436 * IDirect3D3::FindDevice
4438 * This method finds a device with the requested properties and returns a
4439 * device description
4443 * fds: Describes the requested device characteristics
4444 * fdr: Returns the device description
4448 * DDERR_INVALIDPARAMS if no device was found
4450 *****************************************************************************/
4451 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4453 IDirectDrawImpl
*ddraw
= ddraw_from_d3d3(iface
);
4454 D3DDEVICEDESC7 desc7
;
4455 D3DDEVICEDESC desc1
;
4458 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4460 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4462 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4463 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4464 return DDERR_INVALIDPARAMS
;
4466 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4467 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4469 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4470 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4473 if (fds
->dwFlags
& D3DFDS_GUID
)
4475 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4476 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4477 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4478 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4480 WARN("No match for this GUID.\n");
4481 return DDERR_NOTFOUND
;
4486 hr
= IDirect3DImpl_GetCaps(ddraw
->wineD3D
, &desc1
, &desc7
);
4487 if (hr
!= D3D_OK
) return hr
;
4489 /* Now return our own GUID */
4490 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4491 fdr
->ddHwDesc
= desc1
;
4492 fdr
->ddSwDesc
= desc1
;
4494 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4499 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4501 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4503 return d3d3_FindDevice((IDirect3D3
*)&ddraw_from_d3d2(iface
)->IDirect3D3_vtbl
, fds
, fdr
);
4506 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4508 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4510 return d3d3_FindDevice((IDirect3D3
*)&ddraw_from_d3d1(iface
)->IDirect3D3_vtbl
, fds
, fdr
);
4513 /*****************************************************************************
4514 * IDirect3D7::CreateDevice
4516 * Creates an IDirect3DDevice7 interface.
4518 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4519 * DirectDraw surfaces and are created with
4520 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4521 * create the device object and QueryInterfaces for IDirect3DDevice
4524 * refiid: IID of the device to create
4525 * Surface: Initial rendertarget
4526 * Device: Address to return the interface pointer
4530 * DDERR_OUTOFMEMORY if memory allocation failed
4531 * DDERR_INVALIDPARAMS if a device exists already
4533 *****************************************************************************/
4534 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4535 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4537 IDirectDrawSurfaceImpl
*target
= (IDirectDrawSurfaceImpl
*)surface
;
4538 IDirectDrawImpl
*ddraw
= ddraw_from_d3d7(iface
);
4539 IDirect3DDeviceImpl
*object
;
4542 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4544 EnterCriticalSection(&ddraw_cs
);
4547 /* Fail device creation if non-opengl surfaces are used. */
4548 if (ddraw
->ImplType
!= SURFACE_OPENGL
)
4550 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4551 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4553 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4554 * is caught in CreateSurface or QueryInterface. */
4555 LeaveCriticalSection(&ddraw_cs
);
4559 if (ddraw
->d3ddevice
)
4561 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4562 LeaveCriticalSection(&ddraw_cs
);
4563 return DDERR_INVALIDPARAMS
;
4566 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4569 ERR("Failed to allocate device memory.\n");
4570 LeaveCriticalSection(&ddraw_cs
);
4571 return DDERR_OUTOFMEMORY
;
4574 hr
= d3d_device_init(object
, ddraw
, target
);
4577 WARN("Failed to initialize device, hr %#x.\n", hr
);
4578 HeapFree(GetProcessHeap(), 0, object
);
4579 LeaveCriticalSection(&ddraw_cs
);
4583 TRACE("Created device %p.\n", object
);
4584 *device
= (IDirect3DDevice7
*)object
;
4586 LeaveCriticalSection(&ddraw_cs
);
4590 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4591 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4595 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4596 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4598 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4600 hr
= d3d7_CreateDevice((IDirect3D7
*)&ddraw_from_d3d3(iface
)->IDirect3D7_vtbl
, riid
,
4601 (IDirectDrawSurface7
*)surface
, (IDirect3DDevice7
**)device
);
4602 if (*device
) *device
= (IDirect3DDevice3
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice3_vtbl
;
4607 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4608 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4612 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4613 iface
, debugstr_guid(riid
), surface
, device
);
4615 hr
= d3d7_CreateDevice((IDirect3D7
*)&ddraw_from_d3d2(iface
)->IDirect3D7_vtbl
, riid
,
4616 surface
? (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)surface
) : NULL
,
4617 (IDirect3DDevice7
**)device
);
4618 if (*device
) *device
= (IDirect3DDevice2
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice2_vtbl
;
4623 /*****************************************************************************
4624 * IDirect3D7::CreateVertexBuffer
4626 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4632 * desc: Requested Vertex buffer properties
4633 * vertex_buffer: Address to return the interface pointer at
4634 * flags: Some flags, should be 0
4638 * DDERR_OUTOFMEMORY if memory allocation failed
4639 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4640 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4642 *****************************************************************************/
4643 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4644 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4646 IDirect3DVertexBufferImpl
*object
;
4649 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4650 iface
, desc
, vertex_buffer
, flags
);
4652 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4654 TRACE("Vertex buffer description:\n");
4655 TRACE(" dwSize %u\n", desc
->dwSize
);
4656 TRACE(" dwCaps %#x\n", desc
->dwCaps
);
4657 TRACE(" FVF %#x\n", desc
->dwFVF
);
4658 TRACE(" dwNumVertices %u\n", desc
->dwNumVertices
);
4660 /* Now create the vertex buffer */
4661 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4664 ERR("Failed to allocate vertex buffer memory.\n");
4665 return DDERR_OUTOFMEMORY
;
4668 hr
= d3d_vertex_buffer_init(object
, ddraw_from_d3d7(iface
), desc
);
4671 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
4672 HeapFree(GetProcessHeap(), 0, object
);
4676 TRACE("Created vertex buffer %p.\n", object
);
4677 *vertex_buffer
= (IDirect3DVertexBuffer7
*)object
;
4682 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4683 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4685 IDirectDrawImpl
*This
= ddraw_from_d3d3(iface
);
4688 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4689 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4691 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4693 hr
= d3d7_CreateVertexBuffer((IDirect3D7
*)&This
->IDirect3D7_vtbl
,
4694 desc
, (IDirect3DVertexBuffer7
**)vertex_buffer
, flags
);
4696 *vertex_buffer
= (IDirect3DVertexBuffer
*)&((IDirect3DVertexBufferImpl
*)*vertex_buffer
)->IDirect3DVertexBuffer_vtbl
;
4701 /*****************************************************************************
4702 * IDirect3D7::EnumZBufferFormats
4704 * Enumerates all supported Z buffer pixel formats
4710 * callback: callback to call for each pixel format
4711 * context: Pointer to pass back to the callback
4715 * DDERR_INVALIDPARAMS if callback is NULL
4716 * For details, see IWineD3DDevice::EnumZBufferFormats
4718 *****************************************************************************/
4719 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4720 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4722 IDirectDrawImpl
*ddraw
= ddraw_from_d3d7(iface
);
4723 WINED3DDISPLAYMODE d3ddm
;
4724 WINED3DDEVTYPE type
;
4728 /* Order matters. Specifically, BattleZone II (full version) expects the
4729 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4730 static const enum wined3d_format_id formats
[] =
4732 WINED3DFMT_S1_UINT_D15_UNORM
,
4733 WINED3DFMT_D16_UNORM
,
4734 WINED3DFMT_X8D24_UNORM
,
4735 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4736 WINED3DFMT_D24_UNORM_S8_UINT
,
4737 WINED3DFMT_D32_UNORM
,
4740 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4741 iface
, debugstr_guid(device_iid
), callback
, context
);
4743 if (!callback
) return DDERR_INVALIDPARAMS
;
4745 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4746 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4747 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4749 TRACE("Asked for HAL device.\n");
4750 type
= WINED3DDEVTYPE_HAL
;
4752 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4753 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4755 TRACE("Asked for SW device.\n");
4756 type
= WINED3DDEVTYPE_SW
;
4758 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4760 TRACE("Asked for REF device.\n");
4761 type
= WINED3DDEVTYPE_REF
;
4763 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4765 TRACE("Asked for NULLREF device.\n");
4766 type
= WINED3DDEVTYPE_NULLREF
;
4770 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4771 type
= WINED3DDEVTYPE_HAL
;
4774 EnterCriticalSection(&ddraw_cs
);
4775 /* We need an adapter format from somewhere to please wined3d and WGL.
4776 * Use the current display mode. So far all cards offer the same depth
4777 * stencil format for all modes, but if some do not and applications do
4778 * not like that we'll have to find some workaround, like iterating over
4779 * all imaginable formats and collecting all the depth stencil formats we
4781 hr
= IWineD3DDevice_GetDisplayMode(ddraw
->wineD3DDevice
, 0, &d3ddm
);
4783 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4785 hr
= IWineD3D_CheckDeviceFormat(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4786 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, formats
[i
], SURFACE_OPENGL
);
4789 DDPIXELFORMAT pformat
;
4791 memset(&pformat
, 0, sizeof(pformat
));
4792 pformat
.dwSize
= sizeof(pformat
);
4793 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4795 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4796 hr
= callback(&pformat
, context
);
4797 if (hr
!= DDENUMRET_OK
)
4799 TRACE("Format enumeration cancelled by application.\n");
4800 LeaveCriticalSection(&ddraw_cs
);
4805 TRACE("End of enumeration.\n");
4807 LeaveCriticalSection(&ddraw_cs
);
4811 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4812 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4814 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4815 iface
, debugstr_guid(device_iid
), callback
, context
);
4817 return d3d7_EnumZBufferFormats((IDirect3D7
*)&ddraw_from_d3d3(iface
)->IDirect3D7_vtbl
,
4818 device_iid
, callback
, context
);
4821 /*****************************************************************************
4822 * IDirect3D7::EvictManagedTextures
4824 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4825 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4830 * D3D_OK, because it's a stub
4832 *****************************************************************************/
4833 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4835 FIXME("iface %p stub!\n", iface
);
4837 /* TODO: Just enumerate resources using IWineD3DDevice_EnumResources(),
4838 * then unload surfaces / textures. */
4843 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4845 TRACE("iface %p.\n", iface
);
4847 return d3d7_EvictManagedTextures((IDirect3D7
*)&ddraw_from_d3d3(iface
)->IDirect3D7_vtbl
);
4850 /*****************************************************************************
4851 * IDirect3DImpl_GetCaps
4853 * This function retrieves the device caps from wined3d
4854 * and converts it into a D3D7 and D3D - D3D3 structure
4855 * This is a helper function called from various places in ddraw
4858 * wined3d: The interface to get the caps from
4859 * desc1: Old D3D <3 structure to fill (needed)
4860 * desc7: D3D7 device desc structure to fill (needed)
4863 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4865 *****************************************************************************/
4866 HRESULT
IDirect3DImpl_GetCaps(IWineD3D
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4868 WINED3DCAPS wined3d_caps
;
4871 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4873 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4875 EnterCriticalSection(&ddraw_cs
);
4876 hr
= IWineD3D_GetDeviceCaps(wined3d
, 0, WINED3DDEVTYPE_HAL
, &wined3d_caps
);
4877 LeaveCriticalSection(&ddraw_cs
);
4880 WARN("Failed to get device caps, hr %#x.\n", hr
);
4884 /* Copy the results into the d3d7 and d3d3 structures */
4885 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4886 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4887 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4888 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4889 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4890 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4891 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4892 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4893 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4894 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4895 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4897 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4898 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4900 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4901 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4902 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4903 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4905 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4906 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4907 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4908 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4910 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4911 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4913 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4914 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4916 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4917 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4919 /* Remove all non-d3d7 caps */
4920 desc7
->dwDevCaps
&= (
4921 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4922 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4923 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4924 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4925 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4926 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4927 D3DDEVCAPS_HWRASTERIZATION
);
4929 desc7
->dwStencilCaps
&= (
4930 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4931 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4932 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4936 desc7
->dwTextureOpCaps
&= (
4937 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4938 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4939 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4940 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4941 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4942 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4943 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4944 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4946 desc7
->dwVertexProcessingCaps
&= (
4947 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4948 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4950 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4951 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4952 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4953 D3DPMISCCAPS_CULLCCW
);
4955 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4956 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4957 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4958 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4959 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4960 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4961 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4962 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4963 D3DPRASTERCAPS_ZFOG
);
4965 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4966 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4967 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4968 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4970 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4971 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4972 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4973 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4974 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4975 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4977 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4978 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4979 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4980 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4981 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4982 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4984 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4985 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4986 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4987 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4989 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4990 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4991 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4992 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4993 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4994 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4995 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4996 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4998 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4999 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
5000 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
5001 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
5002 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
5004 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
5005 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
5006 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
5007 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
5008 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
5009 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
5010 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
5012 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
5013 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
5014 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
5015 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
5017 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
5018 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
5019 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
5021 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
5023 /* DirectX7 always has the np2 flag set, no matter what the card
5024 * supports. Some old games (Rollcage) check the caps incorrectly.
5025 * If wined3d supports nonpow2 textures it also has np2 conditional
5027 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
5030 /* Fill the missing members, and do some fixup */
5031 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
5032 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
5033 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
5034 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
5035 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
5036 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
5037 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
5038 /* Use the same for the TriCaps */
5039 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
5041 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
5042 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
5043 desc7
->dwMinTextureWidth
= 1;
5044 desc7
->dwMinTextureHeight
= 1;
5046 /* Convert DWORDs safely to WORDs */
5047 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
5048 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
5049 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
5050 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
5052 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
5053 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
5054 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
5055 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
5057 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
5059 desc7
->dwReserved1
= 0;
5060 desc7
->dwReserved2
= 0;
5061 desc7
->dwReserved3
= 0;
5062 desc7
->dwReserved4
= 0;
5064 /* Fill the old structure */
5065 memset(desc1
, 0, sizeof(*desc1
));
5066 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
5067 desc1
->dwFlags
= D3DDD_COLORMODEL
5069 | D3DDD_TRANSFORMCAPS
5071 | D3DDD_LIGHTINGCAPS
5074 | D3DDD_DEVICERENDERBITDEPTH
5075 | D3DDD_DEVICEZBUFFERBITDEPTH
5076 | D3DDD_MAXBUFFERSIZE
5077 | D3DDD_MAXVERTEXCOUNT
;
5079 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
5080 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
5081 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
5082 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
5083 desc1
->bClipping
= TRUE
;
5084 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
5085 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
5086 | D3DLIGHTCAPS_PARALLELPOINT
5087 | D3DLIGHTCAPS_POINT
5088 | D3DLIGHTCAPS_SPOT
;
5090 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
5091 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
5093 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5094 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
5095 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
5096 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
5097 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
5098 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
5099 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
5100 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
5101 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
5102 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
5103 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
5104 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
5105 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
5107 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5108 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
5109 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
5110 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
5111 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
5112 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
5113 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
5114 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
5115 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
5116 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
5117 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
5118 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
5119 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
5121 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
5122 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
5123 desc1
->dwMaxBufferSize
= 0;
5124 desc1
->dwMaxVertexCount
= 65536;
5125 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
5126 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
5127 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
5128 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
5129 desc1
->dwMinStippleWidth
= 1;
5130 desc1
->dwMinStippleHeight
= 1;
5131 desc1
->dwMaxStippleWidth
= 32;
5132 desc1
->dwMaxStippleHeight
= 32;
5133 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
5134 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
5135 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
5136 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
5137 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
5138 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
5139 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
5140 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
5141 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
5142 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
5143 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
5144 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
5145 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
5150 /*****************************************************************************
5151 * IDirectDraw7 VTable
5152 *****************************************************************************/
5153 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
5156 ddraw7_QueryInterface
,
5161 ddraw7_CreateClipper
,
5162 ddraw7_CreatePalette
,
5163 ddraw7_CreateSurface
,
5164 ddraw7_DuplicateSurface
,
5165 ddraw7_EnumDisplayModes
,
5166 ddraw7_EnumSurfaces
,
5167 ddraw7_FlipToGDISurface
,
5169 ddraw7_GetDisplayMode
,
5170 ddraw7_GetFourCCCodes
,
5171 ddraw7_GetGDISurface
,
5172 ddraw7_GetMonitorFrequency
,
5174 ddraw7_GetVerticalBlankStatus
,
5176 ddraw7_RestoreDisplayMode
,
5177 ddraw7_SetCooperativeLevel
,
5178 ddraw7_SetDisplayMode
,
5179 ddraw7_WaitForVerticalBlank
,
5181 ddraw7_GetAvailableVidMem
,
5183 ddraw7_GetSurfaceFromDC
,
5185 ddraw7_RestoreAllSurfaces
,
5186 ddraw7_TestCooperativeLevel
,
5187 ddraw7_GetDeviceIdentifier
,
5189 ddraw7_StartModeTest
,
5193 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
5196 ddraw4_QueryInterface
,
5201 ddraw4_CreateClipper
,
5202 ddraw4_CreatePalette
,
5203 ddraw4_CreateSurface
,
5204 ddraw4_DuplicateSurface
,
5205 ddraw4_EnumDisplayModes
,
5206 ddraw4_EnumSurfaces
,
5207 ddraw4_FlipToGDISurface
,
5209 ddraw4_GetDisplayMode
,
5210 ddraw4_GetFourCCCodes
,
5211 ddraw4_GetGDISurface
,
5212 ddraw4_GetMonitorFrequency
,
5214 ddraw4_GetVerticalBlankStatus
,
5216 ddraw4_RestoreDisplayMode
,
5217 ddraw4_SetCooperativeLevel
,
5218 ddraw4_SetDisplayMode
,
5219 ddraw4_WaitForVerticalBlank
,
5221 ddraw4_GetAvailableVidMem
,
5223 ddraw4_GetSurfaceFromDC
,
5225 ddraw4_RestoreAllSurfaces
,
5226 ddraw4_TestCooperativeLevel
,
5227 ddraw4_GetDeviceIdentifier
,
5230 static const struct IDirectDraw3Vtbl ddraw3_vtbl
=
5233 ddraw3_QueryInterface
,
5238 ddraw3_CreateClipper
,
5239 ddraw3_CreatePalette
,
5240 ddraw3_CreateSurface
,
5241 ddraw3_DuplicateSurface
,
5242 ddraw3_EnumDisplayModes
,
5243 ddraw3_EnumSurfaces
,
5244 ddraw3_FlipToGDISurface
,
5246 ddraw3_GetDisplayMode
,
5247 ddraw3_GetFourCCCodes
,
5248 ddraw3_GetGDISurface
,
5249 ddraw3_GetMonitorFrequency
,
5251 ddraw3_GetVerticalBlankStatus
,
5253 ddraw3_RestoreDisplayMode
,
5254 ddraw3_SetCooperativeLevel
,
5255 ddraw3_SetDisplayMode
,
5256 ddraw3_WaitForVerticalBlank
,
5258 ddraw3_GetAvailableVidMem
,
5260 ddraw3_GetSurfaceFromDC
,
5263 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5266 ddraw2_QueryInterface
,
5271 ddraw2_CreateClipper
,
5272 ddraw2_CreatePalette
,
5273 ddraw2_CreateSurface
,
5274 ddraw2_DuplicateSurface
,
5275 ddraw2_EnumDisplayModes
,
5276 ddraw2_EnumSurfaces
,
5277 ddraw2_FlipToGDISurface
,
5279 ddraw2_GetDisplayMode
,
5280 ddraw2_GetFourCCCodes
,
5281 ddraw2_GetGDISurface
,
5282 ddraw2_GetMonitorFrequency
,
5284 ddraw2_GetVerticalBlankStatus
,
5286 ddraw2_RestoreDisplayMode
,
5287 ddraw2_SetCooperativeLevel
,
5288 ddraw2_SetDisplayMode
,
5289 ddraw2_WaitForVerticalBlank
,
5291 ddraw2_GetAvailableVidMem
,
5294 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5297 ddraw1_QueryInterface
,
5302 ddraw1_CreateClipper
,
5303 ddraw1_CreatePalette
,
5304 ddraw1_CreateSurface
,
5305 ddraw1_DuplicateSurface
,
5306 ddraw1_EnumDisplayModes
,
5307 ddraw1_EnumSurfaces
,
5308 ddraw1_FlipToGDISurface
,
5310 ddraw1_GetDisplayMode
,
5311 ddraw1_GetFourCCCodes
,
5312 ddraw1_GetGDISurface
,
5313 ddraw1_GetMonitorFrequency
,
5315 ddraw1_GetVerticalBlankStatus
,
5317 ddraw1_RestoreDisplayMode
,
5318 ddraw1_SetCooperativeLevel
,
5319 ddraw1_SetDisplayMode
,
5320 ddraw1_WaitForVerticalBlank
,
5323 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5325 /* IUnknown methods */
5326 d3d7_QueryInterface
,
5329 /* IDirect3D7 methods */
5332 d3d7_CreateVertexBuffer
,
5333 d3d7_EnumZBufferFormats
,
5334 d3d7_EvictManagedTextures
5337 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5339 /* IUnknown methods */
5340 d3d3_QueryInterface
,
5343 /* IDirect3D3 methods */
5346 d3d3_CreateMaterial
,
5347 d3d3_CreateViewport
,
5350 d3d3_CreateVertexBuffer
,
5351 d3d3_EnumZBufferFormats
,
5352 d3d3_EvictManagedTextures
5355 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5357 /* IUnknown methods */
5358 d3d2_QueryInterface
,
5361 /* IDirect3D2 methods */
5364 d3d2_CreateMaterial
,
5365 d3d2_CreateViewport
,
5370 static const struct IDirect3DVtbl d3d1_vtbl
=
5372 /* IUnknown methods */
5373 d3d1_QueryInterface
,
5376 /* IDirect3D methods */
5380 d3d1_CreateMaterial
,
5381 d3d1_CreateViewport
,
5385 /*****************************************************************************
5388 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5389 * if none was found.
5391 * This function is in ddraw.c and the DDraw object space because D3D7
5392 * vertex buffers are created using the IDirect3D interface to the ddraw
5393 * object, so they can be valid across D3D devices(theoretically. The ddraw
5394 * object also owns the wined3d device
5398 * fvf: Fvf to find the decl for
5401 * NULL in case of an error, the IWineD3DVertexDeclaration interface for the
5404 *****************************************************************************/
5405 IWineD3DVertexDeclaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5408 IWineD3DVertexDeclaration
* pDecl
= NULL
;
5409 int p
, low
, high
; /* deliberately signed */
5410 struct FvfToDecl
*convertedDecls
= This
->decls
;
5412 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5415 high
= This
->numConvertedDecls
- 1;
5416 while(low
<= high
) {
5417 p
= (low
+ high
) >> 1;
5419 if(convertedDecls
[p
].fvf
== fvf
) {
5420 TRACE("found %p\n", convertedDecls
[p
].decl
);
5421 return convertedDecls
[p
].decl
;
5422 } else if(convertedDecls
[p
].fvf
< fvf
) {
5428 TRACE("not found. Creating and inserting at position %d.\n", low
);
5430 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->wineD3DDevice
,
5431 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5432 if (hr
!= S_OK
) return NULL
;
5434 if(This
->declArraySize
== This
->numConvertedDecls
) {
5435 int grow
= max(This
->declArraySize
/ 2, 8);
5436 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5437 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5438 if(!convertedDecls
) {
5439 /* This will destroy it */
5440 IWineD3DVertexDeclaration_Release(pDecl
);
5443 This
->decls
= convertedDecls
;
5444 This
->declArraySize
+= grow
;
5447 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5448 convertedDecls
[low
].decl
= pDecl
;
5449 convertedDecls
[low
].fvf
= fvf
;
5450 This
->numConvertedDecls
++;
5452 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5456 /* IWineD3DDeviceParent IUnknown methods */
5458 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(IWineD3DDeviceParent
*iface
)
5460 return (struct IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(struct IDirectDrawImpl
, device_parent_vtbl
));
5463 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
, REFIID riid
, void **object
)
5465 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5466 return ddraw7_QueryInterface((IDirectDraw7
*)This
, riid
, object
);
5469 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
5471 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5472 return ddraw7_AddRef((IDirectDraw7
*)This
);
5475 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
5477 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5478 return ddraw7_Release((IDirectDraw7
*)This
);
5481 /* IWineD3DDeviceParent methods */
5483 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
5485 TRACE("iface %p, device %p\n", iface
, device
);
5488 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
5489 IUnknown
*superior
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5490 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
5492 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5493 IDirectDrawSurfaceImpl
*surf
= NULL
;
5495 DDSCAPS2 searchcaps
= This
->tex_root
->surface_desc
.ddsCaps
;
5497 TRACE("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
5498 "\tpool %#x, level %u, face %u, surface %p\n",
5499 iface
, superior
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5501 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5504 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
5505 TRACE("Asked for positive x\n");
5506 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5508 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5510 surf
= This
->tex_root
; break;
5511 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
5512 TRACE("Asked for negative x\n");
5513 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5514 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
5515 TRACE("Asked for positive y\n");
5516 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5517 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
5518 TRACE("Asked for negative y\n");
5519 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5520 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
5521 TRACE("Asked for positive z\n");
5522 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5523 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
5524 TRACE("Asked for negative z\n");
5525 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5526 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
5531 IDirectDrawSurface7
*attached
;
5532 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)This
->tex_root
, &searchcaps
, &attached
);
5533 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5534 IDirectDrawSurface7_Release(attached
);
5536 if (!surf
) ERR("root search surface not found\n");
5538 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5541 IDirectDrawSurface7
*attached
;
5542 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &searchcaps
, &attached
);
5543 if(!attached
) ERR("Surface not found\n");
5544 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5545 IDirectDrawSurface7_Release(attached
);
5549 /* Return the surface */
5550 *surface
= surf
->WineD3DSurface
;
5551 IWineD3DSurface_AddRef(*surface
);
5553 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5558 static HRESULT WINAPI
findRenderTarget(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *ctx
)
5560 IDirectDrawSurfaceImpl
*s
= (IDirectDrawSurfaceImpl
*)surface
;
5561 IDirectDrawSurfaceImpl
**target
= ctx
;
5563 if (!s
->isRenderTarget
)
5566 IDirectDrawSurface7_Release(surface
);
5567 return DDENUMRET_CANCEL
;
5570 /* Recurse into the surface tree */
5571 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
5573 IDirectDrawSurface7_Release(surface
);
5574 if (*target
) return DDENUMRET_CANCEL
;
5576 return DDENUMRET_OK
;
5579 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
5580 IUnknown
*superior
, UINT width
, UINT height
, enum wined3d_format_id format
,
5581 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5582 IWineD3DSurface
**surface
)
5584 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5585 IDirectDrawSurfaceImpl
*d3d_surface
= This
->d3d_target
;
5586 IDirectDrawSurfaceImpl
*target
= NULL
;
5588 TRACE("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5589 "\tmultisample_quality %u, lockable %u, surface %p\n",
5590 iface
, superior
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
5592 if (d3d_surface
->isRenderTarget
)
5594 IDirectDrawSurface7_EnumAttachedSurfaces((IDirectDrawSurface7
*)d3d_surface
, &target
, findRenderTarget
);
5598 target
= d3d_surface
;
5603 target
= This
->d3d_target
;
5604 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
5607 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
5609 *surface
= target
->WineD3DSurface
;
5610 IWineD3DSurface_AddRef(*surface
);
5611 target
->isRenderTarget
= TRUE
;
5613 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, d3d_surface
);
5618 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
5619 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
5620 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
5622 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5623 IDirectDrawSurfaceImpl
*ddraw_surface
;
5624 DDSURFACEDESC2 ddsd
;
5627 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5628 "\tmultisample_quality %u, discard %u, surface %p\n",
5629 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
5633 /* Create a DirectDraw surface */
5634 memset(&ddsd
, 0, sizeof(ddsd
));
5635 ddsd
.dwSize
= sizeof(ddsd
);
5636 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
5637 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
5638 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5639 ddsd
.dwHeight
= height
;
5640 ddsd
.dwWidth
= width
;
5643 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, format
);
5647 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
5650 This
->depthstencil
= TRUE
;
5651 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*)This
, &ddsd
, (IDirectDrawSurface7
**)&ddraw_surface
, NULL
);
5652 This
->depthstencil
= FALSE
;
5655 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
5659 *surface
= ddraw_surface
->WineD3DSurface
;
5660 IWineD3DSurface_AddRef(*surface
);
5661 IDirectDrawSurface7_Release((IDirectDrawSurface7
*)ddraw_surface
);
5666 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
5667 IUnknown
*superior
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5668 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
5670 TRACE("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
5671 iface
, superior
, width
, height
, depth
, format
, pool
, usage
, volume
);
5673 ERR("Not implemented!\n");
5678 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
5679 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
5681 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5682 IDirectDrawSurfaceImpl
*iterator
;
5683 IParentImpl
*object
;
5686 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
5688 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
5691 FIXME("Allocation of memory failed\n");
5693 return DDERR_OUTOFVIDEOMEMORY
;
5696 ddraw_parent_init(object
);
5698 hr
= IWineD3DDevice_CreateSwapChain(This
->wineD3DDevice
, present_parameters
,
5699 This
->ImplType
, object
, swapchain
);
5702 FIXME("(%p) CreateSwapChain failed, returning %#x\n", iface
, hr
);
5703 HeapFree(GetProcessHeap(), 0 , object
);
5708 object
->child
= (IUnknown
*)*swapchain
;
5709 This
->d3d_target
->wineD3DSwapChain
= *swapchain
;
5710 iterator
= This
->d3d_target
->complex_array
[0];
5713 iterator
->wineD3DSwapChain
= *swapchain
;
5714 iterator
= iterator
->complex_array
[0];
5720 static const IWineD3DDeviceParentVtbl ddraw_wined3d_device_parent_vtbl
=
5722 /* IUnknown methods */
5723 device_parent_QueryInterface
,
5724 device_parent_AddRef
,
5725 device_parent_Release
,
5726 /* IWineD3DDeviceParent methods */
5727 device_parent_WineD3DDeviceCreated
,
5728 device_parent_CreateSurface
,
5729 device_parent_CreateRenderTarget
,
5730 device_parent_CreateDepthStencilSurface
,
5731 device_parent_CreateVolume
,
5732 device_parent_CreateSwapChain
,
5735 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, WINED3DDEVTYPE device_type
)
5740 ddraw
->lpVtbl
= &ddraw7_vtbl
;
5741 ddraw
->IDirectDraw_vtbl
= &ddraw1_vtbl
;
5742 ddraw
->IDirectDraw2_vtbl
= &ddraw2_vtbl
;
5743 ddraw
->IDirectDraw3_vtbl
= &ddraw3_vtbl
;
5744 ddraw
->IDirectDraw4_vtbl
= &ddraw4_vtbl
;
5745 ddraw
->IDirect3D_vtbl
= &d3d1_vtbl
;
5746 ddraw
->IDirect3D2_vtbl
= &d3d2_vtbl
;
5747 ddraw
->IDirect3D3_vtbl
= &d3d3_vtbl
;
5748 ddraw
->IDirect3D7_vtbl
= &d3d7_vtbl
;
5749 ddraw
->device_parent_vtbl
= &ddraw_wined3d_device_parent_vtbl
;
5750 ddraw
->numIfaces
= 1;
5753 /* See comments in IDirectDrawImpl_CreateNewSurface for a description of
5755 ddraw
->ImplType
= DefaultSurfaceType
;
5757 /* Get the current screen settings. */
5759 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5761 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5762 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5766 ERR("Failed to load wined3d - broken OpenGL setup?\n");
5767 return DDERR_NODIRECTDRAWSUPPORT
;
5770 ddraw
->wineD3D
= pWineDirect3DCreate(7, (IUnknown
*)ddraw
);
5771 if (!ddraw
->wineD3D
)
5773 WARN("Failed to create a wined3d object.\n");
5774 return E_OUTOFMEMORY
;
5777 hr
= IWineD3D_CreateDevice(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, device_type
, NULL
, 0,
5778 (IWineD3DDeviceParent
*)&ddraw
->device_parent_vtbl
, &ddraw
->wineD3DDevice
);
5781 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5782 IWineD3D_Release(ddraw
->wineD3D
);
5786 /* Get the amount of video memory */
5787 ddraw
->total_vidmem
= IWineD3DDevice_GetAvailableTextureMem(ddraw
->wineD3DDevice
);
5789 list_init(&ddraw
->surface_list
);