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 /* Enable thread safety in wined3d */
520 IWineD3DDevice_SetMultithreaded(This
->wineD3DDevice
);
523 /* Unhandled flags */
524 if(cooplevel
& DDSCL_ALLOWREBOOT
)
525 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
526 if(cooplevel
& DDSCL_ALLOWMODEX
)
527 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
528 if(cooplevel
& DDSCL_FPUSETUP
)
529 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
530 if(cooplevel
& DDSCL_FPUPRESERVE
)
531 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This
);
533 /* Store the cooperative_level */
534 This
->cooperative_level
|= cooplevel
;
535 TRACE("SetCooperativeLevel retuning DD_OK\n");
536 LeaveCriticalSection(&ddraw_cs
);
540 /*****************************************************************************
541 * IDirectDraw7::SetDisplayMode
543 * Sets the display screen resolution, color depth and refresh frequency
544 * when in fullscreen mode (in theory).
545 * Possible return values listed in the SDK suggest that this method fails
546 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
547 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
548 * It seems to be valid to pass 0 for With and Height, this has to be tested
549 * It could mean that the current video mode should be left as-is. (But why
553 * Height, Width: Screen dimension
554 * BPP: Color depth in Bits per pixel
555 * Refreshrate: Screen refresh rate
561 *****************************************************************************/
562 static HRESULT WINAPI
563 IDirectDrawImpl_SetDisplayMode(IDirectDraw7
*iface
,
570 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
571 WINED3DDISPLAYMODE Mode
;
573 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
575 EnterCriticalSection(&ddraw_cs
);
576 if( !Width
|| !Height
)
578 ERR("Width=%d, Height=%d, what to do?\n", Width
, Height
);
579 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
580 LeaveCriticalSection(&ddraw_cs
);
584 /* Check the exclusive mode
585 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
586 return DDERR_NOEXCLUSIVEMODE;
587 * This is WRONG. Don't know if the SDK is completely
588 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
589 * is returned, but Half-Life 1.1.1.1 (Steam version)
594 Mode
.Height
= Height
;
595 Mode
.RefreshRate
= RefreshRate
;
598 case 8: Mode
.Format
= WINED3DFMT_P8
; break;
599 case 15: Mode
.Format
= WINED3DFMT_X1R5G5B5
; break;
600 case 16: Mode
.Format
= WINED3DFMT_R5G6B5
; break;
601 case 24: Mode
.Format
= WINED3DFMT_R8G8B8
; break;
602 case 32: Mode
.Format
= WINED3DFMT_A8R8G8B8
; break;
605 /* TODO: The possible return values from msdn suggest that
606 * the screen mode can't be changed if a surface is locked
607 * or some drawing is in progress
610 /* TODO: Lose the primary surface */
611 hr
= IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
612 0, /* First swapchain */
614 LeaveCriticalSection(&ddraw_cs
);
617 case WINED3DERR_NOTAVAILABLE
: return DDERR_UNSUPPORTED
;
622 /*****************************************************************************
623 * IDirectDraw7::RestoreDisplayMode
625 * Restores the display mode to what it was at creation time. Basically.
627 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
628 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
629 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
630 * -> DD_1 is released. The screen should be left at 1024x768x32.
631 * -> DD_2 is released. The screen should be set to 1400x1050x32
632 * This case is unhandled right now, but Empire Earth does it this way.
633 * (But perhaps there is something in SetCooperativeLevel to prevent this)
635 * The msdn says that this method resets the display mode to what it was before
636 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
640 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
642 *****************************************************************************/
643 static HRESULT WINAPI
644 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7
*iface
)
646 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
647 TRACE("(%p)\n", This
);
649 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This
, IDirectDraw7
),
657 /*****************************************************************************
658 * IDirectDraw7::GetCaps
660 * Returns the drives capabilities
662 * Used for version 1, 2, 4 and 7
665 * DriverCaps: Structure to write the Hardware accelerated caps to
666 * HelCaps: Structure to write the emulation caps to
669 * This implementation returns DD_OK only
671 *****************************************************************************/
672 static HRESULT WINAPI
673 IDirectDrawImpl_GetCaps(IDirectDraw7
*iface
,
677 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
678 TRACE("(%p)->(%p,%p)\n", This
, DriverCaps
, HELCaps
);
680 /* One structure must be != NULL */
681 if( (!DriverCaps
) && (!HELCaps
) )
683 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This
);
684 return DDERR_INVALIDPARAMS
;
689 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &This
->caps
);
692 TRACE("Driver Caps :\n");
693 DDRAW_dump_DDCAPS(DriverCaps
);
699 DD_STRUCT_COPY_BYSIZE(HELCaps
, &This
->caps
);
702 TRACE("HEL Caps :\n");
703 DDRAW_dump_DDCAPS(HELCaps
);
710 /*****************************************************************************
711 * IDirectDraw7::Compact
713 * No idea what it does, MSDN says it's not implemented.
716 * DD_OK, but this is unchecked
718 *****************************************************************************/
719 static HRESULT WINAPI
720 IDirectDrawImpl_Compact(IDirectDraw7
*iface
)
722 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
723 TRACE("(%p)\n", This
);
728 /*****************************************************************************
729 * IDirectDraw7::GetDisplayMode
731 * Returns information about the current display mode
733 * Exists in Version 1, 2, 4 and 7
736 * DDSD: Address of a surface description structure to write the info to
741 *****************************************************************************/
742 static HRESULT WINAPI
743 IDirectDrawImpl_GetDisplayMode(IDirectDraw7
*iface
,
744 DDSURFACEDESC2
*DDSD
)
746 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
748 WINED3DDISPLAYMODE Mode
;
750 TRACE("(%p)->(%p): Relay\n", This
, DDSD
);
752 EnterCriticalSection(&ddraw_cs
);
753 /* This seems sane */
756 LeaveCriticalSection(&ddraw_cs
);
757 return DDERR_INVALIDPARAMS
;
760 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
761 * so one method can be used for all versions (Hopefully)
763 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
768 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
769 LeaveCriticalSection(&ddraw_cs
);
774 memset(DDSD
, 0, Size
);
777 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
778 DDSD
->dwWidth
= Mode
.Width
;
779 DDSD
->dwHeight
= Mode
.Height
;
780 DDSD
->u2
.dwRefreshRate
= 60;
781 DDSD
->ddsCaps
.dwCaps
= 0;
782 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
783 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
784 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
788 TRACE("Returning surface desc :\n");
789 DDRAW_dump_surface_desc(DDSD
);
792 LeaveCriticalSection(&ddraw_cs
);
796 /*****************************************************************************
797 * IDirectDraw7::GetFourCCCodes
799 * Returns an array of supported FourCC codes.
801 * Exists in Version 1, 2, 4 and 7
804 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
805 * of enumerated codes
806 * Codes: Pointer to an array of DWORDs where the supported codes are written
810 * Always returns DD_OK, as it's a stub for now
812 *****************************************************************************/
813 static HRESULT WINAPI
814 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7
*iface
,
815 DWORD
*NumCodes
, DWORD
*Codes
)
817 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
818 FIXME("(%p)->(%p, %p): Stub!\n", This
, NumCodes
, Codes
);
820 if(NumCodes
) *NumCodes
= 0;
825 /*****************************************************************************
826 * IDirectDraw7::GetMonitorFrequency
828 * Returns the monitor's frequency
830 * Exists in Version 1, 2, 4 and 7
833 * Freq: Pointer to a DWORD to write the frequency to
836 * Always returns DD_OK
838 *****************************************************************************/
839 static HRESULT WINAPI
840 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7
*iface
,
843 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
844 TRACE("(%p)->(%p)\n", This
, Freq
);
846 /* Ideally this should be in WineD3D, as it concerns the screen setup,
847 * but for now this should make the games happy
853 /*****************************************************************************
854 * IDirectDraw7::GetVerticalBlankStatus
856 * Returns the Vertical blank status of the monitor. This should be in WineD3D
857 * too basically, but as it's a semi stub, I didn't create a function there
860 * status: Pointer to a BOOL to be filled with the vertical blank status
864 * DDERR_INVALIDPARAMS if status is NULL
866 *****************************************************************************/
867 static HRESULT WINAPI
868 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7
*iface
,
871 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
872 TRACE("(%p)->(%p)\n", This
, status
);
874 /* This looks sane, the MSDN suggests it too */
875 EnterCriticalSection(&ddraw_cs
);
878 LeaveCriticalSection(&ddraw_cs
);
879 return DDERR_INVALIDPARAMS
;
882 *status
= This
->fake_vblank
;
883 This
->fake_vblank
= !This
->fake_vblank
;
884 LeaveCriticalSection(&ddraw_cs
);
888 /*****************************************************************************
889 * IDirectDraw7::GetAvailableVidMem
891 * Returns the total and free video memory
894 * Caps: Specifies the memory type asked for
895 * total: Pointer to a DWORD to be filled with the total memory
896 * free: Pointer to a DWORD to be filled with the free memory
900 * DDERR_INVALIDPARAMS of free and total are NULL
902 *****************************************************************************/
903 static HRESULT WINAPI
904 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
906 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
907 TRACE("(%p)->(%p, %p, %p)\n", This
, Caps
, total
, free
);
911 TRACE("(%p) Asked for memory with description: ", This
);
912 DDRAW_dump_DDSCAPS2(Caps
);
915 EnterCriticalSection(&ddraw_cs
);
917 /* Todo: System memory vs local video memory vs non-local video memory
918 * The MSDN also mentions differences between texture memory and other
919 * resources, but that's not important
922 if( (!total
) && (!free
) )
924 LeaveCriticalSection(&ddraw_cs
);
925 return DDERR_INVALIDPARAMS
;
928 if(total
) *total
= This
->total_vidmem
;
929 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
931 LeaveCriticalSection(&ddraw_cs
);
935 /*****************************************************************************
936 * IDirectDraw7::Initialize
938 * Initializes a DirectDraw interface.
941 * GUID: Interface identifier. Well, don't know what this is really good
945 * Returns DD_OK on the first call,
946 * DDERR_ALREADYINITIALIZED on repeated calls
948 *****************************************************************************/
949 static HRESULT WINAPI
950 IDirectDrawImpl_Initialize(IDirectDraw7
*iface
,
953 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
954 TRACE("(%p)->(%s): No-op\n", This
, debugstr_guid(Guid
));
956 if(This
->initialized
)
958 return DDERR_ALREADYINITIALIZED
;
966 /*****************************************************************************
967 * IDirectDraw7::FlipToGDISurface
969 * "Makes the surface that the GDI writes to the primary surface"
970 * Looks like some windows specific thing we don't have to care about.
971 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
972 * show error boxes ;)
973 * Well, just return DD_OK.
976 * Always returns DD_OK
978 *****************************************************************************/
979 static HRESULT WINAPI
980 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7
*iface
)
982 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
983 TRACE("(%p)\n", This
);
988 /*****************************************************************************
989 * IDirectDraw7::WaitForVerticalBlank
991 * This method allows applications to get in sync with the vertical blank
993 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
994 * redraw the screen, most likely because of this stub
997 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
998 * or DDWAITVB_BLOCKEND
999 * h: Not used, according to MSDN
1002 * Always returns DD_OK
1004 *****************************************************************************/
1005 static HRESULT WINAPI
1006 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7
*iface
,
1010 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1011 FIXME("(%p)->(%x,%p): Stub\n", This
, Flags
, h
);
1013 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1014 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1015 return DDERR_UNSUPPORTED
; /* unchecked */
1020 /*****************************************************************************
1021 * IDirectDraw7::GetScanLine
1023 * Returns the scan line that is being drawn on the monitor
1026 * Scanline: Address to write the scan line value to
1029 * Always returns DD_OK
1031 *****************************************************************************/
1032 static HRESULT WINAPI
IDirectDrawImpl_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1034 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1035 static BOOL hide
= FALSE
;
1036 WINED3DDISPLAYMODE Mode
;
1038 /* This function is called often, so print the fixme only once */
1039 EnterCriticalSection(&ddraw_cs
);
1042 FIXME("(%p)->(%p): Semi-Stub\n", This
, Scanline
);
1046 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1050 /* Fake the line sweeping of the monitor */
1051 /* FIXME: We should synchronize with a source to keep the refresh rate */
1052 *Scanline
= This
->cur_scanline
++;
1053 /* Assume 20 scan lines in the vertical blank */
1054 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1055 This
->cur_scanline
= 0;
1057 LeaveCriticalSection(&ddraw_cs
);
1061 /*****************************************************************************
1062 * IDirectDraw7::TestCooperativeLevel
1064 * Informs the application about the state of the video adapter, depending
1065 * on the cooperative level
1068 * DD_OK if the device is in a sane state
1069 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1070 * if the state is not correct(See below)
1072 *****************************************************************************/
1073 static HRESULT WINAPI
1074 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7
*iface
)
1076 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1078 TRACE("(%p)\n", This
);
1080 EnterCriticalSection(&ddraw_cs
);
1081 /* Description from MSDN:
1082 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1083 * away from the app with e.g. alt-tab. Windowed apps receive
1084 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1085 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1086 * when the video mode has changed
1089 hr
= IWineD3DDevice_TestCooperativeLevel(This
->wineD3DDevice
);
1091 /* Fix the result value. These values are mapped from their
1096 case WINED3DERR_DEVICELOST
:
1097 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
1099 LeaveCriticalSection(&ddraw_cs
);
1100 return DDERR_NOEXCLUSIVEMODE
;
1104 LeaveCriticalSection(&ddraw_cs
);
1105 return DDERR_EXCLUSIVEMODEALREADYSET
;
1108 case WINED3DERR_DEVICENOTRESET
:
1109 LeaveCriticalSection(&ddraw_cs
);
1113 LeaveCriticalSection(&ddraw_cs
);
1116 case WINED3DERR_DRIVERINTERNALERROR
:
1118 ERR("(%p) Unexpected return value %08x from wineD3D, "
1119 " returning DD_OK\n", This
, hr
);
1122 LeaveCriticalSection(&ddraw_cs
);
1126 /*****************************************************************************
1127 * IDirectDraw7::GetGDISurface
1129 * Returns the surface that GDI is treating as the primary surface.
1130 * For Wine this is the front buffer
1133 * GDISurface: Address to write the surface pointer to
1136 * DD_OK if the surface was found
1137 * DDERR_NOTFOUND if the GDI surface wasn't found
1139 *****************************************************************************/
1140 static HRESULT WINAPI
1141 IDirectDrawImpl_GetGDISurface(IDirectDraw7
*iface
,
1142 IDirectDrawSurface7
**GDISurface
)
1144 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1145 IWineD3DSurface
*Surf
;
1146 IDirectDrawSurface7
*ddsurf
;
1149 TRACE("(%p)->(%p)\n", This
, GDISurface
);
1151 /* Get the back buffer from the wineD3DDevice and search its
1152 * attached surfaces for the front buffer
1154 EnterCriticalSection(&ddraw_cs
);
1155 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1157 0, /* first back buffer*/
1158 WINED3DBACKBUFFER_TYPE_MONO
,
1161 if( (hr
!= D3D_OK
) ||
1164 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1165 LeaveCriticalSection(&ddraw_cs
);
1166 return DDERR_NOTFOUND
;
1169 /* GetBackBuffer AddRef()ed the surface, release it */
1170 IWineD3DSurface_Release(Surf
);
1172 IWineD3DSurface_GetParent(Surf
,
1173 (IUnknown
**) &ddsurf
);
1174 IDirectDrawSurface7_Release(ddsurf
); /* For the GetParent */
1176 /* Find the front buffer */
1177 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1178 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1183 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1186 /* The AddRef is OK this time */
1187 LeaveCriticalSection(&ddraw_cs
);
1191 /*****************************************************************************
1192 * IDirectDraw7::EnumDisplayModes
1194 * Enumerates the supported Display modes. The modes can be filtered with
1195 * the DDSD parameter.
1198 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1199 * DDSD: Surface description to filter the modes
1200 * Context: Pointer passed back to the callback function
1201 * cb: Application-provided callback function
1205 * DDERR_INVALIDPARAMS if the callback wasn't set
1207 *****************************************************************************/
1208 static HRESULT WINAPI
1209 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7
*iface
,
1211 DDSURFACEDESC2
*DDSD
,
1213 LPDDENUMMODESCALLBACK2 cb
)
1215 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1216 unsigned int modenum
, fmt
;
1217 WINED3DFORMAT pixelformat
= WINED3DFMT_UNKNOWN
;
1218 WINED3DDISPLAYMODE mode
;
1219 DDSURFACEDESC2 callback_sd
;
1221 WINED3DFORMAT checkFormatList
[] =
1224 WINED3DFMT_A8R8G8B8
,
1225 WINED3DFMT_X8R8G8B8
,
1227 WINED3DFMT_X1R5G5B5
,
1228 WINED3DFMT_A1R5G5B5
,
1229 WINED3DFMT_A4R4G4B4
,
1231 WINED3DFMT_A8R3G3B2
,
1232 WINED3DFMT_X4R4G4B4
,
1233 WINED3DFMT_A2B10G10R10
,
1234 WINED3DFMT_A8B8G8R8
,
1235 WINED3DFMT_X8B8G8R8
,
1236 WINED3DFMT_A2R10G10B10
,
1241 TRACE("(%p)->(%p,%p,%p): Relay\n", This
, DDSD
, Context
, cb
);
1243 EnterCriticalSection(&ddraw_cs
);
1244 /* This looks sane */
1247 LeaveCriticalSection(&ddraw_cs
);
1248 return DDERR_INVALIDPARAMS
;
1253 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1254 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1257 for(fmt
= 0; fmt
< (sizeof(checkFormatList
) / sizeof(checkFormatList
[0])); fmt
++)
1259 if(pixelformat
!= WINED3DFMT_UNKNOWN
&& checkFormatList
[fmt
] != pixelformat
)
1265 while(IWineD3D_EnumAdapterModes(This
->wineD3D
,
1266 WINED3DADAPTER_DEFAULT
,
1267 checkFormatList
[fmt
],
1269 &mode
) == WINED3D_OK
)
1273 if(DDSD
->dwFlags
& DDSD_WIDTH
&& mode
.Width
!= DDSD
->dwWidth
) continue;
1274 if(DDSD
->dwFlags
& DDSD_HEIGHT
&& mode
.Height
!= DDSD
->dwHeight
) continue;
1277 memset(&callback_sd
, 0, sizeof(callback_sd
));
1278 callback_sd
.dwSize
= sizeof(callback_sd
);
1279 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1281 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
1282 if(Flags
& DDEDM_REFRESHRATES
)
1284 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
1285 callback_sd
.u2
.dwRefreshRate
= mode
.RefreshRate
;
1288 callback_sd
.dwWidth
= mode
.Width
;
1289 callback_sd
.dwHeight
= mode
.Height
;
1291 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, mode
.Format
);
1293 TRACE("Enumerating %dx%d@%d\n", callback_sd
.dwWidth
, callback_sd
.dwHeight
, callback_sd
.u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
);
1295 if(cb(&callback_sd
, Context
) == DDENUMRET_CANCEL
)
1297 TRACE("Application asked to terminate the enumeration\n");
1298 LeaveCriticalSection(&ddraw_cs
);
1304 TRACE("End of enumeration\n");
1305 LeaveCriticalSection(&ddraw_cs
);
1309 /*****************************************************************************
1310 * IDirectDraw7::EvaluateMode
1312 * Used with IDirectDraw7::StartModeTest to test video modes.
1313 * EvaluateMode is used to pass or fail a mode, and continue with the next
1317 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1318 * Timeout: Returns the amount of seconds left before the mode would have
1319 * been failed automatically
1322 * This implementation always DD_OK, because it's a stub
1324 *****************************************************************************/
1325 static HRESULT WINAPI
1326 IDirectDrawImpl_EvaluateMode(IDirectDraw7
*iface
,
1330 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1331 FIXME("(%p)->(%d,%p): Stub!\n", This
, Flags
, Timeout
);
1333 /* When implementing this, implement it in WineD3D */
1338 /*****************************************************************************
1339 * IDirectDraw7::GetDeviceIdentifier
1341 * Returns the device identifier, which gives information about the driver
1342 * Our device identifier is defined at the beginning of this file.
1345 * DDDI: Address for the returned structure
1346 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1349 * On success it returns DD_OK
1350 * DDERR_INVALIDPARAMS if DDDI is NULL
1352 *****************************************************************************/
1353 static HRESULT WINAPI
1354 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7
*iface
,
1355 DDDEVICEIDENTIFIER2
*DDDI
,
1358 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1359 TRACE("(%p)->(%p,%08x)\n", This
, DDDI
, Flags
);
1362 return DDERR_INVALIDPARAMS
;
1364 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1365 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1366 * to any modern hardware, nor is it interesting for Wine, so ignore it
1369 *DDDI
= deviceidentifier
;
1373 /*****************************************************************************
1374 * IDirectDraw7::GetSurfaceFromDC
1376 * Returns the Surface for a GDI device context handle.
1377 * Is this related to IDirectDrawSurface::GetDC ???
1380 * hdc: hdc to return the surface for
1381 * Surface: Address to write the surface pointer to
1384 * Always returns DD_OK because it's a stub
1386 *****************************************************************************/
1387 static HRESULT WINAPI
1388 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7
*iface
,
1390 IDirectDrawSurface7
**Surface
)
1392 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1393 FIXME("(%p)->(%p,%p): Stub!\n", This
, hdc
, Surface
);
1395 /* Implementation idea if needed: Loop through all surfaces and compare
1396 * their hdc with hdc. Implement it in WineD3D! */
1397 return DDERR_NOTFOUND
;
1400 /*****************************************************************************
1401 * IDirectDraw7::RestoreAllSurfaces
1403 * Calls the restore method of all surfaces
1408 * Always returns DD_OK because it's a stub
1410 *****************************************************************************/
1411 static HRESULT WINAPI
1412 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7
*iface
)
1414 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1415 FIXME("(%p): Stub\n", This
);
1417 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1418 * get their parent and call their restore method. Do not implement
1419 * it in WineD3D, as restoring a surface means re-creating the
1425 /*****************************************************************************
1426 * IDirectDraw7::StartModeTest
1428 * Tests the specified video modes to update the system registry with
1429 * refresh rate information. StartModeTest starts the mode test,
1430 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1431 * isn't called within 15 seconds, the mode is failed automatically
1433 * As refresh rates are handled by the X server, I don't think this
1434 * Method is important
1437 * Modes: An array of mode specifications
1438 * NumModes: The number of modes in Modes
1439 * Flags: Some flags...
1442 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1443 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1446 *****************************************************************************/
1447 static HRESULT WINAPI
1448 IDirectDrawImpl_StartModeTest(IDirectDraw7
*iface
,
1453 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1454 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This
, Modes
, NumModes
, Flags
);
1456 /* This looks sane */
1457 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
1459 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1460 * As it is not, DDERR_TESTFINISHED is returned
1461 * (hopefully that's correct
1463 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1464 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1470 /*****************************************************************************
1471 * IDirectDrawImpl_RecreateSurfacesCallback
1473 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1474 * It re-recreates the WineD3DSurface. It's pretty straightforward
1476 *****************************************************************************/
1478 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
1479 DDSURFACEDESC2
*desc
,
1482 IDirectDrawSurfaceImpl
*surfImpl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1483 IDirectDrawSurface7
,
1485 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
1487 IParentImpl
*parImpl
= NULL
;
1488 IWineD3DSurface
*wineD3DSurface
;
1491 IWineD3DClipper
*clipper
= NULL
;
1493 WINED3DSURFACE_DESC Desc
;
1494 WINED3DFORMAT Format
;
1495 WINED3DRESOURCETYPE Type
;
1500 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1501 DWORD MultiSampleQuality
;
1505 TRACE("(%p): Enumerated Surface %p\n", This
, surfImpl
);
1507 /* For the enumeration */
1508 IDirectDrawSurface7_Release(surf
);
1510 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
1512 /* Get the objects */
1513 wineD3DSurface
= surfImpl
->WineD3DSurface
;
1514 IWineD3DSurface_GetParent(wineD3DSurface
, &Parent
);
1515 IUnknown_Release(Parent
); /* For the getParent */
1517 /* Is the parent an IParent interface? */
1518 if(IUnknown_QueryInterface(Parent
, &IID_IParent
, &tmp
) == S_OK
)
1520 /* It is a IParent interface! */
1521 IUnknown_Release(Parent
); /* For the QueryInterface */
1522 parImpl
= ICOM_OBJECT(IParentImpl
, IParent
, Parent
);
1523 /* Release the reference the parent interface is holding */
1524 IWineD3DSurface_Release(wineD3DSurface
);
1527 /* get the clipper */
1528 IWineD3DSurface_GetClipper(wineD3DSurface
, &clipper
);
1530 /* Get the surface properties */
1531 Desc
.Format
= &Format
;
1533 Desc
.Usage
= &Usage
;
1536 Desc
.MultiSampleType
= &MultiSampleType
;
1537 Desc
.MultiSampleQuality
= &MultiSampleQuality
;
1538 Desc
.Width
= &Width
;
1539 Desc
.Height
= &Height
;
1541 hr
= IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
1542 if(hr
!= D3D_OK
) return hr
;
1544 /* Create the new surface */
1545 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1546 Width
, Height
, Format
,
1547 TRUE
/* Lockable */,
1548 FALSE
/* Discard */,
1549 surfImpl
->mipmap_level
,
1550 &surfImpl
->WineD3DSurface
,
1556 0 /* SharedHandle */,
1563 IWineD3DSurface_SetClipper(surfImpl
->WineD3DSurface
, clipper
);
1565 /* Update the IParent if it exists */
1568 parImpl
->child
= (IUnknown
*) surfImpl
->WineD3DSurface
;
1569 /* Add a reference for the IParent */
1570 IWineD3DSurface_AddRef(surfImpl
->WineD3DSurface
);
1572 /* TODO: Copy the surface content, except for render targets */
1574 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
1575 TRACE("Surface released successful, next surface\n");
1577 ERR("Something's still holding the old WineD3DSurface\n");
1579 surfImpl
->ImplType
= This
->ImplType
;
1583 IWineD3DClipper_Release(clipper
);
1585 return DDENUMRET_OK
;
1588 /*****************************************************************************
1589 * IDirectDrawImpl_RecreateAllSurfaces
1591 * A function, that converts all wineD3DSurfaces to the new implementation type
1592 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1593 * new WineD3DSurface, copies the content and releases the old surface
1595 *****************************************************************************/
1597 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl
*This
)
1599 DDSURFACEDESC2 desc
;
1600 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
1602 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
1604 /* Should happen almost never */
1605 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
1607 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
, D3D7CB_DestroyDepthStencilSurface
, D3D7CB_DestroySwapChain
);
1609 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1611 memset(&desc
, 0, sizeof(desc
));
1612 desc
.dwSize
= sizeof(desc
);
1614 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This
, IDirectDraw7
),
1618 IDirectDrawImpl_RecreateSurfacesCallback
);
1621 /*****************************************************************************
1622 * D3D7CB_CreateSurface
1624 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1625 * correct mipmap sublevel, and returns it to WineD3D.
1626 * The surfaces are created already by IDirectDraw7::CreateSurface
1629 * With, Height: With and height of the surface
1630 * Format: The requested format
1631 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1632 * level: The mipmap level
1633 * Face: The cube map face type
1634 * Surface: Pointer to pass the created surface back at
1635 * SharedHandle: NULL
1640 *****************************************************************************/
1641 static HRESULT WINAPI
1642 D3D7CB_CreateSurface(IUnknown
*device
,
1643 IUnknown
*pSuperior
,
1644 UINT Width
, UINT Height
,
1645 WINED3DFORMAT Format
,
1646 DWORD Usage
, WINED3DPOOL Pool
, UINT level
,
1647 WINED3DCUBEMAP_FACES Face
,
1648 IWineD3DSurface
**Surface
,
1649 HANDLE
*SharedHandle
)
1651 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
1652 IDirectDrawSurfaceImpl
*surf
= NULL
;
1654 DDSCAPS2 searchcaps
= This
->tex_root
->surface_desc
.ddsCaps
;
1655 TRACE("(%p) call back. surf=%p. Face %d level %d\n", device
, This
->tex_root
, Face
, level
);
1657 searchcaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
1660 case WINED3DCUBEMAP_FACE_POSITIVE_X
:
1661 TRACE("Asked for positive x\n");
1662 if(searchcaps
.dwCaps2
& DDSCAPS2_CUBEMAP
) {
1663 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
1665 surf
= This
->tex_root
; break;
1666 case WINED3DCUBEMAP_FACE_NEGATIVE_X
:
1667 TRACE("Asked for negative x\n");
1668 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
; break;
1669 case WINED3DCUBEMAP_FACE_POSITIVE_Y
:
1670 TRACE("Asked for positive y\n");
1671 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
; break;
1672 case WINED3DCUBEMAP_FACE_NEGATIVE_Y
:
1673 TRACE("Asked for negative y\n");
1674 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
; break;
1675 case WINED3DCUBEMAP_FACE_POSITIVE_Z
:
1676 TRACE("Asked for positive z\n");
1677 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
; break;
1678 case WINED3DCUBEMAP_FACE_NEGATIVE_Z
:
1679 TRACE("Asked for negative z\n");
1680 searchcaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
; break;
1681 default: {ERR("Unexpected cube face\n");} /* Stupid compiler */
1686 IDirectDrawSurface7
*attached
;
1687 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(This
->tex_root
, IDirectDrawSurface7
),
1690 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1691 IDirectDrawSurface7_Release(attached
);
1693 if(!surf
) ERR("root search surface not found\n");
1695 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1698 IDirectDrawSurface7
*attached
;
1699 IDirectDrawSurface7_GetAttachedSurface(ICOM_INTERFACE(surf
, IDirectDrawSurface7
),
1702 if(!attached
) ERR("Surface not found\n");
1703 surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, attached
);
1704 IDirectDrawSurface7_Release(attached
);
1708 /* Return the surface */
1709 *Surface
= surf
->WineD3DSurface
;
1711 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface
, surf
);
1715 ULONG WINAPI
D3D7CB_DestroySwapChain(IWineD3DSwapChain
*pSwapChain
) {
1716 IUnknown
* swapChainParent
;
1717 TRACE("(%p) call back\n", pSwapChain
);
1719 IWineD3DSwapChain_GetParent(pSwapChain
, &swapChainParent
);
1720 IUnknown_Release(swapChainParent
);
1721 return IUnknown_Release(swapChainParent
);
1724 ULONG WINAPI
D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface
*pSurface
) {
1725 IUnknown
* surfaceParent
;
1726 TRACE("(%p) call back\n", pSurface
);
1728 IWineD3DSurface_GetParent(pSurface
, (IUnknown
**) &surfaceParent
);
1729 IUnknown_Release(surfaceParent
);
1730 return IUnknown_Release(surfaceParent
);
1733 /*****************************************************************************
1734 * IDirectDrawImpl_CreateNewSurface
1736 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1737 * with the passed parameters.
1740 * DDSD: Description of the surface to create
1741 * Surf: Address to store the interface pointer at
1746 *****************************************************************************/
1747 static HRESULT WINAPI
1748 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
,
1749 DDSURFACEDESC2
*pDDSD
,
1750 IDirectDrawSurfaceImpl
**ppSurf
,
1754 UINT Width
= 0, Height
= 0;
1755 WINED3DFORMAT Format
= WINED3DFMT_UNKNOWN
;
1756 WINED3DRESOURCETYPE ResType
= WINED3DRTYPE_SURFACE
;
1758 WINED3DSURFTYPE ImplType
= This
->ImplType
;
1759 WINED3DSURFACE_DESC Desc
;
1761 IParentImpl
*parImpl
= NULL
;
1762 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
1764 /* Dummies for GetDesc */
1765 WINED3DPOOL dummy_d3dpool
;
1766 WINED3DMULTISAMPLE_TYPE dummy_mst
;
1770 if (TRACE_ON(ddraw
))
1772 TRACE(" (%p) Requesting surface desc :\n", This
);
1773 DDRAW_dump_surface_desc(pDDSD
);
1776 /* Select the surface type, if it wasn't choosen yet */
1777 if(ImplType
== SURFACE_UNKNOWN
)
1779 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1780 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1782 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
1783 ImplType
= SURFACE_OPENGL
;
1786 /* Otherwise use GDI surfaces for now */
1789 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
1790 ImplType
= SURFACE_GDI
;
1793 /* Policy if all surface implementations are available:
1794 * First, check if a default type was set with winecfg. If not,
1795 * try Xrender surfaces, and use them if they work. Next, check if
1796 * accelerated OpenGL is available, and use GL surfaces in this
1797 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1798 * was created, always use OpenGL surfaces.
1800 * (Note: Xrender surfaces are not implemented for now, the
1801 * unaccelerated implementation uses GDI to render in Software)
1804 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1805 * be re-created. This could be done with IDirectDrawSurface7::Restore
1807 This
->ImplType
= ImplType
;
1811 if((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
1812 (This
->ImplType
!= SURFACE_OPENGL
) && DefaultSurfaceType
== SURFACE_UNKNOWN
)
1814 /* We have to change to OpenGL,
1815 * and re-create all WineD3DSurfaces
1817 ImplType
= SURFACE_OPENGL
;
1818 This
->ImplType
= ImplType
;
1819 TRACE("(%p) Re-creating all surfaces\n", This
);
1820 IDirectDrawImpl_RecreateAllSurfaces(This
);
1821 TRACE("(%p) Done recreating all surfaces\n", This
);
1823 else if(This
->ImplType
!= SURFACE_OPENGL
&& pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1825 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1826 /* Do not fail surface creation, only fail 3D device creation */
1830 /* Get the correct wined3d usage */
1831 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
1832 DDSCAPS_BACKBUFFER
|
1833 DDSCAPS_3DDEVICE
) )
1835 Usage
|= WINED3DUSAGE_RENDERTARGET
;
1837 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
|
1840 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
1842 Usage
|= WINED3DUSAGE_OVERLAY
;
1844 if(This
->depthstencil
|| (pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
) )
1846 /* The depth stencil creation callback sets this flag.
1847 * Set the WineD3D usage to let it know that it's a depth
1850 Usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
1852 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
1854 Pool
= WINED3DPOOL_SYSTEMMEM
;
1856 else if(pDDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_TEXTUREMANAGE
)
1858 Pool
= WINED3DPOOL_MANAGED
;
1859 /* Managed textures have the system memory flag set */
1860 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_SYSTEMMEMORY
;
1862 else if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
1864 /* Videomemory adds localvidmem, this is mutually exclusive with systemmemory
1867 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_LOCALVIDMEM
;
1870 Format
= PixelFormat_DD2WineD3D(&pDDSD
->u4
.ddpfPixelFormat
);
1871 if(Format
== WINED3DFMT_UNKNOWN
)
1873 ERR("Unsupported / Unknown pixelformat\n");
1874 return DDERR_INVALIDPIXELFORMAT
;
1877 /* Create the Surface object */
1878 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
1881 ERR("(%p) Error allocating memory for a surface\n", This
);
1882 return DDERR_OUTOFVIDEOMEMORY
;
1884 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface7
, IDirectDrawSurface7_Vtbl
);
1885 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface3
, IDirectDrawSurface3_Vtbl
);
1886 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawGammaControl
, IDirectDrawGammaControl_Vtbl
);
1887 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture2
, IDirect3DTexture2_Vtbl
);
1888 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture
, IDirect3DTexture1_Vtbl
);
1890 (*ppSurf
)->version
= 7;
1891 (*ppSurf
)->ddraw
= This
;
1892 (*ppSurf
)->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
1893 (*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1894 DD_STRUCT_COPY_BYSIZE(&(*ppSurf
)->surface_desc
, pDDSD
);
1896 /* Surface attachments */
1897 (*ppSurf
)->next_attached
= NULL
;
1898 (*ppSurf
)->first_attached
= *ppSurf
;
1900 /* Needed to re-create the surface on an implementation change */
1901 (*ppSurf
)->ImplType
= ImplType
;
1903 /* For D3DDevice creation */
1904 (*ppSurf
)->isRenderTarget
= FALSE
;
1906 /* A trace message for debugging */
1907 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This
, *ppSurf
);
1909 if(pDDSD
->ddsCaps
.dwCaps
& ( DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
) )
1911 /* Render targets and textures need a IParent interface,
1912 * because WineD3D will destroy them when the swapchain
1915 parImpl
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
));
1918 ERR("Out of memory when allocating memory for a IParent implementation\n");
1919 return DDERR_OUTOFMEMORY
;
1922 ICOM_INIT_INTERFACE(parImpl
, IParent
, IParent_Vtbl
);
1923 Parent
= (IUnknown
*) ICOM_INTERFACE(parImpl
, IParent
);
1924 TRACE("Using IParent interface %p as parent\n", parImpl
);
1928 /* Use the surface as parent */
1929 Parent
= (IUnknown
*) ICOM_INTERFACE(*ppSurf
, IDirectDrawSurface7
);
1930 TRACE("Using Surface interface %p as parent\n", *ppSurf
);
1933 /* Now create the WineD3D Surface */
1934 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1938 TRUE
/* Lockable */,
1939 FALSE
/* Discard */,
1941 &(*ppSurf
)->WineD3DSurface
,
1944 WINED3DMULTISAMPLE_NONE
,
1945 0 /* MultiSampleQuality */,
1946 0 /* SharedHandle */,
1952 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr
);
1956 /* Set the child of the parent implementation if it exists */
1959 parImpl
->child
= (IUnknown
*) (*ppSurf
)->WineD3DSurface
;
1960 /* The IParent releases the WineD3DSurface, and
1961 * the ddraw surface does that too. Hold a reference
1963 IWineD3DSurface_AddRef((*ppSurf
)->WineD3DSurface
);
1966 /* Increase the surface counter, and attach the surface */
1967 InterlockedIncrement(&This
->surfaces
);
1968 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
1970 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1971 * But this could also be delegated to WineDDraw, as it keeps track of all its
1972 * resources. Not implemented for now, as there are more important things ;)
1975 /* Get the pixel format of the WineD3DSurface and store it.
1976 * Don't use the Format choosen above, WineD3D might have
1979 Desc
.Format
= &Format
;
1980 Desc
.Type
= &ResType
;
1981 Desc
.Usage
= &Usage
;
1982 Desc
.Pool
= &dummy_d3dpool
;
1983 Desc
.Size
= &dummy_uint
;
1984 Desc
.MultiSampleType
= &dummy_mst
;
1985 Desc
.MultiSampleQuality
= &dummy_dword
;
1986 Desc
.Width
= &Width
;
1987 Desc
.Height
= &Height
;
1989 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
1990 hr
= IWineD3DSurface_GetDesc((*ppSurf
)->WineD3DSurface
, &Desc
);
1993 ERR("IWineD3DSurface::GetDesc failed\n");
1994 IDirectDrawSurface7_Release( (IDirectDrawSurface7
*) *ppSurf
);
1998 if(Format
== WINED3DFMT_UNKNOWN
)
2000 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
2002 PixelFormat_WineD3DtoDD( &(*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
, Format
);
2004 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
2005 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
2006 * WineD3DDevice might not be useable for 3D yet, so an extra method was created.
2007 * TODO: Test other fourcc formats
2009 if(Format
== WINED3DFMT_DXT1
|| Format
== WINED3DFMT_DXT2
|| Format
== WINED3DFMT_DXT3
||
2010 Format
== WINED3DFMT_DXT4
|| Format
== WINED3DFMT_DXT5
)
2012 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_LINEARSIZE
;
2013 if(Format
== WINED3DFMT_DXT1
)
2015 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
) / 2;
2019 (*ppSurf
)->surface_desc
.u1
.dwLinearSize
= max(4, Width
) * max(4, Height
);
2024 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PITCH
;
2025 (*ppSurf
)->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch((*ppSurf
)->WineD3DSurface
);
2028 /* Application passed a color key? Set it! */
2029 if(pDDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
2031 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2033 (WINEDDCOLORKEY
*) &pDDSD
->u3
.ddckCKDestOverlay
);
2035 if(pDDSD
->dwFlags
& DDSD_CKDESTBLT
)
2037 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2039 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKDestBlt
);
2041 if(pDDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
2043 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2045 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcOverlay
);
2047 if(pDDSD
->dwFlags
& DDSD_CKSRCBLT
)
2049 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
2051 (WINEDDCOLORKEY
*) &pDDSD
->ddckCKSrcBlt
);
2053 if ( pDDSD
->dwFlags
& DDSD_LPSURFACE
)
2055 hr
= IWineD3DSurface_SetMem((*ppSurf
)->WineD3DSurface
, pDDSD
->lpSurface
);
2056 if(hr
!= WINED3D_OK
)
2058 /* No need for a trace here, wined3d does that for us */
2059 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf
), IDirectDrawSurface7
));
2066 /*****************************************************************************
2067 * CreateAdditionalSurfaces
2069 * Creates a new mipmap chain.
2072 * root: Root surface to attach the newly created chain to
2073 * count: number of surfaces to create
2074 * DDSD: Description of the surface. Intentionally not a pointer to avoid side
2075 * effects on the caller
2076 * CubeFaceRoot: Whether the new surface is a root of a cube map face. This
2077 * creates an additional surface without the mipmapping flags
2079 *****************************************************************************/
2081 CreateAdditionalSurfaces(IDirectDrawImpl
*This
,
2082 IDirectDrawSurfaceImpl
*root
,
2084 DDSURFACEDESC2 DDSD
,
2087 UINT i
, j
, level
= 0;
2089 IDirectDrawSurfaceImpl
*last
= root
;
2091 for(i
= 0; i
< count
; i
++)
2093 IDirectDrawSurfaceImpl
*object2
= NULL
;
2095 /* increase the mipmap level, but only if a mipmap is created
2096 * In this case, also halve the size
2098 if(DDSD
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
&& !CubeFaceRoot
)
2101 if(DDSD
.dwWidth
> 1) DDSD
.dwWidth
/= 2;
2102 if(DDSD
.dwHeight
> 1) DDSD
.dwHeight
/= 2;
2103 /* Set the mipmap sublevel flag according to msdn */
2104 DDSD
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2108 DDSD
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2110 CubeFaceRoot
= FALSE
;
2112 hr
= IDirectDrawImpl_CreateNewSurface(This
,
2121 /* Add the new surface to the complex attachment array */
2122 for(j
= 0; j
< MAX_COMPLEX_ATTACHED
; j
++)
2124 if(last
->complex_array
[j
]) continue;
2125 last
->complex_array
[j
] = object2
;
2130 /* Remove the (possible) back buffer cap from the new surface description,
2131 * because only one surface in the flipping chain is a back buffer, one
2132 * is a front buffer, the others are just primary surfaces.
2134 DDSD
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2139 /*****************************************************************************
2140 * IDirectDraw7::CreateSurface
2142 * Creates a new IDirectDrawSurface object and returns its interface.
2144 * The surface connections with wined3d are a bit tricky. Basically it works
2147 * |------------------------| |-----------------|
2148 * | DDraw surface | | WineD3DSurface |
2150 * | WineD3DSurface |-------------->| |
2151 * | Child |<------------->| Parent |
2152 * |------------------------| |-----------------|
2154 * The DDraw surface is the parent of the wined3d surface, and it releases
2155 * the WineD3DSurface when the ddraw surface is destroyed.
2157 * However, for all surfaces which can be in a container in WineD3D,
2158 * we have to do this. These surfaces are ususally complex surfaces,
2159 * so this concerns primary surfaces with a front and a back buffer,
2162 * |------------------------| |-----------------|
2163 * | DDraw surface | | Containter |
2165 * | Child |<------------->| Parent |
2166 * | Texture |<------------->| |
2167 * | WineD3DSurface |<----| | Levels |<--|
2168 * | Complex connection | | | | |
2169 * |------------------------| | |-----------------| |
2173 * | |------------------| | |-----------------| |
2174 * | | IParent | |-------->| WineD3DSurface | |
2176 * | | Child |<------------->| Parent | |
2177 * | | | | Container |<--|
2178 * | |------------------| |-----------------| |
2180 * | |----------------------| |
2181 * | | DDraw surface 2 | |
2183 * |<->| Complex root Child | |
2185 * | | WineD3DSurface |<----| |
2186 * | |----------------------| | |
2188 * | |---------------------| | |-----------------| |
2189 * | | IParent | |----->| WineD3DSurface | |
2191 * | | Child |<---------->| Parent | |
2192 * | |---------------------| | Container |<--|
2193 * | |-----------------| |
2195 * | ---More surfaces can follow--- |
2197 * The reason is that the IWineD3DSwapchain(render target container)
2198 * and the IWineD3DTexure(Texture container) release the parents
2199 * of their surface's children, but by releasing the complex root
2200 * the surfaces which are complexly attached to it are destroyed
2201 * too. See IDirectDrawSurface::Release for a more detailed
2205 * DDSD: Description of the surface to create
2206 * Surf: Address to store the interface pointer at
2207 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2208 * aggregation, so it has to be NULL
2212 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2213 * DDERR_* if an error occurs
2215 *****************************************************************************/
2216 static HRESULT WINAPI
2217 IDirectDrawImpl_CreateSurface(IDirectDraw7
*iface
,
2218 DDSURFACEDESC2
*DDSD
,
2219 IDirectDrawSurface7
**Surf
,
2222 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2223 IDirectDrawSurfaceImpl
*object
= NULL
;
2225 LONG extra_surfaces
= 0;
2226 DDSURFACEDESC2 desc2
;
2227 WINED3DDISPLAYMODE Mode
;
2229 TRACE("(%p)->(%p,%p,%p)\n", This
, DDSD
, Surf
, UnkOuter
);
2231 /* Some checks before we start */
2232 if (TRACE_ON(ddraw
))
2234 TRACE(" (%p) Requesting surface desc :\n", This
);
2235 DDRAW_dump_surface_desc(DDSD
);
2237 EnterCriticalSection(&ddraw_cs
);
2239 if (UnkOuter
!= NULL
)
2241 FIXME("(%p) : outer != NULL?\n", This
);
2242 LeaveCriticalSection(&ddraw_cs
);
2243 return CLASS_E_NOAGGREGATION
; /* unchecked */
2248 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2249 LeaveCriticalSection(&ddraw_cs
);
2250 return E_POINTER
; /* unchecked */
2253 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2255 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2256 DDSD
->dwFlags
|= DDSD_CAPS
;
2258 if (DDSD
->ddsCaps
.dwCaps
== 0)
2260 /* This has been checked on real Windows */
2261 DDSD
->ddsCaps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
2264 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2266 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2267 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2270 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2272 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2273 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2274 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2277 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2278 !(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
2280 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This
);
2282 LeaveCriticalSection(&ddraw_cs
);
2283 return DDERR_NOEXCLUSIVEMODE
;
2286 if(DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FRONTBUFFER
| DDSCAPS_BACKBUFFER
)) {
2287 WARN("Application tried to create an explicit front or back buffer\n");
2288 LeaveCriticalSection(&ddraw_cs
);
2289 return DDERR_INVALIDCAPS
;
2291 /* Check cube maps but only if the size includes them */
2292 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2294 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
&&
2295 !(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
))
2297 WARN("Cube map faces requested without cube map flag\n");
2298 LeaveCriticalSection(&ddraw_cs
);
2299 return DDERR_INVALIDCAPS
;
2301 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2302 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) == 0)
2304 WARN("Cube map without faces requested\n");
2305 LeaveCriticalSection(&ddraw_cs
);
2306 return DDERR_INVALIDPARAMS
;
2309 /* Quick tests confirm those can be created, but we don't do that yet */
2310 if(DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
&&
2311 (DDSD
->ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP_ALLFACES
) != DDSCAPS2_CUBEMAP_ALLFACES
)
2313 FIXME("Partial cube maps not supported yet\n");
2317 /* According to the msdn this flag is ignored by CreateSurface */
2318 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2319 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2321 /* Modify some flags */
2322 memset(&desc2
, 0, sizeof(desc2
));
2323 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
2324 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2325 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2326 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2328 /* Get the video mode from WineD3D - we will need it */
2329 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2330 0, /* Swapchain 0 */
2334 ERR("Failed to read display mode from wined3d\n");
2335 switch(This
->orig_bpp
)
2338 Mode
.Format
= WINED3DFMT_P8
;
2342 Mode
.Format
= WINED3DFMT_X1R5G5B5
;
2346 Mode
.Format
= WINED3DFMT_R5G6B5
;
2350 Mode
.Format
= WINED3DFMT_R8G8B8
;
2354 Mode
.Format
= WINED3DFMT_X8R8G8B8
;
2357 Mode
.Width
= This
->orig_width
;
2358 Mode
.Height
= This
->orig_height
;
2361 /* No pixelformat given? Use the current screen format */
2362 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2364 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2365 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2367 /* Wait: It could be a Z buffer */
2368 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2370 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
2373 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D15S1
);
2376 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16
);
2379 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D24X8
);
2382 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32
);
2385 ERR("Unknown Z buffer bit depth\n");
2390 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2394 /* No Width or no Height? Use the original screen size
2396 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2397 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2399 /* Invalid for non-render targets */
2400 if(!(desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
))
2402 WARN("Creating a non-Primary surface without Width or Height info, returning DDERR_INVALIDPARAMS\n");
2404 LeaveCriticalSection(&ddraw_cs
);
2405 return DDERR_INVALIDPARAMS
;
2408 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2409 desc2
.dwWidth
= Mode
.Width
;
2410 desc2
.dwHeight
= Mode
.Height
;
2413 /* Mipmap count fixes */
2414 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2416 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2418 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2420 /* Mipmap count is given, nothing to do */
2424 /* Undocumented feature: Create sublevels until
2425 * either the width or the height is 1
2427 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2428 desc2
.dwWidth
: desc2
.dwHeight
;
2429 desc2
.u2
.dwMipMapCount
= 0;
2432 desc2
.u2
.dwMipMapCount
+= 1;
2439 /* Not-complex mipmap -> Mipmapcount = 1 */
2440 desc2
.u2
.dwMipMapCount
= 1;
2442 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2444 /* There's a mipmap count in the created surface in any case */
2445 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2447 /* If no mipmap is given, the texture has only one level */
2449 /* The first surface is a front buffer, the back buffer is created afterwards */
2450 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2452 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2455 /* The root surface in a cube map is positive x */
2456 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2458 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2459 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2462 /* Create the first surface */
2463 hr
= IDirectDrawImpl_CreateNewSurface(This
, &desc2
, &object
, 0);
2466 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr
);
2467 LeaveCriticalSection(&ddraw_cs
);
2470 object
->is_complex_root
= TRUE
;
2472 *Surf
= ICOM_INTERFACE(object
, IDirectDrawSurface7
);
2474 /* Create Additional surfaces if necessary
2475 * This applies to Primary surfaces which have a back buffer count
2476 * set, but not to mipmap textures. In case of Mipmap textures,
2477 * wineD3D takes care of the creation of additional surfaces
2479 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2481 extra_surfaces
= DDSD
->dwBackBufferCount
;
2482 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2483 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2487 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2489 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_ALLFACES
;
2490 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2491 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2492 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEZ
;
2493 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEZ
;
2494 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2495 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEZ
;
2496 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEY
;
2497 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2498 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEY
;
2499 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEY
;
2500 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2501 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_POSITIVEY
;
2502 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_NEGATIVEX
;
2503 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
+ 1, desc2
, TRUE
);
2504 desc2
.ddsCaps
.dwCaps2
&= ~DDSCAPS2_CUBEMAP_NEGATIVEX
;
2505 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_CUBEMAP_POSITIVEX
;
2508 hr
|= CreateAdditionalSurfaces(This
, object
, extra_surfaces
, desc2
, FALSE
);
2511 /* This destroys and possibly created surfaces too */
2512 IDirectDrawSurface_Release( ICOM_INTERFACE(object
, IDirectDrawSurface7
) );
2513 LeaveCriticalSection(&ddraw_cs
);
2517 /* Addref the ddraw interface to keep an reference for each surface */
2518 IDirectDraw7_AddRef(iface
);
2519 object
->ifaceToRelease
= (IUnknown
*) iface
;
2521 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2522 * But attach the d3ddevice only if the currently created surface was
2523 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2524 * The only case I can think of where this doesn't apply is when a
2525 * 2D app was configured by the user to run with OpenGL and it didn't create
2526 * the render target as first surface. In this case the render target creation
2527 * will cause the 3D init.
2529 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
2530 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
2532 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
2535 /* Search for the primary to use as render target */
2536 LIST_FOR_EACH(entry
, &This
->surface_list
)
2538 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2539 if((surface
->surface_desc
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
)) ==
2540 (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
))
2544 TRACE("Using primary %p as render target\n", target
);
2549 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
2550 hr
= IDirectDrawImpl_AttachD3DDevice(This
, target
);
2553 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr
);
2557 /* Create a WineD3DTexture if a texture was requested */
2558 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2561 WINED3DFORMAT Format
;
2562 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
2564 This
->tex_root
= object
;
2566 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2568 /* a mipmap is created, create enough levels */
2569 levels
= desc2
.u2
.dwMipMapCount
;
2573 /* No mipmap is created, create one level */
2577 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2578 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
2580 Pool
= WINED3DPOOL_SYSTEMMEM
;
2582 /* Should I forward the MANEGED cap to the managed pool ? */
2584 /* Get the format. It's set already by CreateNewSurface */
2585 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
2587 /* The surfaces are already created, the callback only
2588 * passes the IWineD3DSurface to WineD3D
2590 if(desc2
.ddsCaps
.dwCaps2
& DDSCAPS2_CUBEMAP
)
2592 hr
= IWineD3DDevice_CreateCubeTexture(This
->wineD3DDevice
,
2593 DDSD
->dwWidth
, /* Edgelength */
2598 (IWineD3DCubeTexture
**) &object
->wineD3DTexture
,
2599 0, /* SharedHandle */
2600 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2601 D3D7CB_CreateSurface
);
2605 hr
= IWineD3DDevice_CreateTexture(This
->wineD3DDevice
,
2606 DDSD
->dwWidth
, DDSD
->dwHeight
,
2607 levels
, /* MipMapCount = Levels */
2611 (IWineD3DTexture
**) &object
->wineD3DTexture
,
2612 0, /* SharedHandle */
2613 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2614 D3D7CB_CreateSurface
);
2616 This
->tex_root
= NULL
;
2619 LeaveCriticalSection(&ddraw_cs
);
2623 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2624 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2627 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2628 const DDPIXELFORMAT
*provided
)
2630 /* Some flags must be present in both or neither for a match. */
2631 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2632 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2633 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2635 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2638 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2641 if (requested
->dwFlags
& DDPF_FOURCC
)
2642 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2645 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2646 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2647 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2650 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2651 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2652 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2655 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2656 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2659 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2660 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2662 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2665 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2666 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2673 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
,
2674 const DDSURFACEDESC2
* provided
)
2683 #define CMP(FLAG, FIELD) \
2684 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2685 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2687 static const struct compare_info compare
[] =
2689 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
2690 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
2692 CMP(CKDESTBLT
, ddckCKDestBlt
),
2693 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
2694 CMP(CKSRCBLT
, ddckCKSrcBlt
),
2695 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
2696 CMP(HEIGHT
, dwHeight
),
2697 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
2698 CMP(LPSURFACE
, lpSurface
),
2699 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
2700 CMP(PITCH
, u1
/* lPitch */),
2701 /* PIXELFORMAT: manual */
2702 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
2703 CMP(TEXTURESTAGE
, dwTextureStage
),
2704 CMP(WIDTH
, dwWidth
),
2705 /* ZBUFFERBITDEPTH: "obsolete" */
2712 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2715 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
2717 if (requested
->dwFlags
& compare
[i
].flag
2718 && memcmp((const char *)provided
+ compare
[i
].offset
,
2719 (const char *)requested
+ compare
[i
].offset
,
2720 compare
[i
].size
) != 0)
2724 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
2726 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
2727 &provided
->u4
.ddpfPixelFormat
))
2734 #undef DDENUMSURFACES_SEARCHTYPE
2735 #undef DDENUMSURFACES_MATCHTYPE
2737 /*****************************************************************************
2738 * IDirectDraw7::EnumSurfaces
2740 * Loops through all surfaces attached to this device and calls the
2741 * application callback. This can't be relayed to WineD3DDevice,
2742 * because some WineD3DSurfaces' parents are IParent objects
2745 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2746 * DDSD: Description to filter for
2747 * Context: Application-provided pointer, it's passed unmodified to the
2749 * Callback: Address to call for each surface
2752 * DDERR_INVALIDPARAMS if the callback is NULL
2755 *****************************************************************************/
2756 static HRESULT WINAPI
2757 IDirectDrawImpl_EnumSurfaces(IDirectDraw7
*iface
,
2759 DDSURFACEDESC2
*DDSD
,
2761 LPDDENUMSURFACESCALLBACK7 Callback
)
2763 /* The surface enumeration is handled by WineDDraw,
2764 * because it keeps track of all surfaces attached to
2765 * it. The filtering is done by our callback function,
2766 * because WineDDraw doesn't handle ddraw-like surface
2769 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2770 IDirectDrawSurfaceImpl
*surf
;
2772 DDSURFACEDESC2 desc
;
2773 struct list
*entry
, *entry2
;
2775 all
= Flags
& DDENUMSURFACES_ALL
;
2776 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
2778 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, DDSD
, Context
, Callback
);
2779 EnterCriticalSection(&ddraw_cs
);
2783 LeaveCriticalSection(&ddraw_cs
);
2784 return DDERR_INVALIDPARAMS
;
2787 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2788 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
2790 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2791 if (all
|| (nomatch
!= IDirectDrawImpl_DDSD_Match(DDSD
, &surf
->surface_desc
)))
2793 desc
= surf
->surface_desc
;
2794 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
2795 if(Callback( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, Context
) != DDENUMRET_OK
)
2797 LeaveCriticalSection(&ddraw_cs
);
2802 LeaveCriticalSection(&ddraw_cs
);
2806 static HRESULT WINAPI
2807 findRenderTarget(IDirectDrawSurface7
*surface
,
2808 DDSURFACEDESC2
*desc
,
2811 IDirectDrawSurfaceImpl
*surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surface
);
2812 IDirectDrawSurfaceImpl
**target
= (IDirectDrawSurfaceImpl
**) ctx
;
2814 if(!surf
->isRenderTarget
) {
2816 IDirectDrawSurface7_Release(surface
);
2817 return DDENUMRET_CANCEL
;
2820 /* Recurse into the surface tree */
2821 IDirectDrawSurface7_EnumAttachedSurfaces(surface
, ctx
, findRenderTarget
);
2823 IDirectDrawSurface7_Release(surface
);
2824 if(*target
) return DDENUMRET_CANCEL
;
2825 else return DDENUMRET_OK
; /* Continue with the next neighbor surface */
2828 /*****************************************************************************
2829 * D3D7CB_CreateRenderTarget
2831 * Callback called by WineD3D to create Surfaces for render target usage
2832 * This function takes the D3D target from the IDirectDrawImpl structure,
2833 * and returns the WineD3DSurface. To avoid double usage, the surface
2834 * is marked as render target afterwards
2837 * device: The WineD3DDevice's parent
2838 * Width, Height, Format: Dimensions and pixelformat of the render target
2839 * Ignored, because the surface already exists
2840 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2842 * ppSurface: Address to pass the surface pointer back at
2843 * pSharedHandle: Ignored
2846 * Always returns D3D_OK
2848 *****************************************************************************/
2849 static HRESULT WINAPI
2850 D3D7CB_CreateRenderTarget(IUnknown
*device
, IUnknown
*pSuperior
,
2851 UINT Width
, UINT Height
,
2852 WINED3DFORMAT Format
,
2853 WINED3DMULTISAMPLE_TYPE MultiSample
,
2854 DWORD MultisampleQuality
,
2856 IWineD3DSurface
** ppSurface
,
2857 HANDLE
* pSharedHandle
)
2859 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2860 IDirectDrawSurfaceImpl
*d3dSurface
= This
->d3d_target
, *target
= NULL
;
2861 TRACE("(%p) call back\n", device
);
2863 if(d3dSurface
->isRenderTarget
)
2865 IDirectDrawSurface7_EnumAttachedSurfaces(ICOM_INTERFACE(d3dSurface
, IDirectDrawSurface7
),
2866 &target
, findRenderTarget
);
2870 target
= d3dSurface
;
2875 target
= This
->d3d_target
;
2876 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
2879 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2881 *ppSurface
= target
->WineD3DSurface
;
2882 target
->isRenderTarget
= TRUE
;
2883 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface
, d3dSurface
);
2887 static HRESULT WINAPI
2888 D3D7CB_CreateDepthStencilSurface(IUnknown
*device
,
2889 IUnknown
*pSuperior
,
2892 WINED3DFORMAT Format
,
2893 WINED3DMULTISAMPLE_TYPE MultiSample
,
2894 DWORD MultisampleQuality
,
2896 IWineD3DSurface
** ppSurface
,
2897 HANDLE
* pSharedHandle
)
2899 /* Create a Depth Stencil surface to make WineD3D happy */
2900 HRESULT hr
= D3D_OK
;
2901 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2902 DDSURFACEDESC2 ddsd
;
2904 TRACE("(%p) call back\n", device
);
2908 /* Create a DirectDraw surface */
2909 memset(&ddsd
, 0, sizeof(ddsd
));
2910 ddsd
.dwSize
= sizeof(ddsd
);
2911 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2912 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2913 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2914 ddsd
.dwHeight
= Height
;
2915 ddsd
.dwWidth
= Width
;
2918 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, Format
);
2922 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
2925 This
->depthstencil
= TRUE
;
2926 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*) This
,
2928 (IDirectDrawSurface7
**) &This
->DepthStencilBuffer
,
2930 This
->depthstencil
= FALSE
;
2933 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
2936 *ppSurface
= This
->DepthStencilBuffer
->WineD3DSurface
;
2940 /*****************************************************************************
2941 * D3D7CB_CreateAdditionalSwapChain
2943 * Callback function for WineD3D which creates a new WineD3DSwapchain
2944 * interface. It also creates an IParent interface to store that pointer,
2945 * so the WineD3DSwapchain has a parent and can be released when the D3D
2946 * device is destroyed
2947 *****************************************************************************/
2948 static HRESULT WINAPI
2949 D3D7CB_CreateAdditionalSwapChain(IUnknown
*device
,
2950 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
2951 IWineD3DSwapChain
** ppSwapChain
)
2953 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2954 IParentImpl
*object
= NULL
;
2955 HRESULT res
= D3D_OK
;
2956 IWineD3DSwapChain
*swapchain
;
2957 TRACE("(%p) call back\n", device
);
2959 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
2962 FIXME("Allocation of memory failed\n");
2963 *ppSwapChain
= NULL
;
2964 return DDERR_OUTOFVIDEOMEMORY
;
2967 ICOM_INIT_INTERFACE(object
, IParent
, IParent_Vtbl
);
2970 res
= IWineD3DDevice_CreateAdditionalSwapChain(This
->wineD3DDevice
,
2971 pPresentationParameters
,
2973 (IUnknown
*) ICOM_INTERFACE(object
, IParent
),
2974 D3D7CB_CreateRenderTarget
,
2975 D3D7CB_CreateDepthStencilSurface
);
2978 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
2979 HeapFree(GetProcessHeap(), 0 , object
);
2980 *ppSwapChain
= NULL
;
2984 *ppSwapChain
= swapchain
;
2985 object
->child
= (IUnknown
*) swapchain
;
2991 /*****************************************************************************
2992 * IDirectDrawImpl_AttachD3DDevice
2994 * Initializes the D3D capabilities of WineD3D
2997 * primary: The primary surface for D3D
3003 *****************************************************************************/
3004 static HRESULT WINAPI
3005 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
,
3006 IDirectDrawSurfaceImpl
*primary
)
3011 WINED3DPRESENT_PARAMETERS localParameters
;
3013 TRACE("(%p)->(%p)\n", This
, primary
);
3015 /* Get the window */
3016 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
3020 ERR("IWineD3DDevice::GetHWND failed\n");
3024 /* If there's no window, create a hidden window. WineD3D needs it */
3027 window
= CreateWindowExA(0, This
->classname
, "Hidden D3D Window",
3029 GetSystemMetrics(SM_CXSCREEN
),
3030 GetSystemMetrics(SM_CYSCREEN
),
3031 NULL
, NULL
, GetModuleHandleA(0), NULL
);
3033 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
3034 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This
, window
);
3035 This
->d3d_window
= window
;
3039 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This
, window
);
3042 /* Store the future Render Target surface */
3043 This
->d3d_target
= primary
;
3045 /* Use the surface description for the device parameters, not the
3046 * Device settings. The app might render to an offscreen surface
3048 localParameters
.BackBufferWidth
= primary
->surface_desc
.dwWidth
;
3049 localParameters
.BackBufferHeight
= primary
->surface_desc
.dwHeight
;
3050 localParameters
.BackBufferFormat
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
3051 localParameters
.BackBufferCount
= (primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
) ? primary
->surface_desc
.dwBackBufferCount
: 0;
3052 localParameters
.MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
3053 localParameters
.MultiSampleQuality
= 0;
3054 localParameters
.SwapEffect
= WINED3DSWAPEFFECT_COPY
;
3055 localParameters
.hDeviceWindow
= window
;
3056 localParameters
.Windowed
= !(This
->cooperative_level
& DDSCL_FULLSCREEN
);
3057 localParameters
.EnableAutoDepthStencil
= FALSE
;
3058 localParameters
.AutoDepthStencilFormat
= WINED3DFMT_D16
;
3059 localParameters
.Flags
= 0;
3060 localParameters
.FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
; /* Default rate: It's already set */
3061 localParameters
.PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
3063 TRACE("Passing mode %d\n", localParameters
.BackBufferFormat
);
3065 /* Set this NOW, otherwise creating the depth stencil surface will cause a
3066 * recursive loop until ram or emulated video memory is full
3068 This
->d3d_initialized
= TRUE
;
3070 hr
= IWineD3DDevice_Init3D(This
->wineD3DDevice
,
3072 D3D7CB_CreateAdditionalSwapChain
);
3075 This
->wineD3DDevice
= NULL
;
3079 This
->declArraySize
= 2;
3080 This
->decls
= HeapAlloc(GetProcessHeap(),
3082 sizeof(*This
->decls
) * This
->declArraySize
);
3085 ERR("Error allocating an array for the converted vertex decls\n");
3086 This
->declArraySize
= 0;
3087 hr
= IWineD3DDevice_Uninit3D(This
->wineD3DDevice
,
3088 D3D7CB_DestroyDepthStencilSurface
,
3089 D3D7CB_DestroySwapChain
);
3090 return E_OUTOFMEMORY
;
3093 /* Create an Index Buffer parent */
3094 TRACE("(%p) Successfully initialized 3D\n", This
);
3098 /*****************************************************************************
3099 * DirectDrawCreateClipper (DDRAW.@)
3101 * Creates a new IDirectDrawClipper object.
3104 * Clipper: Address to write the interface pointer to
3105 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3109 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3110 * E_OUTOFMEMORY if allocating the object failed
3112 *****************************************************************************/
3114 DirectDrawCreateClipper(DWORD Flags
,
3115 LPDIRECTDRAWCLIPPER
*Clipper
,
3118 IDirectDrawClipperImpl
* object
;
3119 TRACE("(%08x,%p,%p)\n", Flags
, Clipper
, UnkOuter
);
3121 EnterCriticalSection(&ddraw_cs
);
3122 if (UnkOuter
!= NULL
)
3124 LeaveCriticalSection(&ddraw_cs
);
3125 return CLASS_E_NOAGGREGATION
;
3128 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
3129 sizeof(IDirectDrawClipperImpl
));
3132 LeaveCriticalSection(&ddraw_cs
);
3133 return E_OUTOFMEMORY
;
3136 ICOM_INIT_INTERFACE(object
, IDirectDrawClipper
, IDirectDrawClipper_Vtbl
);
3138 object
->wineD3DClipper
= pWineDirect3DCreateClipper((IUnknown
*) object
);
3139 if(!object
->wineD3DClipper
)
3141 HeapFree(GetProcessHeap(), 0, object
);
3142 LeaveCriticalSection(&ddraw_cs
);
3143 return E_OUTOFMEMORY
;
3146 *Clipper
= (IDirectDrawClipper
*) object
;
3147 LeaveCriticalSection(&ddraw_cs
);
3151 /*****************************************************************************
3152 * IDirectDraw7::CreateClipper
3154 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
3156 *****************************************************************************/
3157 static HRESULT WINAPI
3158 IDirectDrawImpl_CreateClipper(IDirectDraw7
*iface
,
3160 IDirectDrawClipper
**Clipper
,
3163 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3164 TRACE("(%p)->(%x,%p,%p)\n", This
, Flags
, Clipper
, UnkOuter
);
3165 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
3168 /*****************************************************************************
3169 * IDirectDraw7::CreatePalette
3171 * Creates a new IDirectDrawPalette object
3174 * Flags: The flags for the new clipper
3175 * ColorTable: Color table to assign to the new clipper
3176 * Palette: Address to write the interface pointer to
3177 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
3181 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
3182 * E_OUTOFMEMORY if allocating the object failed
3184 *****************************************************************************/
3185 static HRESULT WINAPI
3186 IDirectDrawImpl_CreatePalette(IDirectDraw7
*iface
,
3188 PALETTEENTRY
*ColorTable
,
3189 IDirectDrawPalette
**Palette
,
3190 IUnknown
*pUnkOuter
)
3192 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3193 IDirectDrawPaletteImpl
*object
;
3194 HRESULT hr
= DDERR_GENERIC
;
3195 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, ColorTable
, Palette
, pUnkOuter
);
3197 EnterCriticalSection(&ddraw_cs
);
3198 if(pUnkOuter
!= NULL
)
3200 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
3201 LeaveCriticalSection(&ddraw_cs
);
3202 return CLASS_E_NOAGGREGATION
;
3205 /* The refcount test shows that a cooplevel is required for this */
3206 if(!This
->cooperative_level
)
3208 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
3209 LeaveCriticalSection(&ddraw_cs
);
3210 return DDERR_NOCOOPERATIVELEVELSET
;
3213 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
3216 ERR("Out of memory when allocating memory for a palette implementation\n");
3217 LeaveCriticalSection(&ddraw_cs
);
3218 return E_OUTOFMEMORY
;
3221 ICOM_INIT_INTERFACE(object
, IDirectDrawPalette
, IDirectDrawPalette_Vtbl
);
3223 object
->ddraw_owner
= This
;
3225 hr
= IWineD3DDevice_CreatePalette(This
->wineD3DDevice
, Flags
, ColorTable
, &object
->wineD3DPalette
, (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawPalette
) );
3228 HeapFree(GetProcessHeap(), 0, object
);
3229 LeaveCriticalSection(&ddraw_cs
);
3233 IDirectDraw7_AddRef(iface
);
3234 object
->ifaceToRelease
= (IUnknown
*) iface
;
3235 *Palette
= ICOM_INTERFACE(object
, IDirectDrawPalette
);
3236 LeaveCriticalSection(&ddraw_cs
);
3240 /*****************************************************************************
3241 * IDirectDraw7::DuplicateSurface
3243 * Duplicates a surface. The surface memory points to the same memory as
3244 * the original surface, and it's released when the last surface referencing
3245 * it is released. I guess that's beyond Wine's surface management right now
3246 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3247 * test application to implement this)
3250 * Src: Address of the source surface
3251 * Dest: Address to write the new surface pointer to
3254 * See IDirectDraw7::CreateSurface
3256 *****************************************************************************/
3257 static HRESULT WINAPI
3258 IDirectDrawImpl_DuplicateSurface(IDirectDraw7
*iface
,
3259 IDirectDrawSurface7
*Src
,
3260 IDirectDrawSurface7
**Dest
)
3262 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3263 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Src
);
3265 FIXME("(%p)->(%p,%p)\n", This
, Surf
, Dest
);
3267 /* For now, simply create a new, independent surface */
3268 return IDirectDraw7_CreateSurface(iface
,
3269 &Surf
->surface_desc
,
3274 /*****************************************************************************
3275 * IDirectDraw7 VTable
3276 *****************************************************************************/
3277 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
=
3280 IDirectDrawImpl_QueryInterface
,
3281 IDirectDrawImpl_AddRef
,
3282 IDirectDrawImpl_Release
,
3283 /*** IDirectDraw ***/
3284 IDirectDrawImpl_Compact
,
3285 IDirectDrawImpl_CreateClipper
,
3286 IDirectDrawImpl_CreatePalette
,
3287 IDirectDrawImpl_CreateSurface
,
3288 IDirectDrawImpl_DuplicateSurface
,
3289 IDirectDrawImpl_EnumDisplayModes
,
3290 IDirectDrawImpl_EnumSurfaces
,
3291 IDirectDrawImpl_FlipToGDISurface
,
3292 IDirectDrawImpl_GetCaps
,
3293 IDirectDrawImpl_GetDisplayMode
,
3294 IDirectDrawImpl_GetFourCCCodes
,
3295 IDirectDrawImpl_GetGDISurface
,
3296 IDirectDrawImpl_GetMonitorFrequency
,
3297 IDirectDrawImpl_GetScanLine
,
3298 IDirectDrawImpl_GetVerticalBlankStatus
,
3299 IDirectDrawImpl_Initialize
,
3300 IDirectDrawImpl_RestoreDisplayMode
,
3301 IDirectDrawImpl_SetCooperativeLevel
,
3302 IDirectDrawImpl_SetDisplayMode
,
3303 IDirectDrawImpl_WaitForVerticalBlank
,
3304 /*** IDirectDraw2 ***/
3305 IDirectDrawImpl_GetAvailableVidMem
,
3306 /*** IDirectDraw7 ***/
3307 IDirectDrawImpl_GetSurfaceFromDC
,
3308 IDirectDrawImpl_RestoreAllSurfaces
,
3309 IDirectDrawImpl_TestCooperativeLevel
,
3310 IDirectDrawImpl_GetDeviceIdentifier
,
3311 /*** IDirectDraw7 ***/
3312 IDirectDrawImpl_StartModeTest
,
3313 IDirectDrawImpl_EvaluateMode
3316 /*****************************************************************************
3317 * IDirectDrawImpl_FindDecl
3319 * Finds the WineD3D vertex declaration for a specific fvf, and creates one
3320 * if none was found.
3322 * This function is in ddraw.c and the DDraw object space because D3D7
3323 * vertex buffers are created using the IDirect3D interface to the ddraw
3324 * object, so they can be valid across D3D devices(theoretically. The ddraw
3325 * object also owns the wined3d device
3329 * fvf: Fvf to find the decl for
3332 * NULL in case of an error, the IWineD3DVertexDeclaration interface for the
3335 *****************************************************************************/
3336 IWineD3DVertexDeclaration
*
3337 IDirectDrawImpl_FindDecl(IDirectDrawImpl
*This
,
3341 IWineD3DVertexDeclaration
* pDecl
= NULL
;
3342 int p
, low
, high
; /* deliberately signed */
3343 struct FvfToDecl
*convertedDecls
= This
->decls
;
3345 TRACE("Searching for declaration for fvf %08x... ", fvf
);
3348 high
= This
->numConvertedDecls
- 1;
3349 while(low
<= high
) {
3350 p
= (low
+ high
) >> 1;
3352 if(convertedDecls
[p
].fvf
== fvf
) {
3353 TRACE("found %p\n", convertedDecls
[p
].decl
);
3354 return convertedDecls
[p
].decl
;
3355 } else if(convertedDecls
[p
].fvf
< fvf
) {
3361 TRACE("not found. Creating and inserting at position %d.\n", low
);
3363 hr
= IWineD3DDevice_CreateVertexDeclarationFromFVF(This
->wineD3DDevice
,
3365 (IUnknown
*) ICOM_INTERFACE(This
, IDirectDraw7
),
3367 if (hr
!= S_OK
) return NULL
;
3369 if(This
->declArraySize
== This
->numConvertedDecls
) {
3370 int grow
= max(This
->declArraySize
/ 2, 8);
3371 convertedDecls
= HeapReAlloc(GetProcessHeap(), 0, convertedDecls
,
3372 sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
+ grow
));
3373 if(!convertedDecls
) {
3374 /* This will destroy it */
3375 IWineD3DVertexDeclaration_Release(pDecl
);
3378 This
->decls
= convertedDecls
;
3379 This
->declArraySize
+= grow
;
3382 memmove(convertedDecls
+ low
+ 1, convertedDecls
+ low
, sizeof(convertedDecls
[0]) * (This
->numConvertedDecls
- low
));
3383 convertedDecls
[low
].decl
= pDecl
;
3384 convertedDecls
[low
].fvf
= fvf
;
3385 This
->numConvertedDecls
++;
3387 TRACE("Returning %p. %d decls in array\n", pDecl
, This
->numConvertedDecls
);