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_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*surface
)
2538 WINED3DPRESENT_PARAMETERS presentation_parameters
;
2539 IDirectDrawSurfaceImpl
*target
= surface
;
2540 WINED3DDISPLAYMODE mode
;
2541 HRESULT hr
= WINED3D_OK
;
2543 /* FIXME: wined3d_get_adapter_display_mode() would be more appropriate
2544 * here, since we don't actually have a swapchain yet, but
2545 * wined3d_device_get_display_mode() has some special handling for color
2547 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &mode
);
2550 ERR("Failed to get display mode.\n");
2556 TRACE("Using primary %p.\n", ddraw
->primary
);
2557 target
= ddraw
->primary
;
2560 memset(&presentation_parameters
, 0, sizeof(presentation_parameters
));
2561 presentation_parameters
.BackBufferWidth
= mode
.Width
;
2562 presentation_parameters
.BackBufferHeight
= mode
.Height
;
2563 presentation_parameters
.BackBufferFormat
= mode
.Format
;
2564 presentation_parameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2565 presentation_parameters
.hDeviceWindow
= ddraw
->dest_window
;
2566 presentation_parameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2568 /* If the implementation is OpenGL and there's no d3ddevice, attach a
2569 * d3ddevice. But attach the d3ddevice only if the currently created
2570 * surface was a primary surface (2D app in 3D mode) or a 3DDEVICE surface
2571 * (3D app). The only case I can think of where this doesn't apply is when
2572 * a 2D app was configured by the user to run with OpenGL and it didn't
2573 * create the render target as first surface. In this case the render
2574 * target creation will cause the 3D init. */
2575 if (DefaultSurfaceType
== SURFACE_OPENGL
)
2577 TRACE("Attaching a D3DDevice, rendertarget = %p.\n", target
);
2578 hr
= ddraw_attach_d3d_device(ddraw
, target
, &presentation_parameters
);
2580 else if (surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2582 hr
= wined3d_device_init_gdi(ddraw
->wined3d_device
, &presentation_parameters
);
2584 WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr
);
2589 if (FAILED(hr
= wined3d_device_get_swapchain(ddraw
->wined3d_device
, 0, &ddraw
->wined3d_swapchain
)))
2591 ERR("Failed to get swapchain, hr %#x.\n", hr
);
2592 ddraw
->wined3d_swapchain
= NULL
;
2599 /*****************************************************************************
2600 * IDirectDraw7::CreateSurface
2602 * Creates a new IDirectDrawSurface object and returns its interface.
2604 * The surface connections with wined3d are a bit tricky. Basically it works
2607 * |------------------------| |-----------------|
2608 * | DDraw surface | | WineD3DSurface |
2610 * | WineD3DSurface |-------------->| |
2611 * | Child |<------------->| Parent |
2612 * |------------------------| |-----------------|
2614 * The DDraw surface is the parent of the wined3d surface, and it releases
2615 * the WineD3DSurface when the ddraw surface is destroyed.
2617 * However, for all surfaces which can be in a container in WineD3D,
2618 * we have to do this. These surfaces are usually complex surfaces,
2619 * so this concerns primary surfaces with a front and a back buffer,
2622 * |------------------------| |-----------------|
2623 * | DDraw surface | | Container |
2625 * | Child |<------------->| Parent |
2626 * | Texture |<------------->| |
2627 * | WineD3DSurface |<----| | Levels |<--|
2628 * | Complex connection | | | | |
2629 * |------------------------| | |-----------------| |
2633 * | |------------------| | |-----------------| |
2634 * | | IParent | |-------->| WineD3DSurface | |
2636 * | | Child |<------------->| Parent | |
2637 * | | | | Container |<--|
2638 * | |------------------| |-----------------| |
2640 * | |----------------------| |
2641 * | | DDraw surface 2 | |
2643 * |<->| Complex root Child | |
2645 * | | WineD3DSurface |<----| |
2646 * | |----------------------| | |
2648 * | |---------------------| | |-----------------| |
2649 * | | IParent | |----->| WineD3DSurface | |
2651 * | | Child |<---------->| Parent | |
2652 * | |---------------------| | Container |<--|
2653 * | |-----------------| |
2655 * | ---More surfaces can follow--- |
2657 * The reason is that the IWineD3DSwapchain(render target container)
2658 * and the IWineD3DTexure(Texture container) release the parents
2659 * of their surface's children, but by releasing the complex root
2660 * the surfaces which are complexly attached to it are destroyed
2661 * too. See IDirectDrawSurface::Release for a more detailed
2665 * DDSD: Description of the surface to create
2666 * Surf: Address to store the interface pointer at
2667 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2668 * aggregation, so it has to be NULL
2672 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2673 * DDERR_* if an error occurs
2675 *****************************************************************************/
2676 static HRESULT
CreateSurface(IDirectDrawImpl
*ddraw
, DDSURFACEDESC2
*DDSD
,
2677 IDirectDrawSurfaceImpl
**Surf
, IUnknown
*UnkOuter
, UINT version
)
2679 IDirectDrawSurfaceImpl
*object
= NULL
;
2681 LONG extra_surfaces
= 0;
2682 DDSURFACEDESC2 desc2
;
2683 WINED3DDISPLAYMODE Mode
;
2684 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
2686 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, Surf
, UnkOuter
);
2688 /* Some checks before we start */
2689 if (TRACE_ON(ddraw
))
2691 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
2692 DDRAW_dump_surface_desc(DDSD
);
2694 EnterCriticalSection(&ddraw_cs
);
2696 if (UnkOuter
!= NULL
)
2698 FIXME("(%p) : outer != NULL?\n", ddraw
);
2699 LeaveCriticalSection(&ddraw_cs
);
2700 return CLASS_E_NOAGGREGATION
; /* unchecked */
2705 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
2706 LeaveCriticalSection(&ddraw_cs
);
2707 return E_POINTER
; /* unchecked */
2710 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2712 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2713 DDSD
->dwFlags
|= DDSD_CAPS
;
2716 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2718 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2719 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2722 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2724 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2725 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
2726 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2729 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2730 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
2732 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
2735 LeaveCriticalSection(&ddraw_cs
);
2736 return DDERR_NOEXCLUSIVEMODE
;
2739 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
2741 WARN("Application wanted to create back buffer primary surface\n");
2742 LeaveCriticalSection(&ddraw_cs
);
2743 return DDERR_INVALIDCAPS
;
2746 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
2748 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
2749 WARN("Application tries to put the surface in both system and video memory\n");
2750 LeaveCriticalSection(&ddraw_cs
);
2752 return DDERR_INVALIDCAPS
;
2755 /* Check cube maps but only if the size includes them */
2756 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2758 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2759 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2761 WARN("Cube map faces requested without cube map flag\n");
2762 LeaveCriticalSection(&ddraw_cs
);
2763 return DDERR_INVALIDCAPS
;
2765 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2766 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2768 WARN("Cube map without faces requested\n");
2769 LeaveCriticalSection(&ddraw_cs
);
2770 return DDERR_INVALIDPARAMS
;
2773 /* Quick tests confirm those can be created, but we don't do that yet */
2774 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2775 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2777 FIXME("Partial cube maps not supported yet\n");
2781 /* According to the msdn this flag is ignored by CreateSurface */
2782 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2783 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2785 /* Modify some flags */
2786 copy_to_surfacedesc2(&desc2
, DDSD
);
2787 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2789 /* Get the video mode from WineD3D - we will need it */
2790 hr
= wined3d_device_get_display_mode(ddraw
->wined3d_device
, 0, &Mode
);
2793 ERR("Failed to read display mode from wined3d\n");
2794 switch(ddraw
->orig_bpp
)
2797 Mode
.Format
= WINED3DFMT_P8_UINT
;
2801 Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
;
2805 Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
;
2809 Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
;
2813 Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
;
2816 Mode
.Width
= ddraw
->orig_width
;
2817 Mode
.Height
= ddraw
->orig_height
;
2820 /* No pixelformat given? Use the current screen format */
2821 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2823 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2824 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2826 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2829 /* No Width or no Height? Use the original screen size
2831 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2832 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2834 /* Invalid for non-render targets */
2835 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2837 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2839 LeaveCriticalSection(&ddraw_cs
);
2840 return DDERR_INVALIDPARAMS
;
2843 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2844 desc2
.dwWidth
= Mode
.Width
;
2845 desc2
.dwHeight
= Mode
.Height
;
2848 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
2850 LeaveCriticalSection(&ddraw_cs
);
2851 return DDERR_INVALIDPARAMS
;
2854 /* Mipmap count fixes */
2855 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2857 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2859 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2861 /* Mipmap count is given, should not be 0 */
2862 if( desc2
.u2
.dwMipMapCount
== 0 )
2864 LeaveCriticalSection(&ddraw_cs
);
2865 return DDERR_INVALIDPARAMS
;
2870 /* Undocumented feature: Create sublevels until
2871 * either the width or the height is 1
2873 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2874 desc2
.dwWidth
: desc2
.dwHeight
;
2875 desc2
.u2
.dwMipMapCount
= 0;
2878 desc2
.u2
.dwMipMapCount
+= 1;
2885 /* Not-complex mipmap -> Mipmapcount = 1 */
2886 desc2
.u2
.dwMipMapCount
= 1;
2888 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2890 /* There's a mipmap count in the created surface in any case */
2891 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2893 /* If no mipmap is given, the texture has only one level */
2895 /* The first surface is a front buffer, the back buffer is created afterwards */
2896 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2898 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2901 /* The root surface in a cube map is positive x */
2902 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2904 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2905 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2908 /* Create the first surface */
2909 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0, version
);
2912 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
2913 LeaveCriticalSection(&ddraw_cs
);
2916 object
->is_complex_root
= TRUE
;
2920 /* Create Additional surfaces if necessary
2921 * This applies to Primary surfaces which have a back buffer count
2922 * set, but not to mipmap textures. In case of Mipmap textures,
2923 * wineD3D takes care of the creation of additional surfaces
2925 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2927 extra_surfaces
= DDSD
->dwBackBufferCount
;
2928 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2929 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2930 desc2
.dwBackBufferCount
= 0;
2934 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2936 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2937 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2938 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2939 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2940 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
2941 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2942 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
2943 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
2944 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2945 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
2946 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
2947 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2948 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
2949 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
2950 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
, version
);
2951 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
2952 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2955 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
, version
);
2958 /* This destroys and possibly created surfaces too */
2961 IDirectDrawSurface7_Release(&object
->IDirectDrawSurface7_iface
);
2963 else if (version
== 4)
2965 IDirectDrawSurface4_Release(&object
->IDirectDrawSurface4_iface
);
2969 IDirectDrawSurface_Release(&object
->IDirectDrawSurface_iface
);
2971 LeaveCriticalSection(&ddraw_cs
);
2975 if (!ddraw
->d3d_initialized
&& desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
))
2977 if (FAILED(hr
= ddraw_create_swapchain(ddraw
, object
)))
2979 IDirectDrawSurfaceImpl
*release_surf
;
2980 ERR("Failed to create swapchain, hr %#x.\n", hr
);
2983 /* The earlier created surface structures are in an incomplete
2984 * state here. Wined3d holds the reference on the parents, and it
2985 * released them on the failure already. So the regular release
2986 * method implementation would fail on the attempt to destroy
2987 * either the parents or the swapchain. So free the surface here.
2988 * The surface structure here is a list, not a tree, because
2989 * onscreen targets cannot be cube textures. */
2992 release_surf
= object
;
2993 object
= object
->complex_array
[0];
2994 ddraw_surface_destroy(release_surf
);
2996 LeaveCriticalSection(&ddraw_cs
);
3001 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3002 ddraw
->primary
= object
;
3004 /* Create a WineD3DTexture if a texture was requested */
3005 if (desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3007 ddraw
->tex_root
= object
;
3008 ddraw_surface_create_texture(object
);
3009 ddraw
->tex_root
= NULL
;
3012 LeaveCriticalSection(&ddraw_cs
);
3016 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3017 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3019 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3020 IDirectDrawSurfaceImpl
*impl
;
3023 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3024 iface
, surface_desc
, surface
, outer_unknown
);
3026 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3028 WARN("Application supplied invalid surface descriptor\n");
3029 return DDERR_INVALIDPARAMS
;
3032 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3034 if (TRACE_ON(ddraw
))
3036 TRACE(" (%p) Requesting surface desc :\n", iface
);
3037 DDRAW_dump_surface_desc(surface_desc
);
3040 WARN("Application tried to create an explicit front or back buffer\n");
3041 return DDERR_INVALIDCAPS
;
3044 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 7);
3051 *surface
= &impl
->IDirectDrawSurface7_iface
;
3052 IDirectDraw7_AddRef(iface
);
3053 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3058 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3059 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3061 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3062 IDirectDrawSurfaceImpl
*impl
;
3065 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3066 iface
, surface_desc
, surface
, outer_unknown
);
3068 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3070 WARN("Application supplied invalid surface descriptor\n");
3071 return DDERR_INVALIDPARAMS
;
3074 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3076 if (TRACE_ON(ddraw
))
3078 TRACE(" (%p) Requesting surface desc :\n", iface
);
3079 DDRAW_dump_surface_desc(surface_desc
);
3082 WARN("Application tried to create an explicit front or back buffer\n");
3083 return DDERR_INVALIDCAPS
;
3086 hr
= CreateSurface(This
, surface_desc
, &impl
, outer_unknown
, 4);
3093 *surface
= &impl
->IDirectDrawSurface4_iface
;
3094 IDirectDraw4_AddRef(iface
);
3095 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3100 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3101 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3103 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3104 IDirectDrawSurfaceImpl
*impl
;
3106 DDSURFACEDESC2 surface_desc2
;
3108 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3109 iface
, surface_desc
, surface
, outer_unknown
);
3111 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3113 WARN("Application supplied invalid surface descriptor\n");
3114 return DDERR_INVALIDPARAMS
;
3117 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3118 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3120 if (TRACE_ON(ddraw
))
3122 TRACE(" (%p) Requesting surface desc :\n", iface
);
3123 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3126 WARN("Application tried to create an explicit front or back buffer\n");
3127 return DDERR_INVALIDCAPS
;
3130 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 2);
3137 *surface
= &impl
->IDirectDrawSurface_iface
;
3138 impl
->ifaceToRelease
= NULL
;
3143 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3144 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3146 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3147 IDirectDrawSurfaceImpl
*impl
;
3149 DDSURFACEDESC2 surface_desc2
;
3151 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3152 iface
, surface_desc
, surface
, outer_unknown
);
3154 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3156 WARN("Application supplied invalid surface descriptor\n");
3157 return DDERR_INVALIDPARAMS
;
3160 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3161 * primaries anyway. */
3162 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3163 DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3164 hr
= CreateSurface(This
, &surface_desc2
, &impl
, outer_unknown
, 1);
3171 *surface
= &impl
->IDirectDrawSurface_iface
;
3172 impl
->ifaceToRelease
= NULL
;
3177 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3178 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3181 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3182 const DDPIXELFORMAT
*provided
)
3184 /* Some flags must be present in both or neither for a match. */
3185 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3186 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3187 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3189 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3192 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3195 if (requested
->dwFlags
& DDPF_FOURCC
)
3196 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3199 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3200 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3201 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3204 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3205 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3206 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3209 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3210 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3213 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3214 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3216 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3219 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3220 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3226 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3235 #define CMP(FLAG, FIELD) \
3236 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3237 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3239 static const struct compare_info compare
[] =
3241 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3242 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3244 CMP(CKDESTBLT
, ddckCKDestBlt
),
3245 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3246 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3247 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3248 CMP(HEIGHT
, dwHeight
),
3249 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3250 CMP(LPSURFACE
, lpSurface
),
3251 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3252 CMP(PITCH
, u1
/* lPitch */),
3253 /* PIXELFORMAT: manual */
3254 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3255 CMP(TEXTURESTAGE
, dwTextureStage
),
3256 CMP(WIDTH
, dwWidth
),
3257 /* ZBUFFERBITDEPTH: "obsolete" */
3264 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3267 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3269 if (requested
->dwFlags
& compare
[i
].flag
3270 && memcmp((const char *)provided
+ compare
[i
].offset
,
3271 (const char *)requested
+ compare
[i
].offset
,
3272 compare
[i
].size
) != 0)
3276 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3278 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3279 &provided
->u4
.ddpfPixelFormat
))
3286 #undef DDENUMSURFACES_SEARCHTYPE
3287 #undef DDENUMSURFACES_MATCHTYPE
3289 struct surfacescallback2_context
3291 LPDDENUMSURFACESCALLBACK2 func
;
3295 struct surfacescallback_context
3297 LPDDENUMSURFACESCALLBACK func
;
3301 static HRESULT CALLBACK
EnumSurfacesCallback2Thunk(IDirectDrawSurface7
*surface
,
3302 DDSURFACEDESC2
*surface_desc
, void *context
)
3304 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3305 struct surfacescallback2_context
*cbcontext
= context
;
3307 IDirectDrawSurface4_AddRef(&surface_impl
->IDirectDrawSurface4_iface
);
3308 IDirectDrawSurface7_Release(surface
);
3310 return cbcontext
->func(&surface_impl
->IDirectDrawSurface4_iface
,
3311 surface_desc
, cbcontext
->context
);
3314 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3315 DDSURFACEDESC2
*surface_desc
, void *context
)
3317 IDirectDrawSurfaceImpl
*surface_impl
= impl_from_IDirectDrawSurface7(surface
);
3318 struct surfacescallback_context
*cbcontext
= context
;
3320 IDirectDrawSurface_AddRef(&surface_impl
->IDirectDrawSurface_iface
);
3321 IDirectDrawSurface7_Release(surface
);
3323 return cbcontext
->func(&surface_impl
->IDirectDrawSurface_iface
,
3324 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3327 /*****************************************************************************
3328 * IDirectDraw7::EnumSurfaces
3330 * Loops through all surfaces attached to this device and calls the
3331 * application callback. This can't be relayed to WineD3DDevice,
3332 * because some WineD3DSurfaces' parents are IParent objects
3335 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3336 * DDSD: Description to filter for
3337 * Context: Application-provided pointer, it's passed unmodified to the
3339 * Callback: Address to call for each surface
3342 * DDERR_INVALIDPARAMS if the callback is NULL
3345 *****************************************************************************/
3346 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3347 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3349 /* The surface enumeration is handled by WineDDraw,
3350 * because it keeps track of all surfaces attached to
3351 * it. The filtering is done by our callback function,
3352 * because WineDDraw doesn't handle ddraw-like surface
3355 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3356 IDirectDrawSurfaceImpl
*surf
;
3358 DDSURFACEDESC2 desc
;
3359 struct list
*entry
, *entry2
;
3361 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3362 iface
, Flags
, DDSD
, Context
, Callback
);
3364 all
= Flags
& DDENUMSURFACES_ALL
;
3365 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3367 EnterCriticalSection(&ddraw_cs
);
3371 LeaveCriticalSection(&ddraw_cs
);
3372 return DDERR_INVALIDPARAMS
;
3375 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3376 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3378 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3379 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3381 TRACE("Enumerating surface %p.\n", surf
);
3382 desc
= surf
->surface_desc
;
3383 IDirectDrawSurface7_AddRef(&surf
->IDirectDrawSurface7_iface
);
3384 if (Callback(&surf
->IDirectDrawSurface7_iface
, &desc
, Context
) != DDENUMRET_OK
)
3386 LeaveCriticalSection(&ddraw_cs
);
3391 LeaveCriticalSection(&ddraw_cs
);
3395 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3396 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3398 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3399 struct surfacescallback2_context cbcontext
;
3401 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3402 iface
, flags
, surface_desc
, context
, callback
);
3404 cbcontext
.func
= callback
;
3405 cbcontext
.context
= context
;
3407 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, surface_desc
,
3408 &cbcontext
, EnumSurfacesCallback2Thunk
);
3411 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3412 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3414 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3415 struct surfacescallback_context cbcontext
;
3416 DDSURFACEDESC2 surface_desc2
;
3418 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3419 iface
, flags
, surface_desc
, context
, callback
);
3421 cbcontext
.func
= callback
;
3422 cbcontext
.context
= context
;
3424 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3425 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3426 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3429 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3430 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3432 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3433 struct surfacescallback_context cbcontext
;
3434 DDSURFACEDESC2 surface_desc2
;
3436 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3437 iface
, flags
, surface_desc
, context
, callback
);
3439 cbcontext
.func
= callback
;
3440 cbcontext
.context
= context
;
3442 if (surface_desc
) DDSD_to_DDSD2(surface_desc
, &surface_desc2
);
3443 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
,
3444 surface_desc
? &surface_desc2
: NULL
, &cbcontext
, EnumSurfacesCallbackThunk
);
3447 /*****************************************************************************
3448 * DirectDrawCreateClipper (DDRAW.@)
3450 * Creates a new IDirectDrawClipper object.
3453 * Clipper: Address to write the interface pointer to
3454 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3458 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3459 * E_OUTOFMEMORY if allocating the object failed
3461 *****************************************************************************/
3463 DirectDrawCreateClipper(DWORD Flags
,
3464 LPDIRECTDRAWCLIPPER
*Clipper
,
3467 IDirectDrawClipperImpl
* object
;
3470 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3471 Flags
, Clipper
, UnkOuter
);
3473 EnterCriticalSection(&ddraw_cs
);
3474 if (UnkOuter
!= NULL
)
3476 LeaveCriticalSection(&ddraw_cs
);
3477 return CLASS_E_NOAGGREGATION
;
3480 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3481 sizeof(IDirectDrawClipperImpl
));
3484 LeaveCriticalSection(&ddraw_cs
);
3485 return E_OUTOFMEMORY
;
3488 hr
= ddraw_clipper_init(object
);
3491 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3492 HeapFree(GetProcessHeap(), 0, object
);
3493 LeaveCriticalSection(&ddraw_cs
);
3497 TRACE("Created clipper %p.\n", object
);
3498 *Clipper
= &object
->IDirectDrawClipper_iface
;
3499 LeaveCriticalSection(&ddraw_cs
);
3503 /*****************************************************************************
3504 * IDirectDraw7::CreateClipper
3506 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3508 *****************************************************************************/
3509 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3510 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3512 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3513 iface
, Flags
, Clipper
, UnkOuter
);
3515 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3518 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3519 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3521 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3523 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3524 iface
, flags
, clipper
, outer_unknown
);
3526 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3529 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
3530 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3532 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3534 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3535 iface
, flags
, clipper
, outer_unknown
);
3537 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3540 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
3541 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3543 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3545 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3546 iface
, flags
, clipper
, outer_unknown
);
3548 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3551 /*****************************************************************************
3552 * IDirectDraw7::CreatePalette
3554 * Creates a new IDirectDrawPalette object
3557 * Flags: The flags for the new clipper
3558 * ColorTable: Color table to assign to the new clipper
3559 * Palette: Address to write the interface pointer to
3560 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3564 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3565 * E_OUTOFMEMORY if allocating the object failed
3567 *****************************************************************************/
3568 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
3569 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
3571 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3572 IDirectDrawPaletteImpl
*object
;
3575 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
3576 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3578 EnterCriticalSection(&ddraw_cs
);
3579 if(pUnkOuter
!= NULL
)
3581 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3582 LeaveCriticalSection(&ddraw_cs
);
3583 return CLASS_E_NOAGGREGATION
;
3586 /* The refcount test shows that a cooplevel is required for this */
3587 if(!This
->cooperative_level
)
3589 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3590 LeaveCriticalSection(&ddraw_cs
);
3591 return DDERR_NOCOOPERATIVELEVELSET
;
3594 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3597 ERR("Out of memory when allocating memory for a palette implementation\n");
3598 LeaveCriticalSection(&ddraw_cs
);
3599 return E_OUTOFMEMORY
;
3602 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
3605 WARN("Failed to initialize palette, hr %#x.\n", hr
);
3606 HeapFree(GetProcessHeap(), 0, object
);
3607 LeaveCriticalSection(&ddraw_cs
);
3611 TRACE("Created palette %p.\n", object
);
3612 *Palette
= &object
->IDirectDrawPalette_iface
;
3613 LeaveCriticalSection(&ddraw_cs
);
3617 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
3618 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3620 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3623 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3624 iface
, flags
, entries
, palette
, outer_unknown
);
3626 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3627 if (SUCCEEDED(hr
) && *palette
)
3629 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3630 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3631 IDirectDraw4_AddRef(iface
);
3632 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3637 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
3638 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3640 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3643 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3644 iface
, flags
, entries
, palette
, outer_unknown
);
3646 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3647 if (SUCCEEDED(hr
) && *palette
)
3649 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3650 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3651 impl
->ifaceToRelease
= NULL
;
3657 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
3658 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
3660 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3663 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
3664 iface
, flags
, entries
, palette
, outer_unknown
);
3666 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
3667 if (SUCCEEDED(hr
) && *palette
)
3669 IDirectDrawPaletteImpl
*impl
= impl_from_IDirectDrawPalette(*palette
);
3670 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3671 impl
->ifaceToRelease
= NULL
;
3677 /*****************************************************************************
3678 * IDirectDraw7::DuplicateSurface
3680 * Duplicates a surface. The surface memory points to the same memory as
3681 * the original surface, and it's released when the last surface referencing
3682 * it is released. I guess that's beyond Wine's surface management right now
3683 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3684 * test application to implement this)
3687 * Src: Address of the source surface
3688 * Dest: Address to write the new surface pointer to
3691 * See IDirectDraw7::CreateSurface
3693 *****************************************************************************/
3694 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
3695 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
3697 IDirectDrawSurfaceImpl
*Surf
= unsafe_impl_from_IDirectDrawSurface7(Src
);
3699 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
3701 /* For now, simply create a new, independent surface */
3702 return IDirectDraw7_CreateSurface(iface
,
3703 &Surf
->surface_desc
,
3708 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
3709 IDirectDrawSurface4
**dst
)
3711 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3712 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface4(src
);
3713 IDirectDrawSurface7
*dst7
;
3714 IDirectDrawSurfaceImpl
*dst_impl
;
3717 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3718 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3719 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3725 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3726 *dst
= &dst_impl
->IDirectDrawSurface4_iface
;
3727 IDirectDrawSurface4_AddRef(*dst
);
3728 IDirectDrawSurface7_Release(dst7
);
3733 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
3734 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
3736 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3737 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3738 IDirectDrawSurface7
*dst7
;
3739 IDirectDrawSurfaceImpl
*dst_impl
;
3742 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3743 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3744 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3747 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3748 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3749 IDirectDrawSurface_AddRef(*dst
);
3750 IDirectDrawSurface7_Release(dst7
);
3755 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
3756 IDirectDrawSurface
**dst
)
3758 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3759 IDirectDrawSurfaceImpl
*src_impl
= unsafe_impl_from_IDirectDrawSurface(src
);
3760 IDirectDrawSurface7
*dst7
;
3761 IDirectDrawSurfaceImpl
*dst_impl
;
3764 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
3765 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
,
3766 src_impl
? &src_impl
->IDirectDrawSurface7_iface
: NULL
, &dst7
);
3769 dst_impl
= impl_from_IDirectDrawSurface7(dst7
);
3770 *dst
= &dst_impl
->IDirectDrawSurface_iface
;
3771 IDirectDrawSurface_AddRef(*dst
);
3772 IDirectDrawSurface7_Release(dst7
);
3777 /*****************************************************************************
3778 * IDirect3D7::EnumDevices
3780 * The EnumDevices method for IDirect3D7. It enumerates all supported
3781 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
3784 * callback: Function to call for each enumerated device
3785 * context: Pointer to pass back to the app
3788 * D3D_OK, or the return value of the GetCaps call
3790 *****************************************************************************/
3791 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
3793 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
3794 D3DDEVICEDESC7 device_desc7
;
3795 D3DDEVICEDESC device_desc1
;
3799 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3802 return DDERR_INVALIDPARAMS
;
3804 EnterCriticalSection(&ddraw_cs
);
3806 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
3809 LeaveCriticalSection(&ddraw_cs
);
3813 for (i
= 0; i
< sizeof(device_list7
)/sizeof(device_list7
[0]); i
++)
3817 device_desc7
.deviceGUID
= *device_list7
[i
].device_guid
;
3818 ret
= callback(device_list7
[i
].interface_name
, device_list7
[i
].device_name
, &device_desc7
, context
);
3819 if (ret
!= DDENUMRET_OK
)
3821 TRACE("Application cancelled the enumeration.\n");
3822 LeaveCriticalSection(&ddraw_cs
);
3827 TRACE("End of enumeration.\n");
3829 LeaveCriticalSection(&ddraw_cs
);
3834 /*****************************************************************************
3835 * IDirect3D3::EnumDevices
3837 * Enumerates all supported Direct3DDevice interfaces. This is the
3838 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
3840 * Version 1, 2 and 3
3843 * callback: Application-provided routine to call for each enumerated device
3844 * Context: Pointer to pass to the callback
3847 * D3D_OK on success,
3848 * The result of IDirect3DImpl_GetCaps if it failed
3850 *****************************************************************************/
3851 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3853 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
3855 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
3856 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
3857 D3DDEVICEDESC7 device_desc7
;
3860 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
3861 * name string. Let's put the string in a sufficiently sized array in
3862 * writable memory. */
3863 char device_name
[50];
3864 strcpy(device_name
,"Direct3D HEL");
3866 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3869 return DDERR_INVALIDPARAMS
;
3871 EnterCriticalSection(&ddraw_cs
);
3873 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
3876 LeaveCriticalSection(&ddraw_cs
);
3880 /* Do I have to enumerate the reference id? Note from old d3d7:
3881 * "It seems that enumerating the reference IID on Direct3D 1 games
3882 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
3884 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
3885 * EnumReference which enables / disables enumerating the reference
3886 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
3887 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
3888 * demo directory suggest this.
3890 * Some games(GTA 2) seem to use the second enumerated device, so I have
3891 * to enumerate at least 2 devices. So enumerate the reference device to
3894 * Other games (Rollcage) tell emulation and hal device apart by certain
3895 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
3896 * limitation flag), and it refuses all devices that have the perspective
3897 * flag set. This way it refuses the emulation device, and HAL devices
3898 * never have POW2 unset in d3d7 on windows. */
3899 if (This
->d3dversion
!= 1)
3901 static CHAR reference_description
[] = "RGB Direct3D emulation";
3903 TRACE("Enumerating WineD3D D3DDevice interface.\n");
3904 hal_desc
= device_desc1
;
3905 hel_desc
= device_desc1
;
3906 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
3907 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3908 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3909 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3910 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3911 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
3912 device_name
, &hal_desc
, &hel_desc
, context
);
3913 if (hr
!= D3DENUMRET_OK
)
3915 TRACE("Application cancelled the enumeration.\n");
3916 LeaveCriticalSection(&ddraw_cs
);
3921 strcpy(device_name
,"Direct3D HAL");
3923 TRACE("Enumerating HAL Direct3D device.\n");
3924 hal_desc
= device_desc1
;
3925 hel_desc
= device_desc1
;
3926 /* The hal device does not have the pow2 flag set in hel, but in hal. */
3927 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3928 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3929 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
3930 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
3931 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
3932 device_name
, &hal_desc
, &hel_desc
, context
);
3933 if (hr
!= D3DENUMRET_OK
)
3935 TRACE("Application cancelled the enumeration.\n");
3936 LeaveCriticalSection(&ddraw_cs
);
3940 TRACE("End of enumeration.\n");
3942 LeaveCriticalSection(&ddraw_cs
);
3946 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3948 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
3950 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3952 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
3955 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
3957 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
3959 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
3961 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
3964 /*****************************************************************************
3965 * IDirect3D3::CreateLight
3967 * Creates an IDirect3DLight interface. This interface is used in
3968 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
3969 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
3970 * uses the IDirect3DDevice7 interface with D3D7 lights.
3972 * Version 1, 2 and 3
3975 * light: Address to store the new interface pointer
3976 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
3981 * DDERR_OUTOFMEMORY if memory allocation failed
3982 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
3984 *****************************************************************************/
3985 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
3986 IUnknown
*outer_unknown
)
3988 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
3989 IDirect3DLightImpl
*object
;
3991 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
3993 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
3995 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3998 ERR("Failed to allocate light memory.\n");
3999 return DDERR_OUTOFMEMORY
;
4002 d3d_light_init(object
, This
);
4004 TRACE("Created light %p.\n", object
);
4005 *light
= &object
->IDirect3DLight_iface
;
4010 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4012 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4014 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4016 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4019 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4021 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4023 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4025 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4028 /*****************************************************************************
4029 * IDirect3D3::CreateMaterial
4031 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4032 * and older versions. The IDirect3DMaterial implementation wraps its
4033 * functionality to IDirect3DDevice7::SetMaterial and friends.
4035 * Version 1, 2 and 3
4038 * material: Address to store the new interface's pointer to
4039 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4044 * DDERR_OUTOFMEMORY if memory allocation failed
4045 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4047 *****************************************************************************/
4048 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4049 IUnknown
*outer_unknown
)
4051 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4052 IDirect3DMaterialImpl
*object
;
4054 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4056 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4058 object
= d3d_material_create(This
);
4061 ERR("Failed to allocate material memory.\n");
4062 return DDERR_OUTOFMEMORY
;
4065 TRACE("Created material %p.\n", object
);
4066 *material
= &object
->IDirect3DMaterial3_iface
;
4071 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
,
4072 IUnknown
*outer_unknown
)
4074 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4075 IDirect3DMaterialImpl
*object
;
4077 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4079 object
= d3d_material_create(This
);
4082 ERR("Failed to allocate material memory.\n");
4083 return DDERR_OUTOFMEMORY
;
4086 TRACE("Created material %p.\n", object
);
4087 *material
= &object
->IDirect3DMaterial2_iface
;
4092 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
,
4093 IUnknown
*outer_unknown
)
4095 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4096 IDirect3DMaterialImpl
*object
;
4098 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4100 object
= d3d_material_create(This
);
4103 ERR("Failed to allocate material memory.\n");
4104 return DDERR_OUTOFMEMORY
;
4107 TRACE("Created material %p.\n", object
);
4108 *material
= &object
->IDirect3DMaterial_iface
;
4113 /*****************************************************************************
4114 * IDirect3D3::CreateViewport
4116 * Creates an IDirect3DViewport interface. This interface is used
4117 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4118 * it has been replaced by a viewport structure and
4119 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4120 * uses the IDirect3DDevice7 methods for its functionality
4123 * Viewport: Address to store the new interface pointer
4124 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4129 * DDERR_OUTOFMEMORY if memory allocation failed
4130 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4132 *****************************************************************************/
4133 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4134 IUnknown
*outer_unknown
)
4136 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4137 IDirect3DViewportImpl
*object
;
4139 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4141 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4143 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4146 ERR("Failed to allocate viewport memory.\n");
4147 return DDERR_OUTOFMEMORY
;
4150 d3d_viewport_init(object
, This
);
4152 TRACE("Created viewport %p.\n", object
);
4153 *viewport
= &object
->IDirect3DViewport3_iface
;
4158 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4160 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4162 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4164 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4168 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4170 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4172 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4174 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4178 /*****************************************************************************
4179 * IDirect3D3::FindDevice
4181 * This method finds a device with the requested properties and returns a
4182 * device description
4186 * fds: Describes the requested device characteristics
4187 * fdr: Returns the device description
4191 * DDERR_INVALIDPARAMS if no device was found
4193 *****************************************************************************/
4194 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4196 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4197 D3DDEVICEDESC7 desc7
;
4198 D3DDEVICEDESC desc1
;
4201 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4203 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4205 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4206 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4207 return DDERR_INVALIDPARAMS
;
4209 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4210 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4212 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4213 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4216 if (fds
->dwFlags
& D3DFDS_GUID
)
4218 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4219 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4220 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4221 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4223 WARN("No match for this GUID.\n");
4224 return DDERR_NOTFOUND
;
4229 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &desc1
, &desc7
);
4230 if (hr
!= D3D_OK
) return hr
;
4232 /* Now return our own GUID */
4233 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4234 fdr
->ddHwDesc
= desc1
;
4235 fdr
->ddSwDesc
= desc1
;
4237 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4242 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4244 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4246 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4248 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4251 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4253 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4255 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4257 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4260 /*****************************************************************************
4261 * IDirect3D7::CreateDevice
4263 * Creates an IDirect3DDevice7 interface.
4265 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4266 * DirectDraw surfaces and are created with
4267 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4268 * create the device object and QueryInterfaces for IDirect3DDevice
4271 * refiid: IID of the device to create
4272 * Surface: Initial rendertarget
4273 * Device: Address to return the interface pointer
4277 * DDERR_OUTOFMEMORY if memory allocation failed
4278 * DDERR_INVALIDPARAMS if a device exists already
4280 *****************************************************************************/
4281 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4282 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4284 IDirectDrawSurfaceImpl
*target
= unsafe_impl_from_IDirectDrawSurface7(surface
);
4285 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4286 IDirect3DDeviceImpl
*object
;
4289 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4291 EnterCriticalSection(&ddraw_cs
);
4294 /* Fail device creation if non-opengl surfaces are used. */
4295 if (DefaultSurfaceType
!= SURFACE_OPENGL
)
4297 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4298 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4300 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4301 * is caught in CreateSurface or QueryInterface. */
4302 LeaveCriticalSection(&ddraw_cs
);
4306 if (This
->d3ddevice
)
4308 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4309 LeaveCriticalSection(&ddraw_cs
);
4310 return DDERR_INVALIDPARAMS
;
4313 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4316 ERR("Failed to allocate device memory.\n");
4317 LeaveCriticalSection(&ddraw_cs
);
4318 return DDERR_OUTOFMEMORY
;
4321 hr
= d3d_device_init(object
, This
, target
);
4324 WARN("Failed to initialize device, hr %#x.\n", hr
);
4325 HeapFree(GetProcessHeap(), 0, object
);
4326 LeaveCriticalSection(&ddraw_cs
);
4330 TRACE("Created device %p.\n", object
);
4331 *device
= (IDirect3DDevice7
*)object
;
4333 LeaveCriticalSection(&ddraw_cs
);
4337 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4338 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4340 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4341 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface4(surface
);
4344 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4345 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4347 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4349 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4350 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
,
4351 (IDirect3DDevice7
**)device
);
4352 if (*device
) *device
= (IDirect3DDevice3
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice3_vtbl
;
4357 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4358 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4360 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4361 IDirectDrawSurfaceImpl
*surface_impl
= unsafe_impl_from_IDirectDrawSurface(surface
);
4364 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4365 iface
, debugstr_guid(riid
), surface
, device
);
4367 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4368 surface_impl
? &surface_impl
->IDirectDrawSurface7_iface
: NULL
,
4369 (IDirect3DDevice7
**)device
);
4370 if (*device
) *device
= (IDirect3DDevice2
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice2_vtbl
;
4375 /*****************************************************************************
4376 * IDirect3D7::CreateVertexBuffer
4378 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4384 * desc: Requested Vertex buffer properties
4385 * vertex_buffer: Address to return the interface pointer at
4386 * flags: Some flags, should be 0
4390 * DDERR_OUTOFMEMORY if memory allocation failed
4391 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4392 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4394 *****************************************************************************/
4395 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4396 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4398 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4399 IDirect3DVertexBufferImpl
*object
;
4402 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4403 iface
, desc
, vertex_buffer
, flags
);
4405 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4407 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4410 TRACE("Created vertex buffer %p.\n", object
);
4411 *vertex_buffer
= &object
->IDirect3DVertexBuffer7_iface
;
4414 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4419 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4420 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4422 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4423 IDirect3DVertexBufferImpl
*object
;
4426 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4427 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4430 return CLASS_E_NOAGGREGATION
;
4431 if (!vertex_buffer
|| !desc
)
4432 return DDERR_INVALIDPARAMS
;
4434 hr
= d3d_vertex_buffer_create(&object
, This
, desc
);
4437 TRACE("Created vertex buffer %p.\n", object
);
4438 *vertex_buffer
= &object
->IDirect3DVertexBuffer_iface
;
4441 WARN("Failed to create vertex buffer, hr %#x.\n", hr
);
4446 /*****************************************************************************
4447 * IDirect3D7::EnumZBufferFormats
4449 * Enumerates all supported Z buffer pixel formats
4455 * callback: callback to call for each pixel format
4456 * context: Pointer to pass back to the callback
4460 * DDERR_INVALIDPARAMS if callback is NULL
4461 * For details, see IWineD3DDevice::EnumZBufferFormats
4463 *****************************************************************************/
4464 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4465 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4467 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4468 WINED3DDISPLAYMODE d3ddm
;
4469 WINED3DDEVTYPE type
;
4473 /* Order matters. Specifically, BattleZone II (full version) expects the
4474 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4475 static const enum wined3d_format_id formats
[] =
4477 WINED3DFMT_S1_UINT_D15_UNORM
,
4478 WINED3DFMT_D16_UNORM
,
4479 WINED3DFMT_X8D24_UNORM
,
4480 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4481 WINED3DFMT_D24_UNORM_S8_UINT
,
4482 WINED3DFMT_D32_UNORM
,
4485 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4486 iface
, debugstr_guid(device_iid
), callback
, context
);
4488 if (!callback
) return DDERR_INVALIDPARAMS
;
4490 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4491 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4492 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4494 TRACE("Asked for HAL device.\n");
4495 type
= WINED3DDEVTYPE_HAL
;
4497 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4498 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4500 TRACE("Asked for SW device.\n");
4501 type
= WINED3DDEVTYPE_SW
;
4503 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4505 TRACE("Asked for REF device.\n");
4506 type
= WINED3DDEVTYPE_REF
;
4508 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4510 TRACE("Asked for NULLREF device.\n");
4511 type
= WINED3DDEVTYPE_NULLREF
;
4515 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4516 type
= WINED3DDEVTYPE_HAL
;
4519 EnterCriticalSection(&ddraw_cs
);
4520 /* We need an adapter format from somewhere to please wined3d and WGL.
4521 * Use the current display mode. So far all cards offer the same depth
4522 * stencil format for all modes, but if some do not and applications do
4523 * not like that we'll have to find some workaround, like iterating over
4524 * all imaginable formats and collecting all the depth stencil formats we
4526 hr
= wined3d_device_get_display_mode(This
->wined3d_device
, 0, &d3ddm
);
4528 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
4530 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4531 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, formats
[i
], SURFACE_OPENGL
);
4534 DDPIXELFORMAT pformat
;
4536 memset(&pformat
, 0, sizeof(pformat
));
4537 pformat
.dwSize
= sizeof(pformat
);
4538 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
4540 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
4541 hr
= callback(&pformat
, context
);
4542 if (hr
!= DDENUMRET_OK
)
4544 TRACE("Format enumeration cancelled by application.\n");
4545 LeaveCriticalSection(&ddraw_cs
);
4551 /* Historically some windows drivers used dwZBufferBitDepth=24 for WINED3DFMT_X8D24_UNORM,
4552 * while others used dwZBufferBitDepth=32. In either case the pitch matches a 32 bits per
4553 * pixel format, so we use dwZBufferBitDepth=32. Some games expect 24. Windows Vista and
4554 * newer enumerate both versions, so we do the same(bug 22434) */
4555 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
4556 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, WINED3DFMT_X8D24_UNORM
, SURFACE_OPENGL
);
4559 DDPIXELFORMAT x8d24
=
4561 sizeof(x8d24
), DDPF_ZBUFFER
, 0,
4562 {24}, {0x00000000}, {0x00ffffff}, {0x00000000}
4564 TRACE("Enumerating WINED3DFMT_X8D24_UNORM, dwZBufferBitDepth=24 version\n");
4565 callback(&x8d24
, context
);
4568 TRACE("End of enumeration.\n");
4570 LeaveCriticalSection(&ddraw_cs
);
4574 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
4575 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4577 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4579 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4580 iface
, debugstr_guid(device_iid
), callback
, context
);
4582 return d3d7_EnumZBufferFormats(&This
->IDirect3D7_iface
, device_iid
, callback
, context
);
4585 /*****************************************************************************
4586 * IDirect3D7::EvictManagedTextures
4588 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
4589 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
4594 * D3D_OK, because it's a stub
4596 *****************************************************************************/
4597 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
4599 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4601 TRACE("iface %p!\n", iface
);
4603 EnterCriticalSection(&ddraw_cs
);
4604 if (This
->d3d_initialized
)
4605 wined3d_device_evict_managed_resources(This
->wined3d_device
);
4606 LeaveCriticalSection(&ddraw_cs
);
4611 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
4613 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4615 TRACE("iface %p.\n", iface
);
4617 return d3d7_EvictManagedTextures(&This
->IDirect3D7_iface
);
4620 /*****************************************************************************
4621 * IDirect3DImpl_GetCaps
4623 * This function retrieves the device caps from wined3d
4624 * and converts it into a D3D7 and D3D - D3D3 structure
4625 * This is a helper function called from various places in ddraw
4628 * wined3d: The interface to get the caps from
4629 * desc1: Old D3D <3 structure to fill (needed)
4630 * desc7: D3D7 device desc structure to fill (needed)
4633 * D3D_OK on success, or the return value of IWineD3D::GetCaps
4635 *****************************************************************************/
4636 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
4638 WINED3DCAPS wined3d_caps
;
4641 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
4643 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
4645 EnterCriticalSection(&ddraw_cs
);
4646 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3DDEVTYPE_HAL
, &wined3d_caps
);
4647 LeaveCriticalSection(&ddraw_cs
);
4650 WARN("Failed to get device caps, hr %#x.\n", hr
);
4654 /* Copy the results into the d3d7 and d3d3 structures */
4655 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
4656 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
4657 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
4658 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
4659 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
4660 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
4661 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
4662 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
4663 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
4664 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
4665 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
4667 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
4668 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
4670 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
4671 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
4672 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
4673 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
4675 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
4676 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
4677 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
4678 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
4680 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
4681 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
4683 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
4684 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
4686 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
4687 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
4689 /* Remove all non-d3d7 caps */
4690 desc7
->dwDevCaps
&= (
4691 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
4692 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
4693 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
4694 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
4695 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
4696 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
4697 D3DDEVCAPS_HWRASTERIZATION
);
4699 desc7
->dwStencilCaps
&= (
4700 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
4701 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
4702 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
4706 desc7
->dwTextureOpCaps
&= (
4707 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
4708 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
4709 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
4710 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
4711 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
4712 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
4713 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
4714 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
4716 desc7
->dwVertexProcessingCaps
&= (
4717 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
4718 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
4720 desc7
->dpcLineCaps
.dwMiscCaps
&= (
4721 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
4722 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
4723 D3DPMISCCAPS_CULLCCW
);
4725 desc7
->dpcLineCaps
.dwRasterCaps
&= (
4726 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
4727 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
4728 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
4729 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
4730 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
4731 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
4732 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
4733 D3DPRASTERCAPS_ZFOG
);
4735 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
4736 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4737 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4738 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4740 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
4741 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4742 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4743 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4744 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4745 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4747 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
4748 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
4749 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
4750 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
4751 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
4752 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
4754 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
4755 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
4756 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
4757 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
4759 desc7
->dpcLineCaps
.dwShadeCaps
&= (
4760 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
4761 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
4762 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
4763 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
4764 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
4765 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
4766 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
4768 desc7
->dpcLineCaps
.dwTextureCaps
&= (
4769 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
4770 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
4771 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
4772 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
4774 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
4775 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
4776 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
4777 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
4778 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
4779 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
4780 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
4782 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
4783 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
4784 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
4785 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
4787 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
4788 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
4789 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
4791 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
4793 /* DirectX7 always has the np2 flag set, no matter what the card
4794 * supports. Some old games (Rollcage) check the caps incorrectly.
4795 * If wined3d supports nonpow2 textures it also has np2 conditional
4797 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
4800 /* Fill the missing members, and do some fixup */
4801 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
4802 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
4803 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
4804 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
4805 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
4806 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
4807 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
4808 /* Use the same for the TriCaps */
4809 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
4811 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
4812 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
4813 desc7
->dwMinTextureWidth
= 1;
4814 desc7
->dwMinTextureHeight
= 1;
4816 /* Convert DWORDs safely to WORDs */
4817 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
4818 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
4819 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
4820 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
4822 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
4823 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
4824 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
4825 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
4827 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
4829 desc7
->dwReserved1
= 0;
4830 desc7
->dwReserved2
= 0;
4831 desc7
->dwReserved3
= 0;
4832 desc7
->dwReserved4
= 0;
4834 /* Fill the old structure */
4835 memset(desc1
, 0, sizeof(*desc1
));
4836 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
4837 desc1
->dwFlags
= D3DDD_COLORMODEL
4839 | D3DDD_TRANSFORMCAPS
4841 | D3DDD_LIGHTINGCAPS
4844 | D3DDD_DEVICERENDERBITDEPTH
4845 | D3DDD_DEVICEZBUFFERBITDEPTH
4846 | D3DDD_MAXBUFFERSIZE
4847 | D3DDD_MAXVERTEXCOUNT
;
4849 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
4850 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
4851 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
4852 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
4853 desc1
->bClipping
= TRUE
;
4854 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
4855 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
4856 | D3DLIGHTCAPS_PARALLELPOINT
4857 | D3DLIGHTCAPS_POINT
4858 | D3DLIGHTCAPS_SPOT
;
4860 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
4861 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
4863 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4864 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
4865 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
4866 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
4867 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
4868 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
4869 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
4870 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
4871 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
4872 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
4873 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
4874 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
4875 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
4877 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
4878 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
4879 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
4880 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
4881 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
4882 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
4883 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
4884 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
4885 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
4886 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
4887 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
4888 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
4889 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
4891 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
4892 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
4893 desc1
->dwMaxBufferSize
= 0;
4894 desc1
->dwMaxVertexCount
= 65536;
4895 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
4896 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
4897 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
4898 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
4899 desc1
->dwMinStippleWidth
= 1;
4900 desc1
->dwMinStippleHeight
= 1;
4901 desc1
->dwMaxStippleWidth
= 32;
4902 desc1
->dwMaxStippleHeight
= 32;
4903 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
4904 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
4905 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
4906 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
4907 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
4908 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
4909 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
4910 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
4911 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
4912 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
4913 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
4914 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
4915 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
4920 /*****************************************************************************
4921 * IDirectDraw7 VTable
4922 *****************************************************************************/
4923 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
4926 ddraw7_QueryInterface
,
4931 ddraw7_CreateClipper
,
4932 ddraw7_CreatePalette
,
4933 ddraw7_CreateSurface
,
4934 ddraw7_DuplicateSurface
,
4935 ddraw7_EnumDisplayModes
,
4936 ddraw7_EnumSurfaces
,
4937 ddraw7_FlipToGDISurface
,
4939 ddraw7_GetDisplayMode
,
4940 ddraw7_GetFourCCCodes
,
4941 ddraw7_GetGDISurface
,
4942 ddraw7_GetMonitorFrequency
,
4944 ddraw7_GetVerticalBlankStatus
,
4946 ddraw7_RestoreDisplayMode
,
4947 ddraw7_SetCooperativeLevel
,
4948 ddraw7_SetDisplayMode
,
4949 ddraw7_WaitForVerticalBlank
,
4951 ddraw7_GetAvailableVidMem
,
4953 ddraw7_GetSurfaceFromDC
,
4955 ddraw7_RestoreAllSurfaces
,
4956 ddraw7_TestCooperativeLevel
,
4957 ddraw7_GetDeviceIdentifier
,
4959 ddraw7_StartModeTest
,
4963 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
4966 ddraw4_QueryInterface
,
4971 ddraw4_CreateClipper
,
4972 ddraw4_CreatePalette
,
4973 ddraw4_CreateSurface
,
4974 ddraw4_DuplicateSurface
,
4975 ddraw4_EnumDisplayModes
,
4976 ddraw4_EnumSurfaces
,
4977 ddraw4_FlipToGDISurface
,
4979 ddraw4_GetDisplayMode
,
4980 ddraw4_GetFourCCCodes
,
4981 ddraw4_GetGDISurface
,
4982 ddraw4_GetMonitorFrequency
,
4984 ddraw4_GetVerticalBlankStatus
,
4986 ddraw4_RestoreDisplayMode
,
4987 ddraw4_SetCooperativeLevel
,
4988 ddraw4_SetDisplayMode
,
4989 ddraw4_WaitForVerticalBlank
,
4991 ddraw4_GetAvailableVidMem
,
4993 ddraw4_GetSurfaceFromDC
,
4995 ddraw4_RestoreAllSurfaces
,
4996 ddraw4_TestCooperativeLevel
,
4997 ddraw4_GetDeviceIdentifier
,
5000 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5003 ddraw2_QueryInterface
,
5008 ddraw2_CreateClipper
,
5009 ddraw2_CreatePalette
,
5010 ddraw2_CreateSurface
,
5011 ddraw2_DuplicateSurface
,
5012 ddraw2_EnumDisplayModes
,
5013 ddraw2_EnumSurfaces
,
5014 ddraw2_FlipToGDISurface
,
5016 ddraw2_GetDisplayMode
,
5017 ddraw2_GetFourCCCodes
,
5018 ddraw2_GetGDISurface
,
5019 ddraw2_GetMonitorFrequency
,
5021 ddraw2_GetVerticalBlankStatus
,
5023 ddraw2_RestoreDisplayMode
,
5024 ddraw2_SetCooperativeLevel
,
5025 ddraw2_SetDisplayMode
,
5026 ddraw2_WaitForVerticalBlank
,
5028 ddraw2_GetAvailableVidMem
,
5031 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5034 ddraw1_QueryInterface
,
5039 ddraw1_CreateClipper
,
5040 ddraw1_CreatePalette
,
5041 ddraw1_CreateSurface
,
5042 ddraw1_DuplicateSurface
,
5043 ddraw1_EnumDisplayModes
,
5044 ddraw1_EnumSurfaces
,
5045 ddraw1_FlipToGDISurface
,
5047 ddraw1_GetDisplayMode
,
5048 ddraw1_GetFourCCCodes
,
5049 ddraw1_GetGDISurface
,
5050 ddraw1_GetMonitorFrequency
,
5052 ddraw1_GetVerticalBlankStatus
,
5054 ddraw1_RestoreDisplayMode
,
5055 ddraw1_SetCooperativeLevel
,
5056 ddraw1_SetDisplayMode
,
5057 ddraw1_WaitForVerticalBlank
,
5060 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5062 /* IUnknown methods */
5063 d3d7_QueryInterface
,
5066 /* IDirect3D7 methods */
5069 d3d7_CreateVertexBuffer
,
5070 d3d7_EnumZBufferFormats
,
5071 d3d7_EvictManagedTextures
5074 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5076 /* IUnknown methods */
5077 d3d3_QueryInterface
,
5080 /* IDirect3D3 methods */
5083 d3d3_CreateMaterial
,
5084 d3d3_CreateViewport
,
5087 d3d3_CreateVertexBuffer
,
5088 d3d3_EnumZBufferFormats
,
5089 d3d3_EvictManagedTextures
5092 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5094 /* IUnknown methods */
5095 d3d2_QueryInterface
,
5098 /* IDirect3D2 methods */
5101 d3d2_CreateMaterial
,
5102 d3d2_CreateViewport
,
5107 static const struct IDirect3DVtbl d3d1_vtbl
=
5109 /* IUnknown methods */
5110 d3d1_QueryInterface
,
5113 /* IDirect3D methods */
5117 d3d1_CreateMaterial
,
5118 d3d1_CreateViewport
,
5122 /*****************************************************************************
5125 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5126 * if none was found.
5128 * This function is in ddraw.c and the DDraw object space because D3D7
5129 * vertex buffers are created using the IDirect3D interface to the ddraw
5130 * object, so they can be valid across D3D devices(theoretically. The ddraw
5131 * object also owns the wined3d device
5135 * fvf: Fvf to find the decl for
5138 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5140 *****************************************************************************/
5141 struct wined3d_vertex_declaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5143 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5145 int p
, low
, high
; /* deliberately signed */
5146 struct FvfToDecl
*convertedDecls
= This
->decls
;
5148 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5151 high
= This
->numConvertedDecls
- 1;
5152 while(low
<= high
) {
5153 p
= (low
+ high
) >> 1;
5155 if(convertedDecls
[p
].fvf
== fvf
) {
5156 TRACE("found %p\n", convertedDecls
[p
].decl
);
5157 return convertedDecls
[p
].decl
;
5158 } else if(convertedDecls
[p
].fvf
< fvf
) {
5164 TRACE("not found. Creating and inserting at position %d.\n", low
);
5166 hr
= wined3d_vertex_declaration_create_from_fvf(This
->wined3d_device
,
5167 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5168 if (hr
!= S_OK
) return NULL
;
5170 if(This
->declArraySize
== This
->numConvertedDecls
) {
5171 int grow
= max(This
->declArraySize
/ 2, 8);
5172 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5173 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5174 if (!convertedDecls
)
5176 wined3d_vertex_declaration_decref(pDecl
);
5179 This
->decls
= convertedDecls
;
5180 This
->declArraySize
+= grow
;
5183 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5184 convertedDecls
[low
].decl
= pDecl
;
5185 convertedDecls
[low
].fvf
= fvf
;
5186 This
->numConvertedDecls
++;
5188 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5192 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(struct wined3d_device_parent
*device_parent
)
5194 return CONTAINING_RECORD(device_parent
, struct IDirectDrawImpl
, device_parent
);
5197 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
5198 struct wined3d_device
*device
)
5200 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
5203 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
5204 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5205 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, struct wined3d_surface
**surface
)
5207 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5208 IDirectDrawSurfaceImpl
*surf
= NULL
;
5210 DDSCAPS2 searchcaps
= ddraw
->tex_root
->surface_desc
.ddsCaps
;
5212 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5213 "\tpool %#x, level %u, face %u, surface %p.\n",
5214 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5216 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5219 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
5220 TRACE("Asked for positive x\n");
5221 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5223 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5225 surf
= ddraw
->tex_root
; break;
5226 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
5227 TRACE("Asked for negative x\n");
5228 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5229 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
5230 TRACE("Asked for positive y\n");
5231 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5232 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
5233 TRACE("Asked for negative y\n");
5234 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5235 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
5236 TRACE("Asked for positive z\n");
5237 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5238 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
5239 TRACE("Asked for negative z\n");
5240 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5241 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
5246 IDirectDrawSurface7
*attached
;
5247 IDirectDrawSurface7_GetAttachedSurface(&ddraw
->tex_root
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5248 surf
= unsafe_impl_from_IDirectDrawSurface7(attached
);
5249 IDirectDrawSurface7_Release(attached
);
5251 if (!surf
) ERR("root search surface not found\n");
5253 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5256 IDirectDrawSurface7
*attached
;
5257 IDirectDrawSurface7_GetAttachedSurface(&surf
->IDirectDrawSurface7_iface
, &searchcaps
, &attached
);
5258 if(!attached
) ERR("Surface not found\n");
5259 surf
= impl_from_IDirectDrawSurface7(attached
);
5260 IDirectDrawSurface7_Release(attached
);
5264 /* Return the surface */
5265 *surface
= surf
->wined3d_surface
;
5266 wined3d_surface_incref(*surface
);
5268 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5273 static void STDMETHODCALLTYPE
ddraw_frontbuffer_destroyed(void *parent
)
5275 struct IDirectDrawImpl
*ddraw
= parent
;
5276 ddraw
->wined3d_frontbuffer
= NULL
;
5279 static const struct wined3d_parent_ops ddraw_frontbuffer_parent_ops
=
5281 ddraw_frontbuffer_destroyed
,
5284 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
5285 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5286 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5287 struct wined3d_surface
**surface
)
5289 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5292 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5293 "\tmultisample_quality %u, lockable %u, surface %p.\n",
5294 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
5295 multisample_quality
, lockable
, surface
);
5297 if (ddraw
->wined3d_frontbuffer
)
5299 ERR("Frontbuffer already created.\n");
5303 hr
= wined3d_surface_create(ddraw
->wined3d_device
, width
, height
, format
, lockable
, FALSE
, 0,
5304 WINED3DUSAGE_RENDERTARGET
, WINED3DPOOL_DEFAULT
, multisample_type
, multisample_quality
,
5305 DefaultSurfaceType
, ddraw
, &ddraw_frontbuffer_parent_ops
, surface
);
5307 ddraw
->wined3d_frontbuffer
= *surface
;
5312 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
5313 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
5314 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
5316 ERR("DirectDraw doesn't have and shouldn't try creating implicit depth buffers.\n");
5320 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
5321 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5322 WINED3DPOOL pool
, DWORD usage
, struct wined3d_volume
**volume
)
5324 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
5325 "format %#x, pool %#x, usage %#x, volume %p.\n",
5326 device_parent
, container_parent
, width
, height
, depth
,
5327 format
, pool
, usage
, volume
);
5329 ERR("Not implemented!\n");
5334 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
5335 WINED3DPRESENT_PARAMETERS
*present_parameters
, struct wined3d_swapchain
**swapchain
)
5337 struct IDirectDrawImpl
*ddraw
= ddraw_from_device_parent(device_parent
);
5340 TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent
, present_parameters
, swapchain
);
5342 if (ddraw
->wined3d_swapchain
)
5344 ERR("Swapchain already created.\n");
5348 hr
= wined3d_swapchain_create(ddraw
->wined3d_device
, present_parameters
,
5349 DefaultSurfaceType
, NULL
, &ddraw_null_wined3d_parent_ops
, swapchain
);
5351 WARN("Failed to create swapchain, hr %#x.\n", hr
);
5356 static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops
=
5358 device_parent_wined3d_device_created
,
5359 device_parent_create_surface
,
5360 device_parent_create_rendertarget
,
5361 device_parent_create_depth_stencil
,
5362 device_parent_create_volume
,
5363 device_parent_create_swapchain
,
5366 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, WINED3DDEVTYPE device_type
)
5371 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5372 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5373 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5374 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5375 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5376 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5377 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5378 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5379 ddraw
->device_parent
.ops
= &ddraw_wined3d_device_parent_ops
;
5380 ddraw
->numIfaces
= 1;
5383 /* Get the current screen settings. */
5385 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5387 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5388 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5390 ddraw
->wineD3D
= wined3d_create(7, WINED3D_PALETTE_PER_SURFACE
| WINED3D_LEGACY_DEPTH_BIAS
,
5391 &ddraw
->IDirectDraw7_iface
);
5392 if (!ddraw
->wineD3D
)
5394 WARN("Failed to create a wined3d object.\n");
5395 return E_OUTOFMEMORY
;
5398 hr
= wined3d_device_create(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, device_type
,
5399 NULL
, 0, 8, &ddraw
->device_parent
, &ddraw
->wined3d_device
);
5402 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5403 wined3d_decref(ddraw
->wineD3D
);
5407 list_init(&ddraw
->surface_list
);