2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 /* Device identifier. Don't relay it to WineD3D */
31 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
35 { { 0x00010001, 0x00010001 } },
37 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
38 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
42 static struct enum_device_entry
44 char interface_name
[100];
45 char device_name
[100];
46 const GUID
*device_guid
;
51 "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
53 &IID_IDirect3DTnLHalDevice
,
58 "WINE Direct3D7 Hardware acceleration using WineD3D",
60 &IID_IDirect3DHALDevice
,
65 "WINE Direct3D7 RGB Software Emulation using WineD3D",
67 &IID_IDirect3DRGBDevice
,
71 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
73 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
75 ddraw_null_wined3d_object_destroyed
,
78 static inline IDirectDrawImpl
*impl_from_IDirectDraw(IDirectDraw
*iface
)
80 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw_iface
);
83 static inline IDirectDrawImpl
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
85 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw2_iface
);
88 static inline IDirectDrawImpl
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
90 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw4_iface
);
93 static inline IDirectDrawImpl
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
95 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw7_iface
);
98 static inline IDirectDrawImpl
*impl_from_IDirect3D(IDirect3D
*iface
)
100 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D_iface
);
103 static inline IDirectDrawImpl
*impl_from_IDirect3D2(IDirect3D2
*iface
)
105 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D2_iface
);
108 static inline IDirectDrawImpl
*impl_from_IDirect3D3(IDirect3D3
*iface
)
110 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D3_iface
);
113 static inline IDirectDrawImpl
*impl_from_IDirect3D7(IDirect3D7
*iface
)
115 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D7_iface
);
118 /*****************************************************************************
120 *****************************************************************************/
122 /*****************************************************************************
123 * IDirectDraw7::QueryInterface
125 * Queries different interfaces of the DirectDraw object. It can return
126 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
127 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
129 * The returned interface is AddRef()-ed before it's returned
131 * Used for version 1, 2, 4 and 7
134 * refiid: Interface ID asked for
135 * obj: Used to return the interface pointer
138 * S_OK if an interface was found
139 * E_NOINTERFACE if the requested interface wasn't found
141 *****************************************************************************/
142 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
144 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
146 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
148 /* Can change surface impl type */
149 EnterCriticalSection(&ddraw_cs
);
151 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
156 LeaveCriticalSection(&ddraw_cs
);
157 return DDERR_INVALIDPARAMS
;
160 /* Check DirectDraw Interfaces */
161 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
162 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
165 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
167 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
169 *obj
= &This
->IDirectDraw4_iface
;
170 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
172 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
174 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
175 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
177 LeaveCriticalSection(&ddraw_cs
);
178 return E_NOINTERFACE
;
180 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
182 *obj
= &This
->IDirectDraw2_iface
;
183 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
185 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
187 *obj
= &This
->IDirectDraw_iface
;
188 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
192 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
193 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
194 * who had this idea and why. The older interfaces can query and IDirect3D version
195 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
196 * and messy to implement with the common creation function, so it has been left out here.
198 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
199 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
200 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
201 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
203 /* Check the surface implementation */
204 if (DefaultSurfaceType
!= SURFACE_OPENGL
)
206 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
207 /* Do not abort here, only reject 3D Device creation */
210 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
212 This
->d3dversion
= 1;
213 *obj
= &This
->IDirect3D_iface
;
214 TRACE(" returning Direct3D interface at %p.\n", *obj
);
216 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
218 This
->d3dversion
= 2;
219 *obj
= &This
->IDirect3D2_iface
;
220 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
222 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
224 This
->d3dversion
= 3;
225 *obj
= &This
->IDirect3D3_iface
;
226 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
228 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
230 This
->d3dversion
= 7;
231 *obj
= &This
->IDirect3D7_iface
;
232 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
235 /* Unknown interface */
238 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
239 LeaveCriticalSection(&ddraw_cs
);
240 return E_NOINTERFACE
;
243 IUnknown_AddRef( (IUnknown
*) *obj
);
244 LeaveCriticalSection(&ddraw_cs
);
248 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
250 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
252 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
254 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
257 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
259 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
261 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
263 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
266 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
268 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
270 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
272 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
275 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
277 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
279 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
281 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
284 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
286 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
288 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
290 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
293 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
295 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
297 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
299 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
302 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
304 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
306 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
308 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
311 /*****************************************************************************
312 * IDirectDraw7::AddRef
314 * Increases the interfaces refcount, basically
316 * DDraw refcounting is a bit tricky. The different DirectDraw interface
317 * versions have individual refcounts, but the IDirect3D interfaces do not.
318 * All interfaces are from one object, that means calling QueryInterface on an
319 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
320 * IDirectDrawImpl object.
322 * That means all AddRef and Release implementations of IDirectDrawX work
323 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
324 * except of IDirect3D7 which thunks to IDirectDraw7
326 * Returns: The new refcount
328 *****************************************************************************/
329 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
331 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
332 ULONG ref
= InterlockedIncrement(&This
->ref7
);
334 TRACE("%p increasing refcount to %u.\n", This
, ref
);
336 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
341 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
343 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
344 ULONG ref
= InterlockedIncrement(&This
->ref4
);
346 TRACE("%p increasing refcount to %u.\n", This
, ref
);
348 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
353 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
355 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
356 ULONG ref
= InterlockedIncrement(&This
->ref2
);
358 TRACE("%p increasing refcount to %u.\n", This
, ref
);
360 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
365 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
367 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
368 ULONG ref
= InterlockedIncrement(&This
->ref1
);
370 TRACE("%p increasing refcount to %u.\n", This
, ref
);
372 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
377 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
379 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
381 TRACE("iface %p.\n", iface
);
383 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
386 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
388 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
390 TRACE("iface %p.\n", iface
);
392 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
395 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
397 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
399 TRACE("iface %p.\n", iface
);
401 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
404 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
406 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
408 TRACE("iface %p.\n", iface
);
410 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
413 /*****************************************************************************
416 * Destroys a ddraw object if all refcounts are 0. This is to share code
417 * between the IDirectDrawX::Release functions
420 * This: DirectDraw object to destroy
422 *****************************************************************************/
423 static void ddraw_destroy(IDirectDrawImpl
*This
)
425 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
426 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
428 /* Destroy the device window if we created one */
429 if(This
->devicewindow
!= 0)
431 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
432 DestroyWindow(This
->devicewindow
);
433 This
->devicewindow
= 0;
436 EnterCriticalSection(&ddraw_cs
);
437 list_remove(&This
->ddraw_list_entry
);
438 LeaveCriticalSection(&ddraw_cs
);
440 /* Release the attached WineD3D stuff */
441 wined3d_device_decref(This
->wined3d_device
);
442 wined3d_decref(This
->wineD3D
);
444 /* Now free the object */
445 HeapFree(GetProcessHeap(), 0, This
);
448 /*****************************************************************************
449 * IDirectDraw7::Release
451 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
453 * Returns: The new refcount
454 *****************************************************************************/
455 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
457 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
458 ULONG ref
= InterlockedDecrement(&This
->ref7
);
460 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
462 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
468 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
470 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
471 ULONG ref
= InterlockedDecrement(&This
->ref4
);
473 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
475 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
481 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
483 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
484 ULONG ref
= InterlockedDecrement(&This
->ref2
);
486 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
488 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
494 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
496 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
497 ULONG ref
= InterlockedDecrement(&This
->ref1
);
499 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
501 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
507 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
509 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
511 TRACE("iface %p.\n", iface
);
513 return ddraw7_Release(&This
->IDirectDraw7_iface
);
516 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
518 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
520 TRACE("iface %p.\n", iface
);
522 return ddraw1_Release(&This
->IDirectDraw_iface
);
525 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
527 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
529 TRACE("iface %p.\n", iface
);
531 return ddraw1_Release(&This
->IDirectDraw_iface
);
534 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
536 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
538 TRACE("iface %p.\n", iface
);
540 return ddraw1_Release(&This
->IDirectDraw_iface
);
543 /*****************************************************************************
544 * IDirectDraw methods
545 *****************************************************************************/
547 static HRESULT
ddraw_set_focus_window(IDirectDrawImpl
*ddraw
, HWND window
)
549 /* FIXME: This looks wrong, exclusive mode should imply a destination
551 if ((ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
) && ddraw
->dest_window
)
553 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
554 return DDERR_HWNDALREADYSET
;
557 ddraw
->focuswindow
= window
;
559 /* Use the focus window for drawing too. */
560 ddraw
->dest_window
= ddraw
->focuswindow
;
562 /* Destroy the device window, if we have one. */
563 if (ddraw
->devicewindow
)
565 DestroyWindow(ddraw
->devicewindow
);
566 ddraw
->devicewindow
= NULL
;
572 /*****************************************************************************
573 * IDirectDraw7::SetCooperativeLevel
575 * Sets the cooperative level for the DirectDraw object, and the window
576 * assigned to it. The cooperative level determines the general behavior
577 * of the DirectDraw application
579 * Warning: This is quite tricky, as it's not really documented which
580 * cooperative levels can be combined with each other. If a game fails
581 * after this function, try to check the cooperative levels passed on
582 * Windows, and if it returns something different.
584 * If you think that this function caused the failure because it writes a
585 * fixme, be sure to run again with a +ddraw trace.
587 * What is known about cooperative levels (See the ddraw modes test):
588 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
589 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
590 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
591 * DDSCL_FULLSCREEN can be activated
592 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
594 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
595 * DDSCL_SETFOCUSWINDOW (partially),
596 * DDSCL_MULTITHREADED (work in progress)
598 * Unhandled flags, which should be implemented
599 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
600 * expect any difference to a normal window for wine)
601 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
602 * rendering (Possible test case: Half-Life)
604 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
606 * These don't seem very important for wine:
607 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
610 * DD_OK if the cooperative level was set successfully
611 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
612 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
613 * (Probably others too, have to investigate)
615 *****************************************************************************/
616 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
618 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
622 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
623 DDRAW_dump_cooperativelevel(cooplevel
);
625 EnterCriticalSection(&ddraw_cs
);
627 /* Get the old window */
628 window
= This
->dest_window
;
630 /* Tests suggest that we need one of them: */
631 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
635 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
636 LeaveCriticalSection(&ddraw_cs
);
637 return DDERR_INVALIDPARAMS
;
640 /* Handle those levels first which set various hwnds */
641 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
643 /* This isn't compatible with a lot of flags */
644 if(cooplevel
& ( DDSCL_MULTITHREADED
|
645 DDSCL_CREATEDEVICEWINDOW
|
650 DDSCL_SETDEVICEWINDOW
|
655 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
656 LeaveCriticalSection(&ddraw_cs
);
657 return DDERR_INVALIDPARAMS
;
660 hr
= ddraw_set_focus_window(This
, hwnd
);
661 LeaveCriticalSection(&ddraw_cs
);
665 if(cooplevel
& DDSCL_EXCLUSIVE
)
667 if( !(cooplevel
& DDSCL_FULLSCREEN
) || !hwnd
)
669 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This
);
670 LeaveCriticalSection(&ddraw_cs
);
671 return DDERR_INVALIDPARAMS
;
675 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
676 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
677 wined3d_device_release_focus_window(This
->wined3d_device
);
679 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
681 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
682 wined3d_device_restore_fullscreen_window(This
->wined3d_device
, window
);
684 if (cooplevel
& DDSCL_FULLSCREEN
)
686 WINED3DDISPLAYMODE display_mode
;
688 wined3d_get_adapter_display_mode(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, &display_mode
);
689 wined3d_device_setup_fullscreen_window(This
->wined3d_device
, hwnd
,
690 display_mode
.Width
, display_mode
.Height
);
694 if ((cooplevel
& DDSCL_EXCLUSIVE
)
695 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
697 hr
= wined3d_device_acquire_focus_window(This
->wined3d_device
, hwnd
);
700 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
701 LeaveCriticalSection(&ddraw_cs
);
706 /* Don't override focus windows or private device windows */
707 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
708 This
->dest_window
= hwnd
;
710 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
712 /* Don't create a device window if a focus window is set */
713 if( !(This
->focuswindow
) )
715 HWND devicewindow
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DDraw device window",
716 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
717 NULL
, NULL
, NULL
, NULL
);
720 ERR("Failed to create window, last error %#x.\n", GetLastError());
721 LeaveCriticalSection(&ddraw_cs
);
725 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
726 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
728 This
->devicewindow
= devicewindow
;
729 This
->dest_window
= devicewindow
;
733 if (cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
734 wined3d_device_set_multithreaded(This
->wined3d_device
);
736 /* Unhandled flags */
737 if(cooplevel
& DDSCL_ALLOWREBOOT
)
738 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
739 if(cooplevel
& DDSCL_ALLOWMODEX
)
740 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
741 if(cooplevel
& DDSCL_FPUSETUP
)
742 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
744 /* Store the cooperative_level */
745 This
->cooperative_level
= cooplevel
;
746 TRACE("SetCooperativeLevel retuning DD_OK\n");
747 LeaveCriticalSection(&ddraw_cs
);
751 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
753 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
755 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
757 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
760 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
762 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
764 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
766 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
769 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
771 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
773 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
775 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
778 /*****************************************************************************
780 * Helper function for SetDisplayMode and RestoreDisplayMode
782 * Implements DirectDraw's SetDisplayMode, but ignores the value of
783 * ForceRefreshRate, since it is already handled by
784 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
785 * without worrying that ForceRefreshRate will override the refresh rate. For
786 * argument and return value documentation, see
787 * ddraw7_SetDisplayMode.
789 *****************************************************************************/
790 static HRESULT
ddraw_set_display_mode(IDirectDrawImpl
*ddraw
, DWORD Width
, DWORD Height
,
791 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
793 enum wined3d_format_id format
;
794 WINED3DDISPLAYMODE Mode
;
797 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
798 Height
, BPP
, RefreshRate
, Flags
);
800 EnterCriticalSection(&ddraw_cs
);
801 if( !Width
|| !Height
)
803 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
804 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
805 LeaveCriticalSection(&ddraw_cs
);
811 case 8: format
= WINED3DFMT_P8_UINT
; break;
812 case 15: format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
813 case 16: format
= WINED3DFMT_B5G6R5_UNORM
; break;
814 case 24: format
= WINED3DFMT_B8G8R8_UNORM
; break;
815 case 32: format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
816 default: format
= WINED3DFMT_UNKNOWN
; break;
819 if (FAILED(hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &Mode
)))
821 ERR("Failed to get current display mode, hr %#x.\n", hr
);
823 else if (Mode
.Width
== Width
824 && Mode
.Height
== Height
825 && Mode
.Format
== format
826 && Mode
.RefreshRate
== RefreshRate
)
828 TRACE("Skipping redundant mode setting call.\n");
829 LeaveCriticalSection(&ddraw_cs
);
833 /* Check the exclusive mode
834 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
835 return DDERR_NOEXCLUSIVEMODE;
836 * This is WRONG. Don't know if the SDK is completely
837 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
838 * is returned, but Half-Life 1.1.1.1 (Steam version)
843 Mode
.Height
= Height
;
844 Mode
.RefreshRate
= RefreshRate
;
845 Mode
.Format
= format
;
847 /* TODO: The possible return values from msdn suggest that
848 * the screen mode can't be changed if a surface is locked
849 * or some drawing is in progress
852 /* TODO: Lose the primary surface */
853 hr
= wined3d_device_set_display_mode(ddraw
->wined3d_device
, 0, &Mode
);
855 if (ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
)
856 SetWindowPos(ddraw
->dest_window
, HWND_TOP
, 0, 0, Width
, Height
, SWP_SHOWWINDOW
| SWP_NOACTIVATE
);
858 LeaveCriticalSection(&ddraw_cs
);
861 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
866 /*****************************************************************************
867 * IDirectDraw7::SetDisplayMode
869 * Sets the display screen resolution, color depth and refresh frequency
870 * when in fullscreen mode (in theory).
871 * Possible return values listed in the SDK suggest that this method fails
872 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
873 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
874 * It seems to be valid to pass 0 for With and Height, this has to be tested
875 * It could mean that the current video mode should be left as-is. (But why
879 * Height, Width: Screen dimension
880 * BPP: Color depth in Bits per pixel
881 * Refreshrate: Screen refresh rate
887 *****************************************************************************/
888 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
889 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
891 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
893 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
894 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
896 if (force_refresh_rate
!= 0)
898 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
899 RefreshRate
, force_refresh_rate
);
900 RefreshRate
= force_refresh_rate
;
903 return ddraw_set_display_mode(This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
906 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
907 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
909 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
911 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
912 iface
, width
, height
, bpp
, refresh_rate
, flags
);
914 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
917 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
918 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
920 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
922 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
923 iface
, width
, height
, bpp
, refresh_rate
, flags
);
925 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
928 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
930 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
932 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
934 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
937 /*****************************************************************************
938 * IDirectDraw7::RestoreDisplayMode
940 * Restores the display mode to what it was at creation time. Basically.
942 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
943 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
944 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
945 * -> DD_1 is released. The screen should be left at 1024x768x32.
946 * -> DD_2 is released. The screen should be set to 1400x1050x32
947 * This case is unhandled right now, but Empire Earth does it this way.
948 * (But perhaps there is something in SetCooperativeLevel to prevent this)
950 * The msdn says that this method resets the display mode to what it was before
951 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
955 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
957 *****************************************************************************/
958 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
960 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
962 TRACE("iface %p.\n", iface
);
964 return ddraw_set_display_mode(This
, This
->orig_width
, This
->orig_height
, This
->orig_bpp
, 0, 0);
967 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
969 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
971 TRACE("iface %p.\n", iface
);
973 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
976 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
978 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
980 TRACE("iface %p.\n", iface
);
982 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
985 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
987 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
989 TRACE("iface %p.\n", iface
);
991 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
994 /*****************************************************************************
995 * IDirectDraw7::GetCaps
997 * Returns the drives capabilities
999 * Used for version 1, 2, 4 and 7
1002 * DriverCaps: Structure to write the Hardware accelerated caps to
1003 * HelCaps: Structure to write the emulation caps to
1006 * This implementation returns DD_OK only
1008 *****************************************************************************/
1009 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1011 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1013 WINED3DCAPS winecaps
;
1015 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1017 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1019 /* One structure must be != NULL */
1020 if( (!DriverCaps
) && (!HELCaps
) )
1022 ERR("(%p) Invalid params to ddraw7_GetCaps\n", This
);
1023 return DDERR_INVALIDPARAMS
;
1026 memset(&caps
, 0, sizeof(caps
));
1027 memset(&winecaps
, 0, sizeof(winecaps
));
1028 caps
.dwSize
= sizeof(caps
);
1029 EnterCriticalSection(&ddraw_cs
);
1030 hr
= wined3d_device_get_device_caps(This
->wined3d_device
, &winecaps
);
1033 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1034 LeaveCriticalSection(&ddraw_cs
);
1038 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1039 LeaveCriticalSection(&ddraw_cs
);
1041 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1045 caps
.dwCaps
= winecaps
.DirectDrawCaps
.Caps
;
1046 caps
.dwCaps2
= winecaps
.DirectDrawCaps
.Caps2
;
1047 caps
.dwCKeyCaps
= winecaps
.DirectDrawCaps
.CKeyCaps
;
1048 caps
.dwFXCaps
= winecaps
.DirectDrawCaps
.FXCaps
;
1049 caps
.dwPalCaps
= winecaps
.DirectDrawCaps
.PalCaps
;
1050 caps
.ddsCaps
.dwCaps
= winecaps
.DirectDrawCaps
.ddsCaps
;
1051 caps
.dwSVBCaps
= winecaps
.DirectDrawCaps
.SVBCaps
;
1052 caps
.dwSVBCKeyCaps
= winecaps
.DirectDrawCaps
.SVBCKeyCaps
;
1053 caps
.dwSVBFXCaps
= winecaps
.DirectDrawCaps
.SVBFXCaps
;
1054 caps
.dwVSBCaps
= winecaps
.DirectDrawCaps
.VSBCaps
;
1055 caps
.dwVSBCKeyCaps
= winecaps
.DirectDrawCaps
.VSBCKeyCaps
;
1056 caps
.dwVSBFXCaps
= winecaps
.DirectDrawCaps
.VSBFXCaps
;
1057 caps
.dwSSBCaps
= winecaps
.DirectDrawCaps
.SSBCaps
;
1058 caps
.dwSSBCKeyCaps
= winecaps
.DirectDrawCaps
.SSBCKeyCaps
;
1059 caps
.dwSSBFXCaps
= winecaps
.DirectDrawCaps
.SSBFXCaps
;
1061 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1064 if(DefaultSurfaceType
== SURFACE_GDI
) {
1065 caps
.dwCaps
&= ~DDCAPS_3D
;
1066 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1068 if(winecaps
.DirectDrawCaps
.StrideAlign
!= 0) {
1069 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1070 caps
.dwAlignStrideAlign
= winecaps
.DirectDrawCaps
.StrideAlign
;
1075 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1076 if (TRACE_ON(ddraw
))
1078 TRACE("Driver Caps :\n");
1079 DDRAW_dump_DDCAPS(DriverCaps
);
1085 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1086 if (TRACE_ON(ddraw
))
1088 TRACE("HEL Caps :\n");
1089 DDRAW_dump_DDCAPS(HELCaps
);
1096 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1098 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1100 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1102 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1105 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1107 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1109 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1111 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1114 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1116 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1118 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1120 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1123 /*****************************************************************************
1124 * IDirectDraw7::Compact
1126 * No idea what it does, MSDN says it's not implemented.
1129 * DD_OK, but this is unchecked
1131 *****************************************************************************/
1132 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1134 TRACE("iface %p.\n", iface
);
1139 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1141 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1143 TRACE("iface %p.\n", iface
);
1145 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1148 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1150 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1152 TRACE("iface %p.\n", iface
);
1154 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1157 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1159 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1161 TRACE("iface %p.\n", iface
);
1163 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1166 /*****************************************************************************
1167 * IDirectDraw7::GetDisplayMode
1169 * Returns information about the current display mode
1171 * Exists in Version 1, 2, 4 and 7
1174 * DDSD: Address of a surface description structure to write the info to
1179 *****************************************************************************/
1180 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1182 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1184 WINED3DDISPLAYMODE Mode
;
1187 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1189 EnterCriticalSection(&ddraw_cs
);
1190 /* This seems sane */
1193 LeaveCriticalSection(&ddraw_cs
);
1194 return DDERR_INVALIDPARAMS
;
1197 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1198 * so one method can be used for all versions (Hopefully) */
1199 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &Mode
);
1202 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
1203 LeaveCriticalSection(&ddraw_cs
);
1207 Size
= DDSD
->dwSize
;
1208 memset(DDSD
, 0, Size
);
1210 DDSD
->dwSize
= Size
;
1211 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1212 DDSD
->dwWidth
= Mode
.Width
;
1213 DDSD
->dwHeight
= Mode
.Height
;
1214 DDSD
->u2
.dwRefreshRate
= 60;
1215 DDSD
->ddsCaps
.dwCaps
= 0;
1216 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1217 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
1218 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1222 TRACE("Returning surface desc :\n");
1223 DDRAW_dump_surface_desc(DDSD
);
1226 LeaveCriticalSection(&ddraw_cs
);
1230 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1232 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1234 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1236 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, surface_desc
);
1239 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1241 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1243 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1245 /* FIXME: Test sizes, properly convert surface_desc */
1246 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1249 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1251 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1253 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1255 /* FIXME: Test sizes, properly convert surface_desc */
1256 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1259 /*****************************************************************************
1260 * IDirectDraw7::GetFourCCCodes
1262 * Returns an array of supported FourCC codes.
1264 * Exists in Version 1, 2, 4 and 7
1267 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1268 * of enumerated codes
1269 * Codes: Pointer to an array of DWORDs where the supported codes are written
1273 * Always returns DD_OK, as it's a stub for now
1275 *****************************************************************************/
1276 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1278 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1279 static const enum wined3d_format_id formats
[] =
1281 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1282 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1283 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1285 DWORD count
= 0, i
, outsize
;
1287 WINED3DDISPLAYMODE d3ddm
;
1289 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1291 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &d3ddm
);
1293 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1295 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1297 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, WINED3DDEVTYPE_HAL
,
1298 d3ddm
.Format
, 0, WINED3DRTYPE_SURFACE
, formats
[i
], DefaultSurfaceType
);
1301 if (count
< outsize
)
1302 Codes
[count
] = formats
[i
];
1307 TRACE("Returning %u FourCC codes\n", count
);
1314 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1316 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1318 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1320 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1323 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1325 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1327 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1329 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1332 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1334 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1336 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1338 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1341 /*****************************************************************************
1342 * IDirectDraw7::GetMonitorFrequency
1344 * Returns the monitor's frequency
1346 * Exists in Version 1, 2, 4 and 7
1349 * Freq: Pointer to a DWORD to write the frequency to
1352 * Always returns DD_OK
1354 *****************************************************************************/
1355 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1357 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1359 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1360 * but for now this should make the games happy
1366 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1368 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1370 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1372 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1375 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1377 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1379 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1381 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1384 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1386 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1388 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1390 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1393 /*****************************************************************************
1394 * IDirectDraw7::GetVerticalBlankStatus
1396 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1397 * too basically, but as it's a semi stub, I didn't create a function there
1400 * status: Pointer to a BOOL to be filled with the vertical blank status
1404 * DDERR_INVALIDPARAMS if status is NULL
1406 *****************************************************************************/
1407 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1409 static BOOL fake_vblank
;
1411 TRACE("iface %p, status %p.\n", iface
, status
);
1414 return DDERR_INVALIDPARAMS
;
1416 *status
= fake_vblank
;
1417 fake_vblank
= !fake_vblank
;
1422 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1424 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1426 TRACE("iface %p, status %p.\n", iface
, status
);
1428 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1431 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1433 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1435 TRACE("iface %p, status %p.\n", iface
, status
);
1437 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1440 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1442 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1444 TRACE("iface %p, status %p.\n", iface
, status
);
1446 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1449 /*****************************************************************************
1450 * IDirectDraw7::GetAvailableVidMem
1452 * Returns the total and free video memory
1455 * Caps: Specifies the memory type asked for
1456 * total: Pointer to a DWORD to be filled with the total memory
1457 * free: Pointer to a DWORD to be filled with the free memory
1461 * DDERR_INVALIDPARAMS of free and total are NULL
1463 *****************************************************************************/
1464 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1467 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1470 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1474 TRACE("(%p) Asked for memory with description: ", This
);
1475 DDRAW_dump_DDSCAPS2(Caps
);
1477 EnterCriticalSection(&ddraw_cs
);
1479 /* Todo: System memory vs local video memory vs non-local video memory
1480 * The MSDN also mentions differences between texture memory and other
1481 * resources, but that's not important
1484 if( (!total
) && (!free
) )
1486 LeaveCriticalSection(&ddraw_cs
);
1487 return DDERR_INVALIDPARAMS
;
1491 *free
= wined3d_device_get_available_texture_mem(This
->wined3d_device
);
1494 WINED3DADAPTER_IDENTIFIER desc
= {0};
1496 hr
= wined3d_get_adapter_identifier(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, 0, &desc
);
1497 *total
= desc
.video_memory
;
1500 LeaveCriticalSection(&ddraw_cs
);
1504 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1505 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1507 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1509 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1511 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, caps
, total
, free
);
1514 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1515 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1517 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1520 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1522 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1523 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1526 /*****************************************************************************
1527 * IDirectDraw7::Initialize
1529 * Initializes a DirectDraw interface.
1532 * GUID: Interface identifier. Well, don't know what this is really good
1536 * Returns DD_OK on the first call,
1537 * DDERR_ALREADYINITIALIZED on repeated calls
1539 *****************************************************************************/
1540 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*guid
)
1542 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1544 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1546 if (This
->initialized
)
1547 return DDERR_ALREADYINITIALIZED
;
1549 /* FIXME: To properly take the GUID into account we should call
1550 * ddraw_init() here instead of in DDRAW_Create(). */
1552 FIXME("Ignoring guid %s.\n", debugstr_guid(guid
));
1554 This
->initialized
= TRUE
;
1558 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1560 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1562 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1564 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1567 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1569 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1571 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1573 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1576 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1578 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1580 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1582 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1585 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1587 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1589 return DDERR_ALREADYINITIALIZED
;
1592 /*****************************************************************************
1593 * IDirectDraw7::FlipToGDISurface
1595 * "Makes the surface that the GDI writes to the primary surface"
1596 * Looks like some windows specific thing we don't have to care about.
1597 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1598 * show error boxes ;)
1599 * Well, just return DD_OK.
1602 * Always returns DD_OK
1604 *****************************************************************************/
1605 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1607 FIXME("iface %p stub!\n", iface
);
1612 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1614 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1616 TRACE("iface %p.\n", iface
);
1618 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1621 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1623 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1625 TRACE("iface %p.\n", iface
);
1627 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1630 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1632 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1634 TRACE("iface %p.\n", iface
);
1636 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1639 /*****************************************************************************
1640 * IDirectDraw7::WaitForVerticalBlank
1642 * This method allows applications to get in sync with the vertical blank
1644 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1645 * redraw the screen, most likely because of this stub
1648 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1649 * or DDWAITVB_BLOCKEND
1650 * h: Not used, according to MSDN
1653 * Always returns DD_OK
1655 *****************************************************************************/
1656 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1660 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1662 /* This function is called often, so print the fixme only once */
1665 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1669 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1670 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1671 return DDERR_UNSUPPORTED
; /* unchecked */
1676 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1678 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1680 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1682 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1685 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1687 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1689 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1691 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1694 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1696 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1698 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1700 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1703 /*****************************************************************************
1704 * IDirectDraw7::GetScanLine
1706 * Returns the scan line that is being drawn on the monitor
1709 * Scanline: Address to write the scan line value to
1712 * Always returns DD_OK
1714 *****************************************************************************/
1715 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1717 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1718 static DWORD cur_scanline
;
1719 static BOOL hide
= FALSE
;
1720 WINED3DDISPLAYMODE Mode
;
1722 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1724 /* This function is called often, so print the fixme only once */
1727 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1731 EnterCriticalSection(&ddraw_cs
);
1732 wined3d_device_get_display_mode(This
->wined3d_device
, 0, &Mode
);
1733 LeaveCriticalSection(&ddraw_cs
);
1735 /* Fake the line sweeping of the monitor */
1736 /* FIXME: We should synchronize with a source to keep the refresh rate */
1737 *Scanline
= cur_scanline
++;
1738 /* Assume 20 scan lines in the vertical blank */
1739 if (cur_scanline
>= Mode
.Height
+ 20)
1745 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1747 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1749 TRACE("iface %p, line %p.\n", iface
, line
);
1751 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1754 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1756 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1758 TRACE("iface %p, line %p.\n", iface
, line
);
1760 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1763 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1765 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1767 TRACE("iface %p, line %p.\n", iface
, line
);
1769 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1772 /*****************************************************************************
1773 * IDirectDraw7::TestCooperativeLevel
1775 * Informs the application about the state of the video adapter, depending
1776 * on the cooperative level
1779 * DD_OK if the device is in a sane state
1780 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1781 * if the state is not correct(See below)
1783 *****************************************************************************/
1784 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1786 TRACE("iface %p.\n", iface
);
1791 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1793 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1795 TRACE("iface %p.\n", iface
);
1797 return ddraw7_TestCooperativeLevel(&This
->IDirectDraw7_iface
);
1800 /*****************************************************************************
1801 * IDirectDraw7::GetGDISurface
1803 * Returns the surface that GDI is treating as the primary surface.
1804 * For Wine this is the front buffer
1807 * GDISurface: Address to write the surface pointer to
1810 * DD_OK if the surface was found
1811 * DDERR_NOTFOUND if the GDI surface wasn't found
1813 *****************************************************************************/
1814 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
1816 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1818 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
1820 EnterCriticalSection(&ddraw_cs
);
1822 if (!(*GDISurface
= &This
->primary
->IDirectDrawSurface7_iface
))
1824 WARN("Primary not created yet.\n");
1825 LeaveCriticalSection(&ddraw_cs
);
1826 return DDERR_NOTFOUND
;
1828 IDirectDrawSurface7_AddRef(*GDISurface
);
1830 LeaveCriticalSection(&ddraw_cs
);
1834 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
1836 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1837 IDirectDrawSurface7
*surface7
;
1838 IDirectDrawSurfaceImpl
*surface_impl
;
1841 TRACE("iface %p, surface %p.\n", iface
, surface
);
1843 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
1849 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
1850 *surface
= &surface_impl
->IDirectDrawSurface4_iface
;
1851 IDirectDrawSurface4_AddRef(*surface
);
1852 IDirectDrawSurface7_Release(surface7
);
1857 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
1859 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1860 IDirectDrawSurface7
*surface7
;
1861 IDirectDrawSurfaceImpl
*surface_impl
;
1864 TRACE("iface %p, surface %p.\n", iface
, surface
);
1866 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
1872 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
1873 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
1874 IDirectDrawSurface_AddRef(*surface
);
1875 IDirectDrawSurface7_Release(surface7
);
1880 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
1882 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1883 IDirectDrawSurface7
*surface7
;
1884 IDirectDrawSurfaceImpl
*surface_impl
;
1887 TRACE("iface %p, surface %p.\n", iface
, surface
);
1889 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
1895 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
1896 *surface
= &surface_impl
->IDirectDrawSurface_iface
;
1897 IDirectDrawSurface_AddRef(*surface
);
1898 IDirectDrawSurface7_Release(surface7
);
1903 struct displaymodescallback_context
1905 LPDDENUMMODESCALLBACK func
;
1909 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
1911 struct displaymodescallback_context
*cbcontext
= context
;
1914 DDSD2_to_DDSD(surface_desc
, &desc
);
1915 return cbcontext
->func(&desc
, cbcontext
->context
);
1918 /*****************************************************************************
1919 * IDirectDraw7::EnumDisplayModes
1921 * Enumerates the supported Display modes. The modes can be filtered with
1922 * the DDSD parameter.
1925 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES. For old ddraw
1926 * versions (3 and older?) this is reserved and must be 0.
1927 * DDSD: Surface description to filter the modes
1928 * Context: Pointer passed back to the callback function
1929 * cb: Application-provided callback function
1933 * DDERR_INVALIDPARAMS if the callback wasn't set
1935 *****************************************************************************/
1936 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
1937 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
1939 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1940 unsigned int modenum
, fmt
;
1941 WINED3DDISPLAYMODE mode
;
1942 DDSURFACEDESC2 callback_sd
;
1943 WINED3DDISPLAYMODE
*enum_modes
= NULL
;
1944 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
1945 DDPIXELFORMAT pixelformat
;
1947 static const enum wined3d_format_id checkFormatList
[] =
1949 WINED3DFMT_B8G8R8X8_UNORM
,
1950 WINED3DFMT_B5G6R5_UNORM
,
1954 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
1955 iface
, Flags
, DDSD
, Context
, cb
);
1957 EnterCriticalSection(&ddraw_cs
);
1958 /* This looks sane */
1961 LeaveCriticalSection(&ddraw_cs
);
1962 return DDERR_INVALIDPARAMS
;
1965 if(!(Flags
& DDEDM_REFRESHRATES
))
1967 enum_mode_array_size
= 16;
1968 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
1971 ERR("Out of memory\n");
1972 LeaveCriticalSection(&ddraw_cs
);
1973 return DDERR_OUTOFMEMORY
;
1977 pixelformat
.dwSize
= sizeof(pixelformat
);
1978 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
1981 while (wined3d_enum_adapter_modes(This
->wineD3D
, WINED3DADAPTER_DEFAULT
,
1982 checkFormatList
[fmt
], modenum
++, &mode
) == WINED3D_OK
)
1984 PixelFormat_WineD3DtoDD(&pixelformat
, mode
.Format
);
1987 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
1988 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
1989 if(DDSD
->dwFlags
& DDSD_REFRESHRATE
&& mode
.RefreshRate
!= DDSD
->u2
.dwRefreshRate
) continue;
1990 if (DDSD
->dwFlags
& DDSD_PIXELFORMAT
&&
1991 pixelformat
.u1
.dwRGBBitCount
!= DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
) continue;
1994 if(!(Flags
& DDEDM_REFRESHRATES
))
1996 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
1997 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
1998 * to be reduced to a single unique result in such case.
2003 for (i
= 0; i
< enum_mode_count
; i
++)
2005 if(enum_modes
[i
].Width
== mode
.Width
&& enum_modes
[i
].Height
== mode
.Height
&&
2006 enum_modes
[i
].Format
== mode
.Format
)
2016 memset(&callback_sd
, 0, sizeof(callback_sd
));
2017 callback_sd
.dwSize
= sizeof(callback_sd
);
2018 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2020 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
|DDSD_REFRESHRATE
;
2021 if(Flags
& DDEDM_REFRESHRATES
)
2023 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
2026 callback_sd
.dwWidth
= mode
.Width
;
2027 callback_sd
.dwHeight
= mode
.Height
;
2029 callback_sd
.u4
.ddpfPixelFormat
=pixelformat
;
2031 /* Calc pitch and DWORD align like MSDN says */
2032 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.Width
;
2033 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2035 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2036 callback_sd
.u2
.dwRefreshRate
);
2038 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2040 TRACE("Application asked to terminate the enumeration\n");
2041 HeapFree(GetProcessHeap(), 0, enum_modes
);
2042 LeaveCriticalSection(&ddraw_cs
);
2046 if(!(Flags
& DDEDM_REFRESHRATES
))
2048 if (enum_mode_count
== enum_mode_array_size
)
2050 WINED3DDISPLAYMODE
*new_enum_modes
;
2052 enum_mode_array_size
*= 2;
2053 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2055 if (!new_enum_modes
)
2057 ERR("Out of memory\n");
2058 HeapFree(GetProcessHeap(), 0, enum_modes
);
2059 LeaveCriticalSection(&ddraw_cs
);
2060 return DDERR_OUTOFMEMORY
;
2063 enum_modes
= new_enum_modes
;
2066 enum_modes
[enum_mode_count
++] = mode
;
2071 TRACE("End of enumeration\n");
2072 HeapFree(GetProcessHeap(), 0, enum_modes
);
2073 LeaveCriticalSection(&ddraw_cs
);
2077 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2078 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2080 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2082 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2083 iface
, flags
, surface_desc
, context
, callback
);
2085 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2088 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2089 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2091 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2092 struct displaymodescallback_context cbcontext
;
2093 DDSURFACEDESC2 surface_desc2
;
2095 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2096 iface
, flags
, surface_desc
, context
, callback
);
2098 cbcontext
.func
= callback
;
2099 cbcontext
.context
= context
;
2101 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2102 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
,
2103 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2106 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2107 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2109 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2110 struct displaymodescallback_context cbcontext
;
2111 DDSURFACEDESC2 surface_desc2
;
2113 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2114 iface
, flags
, surface_desc
, context
, callback
);
2116 cbcontext
.func
= callback
;
2117 cbcontext
.context
= context
;
2119 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
2120 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
,
2121 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumDisplayModesCallbackThunk
);
2124 /*****************************************************************************
2125 * IDirectDraw7::EvaluateMode
2127 * Used with IDirectDraw7::StartModeTest to test video modes.
2128 * EvaluateMode is used to pass or fail a mode, and continue with the next
2132 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2133 * Timeout: Returns the amount of seconds left before the mode would have
2134 * been failed automatically
2137 * This implementation always DD_OK, because it's a stub
2139 *****************************************************************************/
2140 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2142 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2144 /* When implementing this, implement it in WineD3D */
2149 /*****************************************************************************
2150 * IDirectDraw7::GetDeviceIdentifier
2152 * Returns the device identifier, which gives information about the driver
2153 * Our device identifier is defined at the beginning of this file.
2156 * DDDI: Address for the returned structure
2157 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2160 * On success it returns DD_OK
2161 * DDERR_INVALIDPARAMS if DDDI is NULL
2163 *****************************************************************************/
2164 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2165 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2167 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2170 return DDERR_INVALIDPARAMS
;
2172 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2173 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2174 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2175 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2176 * bytes too long. So only copy the relevant part of the structure
2179 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2183 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2184 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2186 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2187 DDDEVICEIDENTIFIER2 identifier2
;
2190 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2192 hr
= ddraw7_GetDeviceIdentifier(&This
->IDirectDraw7_iface
, &identifier2
, flags
);
2193 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2198 /*****************************************************************************
2199 * IDirectDraw7::GetSurfaceFromDC
2201 * Returns the Surface for a GDI device context handle.
2202 * Is this related to IDirectDrawSurface::GetDC ???
2205 * hdc: hdc to return the surface for
2206 * Surface: Address to write the surface pointer to
2209 * Always returns DD_OK because it's a stub
2211 *****************************************************************************/
2212 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2213 IDirectDrawSurface7
**Surface
)
2215 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2216 struct wined3d_surface
*wined3d_surface
;
2219 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2221 if (!Surface
) return E_INVALIDARG
;
2223 hr
= wined3d_device_get_surface_from_dc(This
->wined3d_device
, hdc
, &wined3d_surface
);
2226 TRACE("No surface found for dc %p.\n", hdc
);
2228 return DDERR_NOTFOUND
;
2231 *Surface
= wined3d_surface_get_parent(wined3d_surface
);
2232 IDirectDrawSurface7_AddRef(*Surface
);
2233 TRACE("Returning surface %p.\n", Surface
);
2237 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2238 IDirectDrawSurface4
**surface
)
2240 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2241 IDirectDrawSurface7
*surface7
;
2242 IDirectDrawSurfaceImpl
*surface_impl
;
2245 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2247 if (!surface
) return E_INVALIDARG
;
2249 hr
= ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, &surface7
);
2255 surface_impl
= impl_from_IDirectDrawSurface7(surface7
);
2256 /* Tests say this is true */
2257 *surface
= (IDirectDrawSurface4
*)&surface_impl
->IDirectDrawSurface_iface
;
2258 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
2259 IDirectDrawSurface7_Release(surface7
);
2264 /*****************************************************************************
2265 * IDirectDraw7::RestoreAllSurfaces
2267 * Calls the restore method of all surfaces
2272 * Always returns DD_OK because it's a stub
2274 *****************************************************************************/
2275 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2277 FIXME("iface %p stub!\n", iface
);
2279 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2280 * get their parent and call their restore method. Do not implement
2281 * it in WineD3D, as restoring a surface means re-creating the
2287 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2289 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2291 TRACE("iface %p.\n", iface
);
2293 return ddraw7_RestoreAllSurfaces(&This
->IDirectDraw7_iface
);
2296 /*****************************************************************************
2297 * IDirectDraw7::StartModeTest
2299 * Tests the specified video modes to update the system registry with
2300 * refresh rate information. StartModeTest starts the mode test,
2301 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2302 * isn't called within 15 seconds, the mode is failed automatically
2304 * As refresh rates are handled by the X server, I don't think this
2305 * Method is important
2308 * Modes: An array of mode specifications
2309 * NumModes: The number of modes in Modes
2310 * Flags: Some flags...
2313 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2314 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2317 *****************************************************************************/
2318 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2320 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2321 iface
, Modes
, NumModes
, Flags
);
2323 /* This looks sane */
2324 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2326 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2327 * As it is not, DDERR_TESTFINISHED is returned
2328 * (hopefully that's correct
2330 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2331 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2337 /*****************************************************************************
2338 * ddraw_create_surface
2340 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2341 * with the passed parameters.
2344 * DDSD: Description of the surface to create
2345 * Surf: Address to store the interface pointer at
2350 *****************************************************************************/
2351 static HRESULT
ddraw_create_surface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
,
2352 IDirectDrawSurfaceImpl
**ppSurf
, UINT level
, UINT version
)
2356 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2357 This
, pDDSD
, ppSurf
, level
);
2359 if (TRACE_ON(ddraw
))
2361 TRACE(" (%p) Requesting surface desc :\n", This
);
2362 DDRAW_dump_surface_desc(pDDSD
);
2365 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) && DefaultSurfaceType
!= SURFACE_OPENGL
)
2367 WARN("The application requests a 3D capable surface, but a non-OpenGL surface type was set in the registry.\n");
2368 /* Do not fail surface creation, only fail 3D device creation. */
2371 /* Create the Surface object */
2372 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
2375 ERR("(%p) Error allocating memory for a surface\n", This
);
2376 return DDERR_OUTOFVIDEOMEMORY
;
2379 hr
= ddraw_surface_init(*ppSurf
, This
, pDDSD
, level
, version
);
2382 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2383 HeapFree(GetProcessHeap(), 0, *ppSurf
);
2387 /* Increase the surface counter, and attach the surface */
2388 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
2390 TRACE("Created surface %p.\n", *ppSurf
);
2394 /*****************************************************************************
2395 * CreateAdditionalSurfaces
2397 * Creates a new mipmap chain.
2400 * root: Root surface to attach the newly created chain to
2401 * count: number of surfaces to create
2402 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2403 * effects on the caller
2404 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2405 * creates an additional surface without the mipmapping flags
2407 *****************************************************************************/
2409 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2410 IDirectDrawSurfaceImpl
*root
,
2412 DDSURFACEDESC2 DDSD
,
2413 BOOL CubeFaceRoot
, UINT version
)
2415 UINT i
, j
, level
= 0;
2417 IDirectDrawSurfaceImpl
*last
= root
;
2419 for(i
= 0; i
< count
; i
++)
2421 IDirectDrawSurfaceImpl
*object2
= NULL
;
2423 /* increase the mipmap level, but only if a mipmap is created
2424 * In this case, also halve the size
2426 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2429 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2430 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2431 /* Set the mipmap sublevel flag according to msdn */
2432 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2436 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2438 CubeFaceRoot
= FALSE
;
2440 hr
= ddraw_create_surface(This
, &DDSD
, &object2
, level
, version
);
2446 /* Add the new surface to the complex attachment array */
2447 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2449 if(last
->complex_array
[j
]) continue;
2450 last
->complex_array
[j
] = object2
;
2455 /* Remove the (possible) back buffer cap from the new surface description,
2456 * because only one surface in the flipping chain is a back buffer, one
2457 * is a front buffer, the others are just primary surfaces.
2459 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2464 /*****************************************************************************
2465 * ddraw_attach_d3d_device
2467 * Initializes the D3D capabilities of WineD3D
2470 * primary: The primary surface for D3D
2476 *****************************************************************************/
2477 static HRESULT
ddraw_attach_d3d_device(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
,
2478 WINED3DPRESENT_PARAMETERS
*presentation_parameters
)
2480 HWND window
= presentation_parameters
->hDeviceWindow
;
2483 TRACE("ddraw %p, primary %p.\n", ddraw
, primary
);
2485 if (!window
|| window
== GetDesktopWindow())
2487 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
2488 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
2489 NULL
, NULL
, NULL
, NULL
);
2492 ERR("Failed to create window, last error %#x.\n", GetLastError());
2496 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2497 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
2499 presentation_parameters
->hDeviceWindow
= window
;
2503 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
2505 ddraw
->d3d_window
= window
;
2507 /* Store the future Render Target surface */
2508 ddraw
->d3d_target
= primary
;
2510 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2511 * recursive loop until ram or emulated video memory is full. */
2512 ddraw
->d3d_initialized
= TRUE
;
2513 hr
= wined3d_device_init_3d(ddraw
->wined3d_device
, presentation_parameters
);
2516 ddraw
->d3d_target
= NULL
;
2517 ddraw
->d3d_initialized
= FALSE
;
2521 ddraw
->declArraySize
= 2;
2522 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
2525 ERR("Error allocating an array for the converted vertex decls.\n");
2526 ddraw
->declArraySize
= 0;
2527 hr
= wined3d_device_uninit_3d(ddraw
->wined3d_device
);
2528 return E_OUTOFMEMORY
;
2531 TRACE("Successfully initialized 3D.\n");
2536 static HRESULT
ddraw_create_gdi_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
,
2537 WINED3DPRESENT_PARAMETERS
*presentation_parameters
)
2541 ddraw
->d3d_target
= primary
;
2542 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, presentation_parameters
);
2543 ddraw
->d3d_target
= NULL
;
2546 WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr
);
2547 primary
->wined3d_swapchain
= NULL
;
2553 static HRESULT
ddraw_create_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*surface
)
2555 WINED3DPRESENT_PARAMETERS presentation_parameters
;
2556 IDirectDrawSurfaceImpl
*target
= surface
;
2557 HRESULT hr
= WINED3D_OK
;
2561 TRACE("Using primary %p.\n", ddraw
->primary
);
2562 target
= ddraw
->primary
;
2565 memset(&presentation_parameters
, 0, sizeof(presentation_parameters
));
2566 presentation_parameters
.BackBufferWidth
= target
->surface_desc
.dwWidth
;
2567 presentation_parameters
.BackBufferHeight
= target
->surface_desc
.dwHeight
;
2568 presentation_parameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&target
->surface_desc
.u4
.ddpfPixelFormat
);
2569 presentation_parameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2570 presentation_parameters
.hDeviceWindow
= ddraw
->dest_window
;
2571 presentation_parameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2573 /* If the implementation is OpenGL and there's no d3ddevice, attach a
2574 * d3ddevice. But attach the d3ddevice only if the currently created
2575 * surface was a primary surface (2D app in 3D mode) or a 3DDEVICE surface
2576 * (3D app). The only case I can think of where this doesn't apply is when
2577 * a 2D app was configured by the user to run with OpenGL and it didn't
2578 * create the render target as first surface. In this case the render
2579 * target creation will cause the 3D init. */
2580 if (DefaultSurfaceType
== SURFACE_OPENGL
)
2582 TRACE("Attaching a D3DDevice, rendertarget = %p.\n", target
);
2583 hr
= ddraw_attach_d3d_device(ddraw
, target
, &presentation_parameters
);
2585 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2587 hr
= ddraw_create_gdi_swapchain(ddraw
, target
, &presentation_parameters
);
2594 /*****************************************************************************
2595 * IDirectDraw7::CreateSurface
2597 * Creates a new IDirectDrawSurface object and returns its interface.
2599 * The surface connections with wined3d are a bit tricky. Basically it works
2602 * |------------------------| |-----------------|
2603 * | DDraw surface | | WineD3DSurface |
2605 * | WineD3DSurface |-------------->| |
2606 * | Child |<------------->| Parent |
2607 * |------------------------| |-----------------|
2609 * The DDraw surface is the parent of the wined3d surface, and it releases
2610 * the WineD3DSurface when the ddraw surface is destroyed.
2612 * However, for all surfaces which can be in a container in WineD3D,
2613 * we have to do this. These surfaces are usually complex surfaces,
2614 * so this concerns primary surfaces with a front and a back buffer,
2617 * |------------------------| |-----------------|
2618 * | DDraw surface | | Container |
2620 * | Child |<------------->| Parent |
2621 * | Texture |<------------->| |
2622 * | WineD3DSurface |<----| | Levels |<--|
2623 * | Complex connection | | | | |
2624 * |------------------------| | |-----------------| |
2628 * | |------------------| | |-----------------| |
2629 * | | IParent | |-------->| WineD3DSurface | |
2631 * | | Child |<------------->| Parent | |
2632 * | | | | Container |<--|
2633 * | |------------------| |-----------------| |
2635 * | |----------------------| |
2636 * | | DDraw surface 2 | |
2638 * |<->| Complex root Child | |
2640 * | | WineD3DSurface |<----| |
2641 * | |----------------------| | |
2643 * | |---------------------| | |-----------------| |
2644 * | | IParent | |----->| WineD3DSurface | |
2646 * | | Child |<---------->| Parent | |
2647 * | |---------------------| | Container |<--|
2648 * | |-----------------| |
2650 * | ---More surfaces can follow--- |
2652 * The reason is that the IWineD3DSwapchain(render target container)
2653 * and the IWineD3DTexure(Texture container) release the parents
2654 * of their surface's children, but by releasing the complex root
2655 * the surfaces which are complexly attached to it are destroyed
2656 * too. See IDirectDrawSurface::Release for a more detailed
2660 * DDSD: Description of the surface to create
2661 * Surf: Address to store the interface pointer at
2662 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2663 * aggregation, so it has to be NULL
2667 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2668 * DDERR_* if an error occurs
2670 *****************************************************************************/
2671 static HRESULT
CreateSurface(IDirectDrawImpl
*ddraw
, DDSURFACEDESC2
*DDSD
,
2672 IDirectDrawSurfaceImpl
**Surf
, IUnknown
*UnkOuter
, UINT version
)
2674 IDirectDrawSurfaceImpl
*object
= NULL
;
2676 LONG extra_surfaces
= 0;
2677 DDSURFACEDESC2 desc2
;
2678 WINED3DDISPLAYMODE Mode
;
2679 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2681 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, Surf
, UnkOuter
);
2683 /* Some checks before we start */
2684 if (TRACE_ON(ddraw
))
2686 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2687 DDRAW_dump_surface_desc(DDSD
);
2689 EnterCriticalSection(&ddraw_cs
);
2691 if (UnkOuter
!= NULL
)
2693 FIXME("(%p) : outer != NULL?\n", ddraw
);
2694 LeaveCriticalSection(&ddraw_cs
);
2695 return CLASS_E_NOAGGREGATION
; /* unchecked */
2700 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2701 LeaveCriticalSection(&ddraw_cs
);
2702 return E_POINTER
; /* unchecked */
2705 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2707 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2708 DDSD
->dwFlags
|= DDSD_CAPS
;
2711 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2713 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2714 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2717 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2719 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2720 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2721 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2724 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2725 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2727 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2730 LeaveCriticalSection(&ddraw_cs
);
2731 return DDERR_NOEXCLUSIVEMODE
;
2734 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2736 WARN("Application wanted to create back buffer primary surface\n");
2737 LeaveCriticalSection(&ddraw_cs
);
2738 return DDERR_INVALIDCAPS
;
2741 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2743 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2744 WARN("Application tries to put the surface in both system and video memory\n");
2745 LeaveCriticalSection(&ddraw_cs
);
2747 return DDERR_INVALIDCAPS
;
2750 /* Check cube maps but only if the size includes them */
2751 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2753 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2754 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2756 WARN("Cube map faces requested without cube map flag\n");
2757 LeaveCriticalSection(&ddraw_cs
);
2758 return DDERR_INVALIDCAPS
;
2760 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2761 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2763 WARN("Cube map without faces requested\n");
2764 LeaveCriticalSection(&ddraw_cs
);
2765 return DDERR_INVALIDPARAMS
;
2768 /* Quick tests confirm those can be created, but we don't do that yet */
2769 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2770 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2772 FIXME("Partial cube maps not supported yet\n");
2776 /* According to the msdn this flag is ignored by CreateSurface */
2777 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2778 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2780 /* Modify some flags */
2781 copy_to_surfacedesc2(&desc2
, DDSD
);
2782 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2784 /* Get the video mode from WineD3D - we will need it */
2785 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &Mode
);
2788 ERR("Failed to read display mode from wined3d\n");
2789 switch(ddraw
->orig_bpp
)
2792 Mode
.Format
= WINED3DFMT_P8_UINT
;
2796 Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
;
2800 Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
;
2804 Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
;
2808 Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
;
2811 Mode
.Width
= ddraw
->orig_width
;
2812 Mode
.Height
= ddraw
->orig_height
;
2815 /* No pixelformat given? Use the current screen format */
2816 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2818 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2819 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2821 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2824 /* No Width or no Height? Use the original screen size
2826 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2827 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2829 /* Invalid for non-render targets */
2830 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2832 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2834 LeaveCriticalSection(&ddraw_cs
);
2835 return DDERR_INVALIDPARAMS
;
2838 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2839 desc2
.dwWidth
= Mode
.Width
;
2840 desc2
.dwHeight
= Mode
.Height
;
2843 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2845 LeaveCriticalSection(&ddraw_cs
);
2846 return DDERR_INVALIDPARAMS
;
2849 /* Mipmap count fixes */
2850 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2852 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2854 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2856 /* Mipmap count is given, should not be 0 */
2857 if( desc2
.u2
.dwMipMapCount
== 0 )
2859 LeaveCriticalSection(&ddraw_cs
);
2860 return DDERR_INVALIDPARAMS
;
2865 /* Undocumented feature: Create sublevels until
2866 * either the width or the height is 1
2868 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2869 desc2
.dwWidth
: desc2
.dwHeight
;
2870 desc2
.u2
.dwMipMapCount
= 0;
2873 desc2
.u2
.dwMipMapCount
+= 1;
2880 /* Not-complex mipmap -> Mipmapcount = 1 */
2881 desc2
.u2
.dwMipMapCount
= 1;
2883 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2885 /* There's a mipmap count in the created surface in any case */
2886 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2888 /* If no mipmap is given, the texture has only one level */
2890 /* The first surface is a front buffer, the back buffer is created afterwards */
2891 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2893 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2896 /* The root surface in a cube map is positive x */
2897 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2899 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2900 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2903 /* Create the first surface */
2904 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0, version
);
2907 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
2908 LeaveCriticalSection(&ddraw_cs
);
2911 object
->is_complex_root
= TRUE
;
2915 /* Create Additional surfaces if necessary
2916 * This applies to Primary surfaces which have a back buffer count
2917 * set, but not to mipmap textures. In case of Mipmap textures,
2918 * wineD3D takes care of the creation of additional surfaces
2920 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2922 extra_surfaces
= DDSD
->dwBackBufferCount
;
2923 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2924 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2925 desc2
.dwBackBufferCount
= 0;
2929 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2931 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2932 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2933 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2934 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2935 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
2936 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2937 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
2938 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
2939 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2940 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
2941 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
2942 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2943 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
2944 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
2945 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2946 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
2947 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2950 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
, version
);
2953 /* This destroys and possibly created surfaces too */
2956 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
2958 else if (version
== 4)
2960 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
2964 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
2966 LeaveCriticalSection(&ddraw_cs
);
2970 if (!ddraw
->d3d_initialized
&& desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
2972 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, object
)))
2974 IDirectDrawSurfaceImpl
*release_surf
;
2975 ERR("Failed to create swapchain, hr %#x.\n", hr
);
2978 /* The earlier created surface structures are in an incomplete
2979 * state here. Wined3d holds the reference on the parents, and it
2980 * released them on the failure already. So the regular release
2981 * method implementation would fail on the attempt to destroy
2982 * either the parents or the swapchain. So free the surface here.
2983 * The surface structure here is a list, not a tree, because
2984 * onscreen targets cannot be cube textures. */
2987 release_surf
= object
;
2988 object
= object
->complex_array
[0];
2989 ddraw_surface_destroy(release_surf
);
2991 LeaveCriticalSection(&ddraw_cs
);
2996 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2997 ddraw
->primary
= object
;
2999 /* Create a WineD3DTexture if a texture was requested */
3000 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3002 ddraw
->tex_root
= object
;
3003 ddraw_surface_create_texture(object
);
3004 ddraw
->tex_root
= NULL
;
3007 LeaveCriticalSection(&ddraw_cs
);
3011 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3012 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3014 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3015 IDirectDrawSurfaceImpl
*impl
;
3018 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3019 iface
, surface_desc
, surface
, outer_unknown
);
3021 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3023 WARN("Application supplied invalid surface descriptor\n");
3024 return DDERR_INVALIDPARAMS
;
3027 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3029 if (TRACE_ON(ddraw
))
3031 TRACE(" (%p) Requesting surface desc :\n", iface
);
3032 DDRAW_dump_surface_desc(surface_desc
);
3035 WARN("Application tried to create an explicit front or back buffer\n");
3036 return DDERR_INVALIDCAPS
;
3039 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 7);
3046 *surface
= &impl
->IDirectDrawSurface7_iface
;
3047 IDirectDraw7_AddRef(iface
);
3048 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3053 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3054 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3056 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3057 IDirectDrawSurfaceImpl
*impl
;
3060 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3061 iface
, surface_desc
, surface
, outer_unknown
);
3063 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3065 WARN("Application supplied invalid surface descriptor\n");
3066 return DDERR_INVALIDPARAMS
;
3069 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3071 if (TRACE_ON(ddraw
))
3073 TRACE(" (%p) Requesting surface desc :\n", iface
);
3074 DDRAW_dump_surface_desc(surface_desc
);
3077 WARN("Application tried to create an explicit front or back buffer\n");
3078 return DDERR_INVALIDCAPS
;
3081 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 4);
3088 *surface
= &impl
->IDirectDrawSurface4_iface
;
3089 IDirectDraw4_AddRef(iface
);
3090 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3095 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3096 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3098 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3099 IDirectDrawSurfaceImpl
*impl
;
3101 DDSURFACEDESC2 surface_desc2
;
3103 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3104 iface
, surface_desc
, surface
, outer_unknown
);
3106 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3108 WARN("Application supplied invalid surface descriptor\n");
3109 return DDERR_INVALIDPARAMS
;
3112 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3113 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3115 if (TRACE_ON(ddraw
))
3117 TRACE(" (%p) Requesting surface desc :\n", iface
);
3118 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3121 WARN("Application tried to create an explicit front or back buffer\n");
3122 return DDERR_INVALIDCAPS
;
3125 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 2);
3132 *surface
= &impl
->IDirectDrawSurface_iface
;
3133 impl
->ifaceToRelease
= NULL
;
3138 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3139 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3141 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3142 IDirectDrawSurfaceImpl
*impl
;
3144 DDSURFACEDESC2 surface_desc2
;
3146 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3147 iface
, surface_desc
, surface
, outer_unknown
);
3149 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3151 WARN("Application supplied invalid surface descriptor\n");
3152 return DDERR_INVALIDPARAMS
;
3155 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3156 * primaries anyway. */
3157 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3158 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3159 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 1);
3166 *surface
= &impl
->IDirectDrawSurface_iface
;
3167 impl
->ifaceToRelease
= NULL
;
3172 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3173 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3176 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3177 const DDPIXELFORMAT
*provided
)
3179 /* Some flags must be present in both or neither for a match. */
3180 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3181 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3182 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3184 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3187 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3190 if (requested
->dwFlags
& DDPF_FOURCC
)
3191 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3194 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3195 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3196 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3199 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3200 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3201 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3204 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3205 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3208 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3209 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3211 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3214 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3215 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3221 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3230 #define CMP(FLAG, FIELD) \
3231 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3232 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3234 static const struct compare_info compare
[] =
3236 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3237 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3239 CMP(CKDESTBLT
, ddckCKDestBlt
),
3240 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3241 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3242 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3243 CMP(HEIGHT
, dwHeight
),
3244 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3245 CMP(LPSURFACE
, lpSurface
),
3246 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3247 CMP(PITCH
, u1
/* lPitch */),
3248 /* PIXELFORMAT: manual */
3249 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3250 CMP(TEXTURESTAGE
, dwTextureStage
),
3251 CMP(WIDTH
, dwWidth
),
3252 /* ZBUFFERBITDEPTH: "obsolete" */
3259 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3262 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3264 if (requested
->dwFlags
& compare
[i
].flag
3265 && memcmp((const char *)provided
+ compare
[i
].offset
,
3266 (const char *)requested
+ compare
[i
].offset
,
3267 compare
[i
].size
) != 0)
3271 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3273 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3274 &provided
->u4
.ddpfPixelFormat
))
3281 #undef DDENUMSURFACES_SEARCHTYPE
3282 #undef DDENUMSURFACES_MATCHTYPE
3284 struct surfacescallback2_context
3286 LPDDENUMSURFACESCALLBACK2 func
;
3290 struct surfacescallback_context
3292 LPDDENUMSURFACESCALLBACK func
;
3296 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3297 DDSURFACEDESC2
*surface_desc
, void *context
)
3299 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3300 struct surfacescallback2_context
*cbcontext
= context
;
3302 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3303 IDirectDrawSurface7_Release(surface
);
3305 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3306 surface_desc
, cbcontext
->context
);
3309 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3310 DDSURFACEDESC2
*surface_desc
, void *context
)
3312 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3313 struct surfacescallback_context
*cbcontext
= context
;
3315 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3316 IDirectDrawSurface7_Release(surface
);
3318 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3319 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3322 /*****************************************************************************
3323 * IDirectDraw7::EnumSurfaces
3325 * Loops through all surfaces attached to this device and calls the
3326 * application callback. This can't be relayed to WineD3DDevice,
3327 * because some WineD3DSurfaces' parents are IParent objects
3330 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3331 * DDSD: Description to filter for
3332 * Context: Application-provided pointer, it's passed unmodified to the
3334 * Callback: Address to call for each surface
3337 * DDERR_INVALIDPARAMS if the callback is NULL
3340 *****************************************************************************/
3341 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3342 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3344 /* The surface enumeration is handled by WineDDraw,
3345 * because it keeps track of all surfaces attached to
3346 * it. The filtering is done by our callback function,
3347 * because WineDDraw doesn't handle ddraw-like surface
3350 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3351 IDirectDrawSurfaceImpl
*surf
;
3353 DDSURFACEDESC2 desc
;
3354 struct list
*entry
, *entry2
;
3356 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3357 iface
, Flags
, DDSD
, Context
, Callback
);
3359 all
= Flags
& DDENUMSURFACES_ALL
;
3360 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3362 EnterCriticalSection(&ddraw_cs
);
3366 LeaveCriticalSection(&ddraw_cs
);
3367 return DDERR_INVALIDPARAMS
;
3370 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3371 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3373 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3374 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3376 TRACE("Enumerating surface %p.\n", surf
);
3377 desc
= surf
->surface_desc
;
3378 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3379 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3381 LeaveCriticalSection(&ddraw_cs
);
3386 LeaveCriticalSection(&ddraw_cs
);
3390 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3391 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3393 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3394 struct surfacescallback2_context cbcontext
;
3396 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3397 iface
, flags
, surface_desc
, context
, callback
);
3399 cbcontext
.func
= callback
;
3400 cbcontext
.context
= context
;
3402 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, surface_desc
,
3403 &cbcontext
, EnumSurfacesCallback2Thunk
);
3406 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3407 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3409 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3410 struct surfacescallback_context cbcontext
;
3411 DDSURFACEDESC2 surface_desc2
;
3413 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3414 iface
, flags
, surface_desc
, context
, callback
);
3416 cbcontext
.func
= callback
;
3417 cbcontext
.context
= context
;
3419 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3420 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3421 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3424 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3425 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3427 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3428 struct surfacescallback_context cbcontext
;
3429 DDSURFACEDESC2 surface_desc2
;
3431 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3432 iface
, flags
, surface_desc
, context
, callback
);
3434 cbcontext
.func
= callback
;
3435 cbcontext
.context
= context
;
3437 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3438 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3439 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3442 /*****************************************************************************
3443 * DirectDrawCreateClipper (DDRAW.@)
3445 * Creates a new IDirectDrawClipper object.
3448 * Clipper: Address to write the interface pointer to
3449 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3453 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3454 * E_OUTOFMEMORY if allocating the object failed
3456 *****************************************************************************/
3458 DirectDrawCreateClipper(DWORD Flags
,
3459 LPDIRECTDRAWCLIPPER
*Clipper
,
3462 IDirectDrawClipperImpl
* object
;
3465 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3466 Flags
, Clipper
, UnkOuter
);
3468 EnterCriticalSection(&ddraw_cs
);
3469 if (UnkOuter
!= NULL
)
3471 LeaveCriticalSection(&ddraw_cs
);
3472 return CLASS_E_NOAGGREGATION
;
3475 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3476 sizeof(IDirectDrawClipperImpl
));
3479 LeaveCriticalSection(&ddraw_cs
);
3480 return E_OUTOFMEMORY
;
3483 hr
= ddraw_clipper_init(object
);
3486 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3487 HeapFree(GetProcessHeap(), 0, object
);
3488 LeaveCriticalSection(&ddraw_cs
);
3492 TRACE("Created clipper %p.\n", object
);
3493 *Clipper
= &object
->IDirectDrawClipper_iface
;
3494 LeaveCriticalSection(&ddraw_cs
);
3498 /*****************************************************************************
3499 * IDirectDraw7::CreateClipper
3501 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3503 *****************************************************************************/
3504 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3505 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3507 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3508 iface
, Flags
, Clipper
, UnkOuter
);
3510 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3513 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3514 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3516 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3518 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3519 iface
, flags
, clipper
, outer_unknown
);
3521 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3524 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3525 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3527 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3529 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3530 iface
, flags
, clipper
, outer_unknown
);
3532 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3535 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3536 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3538 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3540 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3541 iface
, flags
, clipper
, outer_unknown
);
3543 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3546 /*****************************************************************************
3547 * IDirectDraw7::CreatePalette
3549 * Creates a new IDirectDrawPalette object
3552 * Flags: The flags for the new clipper
3553 * ColorTable: Color table to assign to the new clipper
3554 * Palette: Address to write the interface pointer to
3555 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3559 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3560 * E_OUTOFMEMORY if allocating the object failed
3562 *****************************************************************************/
3563 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3564 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3566 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3567 IDirectDrawPaletteImpl
*object
;
3570 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3571 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3573 EnterCriticalSection(&ddraw_cs
);
3574 if(pUnkOuter
!= NULL
)
3576 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3577 LeaveCriticalSection(&ddraw_cs
);
3578 return CLASS_E_NOAGGREGATION
;
3581 /* The refcount test shows that a cooplevel is required for this */
3582 if(!This
->cooperative_level
)
3584 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3585 LeaveCriticalSection(&ddraw_cs
);
3586 return DDERR_NOCOOPERATIVELEVELSET
;
3589 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3592 ERR("Out of memory when allocating memory for a palette implementation\n");
3593 LeaveCriticalSection(&ddraw_cs
);
3594 return E_OUTOFMEMORY
;
3597 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
3600 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3601 HeapFree(GetProcessHeap(), 0, object
);
3602 LeaveCriticalSection(&ddraw_cs
);
3606 TRACE("Created palette %p.\n", object
);
3607 *Palette
= (IDirectDrawPalette
*)object
;
3608 LeaveCriticalSection(&ddraw_cs
);
3612 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3613 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3615 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3618 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3619 iface
, flags
, entries
, palette
, outer_unknown
);
3621 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3622 if (SUCCEEDED(hr
) && *palette
)
3624 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3625 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3626 IDirectDraw4_AddRef(iface
);
3627 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3632 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3633 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3635 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3638 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3639 iface
, flags
, entries
, palette
, outer_unknown
);
3641 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3642 if (SUCCEEDED(hr
) && *palette
)
3644 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3645 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3646 impl
->ifaceToRelease
= NULL
;
3652 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3653 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3655 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3658 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3659 iface
, flags
, entries
, palette
, outer_unknown
);
3661 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3662 if (SUCCEEDED(hr
) && *palette
)
3664 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
3665 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3666 impl
->ifaceToRelease
= NULL
;
3672 /*****************************************************************************
3673 * IDirectDraw7::DuplicateSurface
3675 * Duplicates a surface. The surface memory points to the same memory as
3676 * the original surface, and it's released when the last surface referencing
3677 * it is released. I guess that's beyond Wine's surface management right now
3678 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3679 * test application to implement this)
3682 * Src: Address of the source surface
3683 * Dest: Address to write the new surface pointer to
3686 * See IDirectDraw7::CreateSurface
3688 *****************************************************************************/
3689 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3690 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3692 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3694 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3696 /* For now, simply create a new, independent surface */
3697 return IDirectDraw7_CreateSurface(iface
,
3698 &Surf
->surface_desc
,
3703 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3704 IDirectDrawSurface4
**dst
)
3706 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3707 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3708 IDirectDrawSurface7
*dst7
;
3709 IDirectDrawSurfaceImpl
*dst_impl
;
3712 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3713 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3714 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3720 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3721 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3722 IDirectDrawSurface4_AddRef(*dst
);
3723 IDirectDrawSurface7_Release(dst7
);
3728 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3729 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3731 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3732 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3733 IDirectDrawSurface7
*dst7
;
3734 IDirectDrawSurfaceImpl
*dst_impl
;
3737 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3738 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3739 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3742 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3743 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3744 IDirectDrawSurface_AddRef(*dst
);
3745 IDirectDrawSurface7_Release(dst7
);
3750 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3751 IDirectDrawSurface
**dst
)
3753 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3754 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3755 IDirectDrawSurface7
*dst7
;
3756 IDirectDrawSurfaceImpl
*dst_impl
;
3759 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3760 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3761 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3764 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3765 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3766 IDirectDrawSurface_AddRef(*dst
);
3767 IDirectDrawSurface7_Release(dst7
);
3772 /*****************************************************************************
3773 * IDirect3D7::EnumDevices
3775 * The EnumDevices method for IDirect3D7. It enumerates all supported
3776 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3779 * callback: Function to call for each enumerated device
3780 * context: Pointer to pass back to the app
3783 * D3D_OK, or the return value of the GetCaps call
3785 *****************************************************************************/
3786 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3788 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
3789 D3DDEVICEDESC7 device_desc7
;
3790 D3DDEVICEDESC device_desc1
;
3794 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3797 return DDERR_INVALIDPARAMS
;
3799 EnterCriticalSection(&ddraw_cs
);
3801 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
3804 LeaveCriticalSection(&ddraw_cs
);
3808 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3812 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3813 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3814 if (ret
!= DDENUMRET_OK
)
3816 TRACE("Application cancelled the enumeration.\n");
3817 LeaveCriticalSection(&ddraw_cs
);
3822 TRACE("End of enumeration.\n");
3824 LeaveCriticalSection(&ddraw_cs
);
3829 /*****************************************************************************
3830 * IDirect3D3::EnumDevices
3832 * Enumerates all supported Direct3DDevice interfaces. This is the
3833 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3835 * Version 1, 2 and 3
3838 * callback: Application-provided routine to call for each enumerated device
3839 * Context: Pointer to pass to the callback
3842 * D3D_OK on success,
3843 * The result of IDirect3DImpl_GetCaps if it failed
3845 *****************************************************************************/
3846 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3848 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3850 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
3851 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3852 D3DDEVICEDESC7 device_desc7
;
3855 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3856 * name string. Let's put the string in a sufficiently sized array in
3857 * writable memory. */
3858 char device_name
[50];
3859 strcpy(device_name
,"Direct3D HEL");
3861 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3864 return DDERR_INVALIDPARAMS
;
3866 EnterCriticalSection(&ddraw_cs
);
3868 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
3871 LeaveCriticalSection(&ddraw_cs
);
3875 /* Do I have to enumerate the reference id? Note from old d3d7:
3876 * "It seems that enumerating the reference IID on Direct3D 1 games
3877 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3879 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3880 * EnumReference which enables / disables enumerating the reference
3881 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3882 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3883 * demo directory suggest this.
3885 * Some games(GTA 2) seem to use the second enumerated device, so I have
3886 * to enumerate at least 2 devices. So enumerate the reference device to
3889 * Other games (Rollcage) tell emulation and hal device apart by certain
3890 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3891 * limitation flag), and it refuses all devices that have the perspective
3892 * flag set. This way it refuses the emulation device, and HAL devices
3893 * never have POW2 unset in d3d7 on windows. */
3894 if (This
->d3dversion
!= 1)
3896 static CHAR reference_description
[] = "RGB Direct3D emulation";
3898 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3899 hal_desc
= device_desc1
;
3900 hel_desc
= device_desc1
;
3901 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3902 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3903 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3904 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3905 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3906 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3907 device_name
, &hal_desc
, &hel_desc
, context
);
3908 if (hr
!= D3DENUMRET_OK
)
3910 TRACE("Application cancelled the enumeration.\n");
3911 LeaveCriticalSection(&ddraw_cs
);
3916 strcpy(device_name
,"Direct3D HAL");
3918 TRACE("Enumerating HAL Direct3D device.\n");
3919 hal_desc
= device_desc1
;
3920 hel_desc
= device_desc1
;
3921 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3922 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3923 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3924 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3925 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3926 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3927 device_name
, &hal_desc
, &hel_desc
, context
);
3928 if (hr
!= D3DENUMRET_OK
)
3930 TRACE("Application cancelled the enumeration.\n");
3931 LeaveCriticalSection(&ddraw_cs
);
3935 TRACE("End of enumeration.\n");
3937 LeaveCriticalSection(&ddraw_cs
);
3941 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3943 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
3945 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3947 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
3950 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3952 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
3954 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3956 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
3959 /*****************************************************************************
3960 * IDirect3D3::CreateLight
3962 * Creates an IDirect3DLight interface. This interface is used in
3963 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3964 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3965 * uses the IDirect3DDevice7 interface with D3D7 lights.
3967 * Version 1, 2 and 3
3970 * light: Address to store the new interface pointer
3971 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3976 * DDERR_OUTOFMEMORY if memory allocation failed
3977 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3979 *****************************************************************************/
3980 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3981 IUnknown
*outer_unknown
)
3983 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
3984 IDirect3DLightImpl
*object
;
3986 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3988 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3990 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3993 ERR("Failed to allocate light memory.\n");
3994 return DDERR_OUTOFMEMORY
;
3997 d3d_light_init(object
, This
);
3999 TRACE("Created light %p.\n", object
);
4000 *light
= &object
->IDirect3DLight_iface
;
4005 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4007 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4009 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4011 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4014 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4016 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4018 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4020 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4023 /*****************************************************************************
4024 * IDirect3D3::CreateMaterial
4026 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4027 * and older versions. The IDirect3DMaterial implementation wraps its
4028 * functionality to IDirect3DDevice7::SetMaterial and friends.
4030 * Version 1, 2 and 3
4033 * material: Address to store the new interface's pointer to
4034 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4039 * DDERR_OUTOFMEMORY if memory allocation failed
4040 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4042 *****************************************************************************/
4043 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4044 IUnknown
*outer_unknown
)
4046 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4047 IDirect3DMaterialImpl
*object
;
4049 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4051 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4053 object
= d3d_material_create(This
);
4056 ERR("Failed to allocate material memory.\n");
4057 return DDERR_OUTOFMEMORY
;
4060 TRACE("Created material %p.\n", object
);
4061 *material
= &object
->IDirect3DMaterial3_iface
;
4066 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4067 IUnknown
*outer_unknown
)
4069 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4070 IDirect3DMaterialImpl
*object
;
4072 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4074 object
= d3d_material_create(This
);
4077 ERR("Failed to allocate material memory.\n");
4078 return DDERR_OUTOFMEMORY
;
4081 TRACE("Created material %p.\n", object
);
4082 *material
= &object
->IDirect3DMaterial2_iface
;
4087 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4088 IUnknown
*outer_unknown
)
4090 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4091 IDirect3DMaterialImpl
*object
;
4093 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4095 object
= d3d_material_create(This
);
4098 ERR("Failed to allocate material memory.\n");
4099 return DDERR_OUTOFMEMORY
;
4102 TRACE("Created material %p.\n", object
);
4103 *material
= &object
->IDirect3DMaterial_iface
;
4108 /*****************************************************************************
4109 * IDirect3D3::CreateViewport
4111 * Creates an IDirect3DViewport interface. This interface is used
4112 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4113 * it has been replaced by a viewport structure and
4114 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4115 * uses the IDirect3DDevice7 methods for its functionality
4118 * Viewport: Address to store the new interface pointer
4119 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4124 * DDERR_OUTOFMEMORY if memory allocation failed
4125 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4127 *****************************************************************************/
4128 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4129 IUnknown
*outer_unknown
)
4131 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4132 IDirect3DViewportImpl
*object
;
4134 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4136 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4138 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4141 ERR("Failed to allocate viewport memory.\n");
4142 return DDERR_OUTOFMEMORY
;
4145 d3d_viewport_init(object
, This
);
4147 TRACE("Created viewport %p.\n", object
);
4148 *viewport
= (IDirect3DViewport3
*)object
;
4153 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4155 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4157 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4159 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4163 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4165 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4167 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4169 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4173 /*****************************************************************************
4174 * IDirect3D3::FindDevice
4176 * This method finds a device with the requested properties and returns a
4177 * device description
4181 * fds: Describes the requested device characteristics
4182 * fdr: Returns the device description
4186 * DDERR_INVALIDPARAMS if no device was found
4188 *****************************************************************************/
4189 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4191 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4192 D3DDEVICEDESC7 desc7
;
4193 D3DDEVICEDESC desc1
;
4196 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4198 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4200 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4201 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4202 return DDERR_INVALIDPARAMS
;
4204 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4205 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4207 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4208 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4211 if (fds
->dwFlags
& D3DFDS_GUID
)
4213 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4214 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4215 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4216 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4218 WARN("No match for this GUID.\n");
4219 return DDERR_NOTFOUND
;
4224 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &desc1
, &desc7
);
4225 if (hr
!= D3D_OK
) return hr
;
4227 /* Now return our own GUID */
4228 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4229 fdr
->ddHwDesc
= desc1
;
4230 fdr
->ddSwDesc
= desc1
;
4232 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4237 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4239 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4241 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4243 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4246 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4248 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4250 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4252 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4255 /*****************************************************************************
4256 * IDirect3D7::CreateDevice
4258 * Creates an IDirect3DDevice7 interface.
4260 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4261 * DirectDraw surfaces and are created with
4262 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4263 * create the device object and QueryInterfaces for IDirect3DDevice
4266 * refiid: IID of the device to create
4267 * Surface: Initial rendertarget
4268 * Device: Address to return the interface pointer
4272 * DDERR_OUTOFMEMORY if memory allocation failed
4273 * DDERR_INVALIDPARAMS if a device exists already
4275 *****************************************************************************/
4276 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4277 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4279 IDirectDrawSurfaceImpl
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4280 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4281 IDirect3DDeviceImpl
*object
;
4284 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4286 EnterCriticalSection(&ddraw_cs
);
4289 /* Fail device creation if non-opengl surfaces are used. */
4290 if (DefaultSurfaceType
!= SURFACE_OPENGL
)
4292 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4293 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4295 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4296 * is caught in CreateSurface or QueryInterface. */
4297 LeaveCriticalSection(&ddraw_cs
);
4301 if (This
->d3ddevice
)
4303 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4304 LeaveCriticalSection(&ddraw_cs
);
4305 return DDERR_INVALIDPARAMS
;
4308 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4311 ERR("Failed to allocate device memory.\n");
4312 LeaveCriticalSection(&ddraw_cs
);
4313 return DDERR_OUTOFMEMORY
;
4316 hr
= d3d_device_init(object
, This
, target
);
4319 WARN("Failed to initialize device, hr %#x.\n", hr
);
4320 HeapFree(GetProcessHeap(), 0, object
);
4321 LeaveCriticalSection(&ddraw_cs
);
4325 TRACE("Created device %p.\n", object
);
4326 *device
= (IDirect3DDevice7
*)object
;
4328 LeaveCriticalSection(&ddraw_cs
);
4332 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4333 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4335 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4336 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4339 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4340 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4342 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4344 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4345 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
,
4346 (IDirect3DDevice7
**)device
);
4347 if (*device
) *device
= (IDirect3DDevice3
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice3_vtbl
;
4352 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4353 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4355 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4356 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4359 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4360 iface
, debugstr_guid(riid
), surface
, device
);
4362 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4363 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
,
4364 (IDirect3DDevice7
**)device
);
4365 if (*device
) *device
= (IDirect3DDevice2
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice2_vtbl
;
4370 /*****************************************************************************
4371 * IDirect3D7::CreateVertexBuffer
4373 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4379 * desc: Requested Vertex buffer properties
4380 * vertex_buffer: Address to return the interface pointer at
4381 * flags: Some flags, should be 0
4385 * DDERR_OUTOFMEMORY if memory allocation failed
4386 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4387 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4389 *****************************************************************************/
4390 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4391 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4393 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4394 IDirect3DVertexBufferImpl
*object
;
4397 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4398 iface
, desc
, vertex_buffer
, flags
);
4400 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4402 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4405 TRACE("Created vertex buffer %p.\n", object
);
4406 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4409 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4414 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4415 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4417 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4418 IDirect3DVertexBufferImpl
*object
;
4421 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4422 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4425 return CLASS_E_NOAGGREGATION
;
4426 if (!vertex_buffer
|| !desc
)
4427 return DDERR_INVALIDPARAMS
;
4429 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4432 TRACE("Created vertex buffer %p.\n", object
);
4433 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4436 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4441 /*****************************************************************************
4442 * IDirect3D7::EnumZBufferFormats
4444 * Enumerates all supported Z buffer pixel formats
4450 * callback: callback to call for each pixel format
4451 * context: Pointer to pass back to the callback
4455 * DDERR_INVALIDPARAMS if callback is NULL
4456 * For details, see IWineD3DDevice::EnumZBufferFormats
4458 *****************************************************************************/
4459 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4460 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4462 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4463 WINED3DDISPLAYMODE d3ddm
;
4464 WINED3DDEVTYPE type
;
4468 /* Order matters. Specifically, BattleZone II (full version) expects the
4469 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4470 static const enum wined3d_format_id formats
[] =
4472 WINED3DFMT_S1_UINT_D15_UNORM
,
4473 WINED3DFMT_D16_UNORM
,
4474 WINED3DFMT_X8D24_UNORM
,
4475 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4476 WINED3DFMT_D24_UNORM_S8_UINT
,
4477 WINED3DFMT_D32_UNORM
,
4480 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4481 iface
, debugstr_guid(device_iid
), callback
, context
);
4483 if (!callback
) return DDERR_INVALIDPARAMS
;
4485 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4486 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4487 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4489 TRACE("Asked for HAL device.\n");
4490 type
= WINED3DDEVTYPE_HAL
;
4492 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4493 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4495 TRACE("Asked for SW device.\n");
4496 type
= WINED3DDEVTYPE_SW
;
4498 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4500 TRACE("Asked for REF device.\n");
4501 type
= WINED3DDEVTYPE_REF
;
4503 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4505 TRACE("Asked for NULLREF device.\n");
4506 type
= WINED3DDEVTYPE_NULLREF
;
4510 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4511 type
= WINED3DDEVTYPE_HAL
;
4514 EnterCriticalSection(&ddraw_cs
);
4515 /* We need an adapter format from somewhere to please wined3d and WGL.
4516 * Use the current display mode. So far all cards offer the same depth
4517 * stencil format for all modes, but if some do not and applications do
4518 * not like that we'll have to find some workaround, like iterating over
4519 * all imaginable formats and collecting all the depth stencil formats we
4521 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &d3ddm
);
4523 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4525 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4526 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, formats
[i
], SURFACE_OPENGL
);
4529 DDPIXELFORMAT pformat
;
4531 memset(&pformat
, 0, sizeof(pformat
));
4532 pformat
.dwSize
= sizeof(pformat
);
4533 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4535 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4536 hr
= callback(&pformat
, context
);
4537 if (hr
!= DDENUMRET_OK
)
4539 TRACE("Format enumeration cancelled by application.\n");
4540 LeaveCriticalSection(&ddraw_cs
);
4546 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4547 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4548 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4549 * newer enumerate both versions, so we do the same(bug 22434) */
4550 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4551 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, SURFACE_OPENGL
);
4554 DDPIXELFORMAT x8d24
=
4556 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4557 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4559 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4560 callback(&x8d24
, context
);
4563 TRACE("End of enumeration.\n");
4565 LeaveCriticalSection(&ddraw_cs
);
4569 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4570 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4572 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4574 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4575 iface
, debugstr_guid(device_iid
), callback
, context
);
4577 return d3d7_EnumZBufferFormats(&This
->IDirect3D7_iface
, device_iid
, callback
, context
);
4580 /*****************************************************************************
4581 * IDirect3D7::EvictManagedTextures
4583 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4584 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4589 * D3D_OK, because it's a stub
4591 *****************************************************************************/
4592 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4594 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4596 TRACE("iface %p!\n", iface
);
4598 EnterCriticalSection(&ddraw_cs
);
4599 if (This
->d3d_initialized
)
4600 wined3d_device_evict_managed_resources(This
->wined3d_device
);
4601 LeaveCriticalSection(&ddraw_cs
);
4606 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4608 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4610 TRACE("iface %p.\n", iface
);
4612 return d3d7_EvictManagedTextures(&This
->IDirect3D7_iface
);
4615 /*****************************************************************************
4616 * IDirect3DImpl_GetCaps
4618 * This function retrieves the device caps from wined3d
4619 * and converts it into a D3D7 and D3D - D3D3 structure
4620 * This is a helper function called from various places in ddraw
4623 * wined3d: The interface to get the caps from
4624 * desc1: Old D3D <3 structure to fill (needed)
4625 * desc7: D3D7 device desc structure to fill (needed)
4628 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4630 *****************************************************************************/
4631 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4633 WINED3DCAPS wined3d_caps
;
4636 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4638 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4640 EnterCriticalSection(&ddraw_cs
);
4641 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3DDEVTYPE_HAL
, &wined3d_caps
);
4642 LeaveCriticalSection(&ddraw_cs
);
4645 WARN("Failed to get device caps, hr %#x.\n", hr
);
4649 /* Copy the results into the d3d7 and d3d3 structures */
4650 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4651 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4652 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4653 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4654 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4655 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4656 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4657 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4658 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4659 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4660 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4662 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4663 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4665 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4666 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4667 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4668 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4670 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4671 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4672 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4673 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4675 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4676 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4678 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4679 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4681 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4682 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4684 /* Remove all non-d3d7 caps */
4685 desc7
->dwDevCaps
&= (
4686 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4687 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4688 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4689 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4690 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4691 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4692 D3DDEVCAPS_HWRASTERIZATION
);
4694 desc7
->dwStencilCaps
&= (
4695 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4696 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4697 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4701 desc7
->dwTextureOpCaps
&= (
4702 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4703 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4704 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4705 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4706 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4707 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4708 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4709 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4711 desc7
->dwVertexProcessingCaps
&= (
4712 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4713 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4715 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4716 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4717 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4718 D3DPMISCCAPS_CULLCCW
);
4720 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4721 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4722 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4723 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4724 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4725 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4726 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4727 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4728 D3DPRASTERCAPS_ZFOG
);
4730 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4731 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4732 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4733 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4735 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4736 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4737 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4738 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4739 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4740 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4742 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4743 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4744 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4745 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4746 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4747 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4749 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4750 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4751 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4752 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4754 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4755 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4756 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4757 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4758 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4759 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4760 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4761 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4763 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4764 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4765 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4766 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4767 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4769 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4770 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4771 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4772 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4773 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4774 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4775 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4777 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4778 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4779 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4780 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4782 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4783 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4784 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4786 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4788 /* DirectX7 always has the np2 flag set, no matter what the card
4789 * supports. Some old games (Rollcage) check the caps incorrectly.
4790 * If wined3d supports nonpow2 textures it also has np2 conditional
4792 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4795 /* Fill the missing members, and do some fixup */
4796 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4797 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4798 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4799 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4800 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4801 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4802 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4803 /* Use the same for the TriCaps */
4804 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4806 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4807 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4808 desc7
->dwMinTextureWidth
= 1;
4809 desc7
->dwMinTextureHeight
= 1;
4811 /* Convert DWORDs safely to WORDs */
4812 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4813 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4814 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4815 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4817 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4818 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4819 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4820 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4822 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4824 desc7
->dwReserved1
= 0;
4825 desc7
->dwReserved2
= 0;
4826 desc7
->dwReserved3
= 0;
4827 desc7
->dwReserved4
= 0;
4829 /* Fill the old structure */
4830 memset(desc1
, 0, sizeof(*desc1
));
4831 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4832 desc1
->dwFlags
= D3DDD_COLORMODEL
4834 | D3DDD_TRANSFORMCAPS
4836 | D3DDD_LIGHTINGCAPS
4839 | D3DDD_DEVICERENDERBITDEPTH
4840 | D3DDD_DEVICEZBUFFERBITDEPTH
4841 | D3DDD_MAXBUFFERSIZE
4842 | D3DDD_MAXVERTEXCOUNT
;
4844 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4845 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4846 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4847 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4848 desc1
->bClipping
= TRUE
;
4849 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4850 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4851 | D3DLIGHTCAPS_PARALLELPOINT
4852 | D3DLIGHTCAPS_POINT
4853 | D3DLIGHTCAPS_SPOT
;
4855 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4856 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4858 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4859 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4860 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4861 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4862 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4863 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4864 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4865 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4866 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4867 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4868 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4869 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4870 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4872 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4873 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4874 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4875 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4876 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4877 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4878 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4879 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4880 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4881 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
4882 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
4883 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
4884 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
4886 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
4887 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
4888 desc1
->dwMaxBufferSize
= 0;
4889 desc1
->dwMaxVertexCount
= 65536;
4890 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
4891 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
4892 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
4893 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
4894 desc1
->dwMinStippleWidth
= 1;
4895 desc1
->dwMinStippleHeight
= 1;
4896 desc1
->dwMaxStippleWidth
= 32;
4897 desc1
->dwMaxStippleHeight
= 32;
4898 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
4899 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
4900 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
4901 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
4902 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
4903 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
4904 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
4905 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
4906 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
4907 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
4908 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
4909 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
4910 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
4915 /*****************************************************************************
4916 * IDirectDraw7 VTable
4917 *****************************************************************************/
4918 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4921 ddraw7_QueryInterface
,
4926 ddraw7_CreateClipper
,
4927 ddraw7_CreatePalette
,
4928 ddraw7_CreateSurface
,
4929 ddraw7_DuplicateSurface
,
4930 ddraw7_EnumDisplayModes
,
4931 ddraw7_EnumSurfaces
,
4932 ddraw7_FlipToGDISurface
,
4934 ddraw7_GetDisplayMode
,
4935 ddraw7_GetFourCCCodes
,
4936 ddraw7_GetGDISurface
,
4937 ddraw7_GetMonitorFrequency
,
4939 ddraw7_GetVerticalBlankStatus
,
4941 ddraw7_RestoreDisplayMode
,
4942 ddraw7_SetCooperativeLevel
,
4943 ddraw7_SetDisplayMode
,
4944 ddraw7_WaitForVerticalBlank
,
4946 ddraw7_GetAvailableVidMem
,
4948 ddraw7_GetSurfaceFromDC
,
4950 ddraw7_RestoreAllSurfaces
,
4951 ddraw7_TestCooperativeLevel
,
4952 ddraw7_GetDeviceIdentifier
,
4954 ddraw7_StartModeTest
,
4958 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4961 ddraw4_QueryInterface
,
4966 ddraw4_CreateClipper
,
4967 ddraw4_CreatePalette
,
4968 ddraw4_CreateSurface
,
4969 ddraw4_DuplicateSurface
,
4970 ddraw4_EnumDisplayModes
,
4971 ddraw4_EnumSurfaces
,
4972 ddraw4_FlipToGDISurface
,
4974 ddraw4_GetDisplayMode
,
4975 ddraw4_GetFourCCCodes
,
4976 ddraw4_GetGDISurface
,
4977 ddraw4_GetMonitorFrequency
,
4979 ddraw4_GetVerticalBlankStatus
,
4981 ddraw4_RestoreDisplayMode
,
4982 ddraw4_SetCooperativeLevel
,
4983 ddraw4_SetDisplayMode
,
4984 ddraw4_WaitForVerticalBlank
,
4986 ddraw4_GetAvailableVidMem
,
4988 ddraw4_GetSurfaceFromDC
,
4990 ddraw4_RestoreAllSurfaces
,
4991 ddraw4_TestCooperativeLevel
,
4992 ddraw4_GetDeviceIdentifier
,
4995 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
4998 ddraw2_QueryInterface
,
5003 ddraw2_CreateClipper
,
5004 ddraw2_CreatePalette
,
5005 ddraw2_CreateSurface
,
5006 ddraw2_DuplicateSurface
,
5007 ddraw2_EnumDisplayModes
,
5008 ddraw2_EnumSurfaces
,
5009 ddraw2_FlipToGDISurface
,
5011 ddraw2_GetDisplayMode
,
5012 ddraw2_GetFourCCCodes
,
5013 ddraw2_GetGDISurface
,
5014 ddraw2_GetMonitorFrequency
,
5016 ddraw2_GetVerticalBlankStatus
,
5018 ddraw2_RestoreDisplayMode
,
5019 ddraw2_SetCooperativeLevel
,
5020 ddraw2_SetDisplayMode
,
5021 ddraw2_WaitForVerticalBlank
,
5023 ddraw2_GetAvailableVidMem
,
5026 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5029 ddraw1_QueryInterface
,
5034 ddraw1_CreateClipper
,
5035 ddraw1_CreatePalette
,
5036 ddraw1_CreateSurface
,
5037 ddraw1_DuplicateSurface
,
5038 ddraw1_EnumDisplayModes
,
5039 ddraw1_EnumSurfaces
,
5040 ddraw1_FlipToGDISurface
,
5042 ddraw1_GetDisplayMode
,
5043 ddraw1_GetFourCCCodes
,
5044 ddraw1_GetGDISurface
,
5045 ddraw1_GetMonitorFrequency
,
5047 ddraw1_GetVerticalBlankStatus
,
5049 ddraw1_RestoreDisplayMode
,
5050 ddraw1_SetCooperativeLevel
,
5051 ddraw1_SetDisplayMode
,
5052 ddraw1_WaitForVerticalBlank
,
5055 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5057 /* IUnknown methods */
5058 d3d7_QueryInterface
,
5061 /* IDirect3D7 methods */
5064 d3d7_CreateVertexBuffer
,
5065 d3d7_EnumZBufferFormats
,
5066 d3d7_EvictManagedTextures
5069 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5071 /* IUnknown methods */
5072 d3d3_QueryInterface
,
5075 /* IDirect3D3 methods */
5078 d3d3_CreateMaterial
,
5079 d3d3_CreateViewport
,
5082 d3d3_CreateVertexBuffer
,
5083 d3d3_EnumZBufferFormats
,
5084 d3d3_EvictManagedTextures
5087 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5089 /* IUnknown methods */
5090 d3d2_QueryInterface
,
5093 /* IDirect3D2 methods */
5096 d3d2_CreateMaterial
,
5097 d3d2_CreateViewport
,
5102 static const struct IDirect3DVtbl d3d1_vtbl
=
5104 /* IUnknown methods */
5105 d3d1_QueryInterface
,
5108 /* IDirect3D methods */
5112 d3d1_CreateMaterial
,
5113 d3d1_CreateViewport
,
5117 /*****************************************************************************
5120 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5121 * if none was found.
5123 * This function is in ddraw.c and the DDraw object space because D3D7
5124 * vertex buffers are created using the IDirect3D interface to the ddraw
5125 * object, so they can be valid across D3D devices(theoretically. The ddraw
5126 * object also owns the wined3d device
5130 * fvf: Fvf to find the decl for
5133 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5135 *****************************************************************************/
5136 struct wined3d_vertex_declaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5138 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5140 int p
, low
, high
; /* deliberately signed */
5141 struct FvfToDecl
*convertedDecls
= This
->decls
;
5143 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5146 high
= This
->numConvertedDecls
- 1;
5147 while(low
<= high
) {
5148 p
= (low
+ high
) >> 1;
5150 if(convertedDecls
[p
].fvf
== fvf
) {
5151 TRACE("found %p\n", convertedDecls
[p
].decl
);
5152 return convertedDecls
[p
].decl
;
5153 } else if(convertedDecls
[p
].fvf
< fvf
) {
5159 TRACE("not found. Creating and inserting at position %d.\n", low
);
5161 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5162 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5163 if (hr
!= S_OK
) return NULL
;
5165 if(This
->declArraySize
== This
->numConvertedDecls
) {
5166 int grow
= max(This
->declArraySize
/ 2, 8);
5167 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5168 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5169 if (!convertedDecls
)
5171 wined3d_vertex_declaration_decref(pDecl
);
5174 This
->decls
= convertedDecls
;
5175 This
->declArraySize
+= grow
;
5178 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5179 convertedDecls
[low
].decl
= pDecl
;
5180 convertedDecls
[low
].fvf
= fvf
;
5181 This
->numConvertedDecls
++;
5183 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5187 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5189 return CONTAINING_RECORD(device_parent
, struct IDirectDrawImpl
, device_parent
);
5192 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5193 struct wined3d_device
*device
)
5195 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5198 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
5199 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5200 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, struct wined3d_surface
**surface
)
5202 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5203 IDirectDrawSurfaceImpl
*surf
= NULL
;
5205 DDSCAPS2 searchcaps
= ddraw
->tex_root
->surface_desc
.ddsCaps
;
5207 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5208 "\tpool %#x, level %u, face %u, surface %p.\n",
5209 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5211 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5214 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
5215 TRACE("Asked for positive x\n");
5216 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5218 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5220 surf
= ddraw
->tex_root
; break;
5221 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
5222 TRACE("Asked for negative x\n");
5223 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5224 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
5225 TRACE("Asked for positive y\n");
5226 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5227 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
5228 TRACE("Asked for negative y\n");
5229 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5230 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
5231 TRACE("Asked for positive z\n");
5232 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5233 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
5234 TRACE("Asked for negative z\n");
5235 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5236 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
5241 IDirectDrawSurface7
*attached
;
5242 IDirectDrawSurface7_GetAttachedSurface(&ddraw
->tex_root
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5243 surf
= unsafe_impl_from_IDirectDrawSurface7(attached
);
5244 IDirectDrawSurface7_Release(attached
);
5246 if (!surf
) ERR("root search surface not found\n");
5248 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5251 IDirectDrawSurface7
*attached
;
5252 IDirectDrawSurface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5253 if(!attached
) ERR("Surface not found\n");
5254 surf
= impl_from_IDirectDrawSurface7(attached
);
5255 IDirectDrawSurface7_Release(attached
);
5259 /* Return the surface */
5260 *surface
= surf
->wined3d_surface
;
5261 wined3d_surface_incref(*surface
);
5263 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5268 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5270 struct IDirectDrawImpl
*ddraw
= parent
;
5271 ddraw
->wined3d_frontbuffer
= NULL
;
5274 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5276 ddraw_frontbuffer_destroyed
,
5279 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
5280 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5281 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5282 struct wined3d_surface
**surface
)
5284 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5287 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5288 "\tmultisample_quality %u, lockable %u, surface %p.\n",
5289 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
5290 multisample_quality
, lockable
, surface
);
5292 if (ddraw
->wined3d_frontbuffer
)
5294 ERR("Frontbuffer already created.\n");
5298 hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format
, lockable
, FALSE
, 0,
5299 WINED3DUSAGE_RENDERTARGET
, WINED3DPOOL_DEFAULT
, multisample_type
, multisample_quality
,
5300 DefaultSurfaceType
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
);
5302 ddraw
->wined3d_frontbuffer
= *surface
;
5307 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
5308 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
5309 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
5311 ERR("DirectDraw doesn't have and shouldn't try creating implicit depth buffers.\n");
5315 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5316 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5317 WINED3DPOOL pool
, DWORD usage
, struct wined3d_volume
**volume
)
5319 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5320 "format %#x, pool %#x, usage %#x, volume %p.\n",
5321 device_parent
, container_parent
, width
, height
, depth
,
5322 format
, pool
, usage
, volume
);
5324 ERR("Not implemented!\n");
5329 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5330 WINED3DPRESENT_PARAMETERS
*present_parameters
, struct wined3d_swapchain
**swapchain
)
5332 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5333 IDirectDrawSurfaceImpl
*iterator
;
5336 TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent
, present_parameters
, swapchain
);
5338 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, present_parameters
,
5339 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5342 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5347 ddraw
->d3d_target
->wined3d_swapchain
= *swapchain
;
5348 iterator
= ddraw
->d3d_target
->complex_array
[0];
5351 iterator
->wined3d_swapchain
= *swapchain
;
5352 iterator
= iterator
->complex_array
[0];
5358 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5360 device_parent_wined3d_device_created
,
5361 device_parent_create_surface
,
5362 device_parent_create_rendertarget
,
5363 device_parent_create_depth_stencil
,
5364 device_parent_create_volume
,
5365 device_parent_create_swapchain
,
5368 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, WINED3DDEVTYPE device_type
)
5373 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5374 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5375 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5376 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5377 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5378 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5379 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5380 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5381 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5382 ddraw
->numIfaces
= 1;
5385 /* Get the current screen settings. */
5387 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5389 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5390 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5392 ddraw
->wineD3D
= wined3d_create(7, WINED3D_PALETTE_PER_SURFACE
| WINED3D_LEGACY_DEPTH_BIAS
,
5393 &ddraw
->IDirectDraw7_iface
);
5394 if (!ddraw
->wineD3D
)
5396 WARN("Failed to create a wined3d object.\n");
5397 return E_OUTOFMEMORY
;
5400 hr
= wined3d_device_create(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, device_type
,
5401 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5404 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5405 wined3d_decref(ddraw
->wineD3D
);
5409 list_init(&ddraw
->surface_list
);