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
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
31 #define NONAMELESSUNION
37 #include "wine/exception.h"
42 #include "ddraw_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
47 static BOOL
IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
, const DDSURFACEDESC2
* provided
);
48 static HRESULT WINAPI
IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
, IDirectDrawSurfaceImpl
*primary
);
49 static HRESULT WINAPI
IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
, IDirectDrawSurfaceImpl
**ppSurf
, UINT level
);
51 /* Device identifier. Don't relay it to WineD3D */
52 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
56 { { 0x00010001, 0x00010001 } },
58 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
59 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
63 /*****************************************************************************
65 *****************************************************************************/
67 /*****************************************************************************
68 * IDirectDraw7::QueryInterface
70 * Queries different interfaces of the DirectDraw object. It can return
71 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
72 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
74 * The returned interface is AddRef()-ed before it's returned
76 * Rules for QueryInterface:
77 * http://msdn.microsoft.com/library/default.asp? \
78 * url=/library/en-us/com/html/6db17ed8-06e4-4bae-bc26-113176cc7e0e.asp
80 * Used for version 1, 2, 4 and 7
83 * refiid: Interface ID asked for
84 * obj: Used to return the interface pointer
87 * S_OK if an interface was found
88 * E_NOINTERFACE if the requested interface wasn't found
90 *****************************************************************************/
92 IDirectDrawImpl_QueryInterface(IDirectDraw7
*iface
,
96 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
98 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
100 /* Can change surface impl type */
101 EnterCriticalSection(&ddraw_cs
);
103 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
108 LeaveCriticalSection(&ddraw_cs
);
109 return DDERR_INVALIDPARAMS
;
112 /* Check DirectDraw Interfaces */
113 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
114 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
116 *obj
= ICOM_INTERFACE(This
, IDirectDraw7
);
117 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
119 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
121 *obj
= ICOM_INTERFACE(This
, IDirectDraw4
);
122 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
124 else if ( IsEqualGUID( &IID_IDirectDraw3
, refiid
) )
126 *obj
= ICOM_INTERFACE(This
, IDirectDraw3
);
127 TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This
, *obj
);
129 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
131 *obj
= ICOM_INTERFACE(This
, IDirectDraw2
);
132 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
134 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
136 *obj
= ICOM_INTERFACE(This
, IDirectDraw
);
137 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
141 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
142 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
143 * who had this idea and why. The older interfaces can query and IDirect3D version
144 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
145 * and messy to implement with the common creation function, so it has been left out here.
147 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
148 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
149 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
150 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
152 /* Check the surface implementation */
153 if(This
->ImplType
== SURFACE_UNKNOWN
)
155 /* Apps may create the IDirect3D Interface before the primary surface.
156 * set the surface implementation */
157 This
->ImplType
= SURFACE_OPENGL
;
158 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
160 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
162 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
163 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
164 /* Should I assert(0) here??? */
166 else if(This
->ImplType
!= SURFACE_OPENGL
)
168 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
169 /* Do not abort here, only reject 3D Device creation */
172 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
174 This
->d3dversion
= 1;
175 *obj
= ICOM_INTERFACE(This
, IDirect3D
);
176 TRACE(" returning Direct3D interface at %p.\n", *obj
);
178 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
180 This
->d3dversion
= 2;
181 *obj
= ICOM_INTERFACE(This
, IDirect3D2
);
182 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
184 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
186 This
->d3dversion
= 3;
187 *obj
= ICOM_INTERFACE(This
, IDirect3D3
);
188 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
190 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
192 This
->d3dversion
= 7;
193 *obj
= ICOM_INTERFACE(This
, IDirect3D7
);
194 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
198 /* Unknown interface */
201 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
202 LeaveCriticalSection(&ddraw_cs
);
203 return E_NOINTERFACE
;
206 IUnknown_AddRef( (IUnknown
*) *obj
);
207 LeaveCriticalSection(&ddraw_cs
);
211 /*****************************************************************************
212 * IDirectDraw7::AddRef
214 * Increases the interfaces refcount, basically
216 * DDraw refcounting is a bit tricky. The different DirectDraw interface
217 * versions have individual refcounts, but the IDirect3D interfaces do not.
218 * All interfaces are from one object, that means calling QueryInterface on an
219 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
220 * IDirectDrawImpl object.
222 * That means all AddRef and Release implementations of IDirectDrawX work
223 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
224 * except of IDirect3D7 which thunks to IDirectDraw7
226 * Returns: The new refcount
228 *****************************************************************************/
230 IDirectDrawImpl_AddRef(IDirectDraw7
*iface
)
232 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
233 ULONG ref
= InterlockedIncrement(&This
->ref7
);
235 TRACE("(%p) : incrementing IDirectDraw7 refcount from %u.\n", This
, ref
-1);
237 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
242 /*****************************************************************************
243 * IDirectDrawImpl_Destroy
245 * Destroys a ddraw object if all refcounts are 0. This is to share code
246 * between the IDirectDrawX::Release functions
249 * This: DirectDraw object to destroy
251 *****************************************************************************/
253 IDirectDrawImpl_Destroy(IDirectDrawImpl
*This
)
255 /* Clear the cooplevel to restore window and display mode */
256 IDirectDraw7_SetCooperativeLevel(ICOM_INTERFACE(This
, IDirectDraw7
),
260 /* Destroy the device window if we created one */
261 if(This
->devicewindow
!= 0)
263 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
264 DestroyWindow(This
->devicewindow
);
265 This
->devicewindow
= 0;
268 /* Unregister the window class */
269 UnregisterClassA(This
->classname
, 0);
271 EnterCriticalSection(&ddraw_cs
);
272 list_remove(&This
->ddraw_list_entry
);
273 LeaveCriticalSection(&ddraw_cs
);
275 /* Release the attached WineD3D stuff */
276 IWineD3DDevice_Release(This
->wineD3DDevice
);
277 IWineD3D_Release(This
->wineD3D
);
279 /* Now free the object */
280 HeapFree(GetProcessHeap(), 0, This
);
283 /*****************************************************************************
284 * IDirectDraw7::Release
286 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
288 * Returns: The new refcount
289 *****************************************************************************/
291 IDirectDrawImpl_Release(IDirectDraw7
*iface
)
293 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
294 ULONG ref
= InterlockedDecrement(&This
->ref7
);
296 TRACE("(%p)->() decrementing IDirectDraw7 refcount from %u.\n", This
, ref
+1);
300 ULONG ifacecount
= InterlockedDecrement(&This
->numIfaces
);
301 if(ifacecount
== 0) IDirectDrawImpl_Destroy(This
);
307 /*****************************************************************************
308 * IDirectDraw methods
309 *****************************************************************************/
311 /*****************************************************************************
312 * IDirectDraw7::SetCooperativeLevel
314 * Sets the cooperative level for the DirectDraw object, and the window
315 * assigned to it. The cooperative level determines the general behavior
316 * of the DirectDraw application
318 * Warning: This is quite tricky, as it's not really documented which
319 * cooperative levels can be combined with each other. If a game fails
320 * after this function, try to check the cooperative levels passed on
321 * Windows, and if it returns something different.
323 * If you think that this function caused the failure because it writes a
324 * fixme, be sure to run again with a +ddraw trace.
326 * What is known about cooperative levels (See the ddraw modes test):
327 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
328 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
329 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
330 * DDSCL_FULLSCREEN can be activated
331 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
333 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
334 * DDSCL_SETFOCUSWINDOW (partially),
335 * DDSCL_MULTITHREADED (work in progress)
337 * Unhandled flags, which should be implemented
338 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
339 * expect any difference to a normal window for wine)
340 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
341 * rendering (Possible test case: Half-life)
343 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
345 * These seem not really imporant for wine
346 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX
349 * DD_OK if the cooperative level was set successfully
350 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
351 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
352 * (Probably others too, have to investigate)
354 *****************************************************************************/
355 static HRESULT WINAPI
356 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7
*iface
,
360 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
364 FIXME("(%p)->(%p,%08x)\n",This
,hwnd
,cooplevel
);
365 DDRAW_dump_cooperativelevel(cooplevel
);
367 EnterCriticalSection(&ddraw_cs
);
369 /* Get the old window */
370 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
, &window
);
373 ERR("IWineD3DDevice::GetHWND failed, hr = %08x\n", hr
);
374 LeaveCriticalSection(&ddraw_cs
);
378 /* Tests suggest that we need one of them: */
379 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
383 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
384 LeaveCriticalSection(&ddraw_cs
);
385 return DDERR_INVALIDPARAMS
;
388 /* Handle those levels first which set various hwnds */
389 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
391 /* This isn't compatible with a lot of flags */
392 if(cooplevel
& ( DDSCL_MULTITHREADED
|
397 DDSCL_SETDEVICEWINDOW
|
402 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
403 LeaveCriticalSection(&ddraw_cs
);
404 return DDERR_INVALIDPARAMS
;
406 else if( (This
->cooperative_level
& DDSCL_FULLSCREEN
) && window
)
408 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
409 LeaveCriticalSection(&ddraw_cs
);
410 return DDERR_HWNDALREADYSET
;
413 This
->focuswindow
= hwnd
;
414 /* Won't use the hwnd param for anything else */
417 /* Use the focus window for drawing too */
418 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, This
->focuswindow
);
420 /* Destroy the device window, if we have one */
421 if(This
->devicewindow
)
423 DestroyWindow(This
->devicewindow
);
424 This
->devicewindow
= NULL
;
427 /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
428 if(cooplevel
& DDSCL_NORMAL
)
430 /* Can't coexist with fullscreen or exclusive */
431 if(cooplevel
& (DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
) )
433 TRACE("(%p) DDSCL_NORMAL is not compative with DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE\n", This
);
434 LeaveCriticalSection(&ddraw_cs
);
435 return DDERR_INVALIDPARAMS
;
438 /* Switching from fullscreen? */
439 if(This
->cooperative_level
& DDSCL_FULLSCREEN
)
441 /* Restore the display mode */
442 IDirectDraw7_RestoreDisplayMode(iface
);
444 This
->cooperative_level
&= ~DDSCL_FULLSCREEN
;
445 This
->cooperative_level
&= ~DDSCL_EXCLUSIVE
;
446 This
->cooperative_level
&= ~DDSCL_ALLOWMODEX
;
449 /* Don't override focus windows or private device windows */
451 !(This
->focuswindow
) &&
452 !(This
->devicewindow
) &&
455 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
458 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
461 else if(cooplevel
& DDSCL_FULLSCREEN
)
463 /* Needs DDSCL_EXCLUSIVE */
464 if(!(cooplevel
& DDSCL_EXCLUSIVE
) )
466 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This
);
467 LeaveCriticalSection(&ddraw_cs
);
468 return DDERR_INVALIDPARAMS
;
473 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
474 return DDERR_INVALIDPARAMS;
478 This
->cooperative_level
&= ~DDSCL_NORMAL
;
479 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
482 /* Don't override focus windows or private device windows */
484 !(This
->focuswindow
) &&
485 !(This
->devicewindow
) &&
488 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
491 else if(cooplevel
& DDSCL_EXCLUSIVE
)
493 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This
);
494 LeaveCriticalSection(&ddraw_cs
);
495 return DDERR_INVALIDPARAMS
;
498 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
500 /* Don't create a device window if a focus window is set */
501 if( !(This
->focuswindow
) )
503 HWND devicewindow
= CreateWindowExA(0, This
->classname
, "DDraw device window",
505 GetSystemMetrics(SM_CXSCREEN
),
506 GetSystemMetrics(SM_CYSCREEN
),
507 NULL
, NULL
, GetModuleHandleA(0), NULL
);
509 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
510 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
512 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, devicewindow
);
513 This
->devicewindow
= devicewindow
;
517 if(cooplevel
& DDSCL_MULTITHREADED
&& !(This
->cooperative_level
& DDSCL_MULTITHREADED
))
519 FIXME("DirectDraw is not fully thread safe yet\n");
521 /* Enable thread safety in wined3d */
522 IWineD3DDevice_SetMultithreaded(This
->wineD3DDevice
);
525 /* Unhandled flags */
526 if(cooplevel
& DDSCL_ALLOWREBOOT
)
527 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
528 if(cooplevel
& DDSCL_ALLOWMODEX
)
529 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
530 if(cooplevel
& DDSCL_FPUSETUP
)
531 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
532 if(cooplevel
& DDSCL_FPUPRESERVE
)
533 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This
);
535 /* Store the cooperative_level */
536 This
->cooperative_level
|= cooplevel
;
537 TRACE("SetCooperativeLevel retuning DD_OK\n");
538 LeaveCriticalSection(&ddraw_cs
);
542 /*****************************************************************************
543 * IDirectDraw7::SetDisplayMode
545 * Sets the display screen resolution, color depth and refresh frequency
546 * when in fullscreen mode (in theory).
547 * Possible return values listed in the SDK suggest that this method fails
548 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
549 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
550 * It seems to be valid to pass 0 for With and Height, this has to be tested
551 * It could mean that the current video mode should be left as-is. (But why
555 * Height, Width: Screen dimension
556 * BPP: Color depth in Bits per pixel
557 * Refreshrate: Screen refresh rate
563 *****************************************************************************/
564 static HRESULT WINAPI
565 IDirectDrawImpl_SetDisplayMode(IDirectDraw7
*iface
,
572 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
573 WINED3DDISPLAYMODE Mode
;
575 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
577 EnterCriticalSection(&ddraw_cs
);
578 if( !Width
|| !Height
)
580 ERR("Width=%d, Height=%d, what to do?\n", Width
, Height
);
581 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
582 LeaveCriticalSection(&ddraw_cs
);
586 /* Check the exclusive mode
587 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
588 return DDERR_NOEXCLUSIVEMODE;
589 * This is WRONG. Don't know if the SDK is completely
590 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
591 * is returned, but Half-Life 1.1.1.1 (Steam version)
596 Mode
.Height
= Height
;
597 Mode
.RefreshRate
= RefreshRate
;
600 case 8: Mode
.Format
= WINED3DFMT_P8
; break;
601 case 15: Mode
.Format
= WINED3DFMT_X1R5G5B5
; break;
602 case 16: Mode
.Format
= WINED3DFMT_R5G6B5
; break;
603 case 24: Mode
.Format
= WINED3DFMT_R8G8B8
; break;
604 case 32: Mode
.Format
= WINED3DFMT_A8R8G8B8
; break;
607 /* TODO: The possible return values from msdn suggest that
608 * the screen mode can't be changed if a surface is locked
609 * or some drawing is in progress
612 /* TODO: Lose the primary surface */
613 hr
= IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
614 0, /* First swapchain */
616 LeaveCriticalSection(&ddraw_cs
);
619 case WINED3DERR_NOTAVAILABLE
: return DDERR_INVALIDMODE
;
624 /*****************************************************************************
625 * IDirectDraw7::RestoreDisplayMode
627 * Restores the display mode to what it was at creation time. Basically.
629 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
630 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
631 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
632 * -> DD_1 is released. The screen should be left at 1024x768x32.
633 * -> DD_2 is released. The screen should be set to 1400x1050x32
634 * This case is unhandled right now, but Empire Earth does it this way.
635 * (But perhaps there is something in SetCooperativeLevel to prevent this)
637 * The msdn says that this method resets the display mode to what it was before
638 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
642 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
644 *****************************************************************************/
645 static HRESULT WINAPI
646 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7
*iface
)
648 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
649 TRACE("(%p)\n", This
);
651 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This
, IDirectDraw7
),
659 /*****************************************************************************
660 * IDirectDraw7::GetCaps
662 * Returns the drives capabilities
664 * Used for version 1, 2, 4 and 7
667 * DriverCaps: Structure to write the Hardware accelerated caps to
668 * HelCaps: Structure to write the emulation caps to
671 * This implementation returns DD_OK only
673 *****************************************************************************/
674 static HRESULT WINAPI
675 IDirectDrawImpl_GetCaps(IDirectDraw7
*iface
,
679 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
680 TRACE("(%p)->(%p,%p)\n", This
, DriverCaps
, HELCaps
);
682 /* One structure must be != NULL */
683 if( (!DriverCaps
) && (!HELCaps
) )
685 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This
);
686 return DDERR_INVALIDPARAMS
;
691 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &This
->caps
);
694 TRACE("Driver Caps :\n");
695 DDRAW_dump_DDCAPS(DriverCaps
);
701 DD_STRUCT_COPY_BYSIZE(HELCaps
, &This
->caps
);
704 TRACE("HEL Caps :\n");
705 DDRAW_dump_DDCAPS(HELCaps
);
712 /*****************************************************************************
713 * IDirectDraw7::Compact
715 * No idea what it does, MSDN says it's not implemented.
718 * DD_OK, but this is unchecked
720 *****************************************************************************/
721 static HRESULT WINAPI
722 IDirectDrawImpl_Compact(IDirectDraw7
*iface
)
724 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
725 TRACE("(%p)\n", This
);
730 /*****************************************************************************
731 * IDirectDraw7::GetDisplayMode
733 * Returns information about the current display mode
735 * Exists in Version 1, 2, 4 and 7
738 * DDSD: Address of a surface description structure to write the info to
743 *****************************************************************************/
744 static HRESULT WINAPI
745 IDirectDrawImpl_GetDisplayMode(IDirectDraw7
*iface
,
746 DDSURFACEDESC2
*DDSD
)
748 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
750 WINED3DDISPLAYMODE Mode
;
752 TRACE("(%p)->(%p): Relay\n", This
, DDSD
);
754 EnterCriticalSection(&ddraw_cs
);
755 /* This seems sane */
758 LeaveCriticalSection(&ddraw_cs
);
759 return DDERR_INVALIDPARAMS
;
762 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
763 * so one method can be used for all versions (Hopefully)
765 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
770 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
771 LeaveCriticalSection(&ddraw_cs
);
776 memset(DDSD
, 0, Size
);
779 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
780 DDSD
->dwWidth
= Mode
.Width
;
781 DDSD
->dwHeight
= Mode
.Height
;
782 DDSD
->u2
.dwRefreshRate
= 60;
783 DDSD
->ddsCaps
.dwCaps
= 0;
784 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
785 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
786 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
790 TRACE("Returning surface desc :\n");
791 DDRAW_dump_surface_desc(DDSD
);
794 LeaveCriticalSection(&ddraw_cs
);
798 /*****************************************************************************
799 * IDirectDraw7::GetFourCCCodes
801 * Returns an array of supported FourCC codes.
803 * Exists in Version 1, 2, 4 and 7
806 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
807 * of enumerated codes
808 * Codes: Pointer to an array of DWORDs where the supported codes are written
812 * Always returns DD_OK, as it's a stub for now
814 *****************************************************************************/
815 static HRESULT WINAPI
816 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7
*iface
,
817 DWORD
*NumCodes
, DWORD
*Codes
)
819 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
820 FIXME("(%p)->(%p, %p): Stub!\n", This
, NumCodes
, Codes
);
822 if(NumCodes
) *NumCodes
= 0;
827 /*****************************************************************************
828 * IDirectDraw7::GetMonitorFrequency
830 * Returns the monitor's frequency
832 * Exists in Version 1, 2, 4 and 7
835 * Freq: Pointer to a DWORD to write the frequency to
838 * Always returns DD_OK
840 *****************************************************************************/
841 static HRESULT WINAPI
842 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7
*iface
,
845 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
846 TRACE("(%p)->(%p)\n", This
, Freq
);
848 /* Ideally this should be in WineD3D, as it concerns the screen setup,
849 * but for now this should make the games happy
855 /*****************************************************************************
856 * IDirectDraw7::GetVerticalBlankStatus
858 * Returns the Vertical blank status of the monitor. This should be in WineD3D
859 * too basically, but as it's a semi stub, I didn't create a function there
862 * status: Pointer to a BOOL to be filled with the vertical blank status
866 * DDERR_INVALIDPARAMS if status is NULL
868 *****************************************************************************/
869 static HRESULT WINAPI
870 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7
*iface
,
873 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
874 TRACE("(%p)->(%p)\n", This
, status
);
876 /* This looks sane, the MSDN suggests it too */
877 EnterCriticalSection(&ddraw_cs
);
880 LeaveCriticalSection(&ddraw_cs
);
881 return DDERR_INVALIDPARAMS
;
884 *status
= This
->fake_vblank
;
885 This
->fake_vblank
= !This
->fake_vblank
;
886 LeaveCriticalSection(&ddraw_cs
);
890 /*****************************************************************************
891 * IDirectDraw7::GetAvailableVidMem
893 * Returns the total and free video memory
896 * Caps: Specifies the memory type asked for
897 * total: Pointer to a DWORD to be filled with the total memory
898 * free: Pointer to a DWORD to be filled with the free memory
902 * DDERR_INVALIDPARAMS of free and total are NULL
904 *****************************************************************************/
905 static HRESULT WINAPI
906 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
908 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
909 TRACE("(%p)->(%p, %p, %p)\n", This
, Caps
, total
, free
);
913 TRACE("(%p) Asked for memory with description: ", This
);
914 DDRAW_dump_DDSCAPS2(Caps
);
917 EnterCriticalSection(&ddraw_cs
);
919 /* Todo: System memory vs local video memory vs non-local video memory
920 * The MSDN also mentions differences between texture memory and other
921 * resources, but that's not important
924 if( (!total
) && (!free
) )
926 LeaveCriticalSection(&ddraw_cs
);
927 return DDERR_INVALIDPARAMS
;
930 if(total
) *total
= This
->total_vidmem
;
931 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
933 LeaveCriticalSection(&ddraw_cs
);
937 /*****************************************************************************
938 * IDirectDraw7::Initialize
940 * Initializes a DirectDraw interface.
943 * GUID: Interface identifier. Well, don't know what this is really good
947 * Returns DD_OK on the first call,
948 * DDERR_ALREADYINITIALIZED on repeated calls
950 *****************************************************************************/
951 static HRESULT WINAPI
952 IDirectDrawImpl_Initialize(IDirectDraw7
*iface
,
955 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
956 TRACE("(%p)->(%s): No-op\n", This
, debugstr_guid(Guid
));
958 if(This
->initialized
)
960 return DDERR_ALREADYINITIALIZED
;
968 /*****************************************************************************
969 * IDirectDraw7::FlipToGDISurface
971 * "Makes the surface that the GDI writes to the primary surface"
972 * Looks like some windows specific thing we don't have to care about.
973 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
974 * show error boxes ;)
975 * Well, just return DD_OK.
978 * Always returns DD_OK
980 *****************************************************************************/
981 static HRESULT WINAPI
982 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7
*iface
)
984 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
985 TRACE("(%p)\n", This
);
990 /*****************************************************************************
991 * IDirectDraw7::WaitForVerticalBlank
993 * This method allows applications to get in sync with the vertical blank
995 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
996 * redraw the screen, most likely because of this stub
999 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1000 * or DDWAITVB_BLOCKEND
1001 * h: Not used, according to MSDN
1004 * Always returns DD_OK
1006 *****************************************************************************/
1007 static HRESULT WINAPI
1008 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7
*iface
,
1012 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1013 FIXME("(%p)->(%x,%p): Stub\n", This
, Flags
, h
);
1015 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1016 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1017 return DDERR_UNSUPPORTED
; /* unchecked */
1022 /*****************************************************************************
1023 * IDirectDraw7::GetScanLine
1025 * Returns the scan line that is being drawn on the monitor
1028 * Scanline: Address to write the scan line value to
1031 * Always returns DD_OK
1033 *****************************************************************************/
1034 static HRESULT WINAPI
IDirectDrawImpl_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1036 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1037 static BOOL hide
= FALSE
;
1038 WINED3DDISPLAYMODE Mode
;
1040 /* This function is called often, so print the fixme only once */
1041 EnterCriticalSection(&ddraw_cs
);
1044 FIXME("(%p)->(%p): Semi-Stub\n", This
, Scanline
);
1048 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1052 /* Fake the line sweeping of the monitor */
1053 /* FIXME: We should synchronize with a source to keep the refresh rate */
1054 *Scanline
= This
->cur_scanline
++;
1055 /* Assume 20 scan lines in the vertical blank */
1056 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1057 This
->cur_scanline
= 0;
1059 LeaveCriticalSection(&ddraw_cs
);
1063 /*****************************************************************************
1064 * IDirectDraw7::TestCooperativeLevel
1066 * Informs the application about the state of the video adapter, depending
1067 * on the cooperative level
1070 * DD_OK if the device is in a sane state
1071 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1072 * if the state is not correct(See below)
1074 *****************************************************************************/
1075 static HRESULT WINAPI
1076 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7
*iface
)
1078 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1080 TRACE("(%p)\n", This
);
1082 EnterCriticalSection(&ddraw_cs
);
1083 /* Description from MSDN:
1084 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1085 * away from the app with e.g. alt-tab. Windowed apps receive
1086 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1087 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1088 * when the video mode has changed
1091 hr
= IWineD3DDevice_TestCooperativeLevel(This
->wineD3DDevice
);
1093 /* Fix the result value. These values are mapped from their
1098 case WINED3DERR_DEVICELOST
:
1099 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
1101 LeaveCriticalSection(&ddraw_cs
);
1102 return DDERR_NOEXCLUSIVEMODE
;
1106 LeaveCriticalSection(&ddraw_cs
);
1107 return DDERR_EXCLUSIVEMODEALREADYSET
;
1110 case WINED3DERR_DEVICENOTRESET
:
1111 LeaveCriticalSection(&ddraw_cs
);
1115 LeaveCriticalSection(&ddraw_cs
);
1118 case WINED3DERR_DRIVERINTERNALERROR
:
1120 ERR("(%p) Unexpected return value %08x from wineD3D, "
1121 " returning DD_OK\n", This
, hr
);
1124 LeaveCriticalSection(&ddraw_cs
);
1128 /*****************************************************************************
1129 * IDirectDraw7::GetGDISurface
1131 * Returns the surface that GDI is treating as the primary surface.
1132 * For Wine this is the front buffer
1135 * GDISurface: Address to write the surface pointer to
1138 * DD_OK if the surface was found
1139 * DDERR_NOTFOUND if the GDI surface wasn't found
1141 *****************************************************************************/
1142 static HRESULT WINAPI
1143 IDirectDrawImpl_GetGDISurface(IDirectDraw7
*iface
,
1144 IDirectDrawSurface7
**GDISurface
)
1146 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1147 IWineD3DSurface
*Surf
;
1148 IDirectDrawSurface7
*ddsurf
;
1151 TRACE("(%p)->(%p)\n", This
, GDISurface
);
1153 /* Get the back buffer from the wineD3DDevice and search its
1154 * attached surfaces for the front buffer
1156 EnterCriticalSection(&ddraw_cs
);
1157 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1159 0, /* first back buffer*/
1160 WINED3DBACKBUFFER_TYPE_MONO
,
1163 if( (hr
!= D3D_OK
) ||
1166 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1167 LeaveCriticalSection(&ddraw_cs
);
1168 return DDERR_NOTFOUND
;
1171 /* GetBackBuffer AddRef()ed the surface, release it */
1172 IWineD3DSurface_Release(Surf
);
1174 IWineD3DSurface_GetParent(Surf
,
1175 (IUnknown
**) &ddsurf
);
1176 IDirectDrawSurface7_Release(ddsurf
); /* For the GetParent */
1178 /* Find the front buffer */
1179 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1180 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1185 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1188 /* The AddRef is OK this time */
1189 LeaveCriticalSection(&ddraw_cs
);
1193 /*****************************************************************************
1194 * IDirectDraw7::EnumDisplayModes
1196 * Enumerates the supported Display modes. The modes can be filtered with
1197 * the DDSD parameter.
1200 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1201 * DDSD: Surface description to filter the modes
1202 * Context: Pointer passed back to the callback function
1203 * cb: Application-provided callback function
1207 * DDERR_INVALIDPARAMS if the callback wasn't set
1209 *****************************************************************************/
1210 static HRESULT WINAPI
1211 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7
*iface
,
1213 DDSURFACEDESC2
*DDSD
,
1215 LPDDENUMMODESCALLBACK2 cb
)
1217 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1218 unsigned int modenum
, fmt
;
1219 WINED3DFORMAT pixelformat
= WINED3DFMT_UNKNOWN
;
1220 WINED3DDISPLAYMODE mode
;
1221 DDSURFACEDESC2 callback_sd
;
1223 WINED3DFORMAT checkFormatList
[] =
1226 WINED3DFMT_A8R8G8B8
,
1227 WINED3DFMT_X8R8G8B8
,
1229 WINED3DFMT_X1R5G5B5
,
1230 WINED3DFMT_A1R5G5B5
,
1231 WINED3DFMT_A4R4G4B4
,
1233 WINED3DFMT_A8R3G3B2
,
1234 WINED3DFMT_X4R4G4B4
,
1235 WINED3DFMT_A2B10G10R10
,
1236 WINED3DFMT_A8B8G8R8
,
1237 WINED3DFMT_X8B8G8R8
,
1238 WINED3DFMT_A2R10G10B10
,
1243 TRACE("(%p)->(%p,%p,%p): Relay\n", This
, DDSD
, Context
, cb
);
1245 EnterCriticalSection(&ddraw_cs
);
1246 /* This looks sane */
1249 LeaveCriticalSection(&ddraw_cs
);
1250 return DDERR_INVALIDPARAMS
;
1255 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1256 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1259 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
1261 if(pixelformat
!= WINED3DFMT_UNKNOWN
&& checkFormatList
[fmt
] != pixelformat
)
1267 while(IWineD3D_EnumAdapterModes(This
->wineD3D
,
1268 WINED3DADAPTER_DEFAULT
,
1269 checkFormatList
[fmt
],
1271 &mode
) == WINED3D_OK
)
1275 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
1276 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
1279 memset(&callback_sd
, 0, sizeof(callback_sd
));
1280 callback_sd
.dwSize
= sizeof(callback_sd
);
1281 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1283 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
1284 if(Flags
& DDEDM_REFRESHRATES
)
1286 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
1287 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
1290 callback_sd
.dwWidth
= mode
.Width
;
1291 callback_sd
.dwHeight
= mode
.Height
;
1293 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, mode
.Format
);
1295 TRACE("Enumerating %dx%d@%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
);
1297 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
1299 TRACE("Application asked to terminate the enumeration\n");
1300 LeaveCriticalSection(&ddraw_cs
);
1306 TRACE("End of enumeration\n");
1307 LeaveCriticalSection(&ddraw_cs
);
1311 /*****************************************************************************
1312 * IDirectDraw7::EvaluateMode
1314 * Used with IDirectDraw7::StartModeTest to test video modes.
1315 * EvaluateMode is used to pass or fail a mode, and continue with the next
1319 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1320 * Timeout: Returns the amount of seconds left before the mode would have
1321 * been failed automatically
1324 * This implementation always DD_OK, because it's a stub
1326 *****************************************************************************/
1327 static HRESULT WINAPI
1328 IDirectDrawImpl_EvaluateMode(IDirectDraw7
*iface
,
1332 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1333 FIXME("(%p)->(%d,%p): Stub!\n", This
, Flags
, Timeout
);
1335 /* When implementing this, implement it in WineD3D */
1340 /*****************************************************************************
1341 * IDirectDraw7::GetDeviceIdentifier
1343 * Returns the device identifier, which gives information about the driver
1344 * Our device identifier is defined at the beginning of this file.
1347 * DDDI: Address for the returned structure
1348 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1351 * On success it returns DD_OK
1352 * DDERR_INVALIDPARAMS if DDDI is NULL
1354 *****************************************************************************/
1355 static HRESULT WINAPI
1356 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7
*iface
,
1357 DDDEVICEIDENTIFIER2
*DDDI
,
1360 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1361 TRACE("(%p)->(%p,%08x)\n", This
, DDDI
, Flags
);
1364 return DDERR_INVALIDPARAMS
;
1366 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1367 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1368 * to any modern hardware, nor is it interesting for Wine, so ignore it
1371 *DDDI
= deviceidentifier
;
1375 /*****************************************************************************
1376 * IDirectDraw7::GetSurfaceFromDC
1378 * Returns the Surface for a GDI device context handle.
1379 * Is this related to IDirectDrawSurface::GetDC ???
1382 * hdc: hdc to return the surface for
1383 * Surface: Address to write the surface pointer to
1386 * Always returns DD_OK because it's a stub
1388 *****************************************************************************/
1389 static HRESULT WINAPI
1390 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7
*iface
,
1392 IDirectDrawSurface7
**Surface
)
1394 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1395 FIXME("(%p)->(%p,%p): Stub!\n", This
, hdc
, Surface
);
1397 /* Implementation idea if needed: Loop through all surfaces and compare
1398 * their hdc with hdc. Implement it in WineD3D! */
1399 return DDERR_NOTFOUND
;
1402 /*****************************************************************************
1403 * IDirectDraw7::RestoreAllSurfaces
1405 * Calls the restore method of all surfaces
1410 * Always returns DD_OK because it's a stub
1412 *****************************************************************************/
1413 static HRESULT WINAPI
1414 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7
*iface
)
1416 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1417 FIXME("(%p): Stub\n", This
);
1419 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1420 * get their parent and call their restore method. Do not implement
1421 * it in WineD3D, as restoring a surface means re-creating the
1427 /*****************************************************************************
1428 * IDirectDraw7::StartModeTest
1430 * Tests the specified video modes to update the system registry with
1431 * refresh rate information. StartModeTest starts the mode test,
1432 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1433 * isn't called within 15 seconds, the mode is failed automatically
1435 * As refresh rates are handled by the X server, I don't think this
1436 * Method is important
1439 * Modes: An array of mode specifications
1440 * NumModes: The number of modes in Modes
1441 * Flags: Some flags...
1444 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1445 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1448 *****************************************************************************/
1449 static HRESULT WINAPI
1450 IDirectDrawImpl_StartModeTest(IDirectDraw7
*iface
,
1455 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1456 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This
, Modes
, NumModes
, Flags
);
1458 /* This looks sane */
1459 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
1461 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1462 * As it is not, DDERR_TESTFINISHED is returned
1463 * (hopefully that's correct
1465 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1466 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1472 /*****************************************************************************
1473 * IDirectDrawImpl_RecreateSurfacesCallback
1475 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1476 * It re-recreates the WineD3DSurface. It's pretty straightforward
1478 *****************************************************************************/
1480 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
1481 DDSURFACEDESC2
*desc
,
1484 IDirectDrawSurfaceImpl
*surfImpl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1485 IDirectDrawSurface7
,
1487 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
1489 IParentImpl
*parImpl
= NULL
;
1490 IWineD3DSurface
*wineD3DSurface
;
1493 IWineD3DClipper
*clipper
= NULL
;
1495 WINED3DSURFACE_DESC Desc
;
1496 WINED3DFORMAT Format
;
1497 WINED3DRESOURCETYPE Type
;
1502 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1503 DWORD MultiSampleQuality
;
1507 TRACE("(%p): Enumerated Surface %p\n", This
, surfImpl
);
1509 /* For the enumeration */
1510 IDirectDrawSurface7_Release(surf
);
1512 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
1514 /* Get the objects */
1515 wineD3DSurface
= surfImpl
->WineD3DSurface
;
1516 IWineD3DSurface_GetParent(wineD3DSurface
, &Parent
);
1517 IUnknown_Release(Parent
); /* For the getParent */
1519 /* Is the parent an IParent interface? */
1520 if(IUnknown_QueryInterface(Parent
, &IID_IParent
, &tmp
) == S_OK
)
1522 /* It is a IParent interface! */
1523 IUnknown_Release(Parent
); /* For the QueryInterface */
1524 parImpl
= ICOM_OBJECT(IParentImpl
, IParent
, Parent
);
1525 /* Release the reference the parent interface is holding */
1526 IWineD3DSurface_Release(wineD3DSurface
);
1529 /* get the clipper */
1530 IWineD3DSurface_GetClipper(wineD3DSurface
, &clipper
);
1532 /* Get the surface properties */
1533 Desc
.Format
= &Format
;
1535 Desc
.Usage
= &Usage
;
1538 Desc
.MultiSampleType
= &MultiSampleType
;
1539 Desc
.MultiSampleQuality
= &MultiSampleQuality
;
1540 Desc
.Width
= &Width
;
1541 Desc
.Height
= &Height
;
1543 hr
= IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
1544 if(hr
!= D3D_OK
) return hr
;
1546 /* Create the new surface */
1547 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1548 Width
, Height
, Format
,
1549 TRUE
/* Lockable */,
1550 FALSE
/* Discard */,
1551 surfImpl
->mipmap_level
,
1552 &surfImpl
->WineD3DSurface
,
1558 0 /* SharedHandle */,
1565 IWineD3DSurface_SetClipper(surfImpl
->WineD3DSurface
, clipper
);
1567 /* Update the IParent if it exists */
1570 parImpl
->child
= (IUnknown
*) surfImpl
->WineD3DSurface
;
1571 /* Add a reference for the IParent */
1572 IWineD3DSurface_AddRef(surfImpl
->WineD3DSurface
);
1574 /* TODO: Copy the surface content, except for render targets */
1576 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
1577 TRACE("Surface released successful, next surface\n");
1579 ERR("Something's still holding the old WineD3DSurface\n");
1581 surfImpl
->ImplType
= This
->ImplType
;
1585 IWineD3DClipper_Release(clipper
);
1587 return DDENUMRET_OK
;
1590 /*****************************************************************************
1591 * IDirectDrawImpl_RecreateAllSurfaces
1593 * A function, that converts all wineD3DSurfaces to the new implementation type
1594 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1595 * new WineD3DSurface, copies the content and releases the old surface
1597 *****************************************************************************/
1599 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl
*This
)
1601 DDSURFACEDESC2 desc
;
1602 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
1604 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
1606 /* Should happen almost never */
1607 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
1609 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
);
1611 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1613 memset(&desc
, 0, sizeof(desc
));
1614 desc
.dwSize
= sizeof(desc
);
1616 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This
, IDirectDraw7
),
1620 IDirectDrawImpl_RecreateSurfacesCallback
);
1623 /*****************************************************************************
1624 * D3D7CB_CreateSurface
1626 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1627 * correct mipmap sublevel, and returns it to WineD3D.
1628 * The surfaces are created already by IDirectDraw7::CreateSurface
1631 * With, Height: With and height of the surface
1632 * Format: The requested format
1633 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1634 * level: The mipmap level
1635 * Face: The cube map face type
1636 * Surface: Pointer to pass the created surface back at
1637 * SharedHandle: NULL
1642 *****************************************************************************/
1643 static HRESULT WINAPI
1644 D3D7CB_CreateSurface(IUnknown
*device
,
1645 IUnknown
*pSuperior
,
1646 UINT Width
, UINT Height
,
1647 WINED3DFORMAT Format
,
1648 DWORD Usage
, WINED3DPOOL Pool
, UINT level
,
1649 WINED3DCUBEMAP_FACES Face
,
1650 IWineD3DSurface
**Surface
,
1651 HANDLE
*SharedHandle
)
1653 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
1654 IDirectDrawSurfaceImpl
*surf
= NULL
;
1656 DDSCAPS2 searchcaps
= This
->tex_root
->surface_desc
.ddsCaps
;
1657 TRACE("(%p) call back. surf=%p. Face %d level %d\n", device
, This
->tex_root
, Face
, level
);
1659 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
1662 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
1663 TRACE("Asked for positive x\n");
1664 if(searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
) {
1665 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
1667 surf
= This
->tex_root
; break;
1668 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
1669 TRACE("Asked for negative x\n");
1670 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
1671 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
1672 TRACE("Asked for positive y\n");
1673 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
1674 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
1675 TRACE("Asked for negative y\n");
1676 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
1677 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
1678 TRACE("Asked for positive z\n");
1679 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
1680 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
1681 TRACE("Asked for negative z\n");
1682 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
1683 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
1688 IDirectDrawSurface7
*attached
;
1689 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This
->tex_root
, IDirectDrawSurface7
),
1692 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1693 IDirectDrawSurface7_Release(attached
);
1695 if(!surf
) ERR("root search surface not found\n");
1697 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1700 IDirectDrawSurface7
*attached
;
1701 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
1704 if(!attached
) ERR("Surface not found\n");
1705 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1706 IDirectDrawSurface7_Release(attached
);
1710 /* Return the surface */
1711 *Surface
= surf
->WineD3DSurface
;
1713 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface
, surf
);
1717 ULONG WINAPI
D3D7CB_DestroySwapChain(IWineD3DSwapChain
*pSwapChain
) {
1718 IUnknown
* swapChainParent
;
1719 TRACE("(%p) call back\n", pSwapChain
);
1721 IWineD3DSwapChain_GetParent(pSwapChain
, &swapChainParent
);
1722 IUnknown_Release(swapChainParent
);
1723 return IUnknown_Release(swapChainParent
);
1726 ULONG WINAPI
D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface
*pSurface
) {
1727 IUnknown
* surfaceParent
;
1728 TRACE("(%p) call back\n", pSurface
);
1730 IWineD3DSurface_GetParent(pSurface
, (IUnknown
**) &surfaceParent
);
1731 IUnknown_Release(surfaceParent
);
1732 return IUnknown_Release(surfaceParent
);
1735 /*****************************************************************************
1736 * IDirectDrawImpl_CreateNewSurface
1738 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1739 * with the passed parameters.
1742 * DDSD: Description of the surface to create
1743 * Surf: Address to store the interface pointer at
1748 *****************************************************************************/
1749 static HRESULT WINAPI
1750 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
,
1751 DDSURFACEDESC2
*pDDSD
,
1752 IDirectDrawSurfaceImpl
**ppSurf
,
1756 UINT Width
= 0, Height
= 0;
1757 WINED3DFORMAT Format
= WINED3DFMT_UNKNOWN
;
1758 WINED3DRESOURCETYPE ResType
= WINED3DRTYPE_SURFACE
;
1760 WINED3DSURFTYPE ImplType
= This
->ImplType
;
1761 WINED3DSURFACE_DESC Desc
;
1763 IParentImpl
*parImpl
= NULL
;
1764 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
1766 /* Dummies for GetDesc */
1767 WINED3DPOOL dummy_d3dpool
;
1768 WINED3DMULTISAMPLE_TYPE dummy_mst
;
1772 if (TRACE_ON(ddraw
))
1774 TRACE(" (%p) Requesting surface desc :\n", This
);
1775 DDRAW_dump_surface_desc(pDDSD
);
1778 /* Select the surface type, if it wasn't choosen yet */
1779 if(ImplType
== SURFACE_UNKNOWN
)
1781 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1782 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1784 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
1785 ImplType
= SURFACE_OPENGL
;
1788 /* Otherwise use GDI surfaces for now */
1791 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
1792 ImplType
= SURFACE_GDI
;
1795 /* Policy if all surface implementations are available:
1796 * First, check if a default type was set with winecfg. If not,
1797 * try Xrender surfaces, and use them if they work. Next, check if
1798 * accelerated OpenGL is available, and use GL surfaces in this
1799 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1800 * was created, always use OpenGL surfaces.
1802 * (Note: Xrender surfaces are not implemented for now, the
1803 * unaccelerated implementation uses GDI to render in Software)
1806 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1807 * be re-created. This could be done with IDirectDrawSurface7::Restore
1809 This
->ImplType
= ImplType
;
1813 if((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
1814 (This
->ImplType
!= SURFACE_OPENGL
) && DefaultSurfaceType
== SURFACE_UNKNOWN
)
1816 /* We have to change to OpenGL,
1817 * and re-create all WineD3DSurfaces
1819 ImplType
= SURFACE_OPENGL
;
1820 This
->ImplType
= ImplType
;
1821 TRACE("(%p) Re-creating all surfaces\n", This
);
1822 IDirectDrawImpl_RecreateAllSurfaces(This
);
1823 TRACE("(%p) Done recreating all surfaces\n", This
);
1825 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1827 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1828 /* Do not fail surface creation, only fail 3D device creation */
1832 /* Get the correct wined3d usage */
1833 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
1834 DDSCAPS_BACKBUFFER
|
1835 DDSCAPS_3DDEVICE
) )
1837 Usage
|= WINED3DUSAGE_RENDERTARGET
;
1839 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
|
1842 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
1844 Usage
|= WINED3DUSAGE_OVERLAY
;
1846 if(This
->depthstencil
|| (pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) )
1848 /* The depth stencil creation callback sets this flag.
1849 * Set the WineD3D usage to let it know that it's a depth
1852 Usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
1854 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
1856 Pool
= WINED3DPOOL_SYSTEMMEM
;
1858 else if(pDDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
1860 Pool
= WINED3DPOOL_MANAGED
;
1861 /* Managed textures have the system memory flag set */
1862 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
1864 else if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
1866 /* Videomemory adds localvidmem, this is mutually exclusive with systemmemory
1869 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
1872 Format
= PixelFormat_DD2WineD3D(&pDDSD
->u4
.ddpfPixelFormat
);
1873 if(Format
== WINED3DFMT_UNKNOWN
)
1875 ERR("Unsupported / Unknown pixelformat\n");
1876 return DDERR_INVALIDPIXELFORMAT
;
1879 /* Create the Surface object */
1880 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
1883 ERR("(%p) Error allocating memory for a surface\n", This
);
1884 return DDERR_OUTOFVIDEOMEMORY
;
1886 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface7
, IDirectDrawSurface7_Vtbl
);
1887 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface3
, IDirectDrawSurface3_Vtbl
);
1888 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawGammaControl
, IDirectDrawGammaControl_Vtbl
);
1889 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture2
, IDirect3DTexture2_Vtbl
);
1890 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture
, IDirect3DTexture1_Vtbl
);
1892 (*ppSurf
)->version
= 7;
1893 (*ppSurf
)->ddraw
= This
;
1894 (*ppSurf
)->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
1895 (*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1896 DD_STRUCT_COPY_BYSIZE(&(*ppSurf
)->surface_desc
, pDDSD
);
1898 /* Surface attachments */
1899 (*ppSurf
)->next_attached
= NULL
;
1900 (*ppSurf
)->first_attached
= *ppSurf
;
1902 /* Needed to re-create the surface on an implementation change */
1903 (*ppSurf
)->ImplType
= ImplType
;
1905 /* For D3DDevice creation */
1906 (*ppSurf
)->isRenderTarget
= FALSE
;
1908 /* A trace message for debugging */
1909 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This
, *ppSurf
);
1911 if(pDDSD
->ddsCaps
.dwCaps
& ( DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
) )
1913 /* Render targets and textures need a IParent interface,
1914 * because WineD3D will destroy them when the swapchain
1917 parImpl
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
));
1920 ERR("Out of memory when allocating memory for a IParent implementation\n");
1921 return DDERR_OUTOFMEMORY
;
1924 ICOM_INIT_INTERFACE(parImpl
, IParent
, IParent_Vtbl
);
1925 Parent
= (IUnknown
*) ICOM_INTERFACE(parImpl
, IParent
);
1926 TRACE("Using IParent interface %p as parent\n", parImpl
);
1930 /* Use the surface as parent */
1931 Parent
= (IUnknown
*) ICOM_INTERFACE(*ppSurf
, IDirectDrawSurface7
);
1932 TRACE("Using Surface interface %p as parent\n", *ppSurf
);
1935 /* Now create the WineD3D Surface */
1936 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1940 TRUE
/* Lockable */,
1941 FALSE
/* Discard */,
1943 &(*ppSurf
)->WineD3DSurface
,
1946 WINED3DMULTISAMPLE_NONE
,
1947 0 /* MultiSampleQuality */,
1948 0 /* SharedHandle */,
1954 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr
);
1958 /* Set the child of the parent implementation if it exists */
1961 parImpl
->child
= (IUnknown
*) (*ppSurf
)->WineD3DSurface
;
1962 /* The IParent releases the WineD3DSurface, and
1963 * the ddraw surface does that too. Hold a reference
1965 IWineD3DSurface_AddRef((*ppSurf
)->WineD3DSurface
);
1968 /* Increase the surface counter, and attach the surface */
1969 InterlockedIncrement(&This
->surfaces
);
1970 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
1972 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1973 * But this could also be delegated to WineDDraw, as it keeps track of all its
1974 * resources. Not implemented for now, as there are more important things ;)
1977 /* Get the pixel format of the WineD3DSurface and store it.
1978 * Don't use the Format choosen above, WineD3D might have
1981 Desc
.Format
= &Format
;
1982 Desc
.Type
= &ResType
;
1983 Desc
.Usage
= &Usage
;
1984 Desc
.Pool
= &dummy_d3dpool
;
1985 Desc
.Size
= &dummy_uint
;
1986 Desc
.MultiSampleType
= &dummy_mst
;
1987 Desc
.MultiSampleQuality
= &dummy_dword
;
1988 Desc
.Width
= &Width
;
1989 Desc
.Height
= &Height
;
1991 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
1992 hr
= IWineD3DSurface_GetDesc((*ppSurf
)->WineD3DSurface
, &Desc
);
1995 ERR("IWineD3DSurface::GetDesc failed\n");
1996 IDirectDrawSurface7_Release( (IDirectDrawSurface7
*) *ppSurf
);
2000 if(Format
== WINED3DFMT_UNKNOWN
)
2002 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
2004 PixelFormat_WineD3DtoDD( &(*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
, Format
);
2006 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
2007 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
2008 * WineD3DDevice might not be useable for 3D yet, so an extra method was created.
2009 * TODO: Test other fourcc formats
2011 if(Format
== WINED3DFMT_DXT1
|| Format
== WINED3DFMT_DXT2
|| Format
== WINED3DFMT_DXT3
||
2012 Format
== WINED3DFMT_DXT4
|| Format
== WINED3DFMT_DXT5
)
2014 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
2015 if(Format
== WINED3DFMT_DXT1
)
2017 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
) / 2;
2021 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
);
2026 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PITCH
;
2027 (*ppSurf
)->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch((*ppSurf
)->WineD3DSurface
);
2030 /* Application passed a color key? Set it! */
2031 if(pDDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2033 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2035 (WINEDDCOLORKEY
*) &pDDSD
->u3
.ddckCKDestOverlay
);
2037 if(pDDSD
->dwFlags
& DDSD_CKDESTBLT
)
2039 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2041 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKDestBlt
);
2043 if(pDDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2045 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2047 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcOverlay
);
2049 if(pDDSD
->dwFlags
& DDSD_CKSRCBLT
)
2051 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2053 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcBlt
);
2055 if ( pDDSD
->dwFlags
& DDSD_LPSURFACE
)
2057 hr
= IWineD3DSurface_SetMem((*ppSurf
)->WineD3DSurface
, pDDSD
->lpSurface
);
2058 if(hr
!= WINED3D_OK
)
2060 /* No need for a trace here, wined3d does that for us */
2061 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf
), IDirectDrawSurface7
));
2068 /*****************************************************************************
2069 * CreateAdditionalSurfaces
2071 * Creates a new mipmap chain.
2074 * root: Root surface to attach the newly created chain to
2075 * count: number of surfaces to create
2076 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2077 * effects on the caller
2078 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2079 * creates an additional surface without the mipmapping flags
2081 *****************************************************************************/
2083 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2084 IDirectDrawSurfaceImpl
*root
,
2086 DDSURFACEDESC2 DDSD
,
2089 UINT i
, j
, level
= 0;
2091 IDirectDrawSurfaceImpl
*last
= root
;
2093 for(i
= 0; i
< count
; i
++)
2095 IDirectDrawSurfaceImpl
*object2
= NULL
;
2097 /* increase the mipmap level, but only if a mipmap is created
2098 * In this case, also halve the size
2100 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2103 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2104 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2105 /* Set the mipmap sublevel flag according to msdn */
2106 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2110 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2112 CubeFaceRoot
= FALSE
;
2114 hr
= IDirectDrawImpl_CreateNewSurface(This
,
2123 /* Add the new surface to the complex attachment array */
2124 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2126 if(last
->complex_array
[j
]) continue;
2127 last
->complex_array
[j
] = object2
;
2132 /* Remove the (possible) back buffer cap from the new surface description,
2133 * because only one surface in the flipping chain is a back buffer, one
2134 * is a front buffer, the others are just primary surfaces.
2136 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2141 /*****************************************************************************
2142 * IDirectDraw7::CreateSurface
2144 * Creates a new IDirectDrawSurface object and returns its interface.
2146 * The surface connections with wined3d are a bit tricky. Basically it works
2149 * |------------------------| |-----------------|
2150 * | DDraw surface | | WineD3DSurface |
2152 * | WineD3DSurface |-------------->| |
2153 * | Child |<------------->| Parent |
2154 * |------------------------| |-----------------|
2156 * The DDraw surface is the parent of the wined3d surface, and it releases
2157 * the WineD3DSurface when the ddraw surface is destroyed.
2159 * However, for all surfaces which can be in a container in WineD3D,
2160 * we have to do this. These surfaces are ususally complex surfaces,
2161 * so this concerns primary surfaces with a front and a back buffer,
2164 * |------------------------| |-----------------|
2165 * | DDraw surface | | Containter |
2167 * | Child |<------------->| Parent |
2168 * | Texture |<------------->| |
2169 * | WineD3DSurface |<----| | Levels |<--|
2170 * | Complex connection | | | | |
2171 * |------------------------| | |-----------------| |
2175 * | |------------------| | |-----------------| |
2176 * | | IParent | |-------->| WineD3DSurface | |
2178 * | | Child |<------------->| Parent | |
2179 * | | | | Container |<--|
2180 * | |------------------| |-----------------| |
2182 * | |----------------------| |
2183 * | | DDraw surface 2 | |
2185 * |<->| Complex root Child | |
2187 * | | WineD3DSurface |<----| |
2188 * | |----------------------| | |
2190 * | |---------------------| | |-----------------| |
2191 * | | IParent | |----->| WineD3DSurface | |
2193 * | | Child |<---------->| Parent | |
2194 * | |---------------------| | Container |<--|
2195 * | |-----------------| |
2197 * | ---More surfaces can follow--- |
2199 * The reason is that the IWineD3DSwapchain(render target container)
2200 * and the IWineD3DTexure(Texture container) release the parents
2201 * of their surface's children, but by releasing the complex root
2202 * the surfaces which are complexly attached to it are destroyed
2203 * too. See IDirectDrawSurface::Release for a more detailed
2207 * DDSD: Description of the surface to create
2208 * Surf: Address to store the interface pointer at
2209 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2210 * aggregation, so it has to be NULL
2214 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2215 * DDERR_* if an error occurs
2217 *****************************************************************************/
2218 static HRESULT WINAPI
2219 IDirectDrawImpl_CreateSurface(IDirectDraw7
*iface
,
2220 DDSURFACEDESC2
*DDSD
,
2221 IDirectDrawSurface7
**Surf
,
2224 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2225 IDirectDrawSurfaceImpl
*object
= NULL
;
2227 LONG extra_surfaces
= 0;
2228 DDSURFACEDESC2 desc2
;
2229 WINED3DDISPLAYMODE Mode
;
2231 TRACE("(%p)->(%p,%p,%p)\n", This
, DDSD
, Surf
, UnkOuter
);
2233 /* Some checks before we start */
2234 if (TRACE_ON(ddraw
))
2236 TRACE(" (%p) Requesting surface desc :\n", This
);
2237 DDRAW_dump_surface_desc(DDSD
);
2239 EnterCriticalSection(&ddraw_cs
);
2241 if (UnkOuter
!= NULL
)
2243 FIXME("(%p) : outer != NULL?\n", This
);
2244 LeaveCriticalSection(&ddraw_cs
);
2245 return CLASS_E_NOAGGREGATION
; /* unchecked */
2250 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2251 LeaveCriticalSection(&ddraw_cs
);
2252 return E_POINTER
; /* unchecked */
2255 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2257 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2258 DDSD
->dwFlags
|= DDSD_CAPS
;
2260 if (DDSD
->ddsCaps
.dwCaps
== 0)
2262 /* This has been checked on real Windows */
2263 DDSD
->ddsCaps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
2266 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2268 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2269 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2272 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2274 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2275 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2276 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2279 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2280 !(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
2282 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This
);
2284 LeaveCriticalSection(&ddraw_cs
);
2285 return DDERR_NOEXCLUSIVEMODE
;
2288 if(DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
)) {
2289 WARN("Application tried to create an explicit front or back buffer\n");
2290 LeaveCriticalSection(&ddraw_cs
);
2291 return DDERR_INVALIDCAPS
;
2293 /* Check cube maps but only if the size includes them */
2294 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2296 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2297 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2299 WARN("Cube map faces requested without cube map flag\n");
2300 LeaveCriticalSection(&ddraw_cs
);
2301 return DDERR_INVALIDCAPS
;
2303 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2304 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2306 WARN("Cube map without faces requested\n");
2307 LeaveCriticalSection(&ddraw_cs
);
2308 return DDERR_INVALIDPARAMS
;
2311 /* Quick tests confirm those can be created, but we don't do that yet */
2312 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2313 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2315 FIXME("Partial cube maps not supported yet\n");
2319 /* According to the msdn this flag is ignored by CreateSurface */
2320 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2321 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2323 /* Modify some flags */
2324 memset(&desc2
, 0, sizeof(desc2
));
2325 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
2326 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2327 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2328 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2330 /* Get the video mode from WineD3D - we will need it */
2331 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2332 0, /* Swapchain 0 */
2336 ERR("Failed to read display mode from wined3d\n");
2337 switch(This
->orig_bpp
)
2340 Mode
.Format
= WINED3DFMT_P8
;
2344 Mode
.Format
= WINED3DFMT_X1R5G5B5
;
2348 Mode
.Format
= WINED3DFMT_R5G6B5
;
2352 Mode
.Format
= WINED3DFMT_R8G8B8
;
2356 Mode
.Format
= WINED3DFMT_X8R8G8B8
;
2359 Mode
.Width
= This
->orig_width
;
2360 Mode
.Height
= This
->orig_height
;
2363 /* No pixelformat given? Use the current screen format */
2364 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2366 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2367 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2369 /* Wait: It could be a Z buffer */
2370 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2372 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
2375 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D15S1
);
2378 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16
);
2381 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D24X8
);
2384 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32
);
2387 ERR("Unknown Z buffer bit depth\n");
2392 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2396 /* No Width or no Height? Use the original screen size
2398 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2399 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2401 /* Invalid for non-render targets */
2402 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2404 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2406 LeaveCriticalSection(&ddraw_cs
);
2407 return DDERR_INVALIDPARAMS
;
2410 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2411 desc2
.dwWidth
= Mode
.Width
;
2412 desc2
.dwHeight
= Mode
.Height
;
2415 /* Mipmap count fixes */
2416 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2418 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2420 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2422 /* Mipmap count is given, nothing to do */
2426 /* Undocumented feature: Create sublevels until
2427 * either the width or the height is 1
2429 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2430 desc2
.dwWidth
: desc2
.dwHeight
;
2431 desc2
.u2
.dwMipMapCount
= 0;
2434 desc2
.u2
.dwMipMapCount
+= 1;
2441 /* Not-complex mipmap -> Mipmapcount = 1 */
2442 desc2
.u2
.dwMipMapCount
= 1;
2444 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2446 /* There's a mipmap count in the created surface in any case */
2447 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2449 /* If no mipmap is given, the texture has only one level */
2451 /* The first surface is a front buffer, the back buffer is created afterwards */
2452 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2454 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2457 /* The root surface in a cube map is positive x */
2458 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2460 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2461 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2464 /* Create the first surface */
2465 hr
= IDirectDrawImpl_CreateNewSurface(This
, &desc2
, &object
, 0);
2468 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr
);
2469 LeaveCriticalSection(&ddraw_cs
);
2472 object
->is_complex_root
= TRUE
;
2474 *Surf
= ICOM_INTERFACE(object
, IDirectDrawSurface7
);
2476 /* Create Additional surfaces if necessary
2477 * This applies to Primary surfaces which have a back buffer count
2478 * set, but not to mipmap textures. In case of Mipmap textures,
2479 * wineD3D takes care of the creation of additional surfaces
2481 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2483 extra_surfaces
= DDSD
->dwBackBufferCount
;
2484 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2485 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2489 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2491 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2492 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2493 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2494 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2495 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
2496 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2497 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
2498 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
2499 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2500 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
2501 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
2502 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2503 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
2504 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
2505 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2506 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
2507 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2510 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
, desc2
, FALSE
);
2513 /* This destroys and possibly created surfaces too */
2514 IDirectDrawSurface_Release( ICOM_INTERFACE(object
, IDirectDrawSurface7
) );
2515 LeaveCriticalSection(&ddraw_cs
);
2519 /* Addref the ddraw interface to keep an reference for each surface */
2520 IDirectDraw7_AddRef(iface
);
2521 object
->ifaceToRelease
= (IUnknown
*) iface
;
2523 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2524 * But attach the d3ddevice only if the currently created surface was
2525 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2526 * The only case I can think of where this doesn't apply is when a
2527 * 2D app was configured by the user to run with OpenGL and it didn't create
2528 * the render target as first surface. In this case the render target creation
2529 * will cause the 3D init.
2531 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
2532 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
2534 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
2537 /* Search for the primary to use as render target */
2538 LIST_FOR_EACH(entry
, &This
->surface_list
)
2540 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2541 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
2542 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
2546 TRACE("Using primary %p as render target\n", target
);
2551 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
2552 hr
= IDirectDrawImpl_AttachD3DDevice(This
, target
);
2555 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr
);
2559 /* Create a WineD3DTexture if a texture was requested */
2560 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2563 WINED3DFORMAT Format
;
2564 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
2566 This
->tex_root
= object
;
2568 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2570 /* a mipmap is created, create enough levels */
2571 levels
= desc2
.u2
.dwMipMapCount
;
2575 /* No mipmap is created, create one level */
2579 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2580 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
2582 Pool
= WINED3DPOOL_SYSTEMMEM
;
2584 /* Should I forward the MANEGED cap to the managed pool ? */
2586 /* Get the format. It's set already by CreateNewSurface */
2587 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
2589 /* The surfaces are already created, the callback only
2590 * passes the IWineD3DSurface to WineD3D
2592 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2594 hr
= IWineD3DDevice_CreateCubeTexture(This
->wineD3DDevice
,
2595 DDSD
->dwWidth
, /* Edgelength */
2600 (IWineD3DCubeTexture
**) &object
->wineD3DTexture
,
2601 0, /* SharedHandle */
2602 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2603 D3D7CB_CreateSurface
);
2607 hr
= IWineD3DDevice_CreateTexture(This
->wineD3DDevice
,
2608 DDSD
->dwWidth
, DDSD
->dwHeight
,
2609 levels
, /* MipMapCount = Levels */
2613 (IWineD3DTexture
**) &object
->wineD3DTexture
,
2614 0, /* SharedHandle */
2615 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2616 D3D7CB_CreateSurface
);
2618 This
->tex_root
= NULL
;
2621 LeaveCriticalSection(&ddraw_cs
);
2625 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2626 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2629 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2630 const DDPIXELFORMAT
*provided
)
2632 /* Some flags must be present in both or neither for a match. */
2633 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2634 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2635 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2637 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2640 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2643 if (requested
->dwFlags
& DDPF_FOURCC
)
2644 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2647 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2648 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2649 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2652 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2653 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2654 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2657 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2658 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2661 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2662 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2664 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2667 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2668 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2675 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
,
2676 const DDSURFACEDESC2
* provided
)
2685 #define CMP(FLAG, FIELD) \
2686 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2687 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2689 static const struct compare_info compare
[] =
2691 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
2692 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
2694 CMP(CKDESTBLT
, ddckCKDestBlt
),
2695 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
2696 CMP(CKSRCBLT
, ddckCKSrcBlt
),
2697 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
2698 CMP(HEIGHT
, dwHeight
),
2699 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
2700 CMP(LPSURFACE
, lpSurface
),
2701 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
2702 CMP(PITCH
, u1
/* lPitch */),
2703 /* PIXELFORMAT: manual */
2704 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
2705 CMP(TEXTURESTAGE
, dwTextureStage
),
2706 CMP(WIDTH
, dwWidth
),
2707 /* ZBUFFERBITDEPTH: "obsolete" */
2714 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2717 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
2719 if (requested
->dwFlags
& compare
[i
].flag
2720 && memcmp((const char *)provided
+ compare
[i
].offset
,
2721 (const char *)requested
+ compare
[i
].offset
,
2722 compare
[i
].size
) != 0)
2726 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
2728 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
2729 &provided
->u4
.ddpfPixelFormat
))
2736 #undef DDENUMSURFACES_SEARCHTYPE
2737 #undef DDENUMSURFACES_MATCHTYPE
2739 /*****************************************************************************
2740 * IDirectDraw7::EnumSurfaces
2742 * Loops through all surfaces attached to this device and calls the
2743 * application callback. This can't be relayed to WineD3DDevice,
2744 * because some WineD3DSurfaces' parents are IParent objects
2747 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2748 * DDSD: Description to filter for
2749 * Context: Application-provided pointer, it's passed unmodified to the
2751 * Callback: Address to call for each surface
2754 * DDERR_INVALIDPARAMS if the callback is NULL
2757 *****************************************************************************/
2758 static HRESULT WINAPI
2759 IDirectDrawImpl_EnumSurfaces(IDirectDraw7
*iface
,
2761 DDSURFACEDESC2
*DDSD
,
2763 LPDDENUMSURFACESCALLBACK7 Callback
)
2765 /* The surface enumeration is handled by WineDDraw,
2766 * because it keeps track of all surfaces attached to
2767 * it. The filtering is done by our callback function,
2768 * because WineDDraw doesn't handle ddraw-like surface
2771 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2772 IDirectDrawSurfaceImpl
*surf
;
2774 DDSURFACEDESC2 desc
;
2775 struct list
*entry
, *entry2
;
2777 all
= Flags
& DDENUMSURFACES_ALL
;
2778 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
2780 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, DDSD
, Context
, Callback
);
2781 EnterCriticalSection(&ddraw_cs
);
2785 LeaveCriticalSection(&ddraw_cs
);
2786 return DDERR_INVALIDPARAMS
;
2789 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2790 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
2792 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2793 if (all
|| (nomatch
!= IDirectDrawImpl_DDSD_Match(DDSD
, &surf
->surface_desc
)))
2795 desc
= surf
->surface_desc
;
2796 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
2797 if(Callback( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, Context
) != DDENUMRET_OK
)
2799 LeaveCriticalSection(&ddraw_cs
);
2804 LeaveCriticalSection(&ddraw_cs
);
2808 static HRESULT WINAPI
2809 findRenderTarget(IDirectDrawSurface7
*surface
,
2810 DDSURFACEDESC2
*desc
,
2813 IDirectDrawSurfaceImpl
*surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2814 IDirectDrawSurfaceImpl
**target
= (IDirectDrawSurfaceImpl
**) ctx
;
2816 if(!surf
->isRenderTarget
) {
2818 IDirectDrawSurface7_Release(surface
);
2819 return DDENUMRET_CANCEL
;
2822 /* Recurse into the surface tree */
2823 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
2825 IDirectDrawSurface7_Release(surface
);
2826 if(*target
) return DDENUMRET_CANCEL
;
2827 else return DDENUMRET_OK
; /* Continue with the next neighbor surface */
2830 /*****************************************************************************
2831 * D3D7CB_CreateRenderTarget
2833 * Callback called by WineD3D to create Surfaces for render target usage
2834 * This function takes the D3D target from the IDirectDrawImpl structure,
2835 * and returns the WineD3DSurface. To avoid double usage, the surface
2836 * is marked as render target afterwards
2839 * device: The WineD3DDevice's parent
2840 * Width, Height, Format: Dimensions and pixelformat of the render target
2841 * Ignored, because the surface already exists
2842 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2844 * ppSurface: Address to pass the surface pointer back at
2845 * pSharedHandle: Ignored
2848 * Always returns D3D_OK
2850 *****************************************************************************/
2851 static HRESULT WINAPI
2852 D3D7CB_CreateRenderTarget(IUnknown
*device
, IUnknown
*pSuperior
,
2853 UINT Width
, UINT Height
,
2854 WINED3DFORMAT Format
,
2855 WINED3DMULTISAMPLE_TYPE MultiSample
,
2856 DWORD MultisampleQuality
,
2858 IWineD3DSurface
** ppSurface
,
2859 HANDLE
* pSharedHandle
)
2861 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2862 IDirectDrawSurfaceImpl
*d3dSurface
= This
->d3d_target
, *target
= NULL
;
2863 TRACE("(%p) call back\n", device
);
2865 if(d3dSurface
->isRenderTarget
)
2867 IDirectDrawSurface7_EnumAttachedSurfaces(ICOM_INTERFACE(d3dSurface
, IDirectDrawSurface7
),
2868 &target
, findRenderTarget
);
2872 target
= d3dSurface
;
2877 target
= This
->d3d_target
;
2878 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
2881 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2883 *ppSurface
= target
->WineD3DSurface
;
2884 target
->isRenderTarget
= TRUE
;
2885 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface
, d3dSurface
);
2889 static HRESULT WINAPI
2890 D3D7CB_CreateDepthStencilSurface(IUnknown
*device
,
2891 IUnknown
*pSuperior
,
2894 WINED3DFORMAT Format
,
2895 WINED3DMULTISAMPLE_TYPE MultiSample
,
2896 DWORD MultisampleQuality
,
2898 IWineD3DSurface
** ppSurface
,
2899 HANDLE
* pSharedHandle
)
2901 /* Create a Depth Stencil surface to make WineD3D happy */
2902 HRESULT hr
= D3D_OK
;
2903 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2904 DDSURFACEDESC2 ddsd
;
2906 TRACE("(%p) call back\n", device
);
2910 /* Create a DirectDraw surface */
2911 memset(&ddsd
, 0, sizeof(ddsd
));
2912 ddsd
.dwSize
= sizeof(ddsd
);
2913 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2914 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2915 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2916 ddsd
.dwHeight
= Height
;
2917 ddsd
.dwWidth
= Width
;
2920 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, Format
);
2924 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
2927 This
->depthstencil
= TRUE
;
2928 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*) This
,
2930 (IDirectDrawSurface7
**) &This
->DepthStencilBuffer
,
2932 This
->depthstencil
= FALSE
;
2935 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
2938 *ppSurface
= This
->DepthStencilBuffer
->WineD3DSurface
;
2942 /*****************************************************************************
2943 * D3D7CB_CreateAdditionalSwapChain
2945 * Callback function for WineD3D which creates a new WineD3DSwapchain
2946 * interface. It also creates an IParent interface to store that pointer,
2947 * so the WineD3DSwapchain has a parent and can be released when the D3D
2948 * device is destroyed
2949 *****************************************************************************/
2950 static HRESULT WINAPI
2951 D3D7CB_CreateAdditionalSwapChain(IUnknown
*device
,
2952 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
2953 IWineD3DSwapChain
** ppSwapChain
)
2955 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2956 IParentImpl
*object
= NULL
;
2957 HRESULT res
= D3D_OK
;
2958 IWineD3DSwapChain
*swapchain
;
2959 TRACE("(%p) call back\n", device
);
2961 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
2964 FIXME("Allocation of memory failed\n");
2965 *ppSwapChain
= NULL
;
2966 return DDERR_OUTOFVIDEOMEMORY
;
2969 ICOM_INIT_INTERFACE(object
, IParent
, IParent_Vtbl
);
2972 res
= IWineD3DDevice_CreateAdditionalSwapChain(This
->wineD3DDevice
,
2973 pPresentationParameters
,
2975 (IUnknown
*) ICOM_INTERFACE(object
, IParent
),
2976 D3D7CB_CreateRenderTarget
,
2977 D3D7CB_CreateDepthStencilSurface
);
2980 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
2981 HeapFree(GetProcessHeap(), 0 , object
);
2982 *ppSwapChain
= NULL
;
2986 *ppSwapChain
= swapchain
;
2987 object
->child
= (IUnknown
*) swapchain
;
2993 /*****************************************************************************
2994 * IDirectDrawImpl_AttachD3DDevice
2996 * Initializes the D3D capabilities of WineD3D
2999 * primary: The primary surface for D3D
3005 *****************************************************************************/
3006 static HRESULT WINAPI
3007 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
,
3008 IDirectDrawSurfaceImpl
*primary
)
3013 WINED3DPRESENT_PARAMETERS localParameters
;
3015 TRACE("(%p)->(%p)\n", This
, primary
);
3017 /* Get the window */
3018 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
3022 ERR("IWineD3DDevice::GetHWND failed\n");
3026 /* If there's no window, create a hidden window. WineD3D needs it */
3029 window
= CreateWindowExA(0, This
->classname
, "Hidden D3D Window",
3031 GetSystemMetrics(SM_CXSCREEN
),
3032 GetSystemMetrics(SM_CYSCREEN
),
3033 NULL
, NULL
, GetModuleHandleA(0), NULL
);
3035 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
3036 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This
, window
);
3037 This
->d3d_window
= window
;
3041 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This
, window
);
3044 /* Store the future Render Target surface */
3045 This
->d3d_target
= primary
;
3047 /* Use the surface description for the device parameters, not the
3048 * Device settings. The app might render to an offscreen surface
3050 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
3051 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
3052 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
3053 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
) ? primary
->surface_desc
.dwBackBufferCount
: 0;
3054 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
3055 localParameters
.MultiSampleQuality
= 0;
3056 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
3057 localParameters
.hDeviceWindow
= window
;
3058 localParameters
.Windowed
= !(This
->cooperative_level
& DDSCL_FULLSCREEN
);
3059 localParameters
.EnableAutoDepthStencil
= FALSE
;
3060 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16
;
3061 localParameters
.Flags
= 0;
3062 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
; /* Default rate: It's already set */
3063 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
3065 TRACE("Passing mode %d\n", localParameters
.BackBufferFormat
);
3067 /* Set this NOW, otherwise creating the depth stencil surface will cause a
3068 * recursive loop until ram or emulated video memory is full
3070 This
->d3d_initialized
= TRUE
;
3072 hr
= IWineD3DDevice_Init3D(This
->wineD3DDevice
,
3074 D3D7CB_CreateAdditionalSwapChain
);
3077 This
->wineD3DDevice
= NULL
;
3081 This
->declArraySize
= 2;
3082 This
->decls
= HeapAlloc(GetProcessHeap(),
3084 sizeof(*This
->decls
) * This
->declArraySize
);
3087 ERR("Error allocating an array for the converted vertex decls\n");
3088 This
->declArraySize
= 0;
3089 hr
= IWineD3DDevice_Uninit3D(This
->wineD3DDevice
,
3090 D3D7CB_DestroyDepthStencilSurface
,
3091 D3D7CB_DestroySwapChain
);
3092 return E_OUTOFMEMORY
;
3095 /* Create an Index Buffer parent */
3096 TRACE("(%p) Successfully initialized 3D\n", This
);
3100 /*****************************************************************************
3101 * DirectDrawCreateClipper (DDRAW.@)
3103 * Creates a new IDirectDrawClipper object.
3106 * Clipper: Address to write the interface pointer to
3107 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3111 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3112 * E_OUTOFMEMORY if allocating the object failed
3114 *****************************************************************************/
3116 DirectDrawCreateClipper(DWORD Flags
,
3117 IDirectDrawClipper
**Clipper
,
3120 IDirectDrawClipperImpl
* object
;
3121 TRACE("(%08x,%p,%p)\n", Flags
, Clipper
, UnkOuter
);
3123 EnterCriticalSection(&ddraw_cs
);
3124 if (UnkOuter
!= NULL
)
3126 LeaveCriticalSection(&ddraw_cs
);
3127 return CLASS_E_NOAGGREGATION
;
3130 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3131 sizeof(IDirectDrawClipperImpl
));
3134 LeaveCriticalSection(&ddraw_cs
);
3135 return E_OUTOFMEMORY
;
3138 ICOM_INIT_INTERFACE(object
, IDirectDrawClipper
, IDirectDrawClipper_Vtbl
);
3140 object
->wineD3DClipper
= pWineDirect3DCreateClipper((IUnknown
*) object
);
3141 if(!object
->wineD3DClipper
)
3143 HeapFree(GetProcessHeap(), 0, object
);
3144 LeaveCriticalSection(&ddraw_cs
);
3145 return E_OUTOFMEMORY
;
3148 *Clipper
= (IDirectDrawClipper
*) object
;
3149 LeaveCriticalSection(&ddraw_cs
);
3153 /*****************************************************************************
3154 * IDirectDraw7::CreateClipper
3156 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3158 *****************************************************************************/
3159 static HRESULT WINAPI
3160 IDirectDrawImpl_CreateClipper(IDirectDraw7
*iface
,
3162 IDirectDrawClipper
**Clipper
,
3165 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3166 TRACE("(%p)->(%x,%p,%p)\n", This
, Flags
, Clipper
, UnkOuter
);
3167 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3170 /*****************************************************************************
3171 * IDirectDraw7::CreatePalette
3173 * Creates a new IDirectDrawPalette object
3176 * Flags: The flags for the new clipper
3177 * ColorTable: Color table to assign to the new clipper
3178 * Palette: Address to write the interface pointer to
3179 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3183 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3184 * E_OUTOFMEMORY if allocating the object failed
3186 *****************************************************************************/
3187 static HRESULT WINAPI
3188 IDirectDrawImpl_CreatePalette(IDirectDraw7
*iface
,
3190 PALETTEENTRY
*ColorTable
,
3191 IDirectDrawPalette
**Palette
,
3192 IUnknown
*pUnkOuter
)
3194 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3195 IDirectDrawPaletteImpl
*object
;
3196 HRESULT hr
= DDERR_GENERIC
;
3197 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3199 EnterCriticalSection(&ddraw_cs
);
3200 if(pUnkOuter
!= NULL
)
3202 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3203 LeaveCriticalSection(&ddraw_cs
);
3204 return CLASS_E_NOAGGREGATION
;
3207 /* The refcount test shows that a cooplevel is required for this */
3208 if(!This
->cooperative_level
)
3210 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3211 LeaveCriticalSection(&ddraw_cs
);
3212 return DDERR_NOCOOPERATIVELEVELSET
;
3215 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3218 ERR("Out of memory when allocating memory for a palette implementation\n");
3219 LeaveCriticalSection(&ddraw_cs
);
3220 return E_OUTOFMEMORY
;
3223 ICOM_INIT_INTERFACE(object
, IDirectDrawPalette
, IDirectDrawPalette_Vtbl
);
3225 object
->ddraw_owner
= This
;
3227 hr
= IWineD3DDevice_CreatePalette(This
->wineD3DDevice
, Flags
, ColorTable
, &object
->wineD3DPalette
, (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawPalette
) );
3230 HeapFree(GetProcessHeap(), 0, object
);
3231 LeaveCriticalSection(&ddraw_cs
);
3235 IDirectDraw7_AddRef(iface
);
3236 object
->ifaceToRelease
= (IUnknown
*) iface
;
3237 *Palette
= ICOM_INTERFACE(object
, IDirectDrawPalette
);
3238 LeaveCriticalSection(&ddraw_cs
);
3242 /*****************************************************************************
3243 * IDirectDraw7::DuplicateSurface
3245 * Duplicates a surface. The surface memory points to the same memory as
3246 * the original surface, and it's released when the last surface referencing
3247 * it is released. I guess that's beyond Wine's surface management right now
3248 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3249 * test application to implement this)
3252 * Src: Address of the source surface
3253 * Dest: Address to write the new surface pointer to
3256 * See IDirectDraw7::CreateSurface
3258 *****************************************************************************/
3259 static HRESULT WINAPI
3260 IDirectDrawImpl_DuplicateSurface(IDirectDraw7
*iface
,
3261 IDirectDrawSurface7
*Src
,
3262 IDirectDrawSurface7
**Dest
)
3264 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3265 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Src
);
3267 FIXME("(%p)->(%p,%p)\n", This
, Surf
, Dest
);
3269 /* For now, simply create a new, independent surface */
3270 return IDirectDraw7_CreateSurface(iface
,
3271 &Surf
->surface_desc
,
3276 /*****************************************************************************
3277 * IDirectDraw7 VTable
3278 *****************************************************************************/
3279 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
=
3282 IDirectDrawImpl_QueryInterface
,
3283 IDirectDrawImpl_AddRef
,
3284 IDirectDrawImpl_Release
,
3285 /*** IDirectDraw ***/
3286 IDirectDrawImpl_Compact
,
3287 IDirectDrawImpl_CreateClipper
,
3288 IDirectDrawImpl_CreatePalette
,
3289 IDirectDrawImpl_CreateSurface
,
3290 IDirectDrawImpl_DuplicateSurface
,
3291 IDirectDrawImpl_EnumDisplayModes
,
3292 IDirectDrawImpl_EnumSurfaces
,
3293 IDirectDrawImpl_FlipToGDISurface
,
3294 IDirectDrawImpl_GetCaps
,
3295 IDirectDrawImpl_GetDisplayMode
,
3296 IDirectDrawImpl_GetFourCCCodes
,
3297 IDirectDrawImpl_GetGDISurface
,
3298 IDirectDrawImpl_GetMonitorFrequency
,
3299 IDirectDrawImpl_GetScanLine
,
3300 IDirectDrawImpl_GetVerticalBlankStatus
,
3301 IDirectDrawImpl_Initialize
,
3302 IDirectDrawImpl_RestoreDisplayMode
,
3303 IDirectDrawImpl_SetCooperativeLevel
,
3304 IDirectDrawImpl_SetDisplayMode
,
3305 IDirectDrawImpl_WaitForVerticalBlank
,
3306 /*** IDirectDraw2 ***/
3307 IDirectDrawImpl_GetAvailableVidMem
,
3308 /*** IDirectDraw7 ***/
3309 IDirectDrawImpl_GetSurfaceFromDC
,
3310 IDirectDrawImpl_RestoreAllSurfaces
,
3311 IDirectDrawImpl_TestCooperativeLevel
,
3312 IDirectDrawImpl_GetDeviceIdentifier
,
3313 /*** IDirectDraw7 ***/
3314 IDirectDrawImpl_StartModeTest
,
3315 IDirectDrawImpl_EvaluateMode
3318 /*****************************************************************************
3319 * IDirectDrawImpl_FindDecl
3321 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
3322 * if none was found.
3324 * This function is in ddraw.c and the DDraw object space because D3D7
3325 * vertex buffers are created using the IDirect3D interface to the ddraw
3326 * object, so they can be valid across D3D devices(theoretically. The ddraw
3327 * object also owns the wined3d device
3331 * fvf: Fvf to find the decl for
3334 * NULL in case of an error, the IWineD3DVertexDeclaration interface for the
3337 *****************************************************************************/
3338 IWineD3DVertexDeclaration
*
3339 IDirectDrawImpl_FindDecl(IDirectDrawImpl
*This
,
3343 IWineD3DVertexDeclaration
* pDecl
= NULL
;
3344 int p
, low
, high
; /* deliberately signed */
3345 struct FvfToDecl
*convertedDecls
= This
->decls
;
3347 TRACE("Searching for declaration for fvf %08x... ", fvf
);
3350 high
= This
->numConvertedDecls
- 1;
3351 while(low
<= high
) {
3352 p
= (low
+ high
) >> 1;
3354 if(convertedDecls
[p
].fvf
== fvf
) {
3355 TRACE("found %p\n", convertedDecls
[p
].decl
);
3356 return convertedDecls
[p
].decl
;
3357 } else if(convertedDecls
[p
].fvf
< fvf
) {
3363 TRACE("not found. Creating and inserting at position %d.\n", low
);
3365 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->wineD3DDevice
,
3367 (IUnknown
*) ICOM_INTERFACE(This
, IDirectDraw7
),
3369 if (hr
!= S_OK
) return NULL
;
3371 if(This
->declArraySize
== This
->numConvertedDecls
) {
3372 int grow
= max(This
->declArraySize
/ 2, 8);
3373 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
3374 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
3375 if(!convertedDecls
) {
3376 /* This will destroy it */
3377 IWineD3DVertexDeclaration_Release(pDecl
);
3380 This
->decls
= convertedDecls
;
3381 This
->declArraySize
+= grow
;
3384 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
3385 convertedDecls
[low
].decl
= pDecl
;
3386 convertedDecls
[low
].fvf
= fvf
;
3387 This
->numConvertedDecls
++;
3389 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);