2 * Copyright 1997-2000 Marcus Meissner
3 * Copyright 1998-2000 Lionel Ulmer
4 * Copyright 2000-2001 TransGaming Technologies Inc.
5 * Copyright 2006 Stefan Dösinger
6 * Copyright 2008 Denver Gingerich
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
26 #include "ddraw_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
30 /* Device identifier. Don't relay it to WineD3D */
31 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
35 { { 0x00010001, 0x00010001 } },
37 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
38 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
42 static void STDMETHODCALLTYPE
ddraw_null_wined3d_object_destroyed(void *parent
) {}
44 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops
=
46 ddraw_null_wined3d_object_destroyed
,
49 static inline IDirectDrawImpl
*impl_from_IDirectDraw(IDirectDraw
*iface
)
51 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw_iface
);
54 static inline IDirectDrawImpl
*impl_from_IDirectDraw2(IDirectDraw2
*iface
)
56 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw2_iface
);
59 static inline IDirectDrawImpl
*impl_from_IDirectDraw3(IDirectDraw3
*iface
)
61 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw3_iface
);
64 static inline IDirectDrawImpl
*impl_from_IDirectDraw4(IDirectDraw4
*iface
)
66 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw4_iface
);
69 static inline IDirectDrawImpl
*impl_from_IDirectDraw7(IDirectDraw7
*iface
)
71 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirectDraw7_iface
);
74 static inline IDirectDrawImpl
*impl_from_IDirect3D(IDirect3D
*iface
)
76 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D_iface
);
79 static inline IDirectDrawImpl
*impl_from_IDirect3D2(IDirect3D2
*iface
)
81 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D2_iface
);
84 static inline IDirectDrawImpl
*impl_from_IDirect3D3(IDirect3D3
*iface
)
86 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D3_iface
);
89 static inline IDirectDrawImpl
*impl_from_IDirect3D7(IDirect3D7
*iface
)
91 return CONTAINING_RECORD(iface
, IDirectDrawImpl
, IDirect3D7_iface
);
94 /*****************************************************************************
96 *****************************************************************************/
98 /*****************************************************************************
99 * IDirectDraw7::QueryInterface
101 * Queries different interfaces of the DirectDraw object. It can return
102 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
103 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
105 * The returned interface is AddRef()-ed before it's returned
107 * Used for version 1, 2, 4 and 7
110 * refiid: Interface ID asked for
111 * obj: Used to return the interface pointer
114 * S_OK if an interface was found
115 * E_NOINTERFACE if the requested interface wasn't found
117 *****************************************************************************/
118 static HRESULT WINAPI
ddraw7_QueryInterface(IDirectDraw7
*iface
, REFIID refiid
, void **obj
)
120 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
122 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(refiid
), obj
);
124 /* Can change surface impl type */
125 EnterCriticalSection(&ddraw_cs
);
127 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
132 LeaveCriticalSection(&ddraw_cs
);
133 return DDERR_INVALIDPARAMS
;
136 /* Check DirectDraw Interfaces */
137 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
138 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
141 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
143 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
145 *obj
= &This
->IDirectDraw4_iface
;
146 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
148 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
150 /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
151 WARN("IDirectDraw3 is not valid in ddraw.dll\n");
153 LeaveCriticalSection(&ddraw_cs
);
154 return E_NOINTERFACE
;
156 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
158 *obj
= &This
->IDirectDraw2_iface
;
159 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
161 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
163 *obj
= &This
->IDirectDraw_iface
;
164 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
168 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
169 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
170 * who had this idea and why. The older interfaces can query and IDirect3D version
171 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
172 * and messy to implement with the common creation function, so it has been left out here.
174 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
175 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
176 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
177 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
179 /* Check the surface implementation */
180 if(This
->ImplType
== SURFACE_UNKNOWN
)
182 /* Apps may create the IDirect3D Interface before the primary surface.
183 * set the surface implementation */
184 This
->ImplType
= SURFACE_OPENGL
;
185 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
187 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
189 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
190 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
191 /* Should I assert(0) here??? */
193 else if(This
->ImplType
!= SURFACE_OPENGL
)
195 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
196 /* Do not abort here, only reject 3D Device creation */
199 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
201 This
->d3dversion
= 1;
202 *obj
= &This
->IDirect3D_iface
;
203 TRACE(" returning Direct3D interface at %p.\n", *obj
);
205 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
207 This
->d3dversion
= 2;
208 *obj
= &This
->IDirect3D2_iface
;
209 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
211 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
213 This
->d3dversion
= 3;
214 *obj
= &This
->IDirect3D3_iface
;
215 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
217 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
219 This
->d3dversion
= 7;
220 *obj
= &This
->IDirect3D7_iface
;
221 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
224 else if (IsEqualGUID(refiid
, &IID_IWineD3DDeviceParent
))
226 *obj
= &This
->device_parent_vtbl
;
229 /* Unknown interface */
232 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
233 LeaveCriticalSection(&ddraw_cs
);
234 return E_NOINTERFACE
;
237 IUnknown_AddRef( (IUnknown
*) *obj
);
238 LeaveCriticalSection(&ddraw_cs
);
242 static HRESULT WINAPI
ddraw4_QueryInterface(IDirectDraw4
*iface
, REFIID riid
, void **object
)
244 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
246 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
248 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
251 static HRESULT WINAPI
ddraw3_QueryInterface(IDirectDraw3
*iface
, REFIID riid
, void **object
)
253 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
255 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
257 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
260 static HRESULT WINAPI
ddraw2_QueryInterface(IDirectDraw2
*iface
, REFIID riid
, void **object
)
262 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
264 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
266 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
269 static HRESULT WINAPI
ddraw1_QueryInterface(IDirectDraw
*iface
, REFIID riid
, void **object
)
271 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
273 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
275 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
278 static HRESULT WINAPI
d3d7_QueryInterface(IDirect3D7
*iface
, REFIID riid
, void **object
)
280 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
282 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
284 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
287 static HRESULT WINAPI
d3d3_QueryInterface(IDirect3D3
*iface
, REFIID riid
, void **object
)
289 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
291 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
293 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
296 static HRESULT WINAPI
d3d2_QueryInterface(IDirect3D2
*iface
, REFIID riid
, void **object
)
298 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
300 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
302 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
305 static HRESULT WINAPI
d3d1_QueryInterface(IDirect3D
*iface
, REFIID riid
, void **object
)
307 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
309 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
311 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
314 /*****************************************************************************
315 * IDirectDraw7::AddRef
317 * Increases the interfaces refcount, basically
319 * DDraw refcounting is a bit tricky. The different DirectDraw interface
320 * versions have individual refcounts, but the IDirect3D interfaces do not.
321 * All interfaces are from one object, that means calling QueryInterface on an
322 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
323 * IDirectDrawImpl object.
325 * That means all AddRef and Release implementations of IDirectDrawX work
326 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
327 * except of IDirect3D7 which thunks to IDirectDraw7
329 * Returns: The new refcount
331 *****************************************************************************/
332 static ULONG WINAPI
ddraw7_AddRef(IDirectDraw7
*iface
)
334 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
335 ULONG ref
= InterlockedIncrement(&This
->ref7
);
337 TRACE("%p increasing refcount to %u.\n", This
, ref
);
339 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
344 static ULONG WINAPI
ddraw4_AddRef(IDirectDraw4
*iface
)
346 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
347 ULONG ref
= InterlockedIncrement(&This
->ref4
);
349 TRACE("%p increasing refcount to %u.\n", This
, ref
);
351 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
356 static ULONG WINAPI
ddraw3_AddRef(IDirectDraw3
*iface
)
358 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
359 ULONG ref
= InterlockedIncrement(&This
->ref3
);
361 TRACE("%p increasing refcount to %u.\n", This
, ref
);
363 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
368 static ULONG WINAPI
ddraw2_AddRef(IDirectDraw2
*iface
)
370 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
371 ULONG ref
= InterlockedIncrement(&This
->ref2
);
373 TRACE("%p increasing refcount to %u.\n", This
, ref
);
375 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
380 static ULONG WINAPI
ddraw1_AddRef(IDirectDraw
*iface
)
382 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
383 ULONG ref
= InterlockedIncrement(&This
->ref1
);
385 TRACE("%p increasing refcount to %u.\n", This
, ref
);
387 if (ref
== 1) InterlockedIncrement(&This
->numIfaces
);
392 static ULONG WINAPI
d3d7_AddRef(IDirect3D7
*iface
)
394 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
396 TRACE("iface %p.\n", iface
);
398 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
401 static ULONG WINAPI
d3d3_AddRef(IDirect3D3
*iface
)
403 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
405 TRACE("iface %p.\n", iface
);
407 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
410 static ULONG WINAPI
d3d2_AddRef(IDirect3D2
*iface
)
412 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
414 TRACE("iface %p.\n", iface
);
416 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
419 static ULONG WINAPI
d3d1_AddRef(IDirect3D
*iface
)
421 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
423 TRACE("iface %p.\n", iface
);
425 return ddraw1_AddRef(&This
->IDirectDraw_iface
);
428 /*****************************************************************************
431 * Destroys a ddraw object if all refcounts are 0. This is to share code
432 * between the IDirectDrawX::Release functions
435 * This: DirectDraw object to destroy
437 *****************************************************************************/
438 static void ddraw_destroy(IDirectDrawImpl
*This
)
440 IDirectDraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, NULL
, DDSCL_NORMAL
);
441 IDirectDraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
443 /* Destroy the device window if we created one */
444 if(This
->devicewindow
!= 0)
446 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
447 DestroyWindow(This
->devicewindow
);
448 This
->devicewindow
= 0;
451 EnterCriticalSection(&ddraw_cs
);
452 list_remove(&This
->ddraw_list_entry
);
453 LeaveCriticalSection(&ddraw_cs
);
455 /* Release the attached WineD3D stuff */
456 IWineD3DDevice_Release(This
->wineD3DDevice
);
457 wined3d_decref(This
->wineD3D
);
459 /* Now free the object */
460 HeapFree(GetProcessHeap(), 0, This
);
463 /*****************************************************************************
464 * IDirectDraw7::Release
466 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
468 * Returns: The new refcount
469 *****************************************************************************/
470 static ULONG WINAPI
ddraw7_Release(IDirectDraw7
*iface
)
472 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
473 ULONG ref
= InterlockedDecrement(&This
->ref7
);
475 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
477 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
483 static ULONG WINAPI
ddraw4_Release(IDirectDraw4
*iface
)
485 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
486 ULONG ref
= InterlockedDecrement(&This
->ref4
);
488 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
490 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
496 static ULONG WINAPI
ddraw3_Release(IDirectDraw3
*iface
)
498 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
499 ULONG ref
= InterlockedDecrement(&This
->ref3
);
501 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
503 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
509 static ULONG WINAPI
ddraw2_Release(IDirectDraw2
*iface
)
511 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
512 ULONG ref
= InterlockedDecrement(&This
->ref2
);
514 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
516 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
522 static ULONG WINAPI
ddraw1_Release(IDirectDraw
*iface
)
524 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
525 ULONG ref
= InterlockedDecrement(&This
->ref1
);
527 TRACE("%p decreasing refcount to %u.\n", This
, ref
);
529 if (!ref
&& !InterlockedDecrement(&This
->numIfaces
))
535 static ULONG WINAPI
d3d7_Release(IDirect3D7
*iface
)
537 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
539 TRACE("iface %p.\n", iface
);
541 return ddraw7_Release(&This
->IDirectDraw7_iface
);
544 static ULONG WINAPI
d3d3_Release(IDirect3D3
*iface
)
546 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
548 TRACE("iface %p.\n", iface
);
550 return ddraw1_Release(&This
->IDirectDraw_iface
);
553 static ULONG WINAPI
d3d2_Release(IDirect3D2
*iface
)
555 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
557 TRACE("iface %p.\n", iface
);
559 return ddraw1_Release(&This
->IDirectDraw_iface
);
562 static ULONG WINAPI
d3d1_Release(IDirect3D
*iface
)
564 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
566 TRACE("iface %p.\n", iface
);
568 return ddraw1_Release(&This
->IDirectDraw_iface
);
571 /*****************************************************************************
572 * IDirectDraw methods
573 *****************************************************************************/
575 /*****************************************************************************
576 * IDirectDraw7::SetCooperativeLevel
578 * Sets the cooperative level for the DirectDraw object, and the window
579 * assigned to it. The cooperative level determines the general behavior
580 * of the DirectDraw application
582 * Warning: This is quite tricky, as it's not really documented which
583 * cooperative levels can be combined with each other. If a game fails
584 * after this function, try to check the cooperative levels passed on
585 * Windows, and if it returns something different.
587 * If you think that this function caused the failure because it writes a
588 * fixme, be sure to run again with a +ddraw trace.
590 * What is known about cooperative levels (See the ddraw modes test):
591 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
592 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
593 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
594 * DDSCL_FULLSCREEN can be activated
595 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
597 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
598 * DDSCL_SETFOCUSWINDOW (partially),
599 * DDSCL_MULTITHREADED (work in progress)
601 * Unhandled flags, which should be implemented
602 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
603 * expect any difference to a normal window for wine)
604 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
605 * rendering (Possible test case: Half-Life)
607 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
609 * These don't seem very important for wine:
610 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
613 * DD_OK if the cooperative level was set successfully
614 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
615 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
616 * (Probably others too, have to investigate)
618 *****************************************************************************/
619 static HRESULT WINAPI
ddraw7_SetCooperativeLevel(IDirectDraw7
*iface
, HWND hwnd
, DWORD cooplevel
)
621 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
624 TRACE("iface %p, window %p, flags %#x.\n", iface
, hwnd
, cooplevel
);
625 DDRAW_dump_cooperativelevel(cooplevel
);
627 EnterCriticalSection(&ddraw_cs
);
629 /* Get the old window */
630 window
= This
->dest_window
;
632 /* Tests suggest that we need one of them: */
633 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
637 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
638 LeaveCriticalSection(&ddraw_cs
);
639 return DDERR_INVALIDPARAMS
;
642 /* Handle those levels first which set various hwnds */
643 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
645 /* This isn't compatible with a lot of flags */
646 if(cooplevel
& ( DDSCL_MULTITHREADED
|
647 DDSCL_CREATEDEVICEWINDOW
|
652 DDSCL_SETDEVICEWINDOW
|
657 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
658 LeaveCriticalSection(&ddraw_cs
);
659 return DDERR_INVALIDPARAMS
;
662 if( (This
->cooperative_level
& DDSCL_EXCLUSIVE
) && window
)
664 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
665 LeaveCriticalSection(&ddraw_cs
);
666 return DDERR_HWNDALREADYSET
;
669 This
->focuswindow
= hwnd
;
670 /* Won't use the hwnd param for anything else */
673 /* Use the focus window for drawing too */
674 This
->dest_window
= This
->focuswindow
;
676 /* Destroy the device window, if we have one */
677 if(This
->devicewindow
)
679 DestroyWindow(This
->devicewindow
);
680 This
->devicewindow
= NULL
;
683 LeaveCriticalSection(&ddraw_cs
);
687 if(cooplevel
& DDSCL_EXCLUSIVE
)
689 if( !(cooplevel
& DDSCL_FULLSCREEN
) || !hwnd
)
691 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This
);
692 LeaveCriticalSection(&ddraw_cs
);
693 return DDERR_INVALIDPARAMS
;
696 else if( !(cooplevel
& DDSCL_NORMAL
) )
698 TRACE("(%p) SetCooperativeLevel needs at least SetFocusWindow or Exclusive or Normal mode\n", This
);
699 LeaveCriticalSection(&ddraw_cs
);
700 return DDERR_INVALIDPARAMS
;
703 if ((This
->cooperative_level
& DDSCL_EXCLUSIVE
)
704 && (hwnd
!= window
|| !(cooplevel
& DDSCL_EXCLUSIVE
)))
705 IWineD3DDevice_ReleaseFocusWindow(This
->wineD3DDevice
);
707 if ((cooplevel
& DDSCL_FULLSCREEN
) != (This
->cooperative_level
& DDSCL_FULLSCREEN
) || hwnd
!= window
)
709 if (This
->cooperative_level
& DDSCL_FULLSCREEN
)
711 IWineD3DDevice_RestoreFullscreenWindow(This
->wineD3DDevice
, window
);
713 if (cooplevel
& DDSCL_FULLSCREEN
)
715 WINED3DDISPLAYMODE display_mode
;
717 wined3d_get_adapter_display_mode(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, &display_mode
);
718 IWineD3DDevice_SetupFullscreenWindow(This
->wineD3DDevice
, hwnd
, display_mode
.Width
, display_mode
.Height
);
722 if ((cooplevel
& DDSCL_EXCLUSIVE
)
723 && (hwnd
!= window
|| !(This
->cooperative_level
& DDSCL_EXCLUSIVE
)))
725 HRESULT hr
= IWineD3DDevice_AcquireFocusWindow(This
->wineD3DDevice
, hwnd
);
728 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
729 LeaveCriticalSection(&ddraw_cs
);
734 /* Don't override focus windows or private device windows */
735 if (hwnd
&& !This
->focuswindow
&& !This
->devicewindow
&& (hwnd
!= window
))
736 This
->dest_window
= hwnd
;
738 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
740 /* Don't create a device window if a focus window is set */
741 if( !(This
->focuswindow
) )
743 HWND devicewindow
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "DDraw device window",
744 WS_POPUP
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
745 NULL
, NULL
, NULL
, NULL
);
748 ERR("Failed to create window, last error %#x.\n", GetLastError());
749 LeaveCriticalSection(&ddraw_cs
);
753 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
754 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
756 This
->devicewindow
= devicewindow
;
757 This
->dest_window
= devicewindow
;
761 if(cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
763 /* Enable thread safety in wined3d */
764 IWineD3DDevice_SetMultithreaded(This
->wineD3DDevice
);
767 /* Unhandled flags */
768 if(cooplevel
& DDSCL_ALLOWREBOOT
)
769 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
770 if(cooplevel
& DDSCL_ALLOWMODEX
)
771 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
772 if(cooplevel
& DDSCL_FPUSETUP
)
773 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
775 /* Store the cooperative_level */
776 This
->cooperative_level
= cooplevel
;
777 TRACE("SetCooperativeLevel retuning DD_OK\n");
778 LeaveCriticalSection(&ddraw_cs
);
782 static HRESULT WINAPI
ddraw4_SetCooperativeLevel(IDirectDraw4
*iface
, HWND window
, DWORD flags
)
784 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
786 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
788 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
791 static HRESULT WINAPI
ddraw3_SetCooperativeLevel(IDirectDraw3
*iface
, HWND window
, DWORD flags
)
793 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
795 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
797 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
800 static HRESULT WINAPI
ddraw2_SetCooperativeLevel(IDirectDraw2
*iface
, HWND window
, DWORD flags
)
802 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
804 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
806 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
809 static HRESULT WINAPI
ddraw1_SetCooperativeLevel(IDirectDraw
*iface
, HWND window
, DWORD flags
)
811 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
813 TRACE("iface %p, window %p, flags %#x.\n", iface
, window
, flags
);
815 return ddraw7_SetCooperativeLevel(&This
->IDirectDraw7_iface
, window
, flags
);
818 /*****************************************************************************
820 * Helper function for SetDisplayMode and RestoreDisplayMode
822 * Implements DirectDraw's SetDisplayMode, but ignores the value of
823 * ForceRefreshRate, since it is already handled by
824 * ddraw7_SetDisplayMode. RestoreDisplayMode can use this function
825 * without worrying that ForceRefreshRate will override the refresh rate. For
826 * argument and return value documentation, see
827 * ddraw7_SetDisplayMode.
829 *****************************************************************************/
830 static HRESULT
ddraw_set_display_mode(IDirectDrawImpl
*ddraw
, DWORD Width
, DWORD Height
,
831 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
833 WINED3DDISPLAYMODE Mode
;
836 TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw
, Width
,
837 Height
, BPP
, RefreshRate
, Flags
);
839 EnterCriticalSection(&ddraw_cs
);
840 if( !Width
|| !Height
)
842 ERR("Width %u, Height %u, what to do?\n", Width
, Height
);
843 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
844 LeaveCriticalSection(&ddraw_cs
);
848 /* Check the exclusive mode
849 if(!(ddraw->cooperative_level & DDSCL_EXCLUSIVE))
850 return DDERR_NOEXCLUSIVEMODE;
851 * This is WRONG. Don't know if the SDK is completely
852 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
853 * is returned, but Half-Life 1.1.1.1 (Steam version)
858 Mode
.Height
= Height
;
859 Mode
.RefreshRate
= RefreshRate
;
862 case 8: Mode
.Format
= WINED3DFMT_P8_UINT
; break;
863 case 15: Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
; break;
864 case 16: Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
; break;
865 case 24: Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
; break;
866 case 32: Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
; break;
869 /* TODO: The possible return values from msdn suggest that
870 * the screen mode can't be changed if a surface is locked
871 * or some drawing is in progress
874 /* TODO: Lose the primary surface */
875 hr
= IWineD3DDevice_SetDisplayMode(ddraw
->wineD3DDevice
, 0, &Mode
);
876 IWineD3DDevice_RestoreFullscreenWindow(ddraw
->wineD3DDevice
, ddraw
->dest_window
);
877 IWineD3DDevice_SetupFullscreenWindow(ddraw
->wineD3DDevice
, ddraw
->dest_window
, Width
, Height
);
878 LeaveCriticalSection(&ddraw_cs
);
881 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
886 /*****************************************************************************
887 * IDirectDraw7::SetDisplayMode
889 * Sets the display screen resolution, color depth and refresh frequency
890 * when in fullscreen mode (in theory).
891 * Possible return values listed in the SDK suggest that this method fails
892 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
893 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
894 * It seems to be valid to pass 0 for With and Height, this has to be tested
895 * It could mean that the current video mode should be left as-is. (But why
899 * Height, Width: Screen dimension
900 * BPP: Color depth in Bits per pixel
901 * Refreshrate: Screen refresh rate
907 *****************************************************************************/
908 static HRESULT WINAPI
ddraw7_SetDisplayMode(IDirectDraw7
*iface
, DWORD Width
, DWORD Height
,
909 DWORD BPP
, DWORD RefreshRate
, DWORD Flags
)
911 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
913 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
914 iface
, Width
, Height
, BPP
, RefreshRate
, Flags
);
916 if (force_refresh_rate
!= 0)
918 TRACE("ForceRefreshRate overriding passed-in refresh rate (%u Hz) to %u Hz\n",
919 RefreshRate
, force_refresh_rate
);
920 RefreshRate
= force_refresh_rate
;
923 return ddraw_set_display_mode(This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
926 static HRESULT WINAPI
ddraw4_SetDisplayMode(IDirectDraw4
*iface
, DWORD width
, DWORD height
,
927 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
929 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
931 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
932 iface
, width
, height
, bpp
, refresh_rate
, flags
);
934 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
937 static HRESULT WINAPI
ddraw3_SetDisplayMode(IDirectDraw3
*iface
, DWORD width
, DWORD height
,
938 DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
940 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
942 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
943 iface
, width
, height
, bpp
, refresh_rate
, flags
);
945 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
948 static HRESULT WINAPI
ddraw2_SetDisplayMode(IDirectDraw2
*iface
,
949 DWORD width
, DWORD height
, DWORD bpp
, DWORD refresh_rate
, DWORD flags
)
951 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
953 TRACE("iface %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n",
954 iface
, width
, height
, bpp
, refresh_rate
, flags
);
956 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, refresh_rate
, flags
);
959 static HRESULT WINAPI
ddraw1_SetDisplayMode(IDirectDraw
*iface
, DWORD width
, DWORD height
, DWORD bpp
)
961 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
963 TRACE("iface %p, width %u, height %u, bpp %u.\n", iface
, width
, height
, bpp
);
965 return ddraw7_SetDisplayMode(&This
->IDirectDraw7_iface
, width
, height
, bpp
, 0, 0);
968 /*****************************************************************************
969 * IDirectDraw7::RestoreDisplayMode
971 * Restores the display mode to what it was at creation time. Basically.
973 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
974 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
975 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
976 * -> DD_1 is released. The screen should be left at 1024x768x32.
977 * -> DD_2 is released. The screen should be set to 1400x1050x32
978 * This case is unhandled right now, but Empire Earth does it this way.
979 * (But perhaps there is something in SetCooperativeLevel to prevent this)
981 * The msdn says that this method resets the display mode to what it was before
982 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
986 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
988 *****************************************************************************/
989 static HRESULT WINAPI
ddraw7_RestoreDisplayMode(IDirectDraw7
*iface
)
991 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
993 TRACE("iface %p.\n", iface
);
995 return ddraw_set_display_mode(This
, This
->orig_width
, This
->orig_height
, This
->orig_bpp
, 0, 0);
998 static HRESULT WINAPI
ddraw4_RestoreDisplayMode(IDirectDraw4
*iface
)
1000 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1002 TRACE("iface %p.\n", iface
);
1004 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1007 static HRESULT WINAPI
ddraw3_RestoreDisplayMode(IDirectDraw3
*iface
)
1009 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1011 TRACE("iface %p.\n", iface
);
1013 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1016 static HRESULT WINAPI
ddraw2_RestoreDisplayMode(IDirectDraw2
*iface
)
1018 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1020 TRACE("iface %p.\n", iface
);
1022 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1025 static HRESULT WINAPI
ddraw1_RestoreDisplayMode(IDirectDraw
*iface
)
1027 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1029 TRACE("iface %p.\n", iface
);
1031 return ddraw7_RestoreDisplayMode(&This
->IDirectDraw7_iface
);
1034 /*****************************************************************************
1035 * IDirectDraw7::GetCaps
1037 * Returns the drives capabilities
1039 * Used for version 1, 2, 4 and 7
1042 * DriverCaps: Structure to write the Hardware accelerated caps to
1043 * HelCaps: Structure to write the emulation caps to
1046 * This implementation returns DD_OK only
1048 *****************************************************************************/
1049 static HRESULT WINAPI
ddraw7_GetCaps(IDirectDraw7
*iface
, DDCAPS
*DriverCaps
, DDCAPS
*HELCaps
)
1051 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1053 WINED3DCAPS winecaps
;
1055 DDSCAPS2 ddscaps
= {0, 0, 0, 0};
1057 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, DriverCaps
, HELCaps
);
1059 /* One structure must be != NULL */
1060 if( (!DriverCaps
) && (!HELCaps
) )
1062 ERR("(%p) Invalid params to ddraw7_GetCaps\n", This
);
1063 return DDERR_INVALIDPARAMS
;
1066 memset(&caps
, 0, sizeof(caps
));
1067 memset(&winecaps
, 0, sizeof(winecaps
));
1068 caps
.dwSize
= sizeof(caps
);
1069 EnterCriticalSection(&ddraw_cs
);
1070 hr
= IWineD3DDevice_GetDeviceCaps(This
->wineD3DDevice
, &winecaps
);
1072 WARN("IWineD3DDevice::GetDeviceCaps failed\n");
1073 LeaveCriticalSection(&ddraw_cs
);
1077 hr
= IDirectDraw7_GetAvailableVidMem(iface
, &ddscaps
, &caps
.dwVidMemTotal
, &caps
.dwVidMemFree
);
1078 LeaveCriticalSection(&ddraw_cs
);
1080 WARN("IDirectDraw7::GetAvailableVidMem failed\n");
1084 caps
.dwCaps
= winecaps
.DirectDrawCaps
.Caps
;
1085 caps
.dwCaps2
= winecaps
.DirectDrawCaps
.Caps2
;
1086 caps
.dwCKeyCaps
= winecaps
.DirectDrawCaps
.CKeyCaps
;
1087 caps
.dwFXCaps
= winecaps
.DirectDrawCaps
.FXCaps
;
1088 caps
.dwPalCaps
= winecaps
.DirectDrawCaps
.PalCaps
;
1089 caps
.ddsCaps
.dwCaps
= winecaps
.DirectDrawCaps
.ddsCaps
;
1090 caps
.dwSVBCaps
= winecaps
.DirectDrawCaps
.SVBCaps
;
1091 caps
.dwSVBCKeyCaps
= winecaps
.DirectDrawCaps
.SVBCKeyCaps
;
1092 caps
.dwSVBFXCaps
= winecaps
.DirectDrawCaps
.SVBFXCaps
;
1093 caps
.dwVSBCaps
= winecaps
.DirectDrawCaps
.VSBCaps
;
1094 caps
.dwVSBCKeyCaps
= winecaps
.DirectDrawCaps
.VSBCKeyCaps
;
1095 caps
.dwVSBFXCaps
= winecaps
.DirectDrawCaps
.VSBFXCaps
;
1096 caps
.dwSSBCaps
= winecaps
.DirectDrawCaps
.SSBCaps
;
1097 caps
.dwSSBCKeyCaps
= winecaps
.DirectDrawCaps
.SSBCKeyCaps
;
1098 caps
.dwSSBFXCaps
= winecaps
.DirectDrawCaps
.SSBFXCaps
;
1100 /* Even if WineD3D supports 3D rendering, remove the cap if ddraw is configured
1103 if(DefaultSurfaceType
== SURFACE_GDI
) {
1104 caps
.dwCaps
&= ~DDCAPS_3D
;
1105 caps
.ddsCaps
.dwCaps
&= ~(DDSCAPS_3DDEVICE
| DDSCAPS_MIPMAP
| DDSCAPS_TEXTURE
| DDSCAPS_ZBUFFER
);
1107 if(winecaps
.DirectDrawCaps
.StrideAlign
!= 0) {
1108 caps
.dwCaps
|= DDCAPS_ALIGNSTRIDE
;
1109 caps
.dwAlignStrideAlign
= winecaps
.DirectDrawCaps
.StrideAlign
;
1114 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &caps
);
1115 if (TRACE_ON(ddraw
))
1117 TRACE("Driver Caps :\n");
1118 DDRAW_dump_DDCAPS(DriverCaps
);
1124 DD_STRUCT_COPY_BYSIZE(HELCaps
, &caps
);
1125 if (TRACE_ON(ddraw
))
1127 TRACE("HEL Caps :\n");
1128 DDRAW_dump_DDCAPS(HELCaps
);
1135 static HRESULT WINAPI
ddraw4_GetCaps(IDirectDraw4
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1137 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1139 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1141 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1144 static HRESULT WINAPI
ddraw3_GetCaps(IDirectDraw3
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1146 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1148 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1150 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1153 static HRESULT WINAPI
ddraw2_GetCaps(IDirectDraw2
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1155 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1157 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1159 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1162 static HRESULT WINAPI
ddraw1_GetCaps(IDirectDraw
*iface
, DDCAPS
*driver_caps
, DDCAPS
*hel_caps
)
1164 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1166 TRACE("iface %p, driver_caps %p, hel_caps %p.\n", iface
, driver_caps
, hel_caps
);
1168 return ddraw7_GetCaps(&This
->IDirectDraw7_iface
, driver_caps
, hel_caps
);
1171 /*****************************************************************************
1172 * IDirectDraw7::Compact
1174 * No idea what it does, MSDN says it's not implemented.
1177 * DD_OK, but this is unchecked
1179 *****************************************************************************/
1180 static HRESULT WINAPI
ddraw7_Compact(IDirectDraw7
*iface
)
1182 TRACE("iface %p.\n", iface
);
1187 static HRESULT WINAPI
ddraw4_Compact(IDirectDraw4
*iface
)
1189 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1191 TRACE("iface %p.\n", iface
);
1193 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1196 static HRESULT WINAPI
ddraw3_Compact(IDirectDraw3
*iface
)
1198 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1200 TRACE("iface %p.\n", iface
);
1202 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1205 static HRESULT WINAPI
ddraw2_Compact(IDirectDraw2
*iface
)
1207 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1209 TRACE("iface %p.\n", iface
);
1211 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1214 static HRESULT WINAPI
ddraw1_Compact(IDirectDraw
*iface
)
1216 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1218 TRACE("iface %p.\n", iface
);
1220 return ddraw7_Compact(&This
->IDirectDraw7_iface
);
1223 /*****************************************************************************
1224 * IDirectDraw7::GetDisplayMode
1226 * Returns information about the current display mode
1228 * Exists in Version 1, 2, 4 and 7
1231 * DDSD: Address of a surface description structure to write the info to
1236 *****************************************************************************/
1237 static HRESULT WINAPI
ddraw7_GetDisplayMode(IDirectDraw7
*iface
, DDSURFACEDESC2
*DDSD
)
1239 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1241 WINED3DDISPLAYMODE Mode
;
1244 TRACE("iface %p, surface_desc %p.\n", iface
, DDSD
);
1246 EnterCriticalSection(&ddraw_cs
);
1247 /* This seems sane */
1250 LeaveCriticalSection(&ddraw_cs
);
1251 return DDERR_INVALIDPARAMS
;
1254 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
1255 * so one method can be used for all versions (Hopefully)
1257 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1258 0 /* swapchain 0 */,
1262 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
1263 LeaveCriticalSection(&ddraw_cs
);
1267 Size
= DDSD
->dwSize
;
1268 memset(DDSD
, 0, Size
);
1270 DDSD
->dwSize
= Size
;
1271 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
1272 DDSD
->dwWidth
= Mode
.Width
;
1273 DDSD
->dwHeight
= Mode
.Height
;
1274 DDSD
->u2
.dwRefreshRate
= 60;
1275 DDSD
->ddsCaps
.dwCaps
= 0;
1276 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
1277 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
1278 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
1282 TRACE("Returning surface desc :\n");
1283 DDRAW_dump_surface_desc(DDSD
);
1286 LeaveCriticalSection(&ddraw_cs
);
1290 static HRESULT WINAPI
ddraw4_GetDisplayMode(IDirectDraw4
*iface
, DDSURFACEDESC2
*surface_desc
)
1292 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1294 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1296 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, surface_desc
);
1299 static HRESULT WINAPI
ddraw3_GetDisplayMode(IDirectDraw3
*iface
, DDSURFACEDESC
*surface_desc
)
1301 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1303 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1305 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1308 static HRESULT WINAPI
ddraw2_GetDisplayMode(IDirectDraw2
*iface
, DDSURFACEDESC
*surface_desc
)
1310 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1312 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1314 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1317 static HRESULT WINAPI
ddraw1_GetDisplayMode(IDirectDraw
*iface
, DDSURFACEDESC
*surface_desc
)
1319 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1321 TRACE("iface %p, surface_desc %p.\n", iface
, surface_desc
);
1323 return ddraw7_GetDisplayMode(&This
->IDirectDraw7_iface
, (DDSURFACEDESC2
*)surface_desc
);
1326 /*****************************************************************************
1327 * IDirectDraw7::GetFourCCCodes
1329 * Returns an array of supported FourCC codes.
1331 * Exists in Version 1, 2, 4 and 7
1334 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
1335 * of enumerated codes
1336 * Codes: Pointer to an array of DWORDs where the supported codes are written
1340 * Always returns DD_OK, as it's a stub for now
1342 *****************************************************************************/
1343 static HRESULT WINAPI
ddraw7_GetFourCCCodes(IDirectDraw7
*iface
, DWORD
*NumCodes
, DWORD
*Codes
)
1345 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1346 static const enum wined3d_format_id formats
[] =
1348 WINED3DFMT_YUY2
, WINED3DFMT_UYVY
, WINED3DFMT_YV12
,
1349 WINED3DFMT_DXT1
, WINED3DFMT_DXT2
, WINED3DFMT_DXT3
, WINED3DFMT_DXT4
, WINED3DFMT_DXT5
,
1350 WINED3DFMT_ATI2N
, WINED3DFMT_NVHU
, WINED3DFMT_NVHS
1352 DWORD count
= 0, i
, outsize
;
1354 WINED3DDISPLAYMODE d3ddm
;
1355 WINED3DSURFTYPE type
= This
->ImplType
;
1357 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, NumCodes
, Codes
);
1359 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1360 0 /* swapchain 0 */,
1363 outsize
= NumCodes
&& Codes
? *NumCodes
: 0;
1365 if(type
== SURFACE_UNKNOWN
) type
= SURFACE_GDI
;
1367 for (i
= 0; i
< (sizeof(formats
) / sizeof(formats
[0])); ++i
)
1369 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, WINED3DDEVTYPE_HAL
,
1370 d3ddm
.Format
, 0, WINED3DRTYPE_SURFACE
, formats
[i
], type
);
1373 if (count
< outsize
)
1374 Codes
[count
] = formats
[i
];
1379 TRACE("Returning %u FourCC codes\n", count
);
1386 static HRESULT WINAPI
ddraw4_GetFourCCCodes(IDirectDraw4
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1388 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1390 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1392 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1395 static HRESULT WINAPI
ddraw3_GetFourCCCodes(IDirectDraw3
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1397 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1399 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1401 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1404 static HRESULT WINAPI
ddraw2_GetFourCCCodes(IDirectDraw2
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1406 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1408 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1410 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1413 static HRESULT WINAPI
ddraw1_GetFourCCCodes(IDirectDraw
*iface
, DWORD
*codes_count
, DWORD
*codes
)
1415 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1417 TRACE("iface %p, codes_count %p, codes %p.\n", iface
, codes_count
, codes
);
1419 return ddraw7_GetFourCCCodes(&This
->IDirectDraw7_iface
, codes_count
, codes
);
1422 /*****************************************************************************
1423 * IDirectDraw7::GetMonitorFrequency
1425 * Returns the monitor's frequency
1427 * Exists in Version 1, 2, 4 and 7
1430 * Freq: Pointer to a DWORD to write the frequency to
1433 * Always returns DD_OK
1435 *****************************************************************************/
1436 static HRESULT WINAPI
ddraw7_GetMonitorFrequency(IDirectDraw7
*iface
, DWORD
*Freq
)
1438 FIXME("iface %p, frequency %p stub!\n", iface
, Freq
);
1440 /* Ideally this should be in WineD3D, as it concerns the screen setup,
1441 * but for now this should make the games happy
1447 static HRESULT WINAPI
ddraw4_GetMonitorFrequency(IDirectDraw4
*iface
, DWORD
*frequency
)
1449 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1451 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1453 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1456 static HRESULT WINAPI
ddraw3_GetMonitorFrequency(IDirectDraw3
*iface
, DWORD
*frequency
)
1458 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1460 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1462 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1465 static HRESULT WINAPI
ddraw2_GetMonitorFrequency(IDirectDraw2
*iface
, DWORD
*frequency
)
1467 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1469 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1471 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1474 static HRESULT WINAPI
ddraw1_GetMonitorFrequency(IDirectDraw
*iface
, DWORD
*frequency
)
1476 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1478 TRACE("iface %p, frequency %p.\n", iface
, frequency
);
1480 return ddraw7_GetMonitorFrequency(&This
->IDirectDraw7_iface
, frequency
);
1483 /*****************************************************************************
1484 * IDirectDraw7::GetVerticalBlankStatus
1486 * Returns the Vertical blank status of the monitor. This should be in WineD3D
1487 * too basically, but as it's a semi stub, I didn't create a function there
1490 * status: Pointer to a BOOL to be filled with the vertical blank status
1494 * DDERR_INVALIDPARAMS if status is NULL
1496 *****************************************************************************/
1497 static HRESULT WINAPI
ddraw7_GetVerticalBlankStatus(IDirectDraw7
*iface
, BOOL
*status
)
1499 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1501 TRACE("iface %p, status %p.\n", iface
, status
);
1503 /* This looks sane, the MSDN suggests it too */
1504 EnterCriticalSection(&ddraw_cs
);
1507 LeaveCriticalSection(&ddraw_cs
);
1508 return DDERR_INVALIDPARAMS
;
1511 *status
= This
->fake_vblank
;
1512 This
->fake_vblank
= !This
->fake_vblank
;
1513 LeaveCriticalSection(&ddraw_cs
);
1517 static HRESULT WINAPI
ddraw4_GetVerticalBlankStatus(IDirectDraw4
*iface
, BOOL
*status
)
1519 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1521 TRACE("iface %p, status %p.\n", iface
, status
);
1523 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1526 static HRESULT WINAPI
ddraw3_GetVerticalBlankStatus(IDirectDraw3
*iface
, BOOL
*status
)
1528 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1530 TRACE("iface %p, status %p.\n", iface
, status
);
1532 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1535 static HRESULT WINAPI
ddraw2_GetVerticalBlankStatus(IDirectDraw2
*iface
, BOOL
*status
)
1537 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1539 TRACE("iface %p, status %p.\n", iface
, status
);
1541 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1544 static HRESULT WINAPI
ddraw1_GetVerticalBlankStatus(IDirectDraw
*iface
, BOOL
*status
)
1546 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1548 TRACE("iface %p, status %p.\n", iface
, status
);
1550 return ddraw7_GetVerticalBlankStatus(&This
->IDirectDraw7_iface
, status
);
1553 /*****************************************************************************
1554 * IDirectDraw7::GetAvailableVidMem
1556 * Returns the total and free video memory
1559 * Caps: Specifies the memory type asked for
1560 * total: Pointer to a DWORD to be filled with the total memory
1561 * free: Pointer to a DWORD to be filled with the free memory
1565 * DDERR_INVALIDPARAMS of free and total are NULL
1567 *****************************************************************************/
1568 static HRESULT WINAPI
ddraw7_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
,
1571 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1573 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, Caps
, total
, free
);
1577 TRACE("(%p) Asked for memory with description: ", This
);
1578 DDRAW_dump_DDSCAPS2(Caps
);
1580 EnterCriticalSection(&ddraw_cs
);
1582 /* Todo: System memory vs local video memory vs non-local video memory
1583 * The MSDN also mentions differences between texture memory and other
1584 * resources, but that's not important
1587 if( (!total
) && (!free
) )
1589 LeaveCriticalSection(&ddraw_cs
);
1590 return DDERR_INVALIDPARAMS
;
1593 if(total
) *total
= This
->total_vidmem
;
1594 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
1596 LeaveCriticalSection(&ddraw_cs
);
1600 static HRESULT WINAPI
ddraw4_GetAvailableVidMem(IDirectDraw4
*iface
,
1601 DDSCAPS2
*caps
, DWORD
*total
, DWORD
*free
)
1603 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1605 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1607 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, caps
, total
, free
);
1610 static HRESULT WINAPI
ddraw3_GetAvailableVidMem(IDirectDraw3
*iface
, DDSCAPS
*caps
, DWORD
*total
,
1613 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1616 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1618 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1619 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1622 static HRESULT WINAPI
ddraw2_GetAvailableVidMem(IDirectDraw2
*iface
,
1623 DDSCAPS
*caps
, DWORD
*total
, DWORD
*free
)
1625 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1628 TRACE("iface %p, caps %p, total %p, free %p.\n", iface
, caps
, total
, free
);
1630 DDRAW_Convert_DDSCAPS_1_To_2(caps
, &caps2
);
1631 return ddraw7_GetAvailableVidMem(&This
->IDirectDraw7_iface
, &caps2
, total
, free
);
1634 /*****************************************************************************
1635 * IDirectDraw7::Initialize
1637 * Initializes a DirectDraw interface.
1640 * GUID: Interface identifier. Well, don't know what this is really good
1644 * Returns DD_OK on the first call,
1645 * DDERR_ALREADYINITIALIZED on repeated calls
1647 *****************************************************************************/
1648 static HRESULT WINAPI
ddraw7_Initialize(IDirectDraw7
*iface
, GUID
*Guid
)
1650 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1652 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(Guid
));
1654 if(This
->initialized
)
1656 return DDERR_ALREADYINITIALIZED
;
1664 static HRESULT WINAPI
ddraw4_Initialize(IDirectDraw4
*iface
, GUID
*guid
)
1666 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1668 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1670 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1673 static HRESULT WINAPI
ddraw3_Initialize(IDirectDraw3
*iface
, GUID
*guid
)
1675 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1677 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1679 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1682 static HRESULT WINAPI
ddraw2_Initialize(IDirectDraw2
*iface
, GUID
*guid
)
1684 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1686 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1688 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1691 static HRESULT WINAPI
ddraw1_Initialize(IDirectDraw
*iface
, GUID
*guid
)
1693 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1695 TRACE("iface %p, guid %s.\n", iface
, debugstr_guid(guid
));
1697 return ddraw7_Initialize(&This
->IDirectDraw7_iface
, guid
);
1700 static HRESULT WINAPI
d3d1_Initialize(IDirect3D
*iface
, REFIID riid
)
1702 TRACE("iface %p, riid %s.\n", iface
, debugstr_guid(riid
));
1707 /*****************************************************************************
1708 * IDirectDraw7::FlipToGDISurface
1710 * "Makes the surface that the GDI writes to the primary surface"
1711 * Looks like some windows specific thing we don't have to care about.
1712 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1713 * show error boxes ;)
1714 * Well, just return DD_OK.
1717 * Always returns DD_OK
1719 *****************************************************************************/
1720 static HRESULT WINAPI
ddraw7_FlipToGDISurface(IDirectDraw7
*iface
)
1722 FIXME("iface %p stub!\n", iface
);
1727 static HRESULT WINAPI
ddraw4_FlipToGDISurface(IDirectDraw4
*iface
)
1729 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1731 TRACE("iface %p.\n", iface
);
1733 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1736 static HRESULT WINAPI
ddraw3_FlipToGDISurface(IDirectDraw3
*iface
)
1738 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1740 TRACE("iface %p.\n", iface
);
1742 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1745 static HRESULT WINAPI
ddraw2_FlipToGDISurface(IDirectDraw2
*iface
)
1747 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1749 TRACE("iface %p.\n", iface
);
1751 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1754 static HRESULT WINAPI
ddraw1_FlipToGDISurface(IDirectDraw
*iface
)
1756 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1758 TRACE("iface %p.\n", iface
);
1760 return ddraw7_FlipToGDISurface(&This
->IDirectDraw7_iface
);
1763 /*****************************************************************************
1764 * IDirectDraw7::WaitForVerticalBlank
1766 * This method allows applications to get in sync with the vertical blank
1768 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1769 * redraw the screen, most likely because of this stub
1772 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1773 * or DDWAITVB_BLOCKEND
1774 * h: Not used, according to MSDN
1777 * Always returns DD_OK
1779 *****************************************************************************/
1780 static HRESULT WINAPI
ddraw7_WaitForVerticalBlank(IDirectDraw7
*iface
, DWORD Flags
, HANDLE event
)
1784 TRACE("iface %p, flags %#x, event %p.\n", iface
, Flags
, event
);
1786 /* This function is called often, so print the fixme only once */
1789 FIXME("iface %p, flags %#x, event %p stub!\n", iface
, Flags
, event
);
1793 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1794 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1795 return DDERR_UNSUPPORTED
; /* unchecked */
1800 static HRESULT WINAPI
ddraw4_WaitForVerticalBlank(IDirectDraw4
*iface
, DWORD flags
, HANDLE event
)
1802 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1804 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1806 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1809 static HRESULT WINAPI
ddraw3_WaitForVerticalBlank(IDirectDraw3
*iface
, DWORD flags
, HANDLE event
)
1811 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1813 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1815 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1818 static HRESULT WINAPI
ddraw2_WaitForVerticalBlank(IDirectDraw2
*iface
, DWORD flags
, HANDLE event
)
1820 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1822 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1824 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1827 static HRESULT WINAPI
ddraw1_WaitForVerticalBlank(IDirectDraw
*iface
, DWORD flags
, HANDLE event
)
1829 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1831 TRACE("iface %p, flags %#x, event %p.\n", iface
, flags
, event
);
1833 return ddraw7_WaitForVerticalBlank(&This
->IDirectDraw7_iface
, flags
, event
);
1836 /*****************************************************************************
1837 * IDirectDraw7::GetScanLine
1839 * Returns the scan line that is being drawn on the monitor
1842 * Scanline: Address to write the scan line value to
1845 * Always returns DD_OK
1847 *****************************************************************************/
1848 static HRESULT WINAPI
ddraw7_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1850 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1851 static BOOL hide
= FALSE
;
1852 WINED3DDISPLAYMODE Mode
;
1854 TRACE("iface %p, line %p.\n", iface
, Scanline
);
1856 /* This function is called often, so print the fixme only once */
1857 EnterCriticalSection(&ddraw_cs
);
1860 FIXME("iface %p, line %p partial stub!\n", iface
, Scanline
);
1864 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1868 /* Fake the line sweeping of the monitor */
1869 /* FIXME: We should synchronize with a source to keep the refresh rate */
1870 *Scanline
= This
->cur_scanline
++;
1871 /* Assume 20 scan lines in the vertical blank */
1872 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1873 This
->cur_scanline
= 0;
1875 LeaveCriticalSection(&ddraw_cs
);
1879 static HRESULT WINAPI
ddraw4_GetScanLine(IDirectDraw4
*iface
, DWORD
*line
)
1881 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1883 TRACE("iface %p, line %p.\n", iface
, line
);
1885 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1888 static HRESULT WINAPI
ddraw3_GetScanLine(IDirectDraw3
*iface
, DWORD
*line
)
1890 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
1892 TRACE("iface %p, line %p.\n", iface
, line
);
1894 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1897 static HRESULT WINAPI
ddraw2_GetScanLine(IDirectDraw2
*iface
, DWORD
*line
)
1899 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
1901 TRACE("iface %p, line %p.\n", iface
, line
);
1903 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1906 static HRESULT WINAPI
ddraw1_GetScanLine(IDirectDraw
*iface
, DWORD
*line
)
1908 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
1910 TRACE("iface %p, line %p.\n", iface
, line
);
1912 return ddraw7_GetScanLine(&This
->IDirectDraw7_iface
, line
);
1915 /*****************************************************************************
1916 * IDirectDraw7::TestCooperativeLevel
1918 * Informs the application about the state of the video adapter, depending
1919 * on the cooperative level
1922 * DD_OK if the device is in a sane state
1923 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1924 * if the state is not correct(See below)
1926 *****************************************************************************/
1927 static HRESULT WINAPI
ddraw7_TestCooperativeLevel(IDirectDraw7
*iface
)
1929 TRACE("iface %p.\n", iface
);
1934 static HRESULT WINAPI
ddraw4_TestCooperativeLevel(IDirectDraw4
*iface
)
1936 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
1938 TRACE("iface %p.\n", iface
);
1940 return ddraw7_TestCooperativeLevel(&This
->IDirectDraw7_iface
);
1943 /*****************************************************************************
1944 * IDirectDraw7::GetGDISurface
1946 * Returns the surface that GDI is treating as the primary surface.
1947 * For Wine this is the front buffer
1950 * GDISurface: Address to write the surface pointer to
1953 * DD_OK if the surface was found
1954 * DDERR_NOTFOUND if the GDI surface wasn't found
1956 *****************************************************************************/
1957 static HRESULT WINAPI
ddraw7_GetGDISurface(IDirectDraw7
*iface
, IDirectDrawSurface7
**GDISurface
)
1959 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
1960 IWineD3DSurface
*Surf
;
1961 IDirectDrawSurface7
*ddsurf
;
1965 TRACE("iface %p, surface %p.\n", iface
, GDISurface
);
1967 /* Get the back buffer from the wineD3DDevice and search its
1968 * attached surfaces for the front buffer
1970 EnterCriticalSection(&ddraw_cs
);
1971 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1973 0, /* first back buffer*/
1974 WINED3DBACKBUFFER_TYPE_MONO
,
1977 if( (hr
!= D3D_OK
) ||
1980 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1981 LeaveCriticalSection(&ddraw_cs
);
1982 return DDERR_NOTFOUND
;
1985 ddsurf
= IWineD3DSurface_GetParent(Surf
);
1986 IWineD3DSurface_Release(Surf
);
1988 /* Find the front buffer */
1989 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1990 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1995 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1998 /* The AddRef is OK this time */
1999 LeaveCriticalSection(&ddraw_cs
);
2003 static HRESULT WINAPI
ddraw4_GetGDISurface(IDirectDraw4
*iface
, IDirectDrawSurface4
**surface
)
2005 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2007 TRACE("iface %p, surface %p.\n", iface
, surface
);
2009 return ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, (IDirectDrawSurface7
**)surface
);
2012 static HRESULT WINAPI
ddraw3_GetGDISurface(IDirectDraw3
*iface
, IDirectDrawSurface
**surface
)
2014 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2015 IDirectDrawSurface7
*surface7
;
2018 TRACE("iface %p, surface %p.\n", iface
, surface
);
2020 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2021 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2026 static HRESULT WINAPI
ddraw2_GetGDISurface(IDirectDraw2
*iface
, IDirectDrawSurface
**surface
)
2028 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2029 IDirectDrawSurface7
*surface7
;
2032 TRACE("iface %p, surface %p.\n", iface
, surface
);
2034 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2035 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2040 static HRESULT WINAPI
ddraw1_GetGDISurface(IDirectDraw
*iface
, IDirectDrawSurface
**surface
)
2042 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2043 IDirectDrawSurface7
*surface7
;
2046 TRACE("iface %p, surface %p.\n", iface
, surface
);
2048 hr
= ddraw7_GetGDISurface(&This
->IDirectDraw7_iface
, &surface7
);
2049 *surface
= surface7
? (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2054 struct displaymodescallback_context
2056 LPDDENUMMODESCALLBACK func
;
2060 static HRESULT CALLBACK
EnumDisplayModesCallbackThunk(DDSURFACEDESC2
*surface_desc
, void *context
)
2062 struct displaymodescallback_context
*cbcontext
= context
;
2065 memcpy(&desc
, surface_desc
, sizeof(desc
));
2066 desc
.dwSize
= sizeof(desc
);
2068 return cbcontext
->func(&desc
, cbcontext
->context
);
2071 /*****************************************************************************
2072 * IDirectDraw7::EnumDisplayModes
2074 * Enumerates the supported Display modes. The modes can be filtered with
2075 * the DDSD parameter.
2078 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
2079 * DDSD: Surface description to filter the modes
2080 * Context: Pointer passed back to the callback function
2081 * cb: Application-provided callback function
2085 * DDERR_INVALIDPARAMS if the callback wasn't set
2087 *****************************************************************************/
2088 static HRESULT WINAPI
ddraw7_EnumDisplayModes(IDirectDraw7
*iface
, DWORD Flags
,
2089 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMMODESCALLBACK2 cb
)
2091 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2092 unsigned int modenum
, fmt
;
2093 enum wined3d_format_id pixelformat
= WINED3DFMT_UNKNOWN
;
2094 WINED3DDISPLAYMODE mode
;
2095 DDSURFACEDESC2 callback_sd
;
2096 WINED3DDISPLAYMODE
*enum_modes
= NULL
;
2097 unsigned enum_mode_count
= 0, enum_mode_array_size
= 0;
2099 static const enum wined3d_format_id checkFormatList
[] =
2101 WINED3DFMT_B8G8R8X8_UNORM
,
2102 WINED3DFMT_B5G6R5_UNORM
,
2106 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2107 iface
, Flags
, DDSD
, Context
, cb
);
2109 EnterCriticalSection(&ddraw_cs
);
2110 /* This looks sane */
2113 LeaveCriticalSection(&ddraw_cs
);
2114 return DDERR_INVALIDPARAMS
;
2119 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
2120 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
2123 if(!(Flags
& DDEDM_REFRESHRATES
))
2125 enum_mode_array_size
= 16;
2126 enum_modes
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2129 ERR("Out of memory\n");
2130 LeaveCriticalSection(&ddraw_cs
);
2131 return DDERR_OUTOFMEMORY
;
2135 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
2137 if(pixelformat
!= WINED3DFMT_UNKNOWN
&& checkFormatList
[fmt
] != pixelformat
)
2143 while (wined3d_enum_adapter_modes(This
->wineD3D
, WINED3DADAPTER_DEFAULT
,
2144 checkFormatList
[fmt
], modenum
++, &mode
) == WINED3D_OK
)
2148 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
2149 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
2152 if(!(Flags
& DDEDM_REFRESHRATES
))
2154 /* DX docs state EnumDisplayMode should return only unique modes. If DDEDM_REFRESHRATES is not set, refresh
2155 * rate doesn't matter when determining if the mode is unique. So modes only differing in refresh rate have
2156 * to be reduced to a single unique result in such case.
2161 for (i
= 0; i
< enum_mode_count
; i
++)
2163 if(enum_modes
[i
].Width
== mode
.Width
&& enum_modes
[i
].Height
== mode
.Height
&&
2164 enum_modes
[i
].Format
== mode
.Format
)
2174 memset(&callback_sd
, 0, sizeof(callback_sd
));
2175 callback_sd
.dwSize
= sizeof(callback_sd
);
2176 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2178 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
2179 if(Flags
& DDEDM_REFRESHRATES
)
2181 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
2182 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
2185 callback_sd
.dwWidth
= mode
.Width
;
2186 callback_sd
.dwHeight
= mode
.Height
;
2188 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, mode
.Format
);
2190 /* Calc pitch and DWORD align like MSDN says */
2191 callback_sd
.u1
.lPitch
= (callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8) * mode
.Width
;
2192 callback_sd
.u1
.lPitch
= (callback_sd
.u1
.lPitch
+ 3) & ~3;
2194 TRACE("Enumerating %dx%dx%d @%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
,
2195 callback_sd
.u2
.dwRefreshRate
);
2197 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
2199 TRACE("Application asked to terminate the enumeration\n");
2200 HeapFree(GetProcessHeap(), 0, enum_modes
);
2201 LeaveCriticalSection(&ddraw_cs
);
2205 if(!(Flags
& DDEDM_REFRESHRATES
))
2207 if (enum_mode_count
== enum_mode_array_size
)
2209 WINED3DDISPLAYMODE
*new_enum_modes
;
2211 enum_mode_array_size
*= 2;
2212 new_enum_modes
= HeapReAlloc(GetProcessHeap(), 0, enum_modes
, sizeof(WINED3DDISPLAYMODE
) * enum_mode_array_size
);
2214 if (!new_enum_modes
)
2216 ERR("Out of memory\n");
2217 HeapFree(GetProcessHeap(), 0, enum_modes
);
2218 LeaveCriticalSection(&ddraw_cs
);
2219 return DDERR_OUTOFMEMORY
;
2222 enum_modes
= new_enum_modes
;
2225 enum_modes
[enum_mode_count
++] = mode
;
2230 TRACE("End of enumeration\n");
2231 HeapFree(GetProcessHeap(), 0, enum_modes
);
2232 LeaveCriticalSection(&ddraw_cs
);
2236 static HRESULT WINAPI
ddraw4_EnumDisplayModes(IDirectDraw4
*iface
, DWORD flags
,
2237 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK2 callback
)
2239 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2241 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2242 iface
, flags
, surface_desc
, context
, callback
);
2244 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
, callback
);
2247 static HRESULT WINAPI
ddraw3_EnumDisplayModes(IDirectDraw3
*iface
, DWORD flags
,
2248 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2250 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2251 struct displaymodescallback_context cbcontext
;
2253 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2254 iface
, flags
, surface_desc
, context
, callback
);
2256 cbcontext
.func
= callback
;
2257 cbcontext
.context
= context
;
2259 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2260 &cbcontext
, EnumDisplayModesCallbackThunk
);
2263 static HRESULT WINAPI
ddraw2_EnumDisplayModes(IDirectDraw2
*iface
, DWORD flags
,
2264 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2266 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
2267 struct displaymodescallback_context cbcontext
;
2269 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2270 iface
, flags
, surface_desc
, context
, callback
);
2272 cbcontext
.func
= callback
;
2273 cbcontext
.context
= context
;
2275 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2276 &cbcontext
, EnumDisplayModesCallbackThunk
);
2279 static HRESULT WINAPI
ddraw1_EnumDisplayModes(IDirectDraw
*iface
, DWORD flags
,
2280 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMMODESCALLBACK callback
)
2282 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
2283 struct displaymodescallback_context cbcontext
;
2285 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
2286 iface
, flags
, surface_desc
, context
, callback
);
2288 cbcontext
.func
= callback
;
2289 cbcontext
.context
= context
;
2291 return ddraw7_EnumDisplayModes(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
2292 &cbcontext
, EnumDisplayModesCallbackThunk
);
2295 /*****************************************************************************
2296 * IDirectDraw7::EvaluateMode
2298 * Used with IDirectDraw7::StartModeTest to test video modes.
2299 * EvaluateMode is used to pass or fail a mode, and continue with the next
2303 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
2304 * Timeout: Returns the amount of seconds left before the mode would have
2305 * been failed automatically
2308 * This implementation always DD_OK, because it's a stub
2310 *****************************************************************************/
2311 static HRESULT WINAPI
ddraw7_EvaluateMode(IDirectDraw7
*iface
, DWORD Flags
, DWORD
*Timeout
)
2313 FIXME("iface %p, flags %#x, timeout %p stub!\n", iface
, Flags
, Timeout
);
2315 /* When implementing this, implement it in WineD3D */
2320 /*****************************************************************************
2321 * IDirectDraw7::GetDeviceIdentifier
2323 * Returns the device identifier, which gives information about the driver
2324 * Our device identifier is defined at the beginning of this file.
2327 * DDDI: Address for the returned structure
2328 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
2331 * On success it returns DD_OK
2332 * DDERR_INVALIDPARAMS if DDDI is NULL
2334 *****************************************************************************/
2335 static HRESULT WINAPI
ddraw7_GetDeviceIdentifier(IDirectDraw7
*iface
,
2336 DDDEVICEIDENTIFIER2
*DDDI
, DWORD Flags
)
2338 TRACE("iface %p, device_identifier %p, flags %#x.\n", iface
, DDDI
, Flags
);
2341 return DDERR_INVALIDPARAMS
;
2343 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
2344 * host adapter, if there's a secondary 3D adapter. This doesn't apply
2345 * to any modern hardware, nor is it interesting for Wine, so ignore it.
2346 * Size of DDDEVICEIDENTIFIER2 may be aligned to 8 bytes and thus 4
2347 * bytes too long. So only copy the relevant part of the structure
2350 memcpy(DDDI
, &deviceidentifier
, FIELD_OFFSET(DDDEVICEIDENTIFIER2
, dwWHQLLevel
) + sizeof(DWORD
));
2354 static HRESULT WINAPI
ddraw4_GetDeviceIdentifier(IDirectDraw4
*iface
,
2355 DDDEVICEIDENTIFIER
*identifier
, DWORD flags
)
2357 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2358 DDDEVICEIDENTIFIER2 identifier2
;
2361 TRACE("iface %p, identifier %p, flags %#x.\n", iface
, identifier
, flags
);
2363 hr
= ddraw7_GetDeviceIdentifier(&This
->IDirectDraw7_iface
, &identifier2
, flags
);
2364 DDRAW_Convert_DDDEVICEIDENTIFIER_2_To_1(&identifier2
, identifier
);
2369 /*****************************************************************************
2370 * IDirectDraw7::GetSurfaceFromDC
2372 * Returns the Surface for a GDI device context handle.
2373 * Is this related to IDirectDrawSurface::GetDC ???
2376 * hdc: hdc to return the surface for
2377 * Surface: Address to write the surface pointer to
2380 * Always returns DD_OK because it's a stub
2382 *****************************************************************************/
2383 static HRESULT WINAPI
ddraw7_GetSurfaceFromDC(IDirectDraw7
*iface
, HDC hdc
,
2384 IDirectDrawSurface7
**Surface
)
2386 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
2387 IWineD3DSurface
*wined3d_surface
;
2390 TRACE("iface %p, dc %p, surface %p.\n", iface
, hdc
, Surface
);
2392 if (!Surface
) return E_INVALIDARG
;
2394 hr
= IWineD3DDevice_GetSurfaceFromDC(This
->wineD3DDevice
, hdc
, &wined3d_surface
);
2397 TRACE("No surface found for dc %p.\n", hdc
);
2399 return DDERR_NOTFOUND
;
2402 *Surface
= IWineD3DSurface_GetParent(wined3d_surface
);
2403 IDirectDrawSurface7_AddRef(*Surface
);
2404 TRACE("Returning surface %p.\n", Surface
);
2408 static HRESULT WINAPI
ddraw4_GetSurfaceFromDC(IDirectDraw4
*iface
, HDC dc
,
2409 IDirectDrawSurface4
**surface
)
2411 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2412 IDirectDrawSurface7
*surface7
;
2415 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2417 if (!surface
) return E_INVALIDARG
;
2419 hr
= ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, &surface7
);
2420 *surface
= surface7
? (IDirectDrawSurface4
*)&((IDirectDrawSurfaceImpl
*)surface7
)->IDirectDrawSurface3_vtbl
: NULL
;
2425 static HRESULT WINAPI
ddraw3_GetSurfaceFromDC(IDirectDraw3
*iface
, HDC dc
,
2426 IDirectDrawSurface
**surface
)
2428 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
2430 TRACE("iface %p, dc %p, surface %p.\n", iface
, dc
, surface
);
2432 return ddraw7_GetSurfaceFromDC(&This
->IDirectDraw7_iface
, dc
, (IDirectDrawSurface7
**)surface
);
2435 /*****************************************************************************
2436 * IDirectDraw7::RestoreAllSurfaces
2438 * Calls the restore method of all surfaces
2443 * Always returns DD_OK because it's a stub
2445 *****************************************************************************/
2446 static HRESULT WINAPI
ddraw7_RestoreAllSurfaces(IDirectDraw7
*iface
)
2448 FIXME("iface %p stub!\n", iface
);
2450 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
2451 * get their parent and call their restore method. Do not implement
2452 * it in WineD3D, as restoring a surface means re-creating the
2458 static HRESULT WINAPI
ddraw4_RestoreAllSurfaces(IDirectDraw4
*iface
)
2460 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
2462 TRACE("iface %p.\n", iface
);
2464 return ddraw7_RestoreAllSurfaces(&This
->IDirectDraw7_iface
);
2467 /*****************************************************************************
2468 * IDirectDraw7::StartModeTest
2470 * Tests the specified video modes to update the system registry with
2471 * refresh rate information. StartModeTest starts the mode test,
2472 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
2473 * isn't called within 15 seconds, the mode is failed automatically
2475 * As refresh rates are handled by the X server, I don't think this
2476 * Method is important
2479 * Modes: An array of mode specifications
2480 * NumModes: The number of modes in Modes
2481 * Flags: Some flags...
2484 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
2485 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
2488 *****************************************************************************/
2489 static HRESULT WINAPI
ddraw7_StartModeTest(IDirectDraw7
*iface
, SIZE
*Modes
, DWORD NumModes
, DWORD Flags
)
2491 FIXME("iface %p, modes %p, mode_count %u, flags %#x partial stub!\n",
2492 iface
, Modes
, NumModes
, Flags
);
2494 /* This looks sane */
2495 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
2497 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
2498 * As it is not, DDERR_TESTFINISHED is returned
2499 * (hopefully that's correct
2501 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
2502 * well, that value doesn't (yet) exist in the wine headers, so ignore it
2508 /*****************************************************************************
2509 * ddraw_recreate_surfaces_cb
2511 * Enumeration callback for ddraw_recreate_surface.
2512 * It re-recreates the WineD3DSurface. It's pretty straightforward
2514 *****************************************************************************/
2515 HRESULT WINAPI
ddraw_recreate_surfaces_cb(IDirectDrawSurface7
*surf
, DDSURFACEDESC2
*desc
, void *Context
)
2517 IDirectDrawSurfaceImpl
*surfImpl
= (IDirectDrawSurfaceImpl
*)surf
;
2518 struct wined3d_resource_desc wined3d_desc
;
2519 struct wined3d_resource
*wined3d_resource
;
2520 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
2521 struct wined3d_clipper
*clipper
= NULL
;
2522 IWineD3DSurface
*wineD3DSurface
;
2523 IWineD3DSwapChain
*swapchain
;
2527 TRACE("surface %p, surface_desc %p, context %p.\n",
2528 surf
, desc
, Context
);
2530 /* For the enumeration */
2531 IDirectDrawSurface7_Release(surf
);
2533 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
2535 /* Get the objects */
2536 swapchain
= surfImpl
->wineD3DSwapChain
;
2537 surfImpl
->wineD3DSwapChain
= NULL
;
2538 wineD3DSurface
= surfImpl
->WineD3DSurface
;
2540 /* get the clipper */
2541 IWineD3DSurface_GetClipper(wineD3DSurface
, &clipper
);
2543 /* Get the surface properties */
2544 wined3d_resource
= IWineD3DSurface_GetResource(wineD3DSurface
);
2545 wined3d_resource_get_desc(wined3d_resource
, &wined3d_desc
);
2547 parent
= IWineD3DSurface_GetParent(wineD3DSurface
);
2548 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
, wined3d_desc
.width
, wined3d_desc
.height
,
2549 wined3d_desc
.format
, TRUE
, FALSE
, surfImpl
->mipmap_level
, wined3d_desc
.usage
, wined3d_desc
.pool
,
2550 wined3d_desc
.multisample_type
, wined3d_desc
.multisample_quality
, This
->ImplType
,
2551 parent
, &ddraw_null_wined3d_parent_ops
, &surfImpl
->WineD3DSurface
);
2554 surfImpl
->WineD3DSurface
= wineD3DSurface
;
2558 IWineD3DSurface_SetClipper(surfImpl
->WineD3DSurface
, clipper
);
2560 /* TODO: Copy the surface content, except for render targets */
2562 /* If there's a swapchain, it owns the wined3d surfaces. So Destroy
2566 /* The backbuffers have the swapchain set as well, but the primary
2567 * owns it and destroys it
2569 if(surfImpl
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) {
2570 IWineD3DDevice_UninitGDI(This
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2572 surfImpl
->isRenderTarget
= FALSE
;
2574 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
2575 TRACE("Surface released successful, next surface\n");
2577 ERR("Something's still holding the old WineD3DSurface\n");
2580 surfImpl
->ImplType
= This
->ImplType
;
2583 wined3d_clipper_decref(clipper
);
2585 return DDENUMRET_OK
;
2588 /*****************************************************************************
2589 * ddraw_recreate_surfaces
2591 * A function, that converts all wineD3DSurfaces to the new implementation type
2592 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
2593 * new WineD3DSurface, copies the content and releases the old surface
2595 *****************************************************************************/
2596 static HRESULT
ddraw_recreate_surfaces(IDirectDrawImpl
*This
)
2598 DDSURFACEDESC2 desc
;
2599 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
2601 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
2603 /* Should happen almost never */
2604 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
2606 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2608 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
2610 memset(&desc
, 0, sizeof(desc
));
2611 desc
.dwSize
= sizeof(desc
);
2613 return IDirectDraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, 0, &desc
, This
,
2614 ddraw_recreate_surfaces_cb
);
2617 ULONG WINAPI
D3D7CB_DestroySwapChain(IWineD3DSwapChain
*swapchain
)
2619 TRACE("swapchain %p.\n", swapchain
);
2621 return IWineD3DSwapChain_Release(swapchain
);
2624 /*****************************************************************************
2625 * ddraw_create_surface
2627 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
2628 * with the passed parameters.
2631 * DDSD: Description of the surface to create
2632 * Surf: Address to store the interface pointer at
2637 *****************************************************************************/
2638 static HRESULT
ddraw_create_surface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
,
2639 IDirectDrawSurfaceImpl
**ppSurf
, UINT level
)
2641 WINED3DSURFTYPE ImplType
= This
->ImplType
;
2644 TRACE("ddraw %p, surface_desc %p, surface %p, level %u.\n",
2645 This
, pDDSD
, ppSurf
, level
);
2647 if (TRACE_ON(ddraw
))
2649 TRACE(" (%p) Requesting surface desc :\n", This
);
2650 DDRAW_dump_surface_desc(pDDSD
);
2653 /* Select the surface type, if it wasn't choosen yet */
2654 if(ImplType
== SURFACE_UNKNOWN
)
2656 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
2657 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2659 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
2660 ImplType
= SURFACE_OPENGL
;
2663 /* Otherwise use GDI surfaces for now */
2666 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
2667 ImplType
= SURFACE_GDI
;
2670 /* Policy if all surface implementations are available:
2671 * First, check if a default type was set with winecfg. If not,
2672 * try Xrender surfaces, and use them if they work. Next, check if
2673 * accelerated OpenGL is available, and use GL surfaces in this
2674 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
2675 * was created, always use OpenGL surfaces.
2677 * (Note: Xrender surfaces are not implemented for now, the
2678 * unaccelerated implementation uses GDI to render in Software)
2681 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
2682 * be re-created. This could be done with IDirectDrawSurface7::Restore
2684 This
->ImplType
= ImplType
;
2688 if ((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2689 && (This
->ImplType
!= SURFACE_OPENGL
)
2690 && DefaultSurfaceType
== SURFACE_UNKNOWN
)
2692 /* We have to change to OpenGL,
2693 * and re-create all WineD3DSurfaces
2695 ImplType
= SURFACE_OPENGL
;
2696 This
->ImplType
= ImplType
;
2697 TRACE("(%p) Re-creating all surfaces\n", This
);
2698 ddraw_recreate_surfaces(This
);
2699 TRACE("(%p) Done recreating all surfaces\n", This
);
2701 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
2703 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
2704 /* Do not fail surface creation, only fail 3D device creation */
2708 /* Create the Surface object */
2709 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
2712 ERR("(%p) Error allocating memory for a surface\n", This
);
2713 return DDERR_OUTOFVIDEOMEMORY
;
2716 hr
= ddraw_surface_init(*ppSurf
, This
, pDDSD
, level
, ImplType
);
2719 WARN("Failed to initialize surface, hr %#x.\n", hr
);
2720 HeapFree(GetProcessHeap(), 0, *ppSurf
);
2724 /* Increase the surface counter, and attach the surface */
2725 InterlockedIncrement(&This
->surfaces
);
2726 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
2728 TRACE("Created surface %p.\n", *ppSurf
);
2732 /*****************************************************************************
2733 * CreateAdditionalSurfaces
2735 * Creates a new mipmap chain.
2738 * root: Root surface to attach the newly created chain to
2739 * count: number of surfaces to create
2740 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2741 * effects on the caller
2742 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2743 * creates an additional surface without the mipmapping flags
2745 *****************************************************************************/
2747 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2748 IDirectDrawSurfaceImpl
*root
,
2750 DDSURFACEDESC2 DDSD
,
2753 UINT i
, j
, level
= 0;
2755 IDirectDrawSurfaceImpl
*last
= root
;
2757 for(i
= 0; i
< count
; i
++)
2759 IDirectDrawSurfaceImpl
*object2
= NULL
;
2761 /* increase the mipmap level, but only if a mipmap is created
2762 * In this case, also halve the size
2764 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2767 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2768 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2769 /* Set the mipmap sublevel flag according to msdn */
2770 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2774 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2776 CubeFaceRoot
= FALSE
;
2778 hr
= ddraw_create_surface(This
, &DDSD
, &object2
, level
);
2784 /* Add the new surface to the complex attachment array */
2785 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2787 if(last
->complex_array
[j
]) continue;
2788 last
->complex_array
[j
] = object2
;
2793 /* Remove the (possible) back buffer cap from the new surface description,
2794 * because only one surface in the flipping chain is a back buffer, one
2795 * is a front buffer, the others are just primary surfaces.
2797 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2802 /* Must set all attached surfaces (e.g. mipmaps) versions as well */
2803 static void ddraw_set_surface_version(IDirectDrawSurfaceImpl
*surface
, UINT version
)
2807 TRACE("surface %p, version %u -> %u.\n", surface
, surface
->version
, version
);
2809 surface
->version
= version
;
2810 for (i
= 0; i
< MAX_COMPLEX_ATTACHED
; ++i
)
2812 if (!surface
->complex_array
[i
]) break;
2813 ddraw_set_surface_version(surface
->complex_array
[i
], version
);
2815 while ((surface
= surface
->next_attached
))
2817 ddraw_set_surface_version(surface
, version
);
2821 /*****************************************************************************
2822 * ddraw_attach_d3d_device
2824 * Initializes the D3D capabilities of WineD3D
2827 * primary: The primary surface for D3D
2833 *****************************************************************************/
2834 static HRESULT
ddraw_attach_d3d_device(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2836 WINED3DPRESENT_PARAMETERS localParameters
;
2837 HWND window
= ddraw
->dest_window
;
2840 TRACE("ddraw %p, primary %p.\n", ddraw
, primary
);
2842 if (!window
|| window
== GetDesktopWindow())
2844 window
= CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME
, "Hidden D3D Window",
2845 WS_DISABLED
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
),
2846 NULL
, NULL
, NULL
, NULL
);
2849 ERR("Failed to create window, last error %#x.\n", GetLastError());
2853 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2854 WARN("No window for the Direct3DDevice, created hidden window %p.\n", window
);
2858 TRACE("Using existing window %p for Direct3D rendering.\n", window
);
2860 ddraw
->d3d_window
= window
;
2862 /* Store the future Render Target surface */
2863 ddraw
->d3d_target
= primary
;
2865 /* Use the surface description for the device parameters, not the device
2866 * settings. The application might render to an offscreen surface. */
2867 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2868 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2869 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2870 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2871 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2872 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2873 localParameters
.MultiSampleQuality
= 0;
2874 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2875 localParameters
.hDeviceWindow
= window
;
2876 localParameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2877 localParameters
.EnableAutoDepthStencil
= TRUE
;
2878 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16_UNORM
;
2879 localParameters
.Flags
= 0;
2880 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2881 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2882 localParameters
.AutoRestoreDisplayMode
= FALSE
;
2884 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2885 * recursive loop until ram or emulated video memory is full. */
2886 ddraw
->d3d_initialized
= TRUE
;
2887 hr
= IWineD3DDevice_Init3D(ddraw
->wineD3DDevice
, &localParameters
);
2890 ddraw
->d3d_target
= NULL
;
2891 ddraw
->d3d_initialized
= FALSE
;
2895 ddraw
->declArraySize
= 2;
2896 ddraw
->decls
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*ddraw
->decls
) * ddraw
->declArraySize
);
2899 ERR("Error allocating an array for the converted vertex decls.\n");
2900 ddraw
->declArraySize
= 0;
2901 hr
= IWineD3DDevice_Uninit3D(ddraw
->wineD3DDevice
, D3D7CB_DestroySwapChain
);
2902 return E_OUTOFMEMORY
;
2905 TRACE("Successfully initialized 3D.\n");
2910 static HRESULT
ddraw_create_gdi_swapchain(IDirectDrawImpl
*ddraw
, IDirectDrawSurfaceImpl
*primary
)
2912 WINED3DPRESENT_PARAMETERS presentation_parameters
;
2916 window
= ddraw
->dest_window
;
2918 memset(&presentation_parameters
, 0, sizeof(presentation_parameters
));
2920 /* Use the surface description for the device parameters, not the device
2921 * settings. The application might render to an offscreen surface. */
2922 presentation_parameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
2923 presentation_parameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
2924 presentation_parameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2925 presentation_parameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2926 ? primary
->surface_desc
.dwBackBufferCount
: 0;
2927 presentation_parameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2928 presentation_parameters
.MultiSampleQuality
= 0;
2929 presentation_parameters
.SwapEffect
= WINED3DSWAPEFFECT_FLIP
;
2930 presentation_parameters
.hDeviceWindow
= window
;
2931 presentation_parameters
.Windowed
= !(ddraw
->cooperative_level
& DDSCL_FULLSCREEN
);
2932 presentation_parameters
.EnableAutoDepthStencil
= FALSE
; /* Not on GDI swapchains */
2933 presentation_parameters
.AutoDepthStencilFormat
= 0;
2934 presentation_parameters
.Flags
= 0;
2935 presentation_parameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
;
2936 presentation_parameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2937 presentation_parameters
.AutoRestoreDisplayMode
= FALSE
;
2939 ddraw
->d3d_target
= primary
;
2940 hr
= IWineD3DDevice_InitGDI(ddraw
->wineD3DDevice
, &presentation_parameters
);
2941 ddraw
->d3d_target
= NULL
;
2944 WARN("Failed to initialize GDI ddraw implementation, hr %#x.\n", hr
);
2945 primary
->wineD3DSwapChain
= NULL
;
2951 /*****************************************************************************
2952 * IDirectDraw7::CreateSurface
2954 * Creates a new IDirectDrawSurface object and returns its interface.
2956 * The surface connections with wined3d are a bit tricky. Basically it works
2959 * |------------------------| |-----------------|
2960 * | DDraw surface | | WineD3DSurface |
2962 * | WineD3DSurface |-------------->| |
2963 * | Child |<------------->| Parent |
2964 * |------------------------| |-----------------|
2966 * The DDraw surface is the parent of the wined3d surface, and it releases
2967 * the WineD3DSurface when the ddraw surface is destroyed.
2969 * However, for all surfaces which can be in a container in WineD3D,
2970 * we have to do this. These surfaces are usually complex surfaces,
2971 * so this concerns primary surfaces with a front and a back buffer,
2974 * |------------------------| |-----------------|
2975 * | DDraw surface | | Container |
2977 * | Child |<------------->| Parent |
2978 * | Texture |<------------->| |
2979 * | WineD3DSurface |<----| | Levels |<--|
2980 * | Complex connection | | | | |
2981 * |------------------------| | |-----------------| |
2985 * | |------------------| | |-----------------| |
2986 * | | IParent | |-------->| WineD3DSurface | |
2988 * | | Child |<------------->| Parent | |
2989 * | | | | Container |<--|
2990 * | |------------------| |-----------------| |
2992 * | |----------------------| |
2993 * | | DDraw surface 2 | |
2995 * |<->| Complex root Child | |
2997 * | | WineD3DSurface |<----| |
2998 * | |----------------------| | |
3000 * | |---------------------| | |-----------------| |
3001 * | | IParent | |----->| WineD3DSurface | |
3003 * | | Child |<---------->| Parent | |
3004 * | |---------------------| | Container |<--|
3005 * | |-----------------| |
3007 * | ---More surfaces can follow--- |
3009 * The reason is that the IWineD3DSwapchain(render target container)
3010 * and the IWineD3DTexure(Texture container) release the parents
3011 * of their surface's children, but by releasing the complex root
3012 * the surfaces which are complexly attached to it are destroyed
3013 * too. See IDirectDrawSurface::Release for a more detailed
3017 * DDSD: Description of the surface to create
3018 * Surf: Address to store the interface pointer at
3019 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
3020 * aggregation, so it has to be NULL
3024 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3025 * DDERR_* if an error occurs
3027 *****************************************************************************/
3028 static HRESULT
CreateSurface(IDirectDrawImpl
*ddraw
, DDSURFACEDESC2
*DDSD
,
3029 IDirectDrawSurface7
**Surf
, IUnknown
*UnkOuter
)
3031 IDirectDrawSurfaceImpl
*object
= NULL
;
3033 LONG extra_surfaces
= 0;
3034 DDSURFACEDESC2 desc2
;
3035 WINED3DDISPLAYMODE Mode
;
3036 const DWORD sysvidmem
= DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
3038 TRACE("ddraw %p, surface_desc %p, surface %p, outer_unknown %p.\n", ddraw
, DDSD
, Surf
, UnkOuter
);
3040 /* Some checks before we start */
3041 if (TRACE_ON(ddraw
))
3043 TRACE(" (%p) Requesting surface desc :\n", ddraw
);
3044 DDRAW_dump_surface_desc(DDSD
);
3046 EnterCriticalSection(&ddraw_cs
);
3048 if (UnkOuter
!= NULL
)
3050 FIXME("(%p) : outer != NULL?\n", ddraw
);
3051 LeaveCriticalSection(&ddraw_cs
);
3052 return CLASS_E_NOAGGREGATION
; /* unchecked */
3057 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", ddraw
);
3058 LeaveCriticalSection(&ddraw_cs
);
3059 return E_POINTER
; /* unchecked */
3062 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
3064 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
3065 DDSD
->dwFlags
|= DDSD_CAPS
;
3068 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
3070 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
3071 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
3074 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
3076 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
3077 WARN("(%p) Null surface pointer specified, ignore it!\n", ddraw
);
3078 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
3081 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
3082 !(ddraw
->cooperative_level
& DDSCL_EXCLUSIVE
))
3084 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n",
3087 LeaveCriticalSection(&ddraw_cs
);
3088 return DDERR_NOEXCLUSIVEMODE
;
3091 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_BACKBUFFER
| DDSCAPS_PRIMARYSURFACE
))
3093 WARN("Application wanted to create back buffer primary surface\n");
3094 LeaveCriticalSection(&ddraw_cs
);
3095 return DDERR_INVALIDCAPS
;
3098 if((DDSD
->ddsCaps
.dwCaps
& sysvidmem
) == sysvidmem
)
3100 /* This is a special switch in ddrawex.dll, but not allowed in ddraw.dll */
3101 WARN("Application tries to put the surface in both system and video memory\n");
3102 LeaveCriticalSection(&ddraw_cs
);
3104 return DDERR_INVALIDCAPS
;
3107 /* Check cube maps but only if the size includes them */
3108 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
3110 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
3111 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
3113 WARN("Cube map faces requested without cube map flag\n");
3114 LeaveCriticalSection(&ddraw_cs
);
3115 return DDERR_INVALIDCAPS
;
3117 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
3118 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
3120 WARN("Cube map without faces requested\n");
3121 LeaveCriticalSection(&ddraw_cs
);
3122 return DDERR_INVALIDPARAMS
;
3125 /* Quick tests confirm those can be created, but we don't do that yet */
3126 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
3127 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
3129 FIXME("Partial cube maps not supported yet\n");
3133 /* According to the msdn this flag is ignored by CreateSurface */
3134 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
3135 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
3137 /* Modify some flags */
3138 memset(&desc2
, 0, sizeof(desc2
));
3139 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
3140 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
3141 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
3142 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
3144 /* Get the video mode from WineD3D - we will need it */
3145 hr
= IWineD3DDevice_GetDisplayMode(ddraw
->wineD3DDevice
, 0, &Mode
);
3148 ERR("Failed to read display mode from wined3d\n");
3149 switch(ddraw
->orig_bpp
)
3152 Mode
.Format
= WINED3DFMT_P8_UINT
;
3156 Mode
.Format
= WINED3DFMT_B5G5R5X1_UNORM
;
3160 Mode
.Format
= WINED3DFMT_B5G6R5_UNORM
;
3164 Mode
.Format
= WINED3DFMT_B8G8R8_UNORM
;
3168 Mode
.Format
= WINED3DFMT_B8G8R8X8_UNORM
;
3171 Mode
.Width
= ddraw
->orig_width
;
3172 Mode
.Height
= ddraw
->orig_height
;
3175 /* No pixelformat given? Use the current screen format */
3176 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
3178 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
3179 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
3181 /* Wait: It could be a Z buffer */
3182 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
3184 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
3187 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_S1_UINT_D15_UNORM
);
3190 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16_UNORM
);
3193 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_X8D24_UNORM
);
3196 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32_UNORM
);
3199 ERR("Unknown Z buffer bit depth\n");
3204 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
3208 /* No Width or no Height? Use the original screen size
3210 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
3211 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
3213 /* Invalid for non-render targets */
3214 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
3216 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
3218 LeaveCriticalSection(&ddraw_cs
);
3219 return DDERR_INVALIDPARAMS
;
3222 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
3223 desc2
.dwWidth
= Mode
.Width
;
3224 desc2
.dwHeight
= Mode
.Height
;
3227 if (!desc2
.dwWidth
|| !desc2
.dwHeight
)
3229 LeaveCriticalSection(&ddraw_cs
);
3230 return DDERR_INVALIDPARAMS
;
3233 /* Mipmap count fixes */
3234 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3236 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
3238 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
3240 /* Mipmap count is given, should not be 0 */
3241 if( desc2
.u2
.dwMipMapCount
== 0 )
3243 LeaveCriticalSection(&ddraw_cs
);
3244 return DDERR_INVALIDPARAMS
;
3249 /* Undocumented feature: Create sublevels until
3250 * either the width or the height is 1
3252 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
3253 desc2
.dwWidth
: desc2
.dwHeight
;
3254 desc2
.u2
.dwMipMapCount
= 0;
3257 desc2
.u2
.dwMipMapCount
+= 1;
3264 /* Not-complex mipmap -> Mipmapcount = 1 */
3265 desc2
.u2
.dwMipMapCount
= 1;
3267 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
3269 /* There's a mipmap count in the created surface in any case */
3270 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
3272 /* If no mipmap is given, the texture has only one level */
3274 /* The first surface is a front buffer, the back buffer is created afterwards */
3275 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
3277 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
3280 /* The root surface in a cube map is positive x */
3281 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3283 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3284 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3287 /* Create the first surface */
3288 hr
= ddraw_create_surface(ddraw
, &desc2
, &object
, 0);
3291 WARN("ddraw_create_surface failed, hr %#x.\n", hr
);
3292 LeaveCriticalSection(&ddraw_cs
);
3295 object
->is_complex_root
= TRUE
;
3297 *Surf
= (IDirectDrawSurface7
*)object
;
3299 /* Create Additional surfaces if necessary
3300 * This applies to Primary surfaces which have a back buffer count
3301 * set, but not to mipmap textures. In case of Mipmap textures,
3302 * wineD3D takes care of the creation of additional surfaces
3304 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
3306 extra_surfaces
= DDSD
->dwBackBufferCount
;
3307 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
3308 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
3309 desc2
.dwBackBufferCount
= 0;
3313 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3315 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
3316 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3317 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3318 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
3319 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
3320 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3321 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
3322 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
3323 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3324 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
3325 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
3326 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3327 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
3328 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
3329 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
3330 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
3331 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
3334 hr
|= CreateAdditionalSurfaces(ddraw
, object
, extra_surfaces
, desc2
, FALSE
);
3337 /* This destroys and possibly created surfaces too */
3338 IDirectDrawSurface_Release((IDirectDrawSurface7
*)object
);
3339 LeaveCriticalSection(&ddraw_cs
);
3343 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
3344 * But attach the d3ddevice only if the currently created surface was
3345 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
3346 * The only case I can think of where this doesn't apply is when a
3347 * 2D app was configured by the user to run with OpenGL and it didn't create
3348 * the render target as first surface. In this case the render target creation
3349 * will cause the 3D init.
3351 if( (ddraw
->ImplType
== SURFACE_OPENGL
) && !(ddraw
->d3d_initialized
) &&
3352 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
3354 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
3357 /* Search for the primary to use as render target */
3358 LIST_FOR_EACH(entry
, &ddraw
->surface_list
)
3360 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3361 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
3362 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
3366 TRACE("Using primary %p as render target\n", target
);
3371 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", ddraw
, target
);
3372 hr
= ddraw_attach_d3d_device(ddraw
, target
);
3375 IDirectDrawSurfaceImpl
*release_surf
;
3376 ERR("ddraw_attach_d3d_device failed, hr %#x\n", hr
);
3379 /* The before created surface structures are in an incomplete state here.
3380 * WineD3D holds the reference on the IParents, and it released them on the failure
3381 * already. So the regular release method implementation would fail on the attempt
3382 * to destroy either the IParents or the swapchain. So free the surface here.
3383 * The surface structure here is a list, not a tree, because onscreen targets
3384 * cannot be cube textures
3388 release_surf
= object
;
3389 object
= object
->complex_array
[0];
3390 ddraw_surface_destroy(release_surf
);
3392 LeaveCriticalSection(&ddraw_cs
);
3396 else if(!(ddraw
->d3d_initialized
) && desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
3398 ddraw_create_gdi_swapchain(ddraw
, object
);
3401 /* Addref the ddraw interface to keep an reference for each surface */
3402 IDirectDraw7_AddRef(&ddraw
->IDirectDraw7_iface
);
3403 object
->ifaceToRelease
= (IUnknown
*)&ddraw
->IDirectDraw7_iface
;
3405 /* Create a WineD3DTexture if a texture was requested */
3406 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
3408 enum wined3d_format_id Format
;
3410 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
3412 ddraw
->tex_root
= object
;
3414 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
3416 /* a mipmap is created, create enough levels */
3417 levels
= desc2
.u2
.dwMipMapCount
;
3421 /* No mipmap is created, create one level */
3425 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
3426 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
3428 Pool
= WINED3DPOOL_SYSTEMMEM
;
3430 /* Should I forward the MANAGED cap to the managed pool ? */
3432 /* Get the format. It's set already by CreateNewSurface */
3433 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
3435 /* The surfaces are already created, the callback only
3436 * passes the IWineD3DSurface to WineD3D
3438 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
3440 hr
= IWineD3DDevice_CreateCubeTexture(ddraw
->wineD3DDevice
, DDSD
->dwWidth
, levels
, 0,
3441 Format
, Pool
, object
, &ddraw_null_wined3d_parent_ops
, &object
->wineD3DTexture
);
3445 hr
= IWineD3DDevice_CreateTexture(ddraw
->wineD3DDevice
, DDSD
->dwWidth
, DDSD
->dwHeight
,
3446 levels
, 0, Format
, Pool
, object
, &ddraw_null_wined3d_parent_ops
, &object
->wineD3DTexture
);
3448 ddraw
->tex_root
= NULL
;
3451 LeaveCriticalSection(&ddraw_cs
);
3455 static HRESULT WINAPI
ddraw7_CreateSurface(IDirectDraw7
*iface
, DDSURFACEDESC2
*surface_desc
,
3456 IDirectDrawSurface7
**surface
, IUnknown
*outer_unknown
)
3458 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3460 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3461 iface
, surface_desc
, surface
, outer_unknown
);
3463 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3465 WARN("Application supplied invalid surface descriptor\n");
3466 return DDERR_INVALIDPARAMS
;
3469 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3471 if (TRACE_ON(ddraw
))
3473 TRACE(" (%p) Requesting surface desc :\n", iface
);
3474 DDRAW_dump_surface_desc(surface_desc
);
3477 WARN("Application tried to create an explicit front or back buffer\n");
3478 return DDERR_INVALIDCAPS
;
3481 return CreateSurface(This
, surface_desc
, surface
, outer_unknown
);
3484 static HRESULT WINAPI
ddraw4_CreateSurface(IDirectDraw4
*iface
,
3485 DDSURFACEDESC2
*surface_desc
, IDirectDrawSurface4
**surface
, IUnknown
*outer_unknown
)
3487 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3488 IDirectDrawSurfaceImpl
*impl
;
3491 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3492 iface
, surface_desc
, surface
, outer_unknown
);
3494 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC2
))
3496 WARN("Application supplied invalid surface descriptor\n");
3497 return DDERR_INVALIDPARAMS
;
3500 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3502 if (TRACE_ON(ddraw
))
3504 TRACE(" (%p) Requesting surface desc :\n", iface
);
3505 DDRAW_dump_surface_desc(surface_desc
);
3508 WARN("Application tried to create an explicit front or back buffer\n");
3509 return DDERR_INVALIDCAPS
;
3512 hr
= CreateSurface(This
, surface_desc
, (IDirectDrawSurface7
**)surface
, outer_unknown
);
3513 impl
= (IDirectDrawSurfaceImpl
*)*surface
;
3514 if (SUCCEEDED(hr
) && impl
)
3516 ddraw_set_surface_version(impl
, 4);
3517 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3518 IDirectDraw4_AddRef(iface
);
3519 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3525 static HRESULT WINAPI
ddraw3_CreateSurface(IDirectDraw3
*iface
, DDSURFACEDESC
*surface_desc
,
3526 IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3528 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3529 IDirectDrawSurface7
*surface7
;
3530 IDirectDrawSurfaceImpl
*impl
;
3533 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3534 iface
, surface_desc
, surface
, outer_unknown
);
3536 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3538 WARN("Application supplied invalid surface descriptor\n");
3539 return DDERR_INVALIDPARAMS
;
3542 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3544 if (TRACE_ON(ddraw
))
3546 TRACE(" (%p) Requesting surface desc :\n", iface
);
3547 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3550 WARN("Application tried to create an explicit front or back buffer\n");
3551 return DDERR_INVALIDCAPS
;
3554 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3561 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3562 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3563 ddraw_set_surface_version(impl
, 3);
3564 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3565 IDirectDraw3_AddRef(iface
);
3566 impl
->ifaceToRelease
= (IUnknown
*)iface
;
3571 static HRESULT WINAPI
ddraw2_CreateSurface(IDirectDraw2
*iface
,
3572 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3574 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3575 IDirectDrawSurface7
*surface7
;
3576 IDirectDrawSurfaceImpl
*impl
;
3579 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3580 iface
, surface_desc
, surface
, outer_unknown
);
3582 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3584 WARN("Application supplied invalid surface descriptor\n");
3585 return DDERR_INVALIDPARAMS
;
3588 if(surface_desc
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
))
3590 if (TRACE_ON(ddraw
))
3592 TRACE(" (%p) Requesting surface desc :\n", iface
);
3593 DDRAW_dump_surface_desc((LPDDSURFACEDESC2
)surface_desc
);
3596 WARN("Application tried to create an explicit front or back buffer\n");
3597 return DDERR_INVALIDCAPS
;
3600 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3607 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3608 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3609 ddraw_set_surface_version(impl
, 2);
3610 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3611 impl
->ifaceToRelease
= NULL
;
3616 static HRESULT WINAPI
ddraw1_CreateSurface(IDirectDraw
*iface
,
3617 DDSURFACEDESC
*surface_desc
, IDirectDrawSurface
**surface
, IUnknown
*outer_unknown
)
3619 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3620 IDirectDrawSurface7
*surface7
;
3621 IDirectDrawSurfaceImpl
*impl
;
3624 TRACE("iface %p, surface_desc %p, surface %p, outer_unknown %p.\n",
3625 iface
, surface_desc
, surface
, outer_unknown
);
3627 if(surface_desc
== NULL
|| surface_desc
->dwSize
!= sizeof(DDSURFACEDESC
))
3629 WARN("Application supplied invalid surface descriptor\n");
3630 return DDERR_INVALIDPARAMS
;
3633 /* Remove front buffer flag, this causes failure in v7, and its added to normal
3634 * primaries anyway. */
3635 surface_desc
->ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
;
3636 hr
= CreateSurface(This
, (DDSURFACEDESC2
*)surface_desc
, &surface7
, outer_unknown
);
3643 impl
= (IDirectDrawSurfaceImpl
*)surface7
;
3644 *surface
= (IDirectDrawSurface
*)&impl
->IDirectDrawSurface3_vtbl
;
3645 ddraw_set_surface_version(impl
, 1);
3646 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
3647 impl
->ifaceToRelease
= NULL
;
3652 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
3653 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
3656 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
3657 const DDPIXELFORMAT
*provided
)
3659 /* Some flags must be present in both or neither for a match. */
3660 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
3661 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
3662 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
3664 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3667 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
3670 if (requested
->dwFlags
& DDPF_FOURCC
)
3671 if (requested
->dwFourCC
!= provided
->dwFourCC
)
3674 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
3675 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3676 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
3679 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3680 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
3681 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
3684 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
3685 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
3688 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
3689 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
3691 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
3694 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
3695 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
3701 static BOOL
ddraw_match_surface_desc(const DDSURFACEDESC2
*requested
, const DDSURFACEDESC2
*provided
)
3710 #define CMP(FLAG, FIELD) \
3711 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
3712 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
3714 static const struct compare_info compare
[] =
3716 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
3717 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
3719 CMP(CKDESTBLT
, ddckCKDestBlt
),
3720 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
3721 CMP(CKSRCBLT
, ddckCKSrcBlt
),
3722 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
3723 CMP(HEIGHT
, dwHeight
),
3724 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
3725 CMP(LPSURFACE
, lpSurface
),
3726 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
3727 CMP(PITCH
, u1
/* lPitch */),
3728 /* PIXELFORMAT: manual */
3729 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
3730 CMP(TEXTURESTAGE
, dwTextureStage
),
3731 CMP(WIDTH
, dwWidth
),
3732 /* ZBUFFERBITDEPTH: "obsolete" */
3739 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
3742 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
3744 if (requested
->dwFlags
& compare
[i
].flag
3745 && memcmp((const char *)provided
+ compare
[i
].offset
,
3746 (const char *)requested
+ compare
[i
].offset
,
3747 compare
[i
].size
) != 0)
3751 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
3753 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
3754 &provided
->u4
.ddpfPixelFormat
))
3761 #undef DDENUMSURFACES_SEARCHTYPE
3762 #undef DDENUMSURFACES_MATCHTYPE
3764 struct surfacescallback_context
3766 LPDDENUMSURFACESCALLBACK func
;
3770 static HRESULT CALLBACK
EnumSurfacesCallbackThunk(IDirectDrawSurface7
*surface
,
3771 DDSURFACEDESC2
*surface_desc
, void *context
)
3773 struct surfacescallback_context
*cbcontext
= context
;
3775 return cbcontext
->func((IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)surface
)->IDirectDrawSurface3_vtbl
,
3776 (DDSURFACEDESC
*)surface_desc
, cbcontext
->context
);
3779 /*****************************************************************************
3780 * IDirectDraw7::EnumSurfaces
3782 * Loops through all surfaces attached to this device and calls the
3783 * application callback. This can't be relayed to WineD3DDevice,
3784 * because some WineD3DSurfaces' parents are IParent objects
3787 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
3788 * DDSD: Description to filter for
3789 * Context: Application-provided pointer, it's passed unmodified to the
3791 * Callback: Address to call for each surface
3794 * DDERR_INVALIDPARAMS if the callback is NULL
3797 *****************************************************************************/
3798 static HRESULT WINAPI
ddraw7_EnumSurfaces(IDirectDraw7
*iface
, DWORD Flags
,
3799 DDSURFACEDESC2
*DDSD
, void *Context
, LPDDENUMSURFACESCALLBACK7 Callback
)
3801 /* The surface enumeration is handled by WineDDraw,
3802 * because it keeps track of all surfaces attached to
3803 * it. The filtering is done by our callback function,
3804 * because WineDDraw doesn't handle ddraw-like surface
3807 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
3808 IDirectDrawSurfaceImpl
*surf
;
3810 DDSURFACEDESC2 desc
;
3811 struct list
*entry
, *entry2
;
3813 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3814 iface
, Flags
, DDSD
, Context
, Callback
);
3816 all
= Flags
& DDENUMSURFACES_ALL
;
3817 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
3819 EnterCriticalSection(&ddraw_cs
);
3823 LeaveCriticalSection(&ddraw_cs
);
3824 return DDERR_INVALIDPARAMS
;
3827 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
3828 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
3830 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
3831 if (all
|| (nomatch
!= ddraw_match_surface_desc(DDSD
, &surf
->surface_desc
)))
3833 desc
= surf
->surface_desc
;
3834 IDirectDrawSurface7_AddRef((IDirectDrawSurface7
*)surf
);
3835 if (Callback((IDirectDrawSurface7
*)surf
, &desc
, Context
) != DDENUMRET_OK
)
3837 LeaveCriticalSection(&ddraw_cs
);
3842 LeaveCriticalSection(&ddraw_cs
);
3846 static HRESULT WINAPI
ddraw4_EnumSurfaces(IDirectDraw4
*iface
, DWORD flags
,
3847 DDSURFACEDESC2
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK2 callback
)
3849 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3851 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3852 iface
, flags
, surface_desc
, context
, callback
);
3854 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, surface_desc
, context
,
3855 (LPDDENUMSURFACESCALLBACK7
)callback
);
3858 static HRESULT WINAPI
ddraw3_EnumSurfaces(IDirectDraw3
*iface
, DWORD flags
,
3859 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3861 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3862 struct surfacescallback_context cbcontext
;
3864 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3865 iface
, flags
, surface_desc
, context
, callback
);
3867 cbcontext
.func
= callback
;
3868 cbcontext
.context
= context
;
3870 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3871 &cbcontext
, EnumSurfacesCallbackThunk
);
3874 static HRESULT WINAPI
ddraw2_EnumSurfaces(IDirectDraw2
*iface
, DWORD flags
,
3875 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3877 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
3878 struct surfacescallback_context cbcontext
;
3880 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3881 iface
, flags
, surface_desc
, context
, callback
);
3883 cbcontext
.func
= callback
;
3884 cbcontext
.context
= context
;
3886 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3887 &cbcontext
, EnumSurfacesCallbackThunk
);
3890 static HRESULT WINAPI
ddraw1_EnumSurfaces(IDirectDraw
*iface
, DWORD flags
,
3891 DDSURFACEDESC
*surface_desc
, void *context
, LPDDENUMSURFACESCALLBACK callback
)
3893 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
3894 struct surfacescallback_context cbcontext
;
3896 TRACE("iface %p, flags %#x, surface_desc %p, context %p, callback %p.\n",
3897 iface
, flags
, surface_desc
, context
, callback
);
3899 cbcontext
.func
= callback
;
3900 cbcontext
.context
= context
;
3902 return ddraw7_EnumSurfaces(&This
->IDirectDraw7_iface
, flags
, (DDSURFACEDESC2
*)surface_desc
,
3903 &cbcontext
, EnumSurfacesCallbackThunk
);
3906 /*****************************************************************************
3907 * DirectDrawCreateClipper (DDRAW.@)
3909 * Creates a new IDirectDrawClipper object.
3912 * Clipper: Address to write the interface pointer to
3913 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3917 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3918 * E_OUTOFMEMORY if allocating the object failed
3920 *****************************************************************************/
3922 DirectDrawCreateClipper(DWORD Flags
,
3923 LPDIRECTDRAWCLIPPER
*Clipper
,
3926 IDirectDrawClipperImpl
* object
;
3929 TRACE("flags %#x, clipper %p, outer_unknown %p.\n",
3930 Flags
, Clipper
, UnkOuter
);
3932 EnterCriticalSection(&ddraw_cs
);
3933 if (UnkOuter
!= NULL
)
3935 LeaveCriticalSection(&ddraw_cs
);
3936 return CLASS_E_NOAGGREGATION
;
3939 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3940 sizeof(IDirectDrawClipperImpl
));
3943 LeaveCriticalSection(&ddraw_cs
);
3944 return E_OUTOFMEMORY
;
3947 hr
= ddraw_clipper_init(object
);
3950 WARN("Failed to initialize clipper, hr %#x.\n", hr
);
3951 HeapFree(GetProcessHeap(), 0, object
);
3952 LeaveCriticalSection(&ddraw_cs
);
3956 TRACE("Created clipper %p.\n", object
);
3957 *Clipper
= (IDirectDrawClipper
*) object
;
3958 LeaveCriticalSection(&ddraw_cs
);
3962 /*****************************************************************************
3963 * IDirectDraw7::CreateClipper
3965 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3967 *****************************************************************************/
3968 static HRESULT WINAPI
ddraw7_CreateClipper(IDirectDraw7
*iface
, DWORD Flags
,
3969 IDirectDrawClipper
**Clipper
, IUnknown
*UnkOuter
)
3971 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3972 iface
, Flags
, Clipper
, UnkOuter
);
3974 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3977 static HRESULT WINAPI
ddraw4_CreateClipper(IDirectDraw4
*iface
, DWORD flags
,
3978 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3980 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
3982 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3983 iface
, flags
, clipper
, outer_unknown
);
3985 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3988 static HRESULT WINAPI
ddraw3_CreateClipper(IDirectDraw3
*iface
, DWORD flags
,
3989 IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
3991 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
3993 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
3994 iface
, flags
, clipper
, outer_unknown
);
3996 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
3999 static HRESULT WINAPI
ddraw2_CreateClipper(IDirectDraw2
*iface
,
4000 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
4002 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
4004 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
4005 iface
, flags
, clipper
, outer_unknown
);
4007 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
4010 static HRESULT WINAPI
ddraw1_CreateClipper(IDirectDraw
*iface
,
4011 DWORD flags
, IDirectDrawClipper
**clipper
, IUnknown
*outer_unknown
)
4013 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
4015 TRACE("iface %p, flags %#x, clipper %p, outer_unknown %p.\n",
4016 iface
, flags
, clipper
, outer_unknown
);
4018 return ddraw7_CreateClipper(&This
->IDirectDraw7_iface
, flags
, clipper
, outer_unknown
);
4021 /*****************************************************************************
4022 * IDirectDraw7::CreatePalette
4024 * Creates a new IDirectDrawPalette object
4027 * Flags: The flags for the new clipper
4028 * ColorTable: Color table to assign to the new clipper
4029 * Palette: Address to write the interface pointer to
4030 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
4034 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
4035 * E_OUTOFMEMORY if allocating the object failed
4037 *****************************************************************************/
4038 static HRESULT WINAPI
ddraw7_CreatePalette(IDirectDraw7
*iface
, DWORD Flags
,
4039 PALETTEENTRY
*ColorTable
, IDirectDrawPalette
**Palette
, IUnknown
*pUnkOuter
)
4041 IDirectDrawImpl
*This
= impl_from_IDirectDraw7(iface
);
4042 IDirectDrawPaletteImpl
*object
;
4045 TRACE("iface %p, flags %#x, color_table %p, palette %p, outer_unknown %p.\n",
4046 iface
, Flags
, ColorTable
, Palette
, pUnkOuter
);
4048 EnterCriticalSection(&ddraw_cs
);
4049 if(pUnkOuter
!= NULL
)
4051 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
4052 LeaveCriticalSection(&ddraw_cs
);
4053 return CLASS_E_NOAGGREGATION
;
4056 /* The refcount test shows that a cooplevel is required for this */
4057 if(!This
->cooperative_level
)
4059 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
4060 LeaveCriticalSection(&ddraw_cs
);
4061 return DDERR_NOCOOPERATIVELEVELSET
;
4064 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
4067 ERR("Out of memory when allocating memory for a palette implementation\n");
4068 LeaveCriticalSection(&ddraw_cs
);
4069 return E_OUTOFMEMORY
;
4072 hr
= ddraw_palette_init(object
, This
, Flags
, ColorTable
);
4075 WARN("Failed to initialize palette, hr %#x.\n", hr
);
4076 HeapFree(GetProcessHeap(), 0, object
);
4077 LeaveCriticalSection(&ddraw_cs
);
4081 TRACE("Created palette %p.\n", object
);
4082 *Palette
= (IDirectDrawPalette
*)object
;
4083 LeaveCriticalSection(&ddraw_cs
);
4087 static HRESULT WINAPI
ddraw4_CreatePalette(IDirectDraw4
*iface
, DWORD flags
, PALETTEENTRY
*entries
,
4088 IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4090 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
4093 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4094 iface
, flags
, entries
, palette
, outer_unknown
);
4096 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4097 if (SUCCEEDED(hr
) && *palette
)
4099 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4100 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4101 IDirectDraw4_AddRef(iface
);
4102 impl
->ifaceToRelease
= (IUnknown
*)iface
;
4107 static HRESULT WINAPI
ddraw3_CreatePalette(IDirectDraw3
*iface
, DWORD flags
,
4108 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4110 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
4113 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4114 iface
, flags
, entries
, palette
, outer_unknown
);
4116 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4117 if (SUCCEEDED(hr
) && *palette
)
4119 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4120 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4121 IDirectDraw4_AddRef(iface
);
4122 impl
->ifaceToRelease
= (IUnknown
*)iface
;
4128 static HRESULT WINAPI
ddraw2_CreatePalette(IDirectDraw2
*iface
, DWORD flags
,
4129 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4131 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
4134 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4135 iface
, flags
, entries
, palette
, outer_unknown
);
4137 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4138 if (SUCCEEDED(hr
) && *palette
)
4140 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4141 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4142 impl
->ifaceToRelease
= NULL
;
4148 static HRESULT WINAPI
ddraw1_CreatePalette(IDirectDraw
*iface
, DWORD flags
,
4149 PALETTEENTRY
*entries
, IDirectDrawPalette
**palette
, IUnknown
*outer_unknown
)
4151 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
4154 TRACE("iface %p, flags %#x, entries %p, palette %p, outer_unknown %p.\n",
4155 iface
, flags
, entries
, palette
, outer_unknown
);
4157 hr
= ddraw7_CreatePalette(&This
->IDirectDraw7_iface
, flags
, entries
, palette
, outer_unknown
);
4158 if (SUCCEEDED(hr
) && *palette
)
4160 IDirectDrawPaletteImpl
*impl
= (IDirectDrawPaletteImpl
*)*palette
;
4161 IDirectDraw7_Release(&This
->IDirectDraw7_iface
);
4162 impl
->ifaceToRelease
= NULL
;
4168 /*****************************************************************************
4169 * IDirectDraw7::DuplicateSurface
4171 * Duplicates a surface. The surface memory points to the same memory as
4172 * the original surface, and it's released when the last surface referencing
4173 * it is released. I guess that's beyond Wine's surface management right now
4174 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
4175 * test application to implement this)
4178 * Src: Address of the source surface
4179 * Dest: Address to write the new surface pointer to
4182 * See IDirectDraw7::CreateSurface
4184 *****************************************************************************/
4185 static HRESULT WINAPI
ddraw7_DuplicateSurface(IDirectDraw7
*iface
,
4186 IDirectDrawSurface7
*Src
, IDirectDrawSurface7
**Dest
)
4188 IDirectDrawSurfaceImpl
*Surf
= (IDirectDrawSurfaceImpl
*)Src
;
4190 FIXME("iface %p, src %p, dst %p partial stub!\n", iface
, Src
, Dest
);
4192 /* For now, simply create a new, independent surface */
4193 return IDirectDraw7_CreateSurface(iface
,
4194 &Surf
->surface_desc
,
4199 static HRESULT WINAPI
ddraw4_DuplicateSurface(IDirectDraw4
*iface
, IDirectDrawSurface4
*src
,
4200 IDirectDrawSurface4
**dst
)
4202 IDirectDrawImpl
*This
= impl_from_IDirectDraw4(iface
);
4204 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4206 return ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, (IDirectDrawSurface7
*)src
,
4207 (IDirectDrawSurface7
**)dst
);
4210 static HRESULT WINAPI
ddraw3_DuplicateSurface(IDirectDraw3
*iface
, IDirectDrawSurface
*src
,
4211 IDirectDrawSurface
**dst
)
4213 IDirectDrawImpl
*This
= impl_from_IDirectDraw3(iface
);
4214 IDirectDrawSurface7
*src7
, *dst7
;
4217 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4218 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4219 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4222 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4226 static HRESULT WINAPI
ddraw2_DuplicateSurface(IDirectDraw2
*iface
,
4227 IDirectDrawSurface
*src
, IDirectDrawSurface
**dst
)
4229 IDirectDrawImpl
*This
= impl_from_IDirectDraw2(iface
);
4230 IDirectDrawSurface7
*src7
, *dst7
;
4233 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4234 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4235 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4238 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4242 static HRESULT WINAPI
ddraw1_DuplicateSurface(IDirectDraw
*iface
, IDirectDrawSurface
*src
,
4243 IDirectDrawSurface
**dst
)
4245 IDirectDrawImpl
*This
= impl_from_IDirectDraw(iface
);
4246 IDirectDrawSurface7
*src7
, *dst7
;
4249 TRACE("iface %p, src %p, dst %p.\n", iface
, src
, dst
);
4250 src7
= (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)src
);
4251 hr
= ddraw7_DuplicateSurface(&This
->IDirectDraw7_iface
, src7
, &dst7
);
4254 *dst
= (IDirectDrawSurface
*)&((IDirectDrawSurfaceImpl
*)dst7
)->IDirectDrawSurface3_vtbl
;
4258 /*****************************************************************************
4259 * IDirect3D7::EnumDevices
4261 * The EnumDevices method for IDirect3D7. It enumerates all supported
4262 * D3D7 devices. Currently the T&L, HAL and RGB devices are enumerated.
4265 * callback: Function to call for each enumerated device
4266 * context: Pointer to pass back to the app
4269 * D3D_OK, or the return value of the GetCaps call
4271 *****************************************************************************/
4272 static HRESULT WINAPI
d3d7_EnumDevices(IDirect3D7
*iface
, LPD3DENUMDEVICESCALLBACK7 callback
, void *context
)
4274 char interface_name_tnl
[] = "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D";
4275 char device_name_tnl
[] = "Wine D3D7 T&L HAL";
4276 char interface_name_hal
[] = "WINE Direct3D7 Hardware acceleration using WineD3D";
4277 char device_name_hal
[] = "Wine D3D7 HAL";
4278 char interface_name_rgb
[] = "WINE Direct3D7 RGB Software Emulation using WineD3D";
4279 char device_name_rgb
[] = "Wine D3D7 RGB";
4281 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4282 D3DDEVICEDESC7 device_desc7
;
4283 D3DDEVICEDESC device_desc1
;
4286 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4288 EnterCriticalSection(&ddraw_cs
);
4290 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
4293 LeaveCriticalSection(&ddraw_cs
);
4296 callback(interface_name_tnl
, device_name_tnl
, &device_desc7
, context
);
4298 device_desc7
.deviceGUID
= IID_IDirect3DHALDevice
;
4299 callback(interface_name_hal
, device_name_hal
, &device_desc7
, context
);
4301 device_desc7
.deviceGUID
= IID_IDirect3DRGBDevice
;
4302 callback(interface_name_rgb
, device_name_rgb
, &device_desc7
, context
);
4304 TRACE("End of enumeration.\n");
4306 LeaveCriticalSection(&ddraw_cs
);
4311 /*****************************************************************************
4312 * IDirect3D3::EnumDevices
4314 * Enumerates all supported Direct3DDevice interfaces. This is the
4315 * implementation for Direct3D 1 to Direc3D 3, Version 7 has its own.
4317 * Version 1, 2 and 3
4320 * callback: Application-provided routine to call for each enumerated device
4321 * Context: Pointer to pass to the callback
4324 * D3D_OK on success,
4325 * The result of IDirect3DImpl_GetCaps if it failed
4327 *****************************************************************************/
4328 static HRESULT WINAPI
d3d3_EnumDevices(IDirect3D3
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4330 static CHAR wined3d_description
[] = "Wine D3DDevice using WineD3D and OpenGL";
4332 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4333 D3DDEVICEDESC device_desc1
, hal_desc
, hel_desc
;
4334 D3DDEVICEDESC7 device_desc7
;
4337 /* Some games (Motoracer 2 demo) have the bad idea to modify the device
4338 * name string. Let's put the string in a sufficiently sized array in
4339 * writable memory. */
4340 char device_name
[50];
4341 strcpy(device_name
,"Direct3D HEL");
4343 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4345 EnterCriticalSection(&ddraw_cs
);
4347 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &device_desc1
, &device_desc7
);
4350 LeaveCriticalSection(&ddraw_cs
);
4354 /* Do I have to enumerate the reference id? Note from old d3d7:
4355 * "It seems that enumerating the reference IID on Direct3D 1 games
4356 * (AvP / Motoracer2) breaks them". So do not enumerate this iid in V1
4358 * There's a registry key HKLM\Software\Microsoft\Direct3D\Drivers,
4359 * EnumReference which enables / disables enumerating the reference
4360 * rasterizer. It's a DWORD, 0 means disabled, 2 means enabled. The
4361 * enablerefrast.reg and disablerefrast.reg files in the DirectX 7.0 sdk
4362 * demo directory suggest this.
4364 * Some games(GTA 2) seem to use the second enumerated device, so I have
4365 * to enumerate at least 2 devices. So enumerate the reference device to
4368 * Other games (Rollcage) tell emulation and hal device apart by certain
4369 * flags. Rollcage expects D3DPTEXTURECAPS_POW2 to be set (yeah, it is a
4370 * limitation flag), and it refuses all devices that have the perspective
4371 * flag set. This way it refuses the emulation device, and HAL devices
4372 * never have POW2 unset in d3d7 on windows. */
4373 if (This
->d3dversion
!= 1)
4375 static CHAR reference_description
[] = "RGB Direct3D emulation";
4377 TRACE("Enumerating WineD3D D3DDevice interface.\n");
4378 hal_desc
= device_desc1
;
4379 hel_desc
= device_desc1
;
4380 /* The rgb device has the pow2 flag set in the hel caps, but not in the hal caps. */
4381 hal_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4382 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4383 hal_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4384 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4385 hr
= callback((GUID
*)&IID_IDirect3DRGBDevice
, reference_description
,
4386 device_name
, &hal_desc
, &hel_desc
, context
);
4387 if (hr
!= D3DENUMRET_OK
)
4389 TRACE("Application cancelled the enumeration.\n");
4390 LeaveCriticalSection(&ddraw_cs
);
4395 strcpy(device_name
,"Direct3D HAL");
4397 TRACE("Enumerating HAL Direct3D device.\n");
4398 hal_desc
= device_desc1
;
4399 hel_desc
= device_desc1
;
4400 /* The hal device does not have the pow2 flag set in hel, but in hal. */
4401 hel_desc
.dpcLineCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4402 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4403 hel_desc
.dpcTriCaps
.dwTextureCaps
&= ~(D3DPTEXTURECAPS_POW2
4404 | D3DPTEXTURECAPS_NONPOW2CONDITIONAL
| D3DPTEXTURECAPS_PERSPECTIVE
);
4405 hr
= callback((GUID
*)&IID_IDirect3DHALDevice
, wined3d_description
,
4406 device_name
, &hal_desc
, &hel_desc
, context
);
4407 if (hr
!= D3DENUMRET_OK
)
4409 TRACE("Application cancelled the enumeration.\n");
4410 LeaveCriticalSection(&ddraw_cs
);
4414 TRACE("End of enumeration.\n");
4416 LeaveCriticalSection(&ddraw_cs
);
4420 static HRESULT WINAPI
d3d2_EnumDevices(IDirect3D2
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4422 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4424 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4426 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4429 static HRESULT WINAPI
d3d1_EnumDevices(IDirect3D
*iface
, LPD3DENUMDEVICESCALLBACK callback
, void *context
)
4431 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4433 TRACE("iface %p, callback %p, context %p.\n", iface
, callback
, context
);
4435 return d3d3_EnumDevices(&This
->IDirect3D3_iface
, callback
, context
);
4438 /*****************************************************************************
4439 * IDirect3D3::CreateLight
4441 * Creates an IDirect3DLight interface. This interface is used in
4442 * Direct3D3 or earlier for lighting. In Direct3D7 it has been replaced
4443 * by the DIRECT3DLIGHT7 structure. Wine's Direct3DLight implementation
4444 * uses the IDirect3DDevice7 interface with D3D7 lights.
4446 * Version 1, 2 and 3
4449 * light: Address to store the new interface pointer
4450 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4455 * DDERR_OUTOFMEMORY if memory allocation failed
4456 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4458 *****************************************************************************/
4459 static HRESULT WINAPI
d3d3_CreateLight(IDirect3D3
*iface
, IDirect3DLight
**light
,
4460 IUnknown
*outer_unknown
)
4462 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4463 IDirect3DLightImpl
*object
;
4465 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4467 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4469 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4472 ERR("Failed to allocate light memory.\n");
4473 return DDERR_OUTOFMEMORY
;
4476 d3d_light_init(object
, This
);
4478 TRACE("Created light %p.\n", object
);
4479 *light
= (IDirect3DLight
*)object
;
4484 static HRESULT WINAPI
d3d2_CreateLight(IDirect3D2
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4486 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4488 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4490 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4493 static HRESULT WINAPI
d3d1_CreateLight(IDirect3D
*iface
, IDirect3DLight
**light
, IUnknown
*outer_unknown
)
4495 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4497 TRACE("iface %p, light %p, outer_unknown %p.\n", iface
, light
, outer_unknown
);
4499 return d3d3_CreateLight(&This
->IDirect3D3_iface
, light
, outer_unknown
);
4502 /*****************************************************************************
4503 * IDirect3D3::CreateMaterial
4505 * Creates an IDirect3DMaterial interface. This interface is used by Direct3D3
4506 * and older versions. The IDirect3DMaterial implementation wraps its
4507 * functionality to IDirect3DDevice7::SetMaterial and friends.
4509 * Version 1, 2 and 3
4512 * material: Address to store the new interface's pointer to
4513 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4518 * DDERR_OUTOFMEMORY if memory allocation failed
4519 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4521 *****************************************************************************/
4522 static HRESULT WINAPI
d3d3_CreateMaterial(IDirect3D3
*iface
, IDirect3DMaterial3
**material
,
4523 IUnknown
*outer_unknown
)
4525 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4526 IDirect3DMaterialImpl
*object
;
4528 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4530 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4532 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4535 ERR("Failed to allocate material memory.\n");
4536 return DDERR_OUTOFMEMORY
;
4539 d3d_material_init(object
, This
);
4541 TRACE("Created material %p.\n", object
);
4542 *material
= (IDirect3DMaterial3
*)object
;
4547 static HRESULT WINAPI
d3d2_CreateMaterial(IDirect3D2
*iface
, IDirect3DMaterial2
**material
, IUnknown
*outer_unknown
)
4549 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4550 IDirect3DMaterial3
*material3
;
4553 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4555 hr
= d3d3_CreateMaterial(&This
->IDirect3D3_iface
, &material3
, outer_unknown
);
4556 *material
= material3
? (IDirect3DMaterial2
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial2_vtbl
: NULL
;
4558 TRACE("Returning material %p.\n", *material
);
4563 static HRESULT WINAPI
d3d1_CreateMaterial(IDirect3D
*iface
, IDirect3DMaterial
**material
, IUnknown
*outer_unknown
)
4565 IDirect3DMaterial3
*material3
;
4568 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4570 TRACE("iface %p, material %p, outer_unknown %p.\n", iface
, material
, outer_unknown
);
4572 hr
= d3d3_CreateMaterial(&This
->IDirect3D3_iface
, &material3
, outer_unknown
);
4573 *material
= material3
? (IDirect3DMaterial
*)&((IDirect3DMaterialImpl
*)material3
)->IDirect3DMaterial_vtbl
: NULL
;
4575 TRACE("Returning material %p.\n", *material
);
4580 /*****************************************************************************
4581 * IDirect3D3::CreateViewport
4583 * Creates an IDirect3DViewport interface. This interface is used
4584 * by Direct3D and earlier versions for Viewport management. In Direct3D7
4585 * it has been replaced by a viewport structure and
4586 * IDirect3DDevice7::*Viewport. Wine's IDirect3DViewport implementation
4587 * uses the IDirect3DDevice7 methods for its functionality
4590 * Viewport: Address to store the new interface pointer
4591 * outer_unknown: Basically for aggregation, but ddraw doesn't support it.
4596 * DDERR_OUTOFMEMORY if memory allocation failed
4597 * CLASS_E_NOAGGREGATION if outer_unknown != NULL
4599 *****************************************************************************/
4600 static HRESULT WINAPI
d3d3_CreateViewport(IDirect3D3
*iface
, IDirect3DViewport3
**viewport
,
4601 IUnknown
*outer_unknown
)
4603 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4604 IDirect3DViewportImpl
*object
;
4606 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4608 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4610 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4613 ERR("Failed to allocate viewport memory.\n");
4614 return DDERR_OUTOFMEMORY
;
4617 d3d_viewport_init(object
, This
);
4619 TRACE("Created viewport %p.\n", object
);
4620 *viewport
= (IDirect3DViewport3
*)object
;
4625 static HRESULT WINAPI
d3d2_CreateViewport(IDirect3D2
*iface
, IDirect3DViewport2
**viewport
, IUnknown
*outer_unknown
)
4627 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4629 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4631 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4635 static HRESULT WINAPI
d3d1_CreateViewport(IDirect3D
*iface
, IDirect3DViewport
**viewport
, IUnknown
*outer_unknown
)
4637 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4639 TRACE("iface %p, viewport %p, outer_unknown %p.\n", iface
, viewport
, outer_unknown
);
4641 return d3d3_CreateViewport(&This
->IDirect3D3_iface
, (IDirect3DViewport3
**)viewport
,
4645 /*****************************************************************************
4646 * IDirect3D3::FindDevice
4648 * This method finds a device with the requested properties and returns a
4649 * device description
4653 * fds: Describes the requested device characteristics
4654 * fdr: Returns the device description
4658 * DDERR_INVALIDPARAMS if no device was found
4660 *****************************************************************************/
4661 static HRESULT WINAPI
d3d3_FindDevice(IDirect3D3
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4663 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4664 D3DDEVICEDESC7 desc7
;
4665 D3DDEVICEDESC desc1
;
4668 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4670 if (!fds
|| !fdr
) return DDERR_INVALIDPARAMS
;
4672 if (fds
->dwSize
!= sizeof(D3DFINDDEVICESEARCH
)
4673 || fdr
->dwSize
!= sizeof(D3DFINDDEVICERESULT
))
4674 return DDERR_INVALIDPARAMS
;
4676 if ((fds
->dwFlags
& D3DFDS_COLORMODEL
)
4677 && fds
->dcmColorModel
!= D3DCOLOR_RGB
)
4679 WARN("Trying to request a non-RGB D3D color model. Not supported.\n");
4680 return DDERR_INVALIDPARAMS
; /* No real idea what to return here :-) */
4683 if (fds
->dwFlags
& D3DFDS_GUID
)
4685 TRACE("Trying to match guid %s.\n", debugstr_guid(&(fds
->guid
)));
4686 if (!IsEqualGUID(&IID_D3DDEVICE_WineD3D
, &fds
->guid
)
4687 && !IsEqualGUID(&IID_IDirect3DHALDevice
, &fds
->guid
)
4688 && !IsEqualGUID(&IID_IDirect3DRGBDevice
, &fds
->guid
))
4690 WARN("No match for this GUID.\n");
4691 return DDERR_NOTFOUND
;
4696 hr
= IDirect3DImpl_GetCaps(This
->wineD3D
, &desc1
, &desc7
);
4697 if (hr
!= D3D_OK
) return hr
;
4699 /* Now return our own GUID */
4700 fdr
->guid
= IID_D3DDEVICE_WineD3D
;
4701 fdr
->ddHwDesc
= desc1
;
4702 fdr
->ddSwDesc
= desc1
;
4704 TRACE("Returning Wine's wined3d device with (undumped) capabilities.\n");
4709 static HRESULT WINAPI
d3d2_FindDevice(IDirect3D2
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4711 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4713 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4715 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4718 static HRESULT WINAPI
d3d1_FindDevice(IDirect3D
*iface
, D3DFINDDEVICESEARCH
*fds
, D3DFINDDEVICERESULT
*fdr
)
4720 IDirectDrawImpl
*This
= impl_from_IDirect3D(iface
);
4722 TRACE("iface %p, fds %p, fdr %p.\n", iface
, fds
, fdr
);
4724 return d3d3_FindDevice(&This
->IDirect3D3_iface
, fds
, fdr
);
4727 /*****************************************************************************
4728 * IDirect3D7::CreateDevice
4730 * Creates an IDirect3DDevice7 interface.
4732 * Version 2, 3 and 7. IDirect3DDevice 1 interfaces are interfaces to
4733 * DirectDraw surfaces and are created with
4734 * IDirectDrawSurface::QueryInterface. This method uses CreateDevice to
4735 * create the device object and QueryInterfaces for IDirect3DDevice
4738 * refiid: IID of the device to create
4739 * Surface: Initial rendertarget
4740 * Device: Address to return the interface pointer
4744 * DDERR_OUTOFMEMORY if memory allocation failed
4745 * DDERR_INVALIDPARAMS if a device exists already
4747 *****************************************************************************/
4748 static HRESULT WINAPI
d3d7_CreateDevice(IDirect3D7
*iface
, REFCLSID riid
,
4749 IDirectDrawSurface7
*surface
, IDirect3DDevice7
**device
)
4751 IDirectDrawSurfaceImpl
*target
= (IDirectDrawSurfaceImpl
*)surface
;
4752 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4753 IDirect3DDeviceImpl
*object
;
4756 TRACE("iface %p, riid %s, surface %p, device %p.\n", iface
, debugstr_guid(riid
), surface
, device
);
4758 EnterCriticalSection(&ddraw_cs
);
4761 /* Fail device creation if non-opengl surfaces are used. */
4762 if (This
->ImplType
!= SURFACE_OPENGL
)
4764 ERR("The application wants to create a Direct3D device, but non-opengl surfaces are set in the registry.\n");
4765 ERR("Please set the surface implementation to opengl or autodetection to allow 3D rendering.\n");
4767 /* We only hit this path if a default surface is set in the registry. Incorrect autodetection
4768 * is caught in CreateSurface or QueryInterface. */
4769 LeaveCriticalSection(&ddraw_cs
);
4773 if (This
->d3ddevice
)
4775 FIXME("Only one Direct3D device per DirectDraw object supported.\n");
4776 LeaveCriticalSection(&ddraw_cs
);
4777 return DDERR_INVALIDPARAMS
;
4780 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4783 ERR("Failed to allocate device memory.\n");
4784 LeaveCriticalSection(&ddraw_cs
);
4785 return DDERR_OUTOFMEMORY
;
4788 hr
= d3d_device_init(object
, This
, target
);
4791 WARN("Failed to initialize device, hr %#x.\n", hr
);
4792 HeapFree(GetProcessHeap(), 0, object
);
4793 LeaveCriticalSection(&ddraw_cs
);
4797 TRACE("Created device %p.\n", object
);
4798 *device
= (IDirect3DDevice7
*)object
;
4800 LeaveCriticalSection(&ddraw_cs
);
4804 static HRESULT WINAPI
d3d3_CreateDevice(IDirect3D3
*iface
, REFCLSID riid
,
4805 IDirectDrawSurface4
*surface
, IDirect3DDevice3
**device
, IUnknown
*outer_unknown
)
4807 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4810 TRACE("iface %p, riid %s, surface %p, device %p, outer_unknown %p.\n",
4811 iface
, debugstr_guid(riid
), surface
, device
, outer_unknown
);
4813 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4815 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
, (IDirectDrawSurface7
*)surface
,
4816 (IDirect3DDevice7
**)device
);
4817 if (*device
) *device
= (IDirect3DDevice3
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice3_vtbl
;
4822 static HRESULT WINAPI
d3d2_CreateDevice(IDirect3D2
*iface
, REFCLSID riid
,
4823 IDirectDrawSurface
*surface
, IDirect3DDevice2
**device
)
4825 IDirectDrawImpl
*This
= impl_from_IDirect3D2(iface
);
4828 TRACE("iface %p, riid %s, surface %p, device %p.\n",
4829 iface
, debugstr_guid(riid
), surface
, device
);
4831 hr
= d3d7_CreateDevice(&This
->IDirect3D7_iface
, riid
,
4832 surface
? (IDirectDrawSurface7
*)surface_from_surface3((IDirectDrawSurface3
*)surface
) : NULL
,
4833 (IDirect3DDevice7
**)device
);
4834 if (*device
) *device
= (IDirect3DDevice2
*)&((IDirect3DDeviceImpl
*)*device
)->IDirect3DDevice2_vtbl
;
4839 /*****************************************************************************
4840 * IDirect3D7::CreateVertexBuffer
4842 * Creates a new vertex buffer object and returns a IDirect3DVertexBuffer7
4848 * desc: Requested Vertex buffer properties
4849 * vertex_buffer: Address to return the interface pointer at
4850 * flags: Some flags, should be 0
4854 * DDERR_OUTOFMEMORY if memory allocation failed
4855 * The return value of IWineD3DDevice::CreateVertexBuffer if this call fails
4856 * DDERR_INVALIDPARAMS if desc or vertex_buffer are NULL
4858 *****************************************************************************/
4859 static HRESULT WINAPI
d3d7_CreateVertexBuffer(IDirect3D7
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4860 IDirect3DVertexBuffer7
**vertex_buffer
, DWORD flags
)
4862 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4863 IDirect3DVertexBufferImpl
*object
;
4866 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x.\n",
4867 iface
, desc
, vertex_buffer
, flags
);
4869 if (!vertex_buffer
|| !desc
) return DDERR_INVALIDPARAMS
;
4871 TRACE("Vertex buffer description:\n");
4872 TRACE(" dwSize %u\n", desc
->dwSize
);
4873 TRACE(" dwCaps %#x\n", desc
->dwCaps
);
4874 TRACE(" FVF %#x\n", desc
->dwFVF
);
4875 TRACE(" dwNumVertices %u\n", desc
->dwNumVertices
);
4877 /* Now create the vertex buffer */
4878 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
4881 ERR("Failed to allocate vertex buffer memory.\n");
4882 return DDERR_OUTOFMEMORY
;
4885 hr
= d3d_vertex_buffer_init(object
, This
, desc
);
4888 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
4889 HeapFree(GetProcessHeap(), 0, object
);
4893 TRACE("Created vertex buffer %p.\n", object
);
4894 *vertex_buffer
= (IDirect3DVertexBuffer7
*)object
;
4899 static HRESULT WINAPI
d3d3_CreateVertexBuffer(IDirect3D3
*iface
, D3DVERTEXBUFFERDESC
*desc
,
4900 IDirect3DVertexBuffer
**vertex_buffer
, DWORD flags
, IUnknown
*outer_unknown
)
4902 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
4905 TRACE("iface %p, desc %p, vertex_buffer %p, flags %#x, outer_unknown %p.\n",
4906 iface
, desc
, vertex_buffer
, flags
, outer_unknown
);
4908 if (outer_unknown
) return CLASS_E_NOAGGREGATION
;
4910 hr
= d3d7_CreateVertexBuffer(&This
->IDirect3D7_iface
, desc
,
4911 (IDirect3DVertexBuffer7
**)vertex_buffer
, flags
);
4913 *vertex_buffer
= (IDirect3DVertexBuffer
*)&((IDirect3DVertexBufferImpl
*)*vertex_buffer
)->IDirect3DVertexBuffer_vtbl
;
4918 /*****************************************************************************
4919 * IDirect3D7::EnumZBufferFormats
4921 * Enumerates all supported Z buffer pixel formats
4927 * callback: callback to call for each pixel format
4928 * context: Pointer to pass back to the callback
4932 * DDERR_INVALIDPARAMS if callback is NULL
4933 * For details, see IWineD3DDevice::EnumZBufferFormats
4935 *****************************************************************************/
4936 static HRESULT WINAPI
d3d7_EnumZBufferFormats(IDirect3D7
*iface
, REFCLSID device_iid
,
4937 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
4939 IDirectDrawImpl
*This
= impl_from_IDirect3D7(iface
);
4940 WINED3DDISPLAYMODE d3ddm
;
4941 WINED3DDEVTYPE type
;
4945 /* Order matters. Specifically, BattleZone II (full version) expects the
4946 * 16-bit depth formats to be listed before the 24 and 32 ones. */
4947 static const enum wined3d_format_id formats
[] =
4949 WINED3DFMT_S1_UINT_D15_UNORM
,
4950 WINED3DFMT_D16_UNORM
,
4951 WINED3DFMT_X8D24_UNORM
,
4952 WINED3DFMT_S4X4_UINT_D24_UNORM
,
4953 WINED3DFMT_D24_UNORM_S8_UINT
,
4954 WINED3DFMT_D32_UNORM
,
4957 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
4958 iface
, debugstr_guid(device_iid
), callback
, context
);
4960 if (!callback
) return DDERR_INVALIDPARAMS
;
4962 if (IsEqualGUID(device_iid
, &IID_IDirect3DHALDevice
)
4963 || IsEqualGUID(device_iid
, &IID_IDirect3DTnLHalDevice
)
4964 || IsEqualGUID(device_iid
, &IID_D3DDEVICE_WineD3D
))
4966 TRACE("Asked for HAL device.\n");
4967 type
= WINED3DDEVTYPE_HAL
;
4969 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRGBDevice
)
4970 || IsEqualGUID(device_iid
, &IID_IDirect3DMMXDevice
))
4972 TRACE("Asked for SW device.\n");
4973 type
= WINED3DDEVTYPE_SW
;
4975 else if (IsEqualGUID(device_iid
, &IID_IDirect3DRefDevice
))
4977 TRACE("Asked for REF device.\n");
4978 type
= WINED3DDEVTYPE_REF
;
4980 else if (IsEqualGUID(device_iid
, &IID_IDirect3DNullDevice
))
4982 TRACE("Asked for NULLREF device.\n");
4983 type
= WINED3DDEVTYPE_NULLREF
;
4987 FIXME("Unexpected device GUID %s.\n", debugstr_guid(device_iid
));
4988 type
= WINED3DDEVTYPE_HAL
;
4991 EnterCriticalSection(&ddraw_cs
);
4992 /* We need an adapter format from somewhere to please wined3d and WGL.
4993 * Use the current display mode. So far all cards offer the same depth
4994 * stencil format for all modes, but if some do not and applications do
4995 * not like that we'll have to find some workaround, like iterating over
4996 * all imaginable formats and collecting all the depth stencil formats we
4998 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
, 0, &d3ddm
);
5000 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
5002 hr
= wined3d_check_device_format(This
->wineD3D
, WINED3DADAPTER_DEFAULT
, type
, d3ddm
.Format
,
5003 WINED3DUSAGE_DEPTHSTENCIL
, WINED3DRTYPE_SURFACE
, formats
[i
], SURFACE_OPENGL
);
5006 DDPIXELFORMAT pformat
;
5008 memset(&pformat
, 0, sizeof(pformat
));
5009 pformat
.dwSize
= sizeof(pformat
);
5010 PixelFormat_WineD3DtoDD(&pformat
, formats
[i
]);
5012 TRACE("Enumerating wined3d format %#x.\n", formats
[i
]);
5013 hr
= callback(&pformat
, context
);
5014 if (hr
!= DDENUMRET_OK
)
5016 TRACE("Format enumeration cancelled by application.\n");
5017 LeaveCriticalSection(&ddraw_cs
);
5022 TRACE("End of enumeration.\n");
5024 LeaveCriticalSection(&ddraw_cs
);
5028 static HRESULT WINAPI
d3d3_EnumZBufferFormats(IDirect3D3
*iface
, REFCLSID device_iid
,
5029 LPD3DENUMPIXELFORMATSCALLBACK callback
, void *context
)
5031 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
5033 TRACE("iface %p, device_iid %s, callback %p, context %p.\n",
5034 iface
, debugstr_guid(device_iid
), callback
, context
);
5036 return d3d7_EnumZBufferFormats(&This
->IDirect3D7_iface
, device_iid
, callback
, context
);
5039 /*****************************************************************************
5040 * IDirect3D7::EvictManagedTextures
5042 * Removes all managed textures (=surfaces with DDSCAPS2_TEXTUREMANAGE or
5043 * DDSCAPS2_D3DTEXTUREMANAGE caps) to be removed from video memory.
5048 * D3D_OK, because it's a stub
5050 *****************************************************************************/
5051 static HRESULT WINAPI
d3d7_EvictManagedTextures(IDirect3D7
*iface
)
5053 FIXME("iface %p stub!\n", iface
);
5055 /* TODO: Just enumerate resources using IWineD3DDevice_EnumResources(),
5056 * then unload surfaces / textures. */
5061 static HRESULT WINAPI
d3d3_EvictManagedTextures(IDirect3D3
*iface
)
5063 IDirectDrawImpl
*This
= impl_from_IDirect3D3(iface
);
5065 TRACE("iface %p.\n", iface
);
5067 return d3d7_EvictManagedTextures(&This
->IDirect3D7_iface
);
5070 /*****************************************************************************
5071 * IDirect3DImpl_GetCaps
5073 * This function retrieves the device caps from wined3d
5074 * and converts it into a D3D7 and D3D - D3D3 structure
5075 * This is a helper function called from various places in ddraw
5078 * wined3d: The interface to get the caps from
5079 * desc1: Old D3D <3 structure to fill (needed)
5080 * desc7: D3D7 device desc structure to fill (needed)
5083 * D3D_OK on success, or the return value of IWineD3D::GetCaps
5085 *****************************************************************************/
5086 HRESULT
IDirect3DImpl_GetCaps(const struct wined3d
*wined3d
, D3DDEVICEDESC
*desc1
, D3DDEVICEDESC7
*desc7
)
5088 WINED3DCAPS wined3d_caps
;
5091 TRACE("wined3d %p, desc1 %p, desc7 %p.\n", wined3d
, desc1
, desc7
);
5093 memset(&wined3d_caps
, 0, sizeof(wined3d_caps
));
5095 EnterCriticalSection(&ddraw_cs
);
5096 hr
= wined3d_get_device_caps(wined3d
, 0, WINED3DDEVTYPE_HAL
, &wined3d_caps
);
5097 LeaveCriticalSection(&ddraw_cs
);
5100 WARN("Failed to get device caps, hr %#x.\n", hr
);
5104 /* Copy the results into the d3d7 and d3d3 structures */
5105 desc7
->dwDevCaps
= wined3d_caps
.DevCaps
;
5106 desc7
->dpcLineCaps
.dwMiscCaps
= wined3d_caps
.PrimitiveMiscCaps
;
5107 desc7
->dpcLineCaps
.dwRasterCaps
= wined3d_caps
.RasterCaps
;
5108 desc7
->dpcLineCaps
.dwZCmpCaps
= wined3d_caps
.ZCmpCaps
;
5109 desc7
->dpcLineCaps
.dwSrcBlendCaps
= wined3d_caps
.SrcBlendCaps
;
5110 desc7
->dpcLineCaps
.dwDestBlendCaps
= wined3d_caps
.DestBlendCaps
;
5111 desc7
->dpcLineCaps
.dwAlphaCmpCaps
= wined3d_caps
.AlphaCmpCaps
;
5112 desc7
->dpcLineCaps
.dwShadeCaps
= wined3d_caps
.ShadeCaps
;
5113 desc7
->dpcLineCaps
.dwTextureCaps
= wined3d_caps
.TextureCaps
;
5114 desc7
->dpcLineCaps
.dwTextureFilterCaps
= wined3d_caps
.TextureFilterCaps
;
5115 desc7
->dpcLineCaps
.dwTextureAddressCaps
= wined3d_caps
.TextureAddressCaps
;
5117 desc7
->dwMaxTextureWidth
= wined3d_caps
.MaxTextureWidth
;
5118 desc7
->dwMaxTextureHeight
= wined3d_caps
.MaxTextureHeight
;
5120 desc7
->dwMaxTextureRepeat
= wined3d_caps
.MaxTextureRepeat
;
5121 desc7
->dwMaxTextureAspectRatio
= wined3d_caps
.MaxTextureAspectRatio
;
5122 desc7
->dwMaxAnisotropy
= wined3d_caps
.MaxAnisotropy
;
5123 desc7
->dvMaxVertexW
= wined3d_caps
.MaxVertexW
;
5125 desc7
->dvGuardBandLeft
= wined3d_caps
.GuardBandLeft
;
5126 desc7
->dvGuardBandTop
= wined3d_caps
.GuardBandTop
;
5127 desc7
->dvGuardBandRight
= wined3d_caps
.GuardBandRight
;
5128 desc7
->dvGuardBandBottom
= wined3d_caps
.GuardBandBottom
;
5130 desc7
->dvExtentsAdjust
= wined3d_caps
.ExtentsAdjust
;
5131 desc7
->dwStencilCaps
= wined3d_caps
.StencilCaps
;
5133 desc7
->dwFVFCaps
= wined3d_caps
.FVFCaps
;
5134 desc7
->dwTextureOpCaps
= wined3d_caps
.TextureOpCaps
;
5136 desc7
->dwVertexProcessingCaps
= wined3d_caps
.VertexProcessingCaps
;
5137 desc7
->dwMaxActiveLights
= wined3d_caps
.MaxActiveLights
;
5139 /* Remove all non-d3d7 caps */
5140 desc7
->dwDevCaps
&= (
5141 D3DDEVCAPS_FLOATTLVERTEX
| D3DDEVCAPS_SORTINCREASINGZ
| D3DDEVCAPS_SORTDECREASINGZ
|
5142 D3DDEVCAPS_SORTEXACT
| D3DDEVCAPS_EXECUTESYSTEMMEMORY
| D3DDEVCAPS_EXECUTEVIDEOMEMORY
|
5143 D3DDEVCAPS_TLVERTEXSYSTEMMEMORY
| D3DDEVCAPS_TLVERTEXVIDEOMEMORY
| D3DDEVCAPS_TEXTURESYSTEMMEMORY
|
5144 D3DDEVCAPS_TEXTUREVIDEOMEMORY
| D3DDEVCAPS_DRAWPRIMTLVERTEX
| D3DDEVCAPS_CANRENDERAFTERFLIP
|
5145 D3DDEVCAPS_TEXTURENONLOCALVIDMEM
| D3DDEVCAPS_DRAWPRIMITIVES2
| D3DDEVCAPS_SEPARATETEXTUREMEMORIES
|
5146 D3DDEVCAPS_DRAWPRIMITIVES2EX
| D3DDEVCAPS_HWTRANSFORMANDLIGHT
| D3DDEVCAPS_CANBLTSYSTONONLOCAL
|
5147 D3DDEVCAPS_HWRASTERIZATION
);
5149 desc7
->dwStencilCaps
&= (
5150 D3DSTENCILCAPS_KEEP
| D3DSTENCILCAPS_ZERO
| D3DSTENCILCAPS_REPLACE
|
5151 D3DSTENCILCAPS_INCRSAT
| D3DSTENCILCAPS_DECRSAT
| D3DSTENCILCAPS_INVERT
|
5152 D3DSTENCILCAPS_INCR
| D3DSTENCILCAPS_DECR
);
5156 desc7
->dwTextureOpCaps
&= (
5157 D3DTEXOPCAPS_DISABLE
| D3DTEXOPCAPS_SELECTARG1
| D3DTEXOPCAPS_SELECTARG2
|
5158 D3DTEXOPCAPS_MODULATE
| D3DTEXOPCAPS_MODULATE2X
| D3DTEXOPCAPS_MODULATE4X
|
5159 D3DTEXOPCAPS_ADD
| D3DTEXOPCAPS_ADDSIGNED
| D3DTEXOPCAPS_ADDSIGNED2X
|
5160 D3DTEXOPCAPS_SUBTRACT
| D3DTEXOPCAPS_ADDSMOOTH
| D3DTEXOPCAPS_BLENDTEXTUREALPHA
|
5161 D3DTEXOPCAPS_BLENDFACTORALPHA
| D3DTEXOPCAPS_BLENDTEXTUREALPHAPM
| D3DTEXOPCAPS_BLENDCURRENTALPHA
|
5162 D3DTEXOPCAPS_PREMODULATE
| D3DTEXOPCAPS_MODULATEALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATECOLOR_ADDALPHA
|
5163 D3DTEXOPCAPS_MODULATEINVALPHA_ADDCOLOR
| D3DTEXOPCAPS_MODULATEINVCOLOR_ADDALPHA
| D3DTEXOPCAPS_BUMPENVMAP
|
5164 D3DTEXOPCAPS_BUMPENVMAPLUMINANCE
| D3DTEXOPCAPS_DOTPRODUCT3
);
5166 desc7
->dwVertexProcessingCaps
&= (
5167 D3DVTXPCAPS_TEXGEN
| D3DVTXPCAPS_MATERIALSOURCE7
| D3DVTXPCAPS_VERTEXFOG
|
5168 D3DVTXPCAPS_DIRECTIONALLIGHTS
| D3DVTXPCAPS_POSITIONALLIGHTS
| D3DVTXPCAPS_LOCALVIEWER
);
5170 desc7
->dpcLineCaps
.dwMiscCaps
&= (
5171 D3DPMISCCAPS_MASKPLANES
| D3DPMISCCAPS_MASKZ
| D3DPMISCCAPS_LINEPATTERNREP
|
5172 D3DPMISCCAPS_CONFORMANT
| D3DPMISCCAPS_CULLNONE
| D3DPMISCCAPS_CULLCW
|
5173 D3DPMISCCAPS_CULLCCW
);
5175 desc7
->dpcLineCaps
.dwRasterCaps
&= (
5176 D3DPRASTERCAPS_DITHER
| D3DPRASTERCAPS_ROP2
| D3DPRASTERCAPS_XOR
|
5177 D3DPRASTERCAPS_PAT
| D3DPRASTERCAPS_ZTEST
| D3DPRASTERCAPS_SUBPIXEL
|
5178 D3DPRASTERCAPS_SUBPIXELX
| D3DPRASTERCAPS_FOGVERTEX
| D3DPRASTERCAPS_FOGTABLE
|
5179 D3DPRASTERCAPS_STIPPLE
| D3DPRASTERCAPS_ANTIALIASSORTDEPENDENT
| D3DPRASTERCAPS_ANTIALIASSORTINDEPENDENT
|
5180 D3DPRASTERCAPS_ANTIALIASEDGES
| D3DPRASTERCAPS_MIPMAPLODBIAS
| D3DPRASTERCAPS_ZBIAS
|
5181 D3DPRASTERCAPS_ZBUFFERLESSHSR
| D3DPRASTERCAPS_FOGRANGE
| D3DPRASTERCAPS_ANISOTROPY
|
5182 D3DPRASTERCAPS_WBUFFER
| D3DPRASTERCAPS_TRANSLUCENTSORTINDEPENDENT
| D3DPRASTERCAPS_WFOG
|
5183 D3DPRASTERCAPS_ZFOG
);
5185 desc7
->dpcLineCaps
.dwZCmpCaps
&= (
5186 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
5187 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
5188 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
5190 desc7
->dpcLineCaps
.dwSrcBlendCaps
&= (
5191 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
5192 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
5193 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
5194 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
5195 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
5197 desc7
->dpcLineCaps
.dwDestBlendCaps
&= (
5198 D3DPBLENDCAPS_ZERO
| D3DPBLENDCAPS_ONE
| D3DPBLENDCAPS_SRCCOLOR
|
5199 D3DPBLENDCAPS_INVSRCCOLOR
| D3DPBLENDCAPS_SRCALPHA
| D3DPBLENDCAPS_INVSRCALPHA
|
5200 D3DPBLENDCAPS_DESTALPHA
| D3DPBLENDCAPS_INVDESTALPHA
| D3DPBLENDCAPS_DESTCOLOR
|
5201 D3DPBLENDCAPS_INVDESTCOLOR
| D3DPBLENDCAPS_SRCALPHASAT
| D3DPBLENDCAPS_BOTHSRCALPHA
|
5202 D3DPBLENDCAPS_BOTHINVSRCALPHA
);
5204 desc7
->dpcLineCaps
.dwAlphaCmpCaps
&= (
5205 D3DPCMPCAPS_NEVER
| D3DPCMPCAPS_LESS
| D3DPCMPCAPS_EQUAL
|
5206 D3DPCMPCAPS_LESSEQUAL
| D3DPCMPCAPS_GREATER
| D3DPCMPCAPS_NOTEQUAL
|
5207 D3DPCMPCAPS_GREATEREQUAL
| D3DPCMPCAPS_ALWAYS
);
5209 desc7
->dpcLineCaps
.dwShadeCaps
&= (
5210 D3DPSHADECAPS_COLORFLATMONO
| D3DPSHADECAPS_COLORFLATRGB
| D3DPSHADECAPS_COLORGOURAUDMONO
|
5211 D3DPSHADECAPS_COLORGOURAUDRGB
| D3DPSHADECAPS_COLORPHONGMONO
| D3DPSHADECAPS_COLORPHONGRGB
|
5212 D3DPSHADECAPS_SPECULARFLATMONO
| D3DPSHADECAPS_SPECULARFLATRGB
| D3DPSHADECAPS_SPECULARGOURAUDMONO
|
5213 D3DPSHADECAPS_SPECULARGOURAUDRGB
| D3DPSHADECAPS_SPECULARPHONGMONO
| D3DPSHADECAPS_SPECULARPHONGRGB
|
5214 D3DPSHADECAPS_ALPHAFLATBLEND
| D3DPSHADECAPS_ALPHAFLATSTIPPLED
| D3DPSHADECAPS_ALPHAGOURAUDBLEND
|
5215 D3DPSHADECAPS_ALPHAGOURAUDSTIPPLED
| D3DPSHADECAPS_ALPHAPHONGBLEND
| D3DPSHADECAPS_ALPHAPHONGSTIPPLED
|
5216 D3DPSHADECAPS_FOGFLAT
| D3DPSHADECAPS_FOGGOURAUD
| D3DPSHADECAPS_FOGPHONG
);
5218 desc7
->dpcLineCaps
.dwTextureCaps
&= (
5219 D3DPTEXTURECAPS_PERSPECTIVE
| D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_ALPHA
|
5220 D3DPTEXTURECAPS_TRANSPARENCY
| D3DPTEXTURECAPS_BORDER
| D3DPTEXTURECAPS_SQUAREONLY
|
5221 D3DPTEXTURECAPS_TEXREPEATNOTSCALEDBYSIZE
| D3DPTEXTURECAPS_ALPHAPALETTE
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
|
5222 D3DPTEXTURECAPS_PROJECTED
| D3DPTEXTURECAPS_CUBEMAP
| D3DPTEXTURECAPS_COLORKEYBLEND
);
5224 desc7
->dpcLineCaps
.dwTextureFilterCaps
&= (
5225 D3DPTFILTERCAPS_NEAREST
| D3DPTFILTERCAPS_LINEAR
| D3DPTFILTERCAPS_MIPNEAREST
|
5226 D3DPTFILTERCAPS_MIPLINEAR
| D3DPTFILTERCAPS_LINEARMIPNEAREST
| D3DPTFILTERCAPS_LINEARMIPLINEAR
|
5227 D3DPTFILTERCAPS_MINFPOINT
| D3DPTFILTERCAPS_MINFLINEAR
| D3DPTFILTERCAPS_MINFANISOTROPIC
|
5228 D3DPTFILTERCAPS_MIPFPOINT
| D3DPTFILTERCAPS_MIPFLINEAR
| D3DPTFILTERCAPS_MAGFPOINT
|
5229 D3DPTFILTERCAPS_MAGFLINEAR
| D3DPTFILTERCAPS_MAGFANISOTROPIC
| D3DPTFILTERCAPS_MAGFAFLATCUBIC
|
5230 D3DPTFILTERCAPS_MAGFGAUSSIANCUBIC
);
5232 desc7
->dpcLineCaps
.dwTextureBlendCaps
&= (
5233 D3DPTBLENDCAPS_DECAL
| D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_DECALALPHA
|
5234 D3DPTBLENDCAPS_MODULATEALPHA
| D3DPTBLENDCAPS_DECALMASK
| D3DPTBLENDCAPS_MODULATEMASK
|
5235 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_ADD
);
5237 desc7
->dpcLineCaps
.dwTextureAddressCaps
&= (
5238 D3DPTADDRESSCAPS_WRAP
| D3DPTADDRESSCAPS_MIRROR
| D3DPTADDRESSCAPS_CLAMP
|
5239 D3DPTADDRESSCAPS_BORDER
| D3DPTADDRESSCAPS_INDEPENDENTUV
);
5241 if (!(desc7
->dpcLineCaps
.dwTextureCaps
& D3DPTEXTURECAPS_POW2
))
5243 /* DirectX7 always has the np2 flag set, no matter what the card
5244 * supports. Some old games (Rollcage) check the caps incorrectly.
5245 * If wined3d supports nonpow2 textures it also has np2 conditional
5247 desc7
->dpcLineCaps
.dwTextureCaps
|= D3DPTEXTURECAPS_POW2
| D3DPTEXTURECAPS_NONPOW2CONDITIONAL
;
5250 /* Fill the missing members, and do some fixup */
5251 desc7
->dpcLineCaps
.dwSize
= sizeof(desc7
->dpcLineCaps
);
5252 desc7
->dpcLineCaps
.dwTextureBlendCaps
= D3DPTBLENDCAPS_ADD
| D3DPTBLENDCAPS_MODULATEMASK
|
5253 D3DPTBLENDCAPS_COPY
| D3DPTBLENDCAPS_DECAL
|
5254 D3DPTBLENDCAPS_DECALALPHA
| D3DPTBLENDCAPS_DECALMASK
|
5255 D3DPTBLENDCAPS_MODULATE
| D3DPTBLENDCAPS_MODULATEALPHA
;
5256 desc7
->dpcLineCaps
.dwStippleWidth
= 32;
5257 desc7
->dpcLineCaps
.dwStippleHeight
= 32;
5258 /* Use the same for the TriCaps */
5259 desc7
->dpcTriCaps
= desc7
->dpcLineCaps
;
5261 desc7
->dwDeviceRenderBitDepth
= DDBD_16
| DDBD_24
| DDBD_32
;
5262 desc7
->dwDeviceZBufferBitDepth
= DDBD_16
| DDBD_24
;
5263 desc7
->dwMinTextureWidth
= 1;
5264 desc7
->dwMinTextureHeight
= 1;
5266 /* Convert DWORDs safely to WORDs */
5267 if (wined3d_caps
.MaxTextureBlendStages
> 0xffff) desc7
->wMaxTextureBlendStages
= 0xffff;
5268 else desc7
->wMaxTextureBlendStages
= (WORD
)wined3d_caps
.MaxTextureBlendStages
;
5269 if (wined3d_caps
.MaxSimultaneousTextures
> 0xffff) desc7
->wMaxSimultaneousTextures
= 0xffff;
5270 else desc7
->wMaxSimultaneousTextures
= (WORD
)wined3d_caps
.MaxSimultaneousTextures
;
5272 if (wined3d_caps
.MaxUserClipPlanes
> 0xffff) desc7
->wMaxUserClipPlanes
= 0xffff;
5273 else desc7
->wMaxUserClipPlanes
= (WORD
)wined3d_caps
.MaxUserClipPlanes
;
5274 if (wined3d_caps
.MaxVertexBlendMatrices
> 0xffff) desc7
->wMaxVertexBlendMatrices
= 0xffff;
5275 else desc7
->wMaxVertexBlendMatrices
= (WORD
)wined3d_caps
.MaxVertexBlendMatrices
;
5277 desc7
->deviceGUID
= IID_IDirect3DTnLHalDevice
;
5279 desc7
->dwReserved1
= 0;
5280 desc7
->dwReserved2
= 0;
5281 desc7
->dwReserved3
= 0;
5282 desc7
->dwReserved4
= 0;
5284 /* Fill the old structure */
5285 memset(desc1
, 0, sizeof(*desc1
));
5286 desc1
->dwSize
= sizeof(D3DDEVICEDESC
);
5287 desc1
->dwFlags
= D3DDD_COLORMODEL
5289 | D3DDD_TRANSFORMCAPS
5291 | D3DDD_LIGHTINGCAPS
5294 | D3DDD_DEVICERENDERBITDEPTH
5295 | D3DDD_DEVICEZBUFFERBITDEPTH
5296 | D3DDD_MAXBUFFERSIZE
5297 | D3DDD_MAXVERTEXCOUNT
;
5299 desc1
->dcmColorModel
= D3DCOLOR_RGB
;
5300 desc1
->dwDevCaps
= desc7
->dwDevCaps
;
5301 desc1
->dtcTransformCaps
.dwSize
= sizeof(D3DTRANSFORMCAPS
);
5302 desc1
->dtcTransformCaps
.dwCaps
= D3DTRANSFORMCAPS_CLIP
;
5303 desc1
->bClipping
= TRUE
;
5304 desc1
->dlcLightingCaps
.dwSize
= sizeof(D3DLIGHTINGCAPS
);
5305 desc1
->dlcLightingCaps
.dwCaps
= D3DLIGHTCAPS_DIRECTIONAL
5306 | D3DLIGHTCAPS_PARALLELPOINT
5307 | D3DLIGHTCAPS_POINT
5308 | D3DLIGHTCAPS_SPOT
;
5310 desc1
->dlcLightingCaps
.dwLightingModel
= D3DLIGHTINGMODEL_RGB
;
5311 desc1
->dlcLightingCaps
.dwNumLights
= desc7
->dwMaxActiveLights
;
5313 desc1
->dpcLineCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5314 desc1
->dpcLineCaps
.dwMiscCaps
= desc7
->dpcLineCaps
.dwMiscCaps
;
5315 desc1
->dpcLineCaps
.dwRasterCaps
= desc7
->dpcLineCaps
.dwRasterCaps
;
5316 desc1
->dpcLineCaps
.dwZCmpCaps
= desc7
->dpcLineCaps
.dwZCmpCaps
;
5317 desc1
->dpcLineCaps
.dwSrcBlendCaps
= desc7
->dpcLineCaps
.dwSrcBlendCaps
;
5318 desc1
->dpcLineCaps
.dwDestBlendCaps
= desc7
->dpcLineCaps
.dwDestBlendCaps
;
5319 desc1
->dpcLineCaps
.dwShadeCaps
= desc7
->dpcLineCaps
.dwShadeCaps
;
5320 desc1
->dpcLineCaps
.dwTextureCaps
= desc7
->dpcLineCaps
.dwTextureCaps
;
5321 desc1
->dpcLineCaps
.dwTextureFilterCaps
= desc7
->dpcLineCaps
.dwTextureFilterCaps
;
5322 desc1
->dpcLineCaps
.dwTextureBlendCaps
= desc7
->dpcLineCaps
.dwTextureBlendCaps
;
5323 desc1
->dpcLineCaps
.dwTextureAddressCaps
= desc7
->dpcLineCaps
.dwTextureAddressCaps
;
5324 desc1
->dpcLineCaps
.dwStippleWidth
= desc7
->dpcLineCaps
.dwStippleWidth
;
5325 desc1
->dpcLineCaps
.dwAlphaCmpCaps
= desc7
->dpcLineCaps
.dwAlphaCmpCaps
;
5327 desc1
->dpcTriCaps
.dwSize
= sizeof(D3DPRIMCAPS
);
5328 desc1
->dpcTriCaps
.dwMiscCaps
= desc7
->dpcTriCaps
.dwMiscCaps
;
5329 desc1
->dpcTriCaps
.dwRasterCaps
= desc7
->dpcTriCaps
.dwRasterCaps
;
5330 desc1
->dpcTriCaps
.dwZCmpCaps
= desc7
->dpcTriCaps
.dwZCmpCaps
;
5331 desc1
->dpcTriCaps
.dwSrcBlendCaps
= desc7
->dpcTriCaps
.dwSrcBlendCaps
;
5332 desc1
->dpcTriCaps
.dwDestBlendCaps
= desc7
->dpcTriCaps
.dwDestBlendCaps
;
5333 desc1
->dpcTriCaps
.dwShadeCaps
= desc7
->dpcTriCaps
.dwShadeCaps
;
5334 desc1
->dpcTriCaps
.dwTextureCaps
= desc7
->dpcTriCaps
.dwTextureCaps
;
5335 desc1
->dpcTriCaps
.dwTextureFilterCaps
= desc7
->dpcTriCaps
.dwTextureFilterCaps
;
5336 desc1
->dpcTriCaps
.dwTextureBlendCaps
= desc7
->dpcTriCaps
.dwTextureBlendCaps
;
5337 desc1
->dpcTriCaps
.dwTextureAddressCaps
= desc7
->dpcTriCaps
.dwTextureAddressCaps
;
5338 desc1
->dpcTriCaps
.dwStippleWidth
= desc7
->dpcTriCaps
.dwStippleWidth
;
5339 desc1
->dpcTriCaps
.dwAlphaCmpCaps
= desc7
->dpcTriCaps
.dwAlphaCmpCaps
;
5341 desc1
->dwDeviceRenderBitDepth
= desc7
->dwDeviceRenderBitDepth
;
5342 desc1
->dwDeviceZBufferBitDepth
= desc7
->dwDeviceZBufferBitDepth
;
5343 desc1
->dwMaxBufferSize
= 0;
5344 desc1
->dwMaxVertexCount
= 65536;
5345 desc1
->dwMinTextureWidth
= desc7
->dwMinTextureWidth
;
5346 desc1
->dwMinTextureHeight
= desc7
->dwMinTextureHeight
;
5347 desc1
->dwMaxTextureWidth
= desc7
->dwMaxTextureWidth
;
5348 desc1
->dwMaxTextureHeight
= desc7
->dwMaxTextureHeight
;
5349 desc1
->dwMinStippleWidth
= 1;
5350 desc1
->dwMinStippleHeight
= 1;
5351 desc1
->dwMaxStippleWidth
= 32;
5352 desc1
->dwMaxStippleHeight
= 32;
5353 desc1
->dwMaxTextureRepeat
= desc7
->dwMaxTextureRepeat
;
5354 desc1
->dwMaxTextureAspectRatio
= desc7
->dwMaxTextureAspectRatio
;
5355 desc1
->dwMaxAnisotropy
= desc7
->dwMaxAnisotropy
;
5356 desc1
->dvGuardBandLeft
= desc7
->dvGuardBandLeft
;
5357 desc1
->dvGuardBandRight
= desc7
->dvGuardBandRight
;
5358 desc1
->dvGuardBandTop
= desc7
->dvGuardBandTop
;
5359 desc1
->dvGuardBandBottom
= desc7
->dvGuardBandBottom
;
5360 desc1
->dvExtentsAdjust
= desc7
->dvExtentsAdjust
;
5361 desc1
->dwStencilCaps
= desc7
->dwStencilCaps
;
5362 desc1
->dwFVFCaps
= desc7
->dwFVFCaps
;
5363 desc1
->dwTextureOpCaps
= desc7
->dwTextureOpCaps
;
5364 desc1
->wMaxTextureBlendStages
= desc7
->wMaxTextureBlendStages
;
5365 desc1
->wMaxSimultaneousTextures
= desc7
->wMaxSimultaneousTextures
;
5370 /*****************************************************************************
5371 * IDirectDraw7 VTable
5372 *****************************************************************************/
5373 static const struct IDirectDraw7Vtbl ddraw7_vtbl
=
5376 ddraw7_QueryInterface
,
5381 ddraw7_CreateClipper
,
5382 ddraw7_CreatePalette
,
5383 ddraw7_CreateSurface
,
5384 ddraw7_DuplicateSurface
,
5385 ddraw7_EnumDisplayModes
,
5386 ddraw7_EnumSurfaces
,
5387 ddraw7_FlipToGDISurface
,
5389 ddraw7_GetDisplayMode
,
5390 ddraw7_GetFourCCCodes
,
5391 ddraw7_GetGDISurface
,
5392 ddraw7_GetMonitorFrequency
,
5394 ddraw7_GetVerticalBlankStatus
,
5396 ddraw7_RestoreDisplayMode
,
5397 ddraw7_SetCooperativeLevel
,
5398 ddraw7_SetDisplayMode
,
5399 ddraw7_WaitForVerticalBlank
,
5401 ddraw7_GetAvailableVidMem
,
5403 ddraw7_GetSurfaceFromDC
,
5405 ddraw7_RestoreAllSurfaces
,
5406 ddraw7_TestCooperativeLevel
,
5407 ddraw7_GetDeviceIdentifier
,
5409 ddraw7_StartModeTest
,
5413 static const struct IDirectDraw4Vtbl ddraw4_vtbl
=
5416 ddraw4_QueryInterface
,
5421 ddraw4_CreateClipper
,
5422 ddraw4_CreatePalette
,
5423 ddraw4_CreateSurface
,
5424 ddraw4_DuplicateSurface
,
5425 ddraw4_EnumDisplayModes
,
5426 ddraw4_EnumSurfaces
,
5427 ddraw4_FlipToGDISurface
,
5429 ddraw4_GetDisplayMode
,
5430 ddraw4_GetFourCCCodes
,
5431 ddraw4_GetGDISurface
,
5432 ddraw4_GetMonitorFrequency
,
5434 ddraw4_GetVerticalBlankStatus
,
5436 ddraw4_RestoreDisplayMode
,
5437 ddraw4_SetCooperativeLevel
,
5438 ddraw4_SetDisplayMode
,
5439 ddraw4_WaitForVerticalBlank
,
5441 ddraw4_GetAvailableVidMem
,
5443 ddraw4_GetSurfaceFromDC
,
5445 ddraw4_RestoreAllSurfaces
,
5446 ddraw4_TestCooperativeLevel
,
5447 ddraw4_GetDeviceIdentifier
,
5450 static const struct IDirectDraw3Vtbl ddraw3_vtbl
=
5453 ddraw3_QueryInterface
,
5458 ddraw3_CreateClipper
,
5459 ddraw3_CreatePalette
,
5460 ddraw3_CreateSurface
,
5461 ddraw3_DuplicateSurface
,
5462 ddraw3_EnumDisplayModes
,
5463 ddraw3_EnumSurfaces
,
5464 ddraw3_FlipToGDISurface
,
5466 ddraw3_GetDisplayMode
,
5467 ddraw3_GetFourCCCodes
,
5468 ddraw3_GetGDISurface
,
5469 ddraw3_GetMonitorFrequency
,
5471 ddraw3_GetVerticalBlankStatus
,
5473 ddraw3_RestoreDisplayMode
,
5474 ddraw3_SetCooperativeLevel
,
5475 ddraw3_SetDisplayMode
,
5476 ddraw3_WaitForVerticalBlank
,
5478 ddraw3_GetAvailableVidMem
,
5480 ddraw3_GetSurfaceFromDC
,
5483 static const struct IDirectDraw2Vtbl ddraw2_vtbl
=
5486 ddraw2_QueryInterface
,
5491 ddraw2_CreateClipper
,
5492 ddraw2_CreatePalette
,
5493 ddraw2_CreateSurface
,
5494 ddraw2_DuplicateSurface
,
5495 ddraw2_EnumDisplayModes
,
5496 ddraw2_EnumSurfaces
,
5497 ddraw2_FlipToGDISurface
,
5499 ddraw2_GetDisplayMode
,
5500 ddraw2_GetFourCCCodes
,
5501 ddraw2_GetGDISurface
,
5502 ddraw2_GetMonitorFrequency
,
5504 ddraw2_GetVerticalBlankStatus
,
5506 ddraw2_RestoreDisplayMode
,
5507 ddraw2_SetCooperativeLevel
,
5508 ddraw2_SetDisplayMode
,
5509 ddraw2_WaitForVerticalBlank
,
5511 ddraw2_GetAvailableVidMem
,
5514 static const struct IDirectDrawVtbl ddraw1_vtbl
=
5517 ddraw1_QueryInterface
,
5522 ddraw1_CreateClipper
,
5523 ddraw1_CreatePalette
,
5524 ddraw1_CreateSurface
,
5525 ddraw1_DuplicateSurface
,
5526 ddraw1_EnumDisplayModes
,
5527 ddraw1_EnumSurfaces
,
5528 ddraw1_FlipToGDISurface
,
5530 ddraw1_GetDisplayMode
,
5531 ddraw1_GetFourCCCodes
,
5532 ddraw1_GetGDISurface
,
5533 ddraw1_GetMonitorFrequency
,
5535 ddraw1_GetVerticalBlankStatus
,
5537 ddraw1_RestoreDisplayMode
,
5538 ddraw1_SetCooperativeLevel
,
5539 ddraw1_SetDisplayMode
,
5540 ddraw1_WaitForVerticalBlank
,
5543 static const struct IDirect3D7Vtbl d3d7_vtbl
=
5545 /* IUnknown methods */
5546 d3d7_QueryInterface
,
5549 /* IDirect3D7 methods */
5552 d3d7_CreateVertexBuffer
,
5553 d3d7_EnumZBufferFormats
,
5554 d3d7_EvictManagedTextures
5557 static const struct IDirect3D3Vtbl d3d3_vtbl
=
5559 /* IUnknown methods */
5560 d3d3_QueryInterface
,
5563 /* IDirect3D3 methods */
5566 d3d3_CreateMaterial
,
5567 d3d3_CreateViewport
,
5570 d3d3_CreateVertexBuffer
,
5571 d3d3_EnumZBufferFormats
,
5572 d3d3_EvictManagedTextures
5575 static const struct IDirect3D2Vtbl d3d2_vtbl
=
5577 /* IUnknown methods */
5578 d3d2_QueryInterface
,
5581 /* IDirect3D2 methods */
5584 d3d2_CreateMaterial
,
5585 d3d2_CreateViewport
,
5590 static const struct IDirect3DVtbl d3d1_vtbl
=
5592 /* IUnknown methods */
5593 d3d1_QueryInterface
,
5596 /* IDirect3D methods */
5600 d3d1_CreateMaterial
,
5601 d3d1_CreateViewport
,
5605 /*****************************************************************************
5608 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
5609 * if none was found.
5611 * This function is in ddraw.c and the DDraw object space because D3D7
5612 * vertex buffers are created using the IDirect3D interface to the ddraw
5613 * object, so they can be valid across D3D devices(theoretically. The ddraw
5614 * object also owns the wined3d device
5618 * fvf: Fvf to find the decl for
5621 * NULL in case of an error, the vertex declaration for the FVF otherwise.
5623 *****************************************************************************/
5624 struct wined3d_vertex_declaration
*ddraw_find_decl(IDirectDrawImpl
*This
, DWORD fvf
)
5626 struct wined3d_vertex_declaration
*pDecl
= NULL
;
5628 int p
, low
, high
; /* deliberately signed */
5629 struct FvfToDecl
*convertedDecls
= This
->decls
;
5631 TRACE("Searching for declaration for fvf %08x... ", fvf
);
5634 high
= This
->numConvertedDecls
- 1;
5635 while(low
<= high
) {
5636 p
= (low
+ high
) >> 1;
5638 if(convertedDecls
[p
].fvf
== fvf
) {
5639 TRACE("found %p\n", convertedDecls
[p
].decl
);
5640 return convertedDecls
[p
].decl
;
5641 } else if(convertedDecls
[p
].fvf
< fvf
) {
5647 TRACE("not found. Creating and inserting at position %d.\n", low
);
5649 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->wineD3DDevice
,
5650 fvf
, This
, &ddraw_null_wined3d_parent_ops
, &pDecl
);
5651 if (hr
!= S_OK
) return NULL
;
5653 if(This
->declArraySize
== This
->numConvertedDecls
) {
5654 int grow
= max(This
->declArraySize
/ 2, 8);
5655 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
5656 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
5657 if (!convertedDecls
)
5659 wined3d_vertex_declaration_decref(pDecl
);
5662 This
->decls
= convertedDecls
;
5663 This
->declArraySize
+= grow
;
5666 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
5667 convertedDecls
[low
].decl
= pDecl
;
5668 convertedDecls
[low
].fvf
= fvf
;
5669 This
->numConvertedDecls
++;
5671 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);
5675 /* IWineD3DDeviceParent IUnknown methods */
5677 static inline struct IDirectDrawImpl
*ddraw_from_device_parent(IWineD3DDeviceParent
*iface
)
5679 return (struct IDirectDrawImpl
*)((char*)iface
- FIELD_OFFSET(struct IDirectDrawImpl
, device_parent_vtbl
));
5682 static HRESULT STDMETHODCALLTYPE
device_parent_QueryInterface(IWineD3DDeviceParent
*iface
, REFIID riid
, void **object
)
5684 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5685 return ddraw7_QueryInterface(&This
->IDirectDraw7_iface
, riid
, object
);
5688 static ULONG STDMETHODCALLTYPE
device_parent_AddRef(IWineD3DDeviceParent
*iface
)
5690 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5691 return ddraw7_AddRef(&This
->IDirectDraw7_iface
);
5694 static ULONG STDMETHODCALLTYPE
device_parent_Release(IWineD3DDeviceParent
*iface
)
5696 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5697 return ddraw7_Release(&This
->IDirectDraw7_iface
);
5700 /* IWineD3DDeviceParent methods */
5702 static void STDMETHODCALLTYPE
device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent
*iface
, IWineD3DDevice
*device
)
5704 TRACE("iface %p, device %p\n", iface
, device
);
5707 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSurface(IWineD3DDeviceParent
*iface
,
5708 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
5709 WINED3DPOOL pool
, UINT level
, WINED3DCUBEMAP_FACES face
, IWineD3DSurface
**surface
)
5711 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5712 IDirectDrawSurfaceImpl
*surf
= NULL
;
5714 DDSCAPS2 searchcaps
= This
->tex_root
->surface_desc
.ddsCaps
;
5716 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
5717 "\tpool %#x, level %u, face %u, surface %p\n",
5718 iface
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
5720 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
5723 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
5724 TRACE("Asked for positive x\n");
5725 if (searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
5727 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
5729 surf
= This
->tex_root
; break;
5730 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
5731 TRACE("Asked for negative x\n");
5732 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
5733 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
5734 TRACE("Asked for positive y\n");
5735 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
5736 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
5737 TRACE("Asked for negative y\n");
5738 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
5739 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
5740 TRACE("Asked for positive z\n");
5741 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
5742 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
5743 TRACE("Asked for negative z\n");
5744 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
5745 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
5750 IDirectDrawSurface7
*attached
;
5751 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)This
->tex_root
, &searchcaps
, &attached
);
5752 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5753 IDirectDrawSurface7_Release(attached
);
5755 if (!surf
) ERR("root search surface not found\n");
5757 /* Find the wanted mipmap. There are enough mipmaps in the chain */
5760 IDirectDrawSurface7
*attached
;
5761 IDirectDrawSurface7_GetAttachedSurface((IDirectDrawSurface7
*)surf
, &searchcaps
, &attached
);
5762 if(!attached
) ERR("Surface not found\n");
5763 surf
= (IDirectDrawSurfaceImpl
*)attached
;
5764 IDirectDrawSurface7_Release(attached
);
5768 /* Return the surface */
5769 *surface
= surf
->WineD3DSurface
;
5770 IWineD3DSurface_AddRef(*surface
);
5772 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, surf
);
5777 static HRESULT WINAPI
findRenderTarget(IDirectDrawSurface7
*surface
, DDSURFACEDESC2
*surface_desc
, void *ctx
)
5779 IDirectDrawSurfaceImpl
*s
= (IDirectDrawSurfaceImpl
*)surface
;
5780 IDirectDrawSurfaceImpl
**target
= ctx
;
5782 if (!s
->isRenderTarget
)
5785 IDirectDrawSurface7_Release(surface
);
5786 return DDENUMRET_CANCEL
;
5789 /* Recurse into the surface tree */
5790 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
5792 IDirectDrawSurface7_Release(surface
);
5793 if (*target
) return DDENUMRET_CANCEL
;
5795 return DDENUMRET_OK
;
5798 static HRESULT STDMETHODCALLTYPE
device_parent_CreateRenderTarget(IWineD3DDeviceParent
*iface
,
5799 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
5800 WINED3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, BOOL lockable
,
5801 IWineD3DSurface
**surface
)
5803 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5804 IDirectDrawSurfaceImpl
*d3d_surface
= This
->d3d_target
;
5805 IDirectDrawSurfaceImpl
*target
= NULL
;
5807 TRACE("iface %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5808 "\tmultisample_quality %u, lockable %u, surface %p\n",
5809 iface
, container_parent
, width
, height
, format
, multisample_type
, multisample_quality
, lockable
, surface
);
5811 if (d3d_surface
->isRenderTarget
)
5813 IDirectDrawSurface7_EnumAttachedSurfaces((IDirectDrawSurface7
*)d3d_surface
, &target
, findRenderTarget
);
5817 target
= d3d_surface
;
5822 target
= This
->d3d_target
;
5823 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
5826 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
5828 *surface
= target
->WineD3DSurface
;
5829 IWineD3DSurface_AddRef(*surface
);
5830 target
->isRenderTarget
= TRUE
;
5832 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *surface
, d3d_surface
);
5837 static HRESULT STDMETHODCALLTYPE
device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent
*iface
,
5838 UINT width
, UINT height
, enum wined3d_format_id format
, WINED3DMULTISAMPLE_TYPE multisample_type
,
5839 DWORD multisample_quality
, BOOL discard
, IWineD3DSurface
**surface
)
5841 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5842 IDirectDrawSurfaceImpl
*ddraw_surface
;
5843 DDSURFACEDESC2 ddsd
;
5846 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x,\n"
5847 "\tmultisample_quality %u, discard %u, surface %p\n",
5848 iface
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
5852 /* Create a DirectDraw surface */
5853 memset(&ddsd
, 0, sizeof(ddsd
));
5854 ddsd
.dwSize
= sizeof(ddsd
);
5855 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
5856 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
5857 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5858 ddsd
.dwHeight
= height
;
5859 ddsd
.dwWidth
= width
;
5862 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, format
);
5866 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
5869 This
->depthstencil
= TRUE
;
5870 hr
= IDirectDraw7_CreateSurface(&This
->IDirectDraw7_iface
, &ddsd
,
5871 (IDirectDrawSurface7
**)&ddraw_surface
, NULL
);
5872 This
->depthstencil
= FALSE
;
5875 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
5879 *surface
= ddraw_surface
->WineD3DSurface
;
5880 IWineD3DSurface_AddRef(*surface
);
5881 IDirectDrawSurface7_Release((IDirectDrawSurface7
*)ddraw_surface
);
5886 static HRESULT STDMETHODCALLTYPE
device_parent_CreateVolume(IWineD3DDeviceParent
*iface
,
5887 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
5888 WINED3DPOOL pool
, DWORD usage
, IWineD3DVolume
**volume
)
5890 TRACE("iface %p, container_parent %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p\n",
5891 iface
, container_parent
, width
, height
, depth
, format
, pool
, usage
, volume
);
5893 ERR("Not implemented!\n");
5898 static HRESULT STDMETHODCALLTYPE
device_parent_CreateSwapChain(IWineD3DDeviceParent
*iface
,
5899 WINED3DPRESENT_PARAMETERS
*present_parameters
, IWineD3DSwapChain
**swapchain
)
5901 struct IDirectDrawImpl
*This
= ddraw_from_device_parent(iface
);
5902 IDirectDrawSurfaceImpl
*iterator
;
5905 TRACE("iface %p, present_parameters %p, swapchain %p\n", iface
, present_parameters
, swapchain
);
5907 hr
= IWineD3DDevice_CreateSwapChain(This
->wineD3DDevice
, present_parameters
,
5908 This
->ImplType
, NULL
, swapchain
);
5911 FIXME("(%p) CreateSwapChain failed, returning %#x\n", iface
, hr
);
5916 This
->d3d_target
->wineD3DSwapChain
= *swapchain
;
5917 iterator
= This
->d3d_target
->complex_array
[0];
5920 iterator
->wineD3DSwapChain
= *swapchain
;
5921 iterator
= iterator
->complex_array
[0];
5927 static const IWineD3DDeviceParentVtbl ddraw_wined3d_device_parent_vtbl
=
5929 /* IUnknown methods */
5930 device_parent_QueryInterface
,
5931 device_parent_AddRef
,
5932 device_parent_Release
,
5933 /* IWineD3DDeviceParent methods */
5934 device_parent_WineD3DDeviceCreated
,
5935 device_parent_CreateSurface
,
5936 device_parent_CreateRenderTarget
,
5937 device_parent_CreateDepthStencilSurface
,
5938 device_parent_CreateVolume
,
5939 device_parent_CreateSwapChain
,
5942 HRESULT
ddraw_init(IDirectDrawImpl
*ddraw
, WINED3DDEVTYPE device_type
)
5947 ddraw
->IDirectDraw7_iface
.lpVtbl
= &ddraw7_vtbl
;
5948 ddraw
->IDirectDraw_iface
.lpVtbl
= &ddraw1_vtbl
;
5949 ddraw
->IDirectDraw2_iface
.lpVtbl
= &ddraw2_vtbl
;
5950 ddraw
->IDirectDraw3_iface
.lpVtbl
= &ddraw3_vtbl
;
5951 ddraw
->IDirectDraw4_iface
.lpVtbl
= &ddraw4_vtbl
;
5952 ddraw
->IDirect3D_iface
.lpVtbl
= &d3d1_vtbl
;
5953 ddraw
->IDirect3D2_iface
.lpVtbl
= &d3d2_vtbl
;
5954 ddraw
->IDirect3D3_iface
.lpVtbl
= &d3d3_vtbl
;
5955 ddraw
->IDirect3D7_iface
.lpVtbl
= &d3d7_vtbl
;
5956 ddraw
->device_parent_vtbl
= &ddraw_wined3d_device_parent_vtbl
;
5957 ddraw
->numIfaces
= 1;
5960 /* See comments in IDirectDrawImpl_CreateNewSurface for a description of
5962 ddraw
->ImplType
= DefaultSurfaceType
;
5964 /* Get the current screen settings. */
5966 ddraw
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
5968 ddraw
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
5969 ddraw
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
5971 ddraw
->wineD3D
= wined3d_create(7, &ddraw
->IDirectDraw7_iface
);
5972 if (!ddraw
->wineD3D
)
5974 WARN("Failed to create a wined3d object.\n");
5975 return E_OUTOFMEMORY
;
5978 hr
= wined3d_device_create(ddraw
->wineD3D
, WINED3DADAPTER_DEFAULT
, device_type
, NULL
, 0,
5979 (IWineD3DDeviceParent
*)&ddraw
->device_parent_vtbl
, &ddraw
->wineD3DDevice
);
5982 WARN("Failed to create a wined3d device, hr %#x.\n", hr
);
5983 wined3d_decref(ddraw
->wineD3D
);
5987 /* Get the amount of video memory */
5988 ddraw
->total_vidmem
= IWineD3DDevice_GetAvailableTextureMem(ddraw
->wineD3DDevice
);
5990 list_init(&ddraw
->surface_list
);