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
38 #include "wine/exception.h"
44 #include "ddraw_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
49 static BOOL
IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
, const DDSURFACEDESC2
* provided
);
50 static HRESULT WINAPI
IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
, IDirectDrawSurfaceImpl
*primary
);
51 static HRESULT WINAPI
IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
, DDSURFACEDESC2
*pDDSD
, IDirectDrawSurfaceImpl
**ppSurf
, UINT level
);
53 /* Device identifier. Don't relay it to WineD3D */
54 static const DDDEVICEIDENTIFIER2 deviceidentifier
=
58 { { 0x00010001, 0x00010001 } },
60 /* a8373c10-7ac4-4deb-849a-009844d08b2d */
61 {0xa8373c10,0x7ac4,0x4deb, {0x84,0x9a,0x00,0x98,0x44,0xd0,0x8b,0x2d}},
65 /*****************************************************************************
67 *****************************************************************************/
69 /*****************************************************************************
70 * IDirectDraw7::QueryInterface
72 * Queries different interfaces of the DirectDraw object. It can return
73 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
74 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
76 * The returned interface is AddRef()-ed before it's returned
78 * Rules for QueryInterface:
79 * http://msdn.microsoft.com/library/default.asp? \
80 * url=/library/en-us/com/html/6db17ed8-06e4-4bae-bc26-113176cc7e0e.asp
82 * Used for version 1, 2, 4 and 7
85 * refiid: Interface ID asked for
86 * obj: Used to return the interface pointer
89 * S_OK if an interface was found
90 * E_NOINTERFACE if the requested interface wasn't found
92 *****************************************************************************/
94 IDirectDrawImpl_QueryInterface(IDirectDraw7
*iface
,
98 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
100 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
102 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
106 return DDERR_INVALIDPARAMS
;
108 /* Check DirectDraw Interfaces */
109 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
110 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
112 *obj
= ICOM_INTERFACE(This
, IDirectDraw7
);
113 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
115 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
117 *obj
= ICOM_INTERFACE(This
, IDirectDraw4
);
118 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
120 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
122 *obj
= ICOM_INTERFACE(This
, IDirectDraw2
);
123 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
125 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
127 *obj
= ICOM_INTERFACE(This
, IDirectDraw
);
128 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
132 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
133 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
134 * who had this idea and why. The older interfaces can query and IDirect3D version
135 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
136 * and messy to implement with the common creation function, so it has been left out here.
138 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
139 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
140 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
141 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
143 /* Check the surface implementation */
144 if(This
->ImplType
== SURFACE_UNKNOWN
)
146 /* Apps may create the IDirect3D Interface before the primary surface.
147 * set the surface implementation */
148 This
->ImplType
= SURFACE_OPENGL
;
149 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
151 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
153 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
154 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
155 /* Should I assert(0) here??? */
157 else if(This
->ImplType
!= SURFACE_OPENGL
)
159 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
160 /* Do not abort here, only reject 3D Device creation */
163 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
165 This
->d3dversion
= 1;
166 *obj
= ICOM_INTERFACE(This
, IDirect3D
);
167 TRACE(" returning Direct3D interface at %p.\n", *obj
);
169 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
171 This
->d3dversion
= 2;
172 *obj
= ICOM_INTERFACE(This
, IDirect3D2
);
173 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
175 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
177 This
->d3dversion
= 3;
178 *obj
= ICOM_INTERFACE(This
, IDirect3D3
);
179 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
181 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
183 This
->d3dversion
= 7;
184 *obj
= ICOM_INTERFACE(This
, IDirect3D7
);
185 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
189 /* Unknown interface */
192 ERR("(%p)->(%s, %p): No interface found\n", This
, debugstr_guid(refiid
), obj
);
193 return E_NOINTERFACE
;
196 IUnknown_AddRef( (IUnknown
*) *obj
);
200 /*****************************************************************************
201 * IDirectDraw7::AddRef
203 * Increases the interfaces refcount, basically
205 * DDraw refcounting is a bit tricky. The different DirectDraw interface
206 * versions have individual refcounts, but the IDirect3D interfaces do not.
207 * All interfaces are from one object, that means calling QueryInterface on an
208 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
209 * IDirectDrawImpl object.
211 * That means all AddRef and Release implementations of IDirectDrawX work
212 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
213 * except of IDirect3D7 which thunks to IDirectDraw7
215 * Returns: The new refcount
217 *****************************************************************************/
219 IDirectDrawImpl_AddRef(IDirectDraw7
*iface
)
221 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
222 ULONG ref
= InterlockedIncrement(&This
->ref7
);
224 TRACE("(%p) : incrementing IDirectDraw7 refcount from %u.\n", This
, ref
-1);
226 if(ref
== 1) InterlockedIncrement(&This
->numIfaces
);
231 /*****************************************************************************
232 * IDirectDrawImpl_Destroy
234 * Destroys a ddraw object if all refcounts are 0. This is to share code
235 * between the IDirectDrawX::Release functions
238 * This: DirectDraw object to destroy
240 *****************************************************************************/
242 IDirectDrawImpl_Destroy(IDirectDrawImpl
*This
)
244 /* Clear the cooplevel to restore window and display mode */
245 IDirectDraw7_SetCooperativeLevel(ICOM_INTERFACE(This
, IDirectDraw7
),
249 /* Destroy the device window if we created one */
250 if(This
->devicewindow
!= 0)
252 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
253 DestroyWindow(This
->devicewindow
);
254 This
->devicewindow
= 0;
257 /* Unregister the window class */
258 UnregisterClassA(This
->classname
, 0);
260 remove_ddraw_object(This
);
262 /* Release the attached WineD3D stuff */
263 IWineD3DDevice_Release(This
->wineD3DDevice
);
264 IWineD3D_Release(This
->wineD3D
);
266 /* Now free the object */
267 HeapFree(GetProcessHeap(), 0, This
);
270 /*****************************************************************************
271 * IDirectDraw7::Release
273 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
275 * Returns: The new refcount
276 *****************************************************************************/
278 IDirectDrawImpl_Release(IDirectDraw7
*iface
)
280 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
281 ULONG ref
= InterlockedDecrement(&This
->ref7
);
283 TRACE("(%p)->() decrementing IDirectDraw7 refcount from %u.\n", This
, ref
+1);
287 ULONG ifacecount
= InterlockedDecrement(&This
->numIfaces
);
288 if(ifacecount
== 0) IDirectDrawImpl_Destroy(This
);
294 /*****************************************************************************
295 * IDirectDraw methods
296 *****************************************************************************/
298 /*****************************************************************************
299 * IDirectDrawImpl_SetupExclusiveWindow
301 * Helper function that modifies a HWND's Style and ExStyle for proper
305 * This: Pointer to the DirectDraw implementation
306 * HWND: Window to setup
308 *****************************************************************************/
310 IDirectDrawImpl_SetupFullscreenWindow(IDirectDrawImpl
*This
,
314 /* Don't do anything if an original style is stored.
315 * That shouldn't happen
317 TRACE("(%p): Setting up window %p for exclusive mode\n", This
, window
);
318 if( (This
->style
!= 0) && (This
->exStyle
!= 0) )
320 ERR("(%p) Want to change the window parameters of HWND %p, but \
321 another style is stored for restauration afterwards\n", This
, window
);
324 /* Get the parameters and save them */
325 style
= GetWindowLongW(window
, GWL_STYLE
);
326 exStyle
= GetWindowLongW(window
, GWL_EXSTYLE
);
328 This
->exStyle
= exStyle
;
330 /* Filter out window decorations */
331 style
&= ~WS_CAPTION
;
332 style
&= ~WS_THICKFRAME
;
333 exStyle
&= ~WS_EX_WINDOWEDGE
;
334 exStyle
&= ~WS_EX_CLIENTEDGE
;
336 /* Make sure the window is managed, otherwise we won't get keyboard input */
337 style
|= WS_POPUP
| WS_SYSMENU
;
339 TRACE("Old style was %08x,%08x, setting to %08x,%08x\n",
340 This
->style
, This
->exStyle
, style
, exStyle
);
342 SetWindowLongW(window
, GWL_STYLE
, style
);
343 SetWindowLongW(window
, GWL_EXSTYLE
, exStyle
);
345 /* Inform the window about the update.
346 * TODO: Should I move it to 0/0 too?
348 SetWindowPos(window
, 0 /* InsertAfter, ignored */,
349 0, 0, 0, 0, /* Pos, Size, ignored */
350 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
);
353 /*****************************************************************************
354 * IDirectDrawImpl_RestoreWindow
356 * Helper function that restores a windows' properties when taking it out
360 * This: Pointer to the DirectDraw implementation
361 * HWND: Window to setup
363 *****************************************************************************/
365 IDirectDrawImpl_RestoreWindow(IDirectDrawImpl
*This
,
368 if( (This
->style
== 0) && (This
->exStyle
== 0) )
370 /* This could be a DDSCL_NORMAL -> DDSCL_NORMAL
375 TRACE("(%p): Restoring window settings of window %p to %08x, %08x\n",
376 This
, window
, This
->style
, This
->exStyle
);
378 SetWindowLongW(window
, GWL_STYLE
, This
->style
);
379 SetWindowLongW(window
, GWL_EXSTYLE
, This
->exStyle
);
381 /* Delete the old values */
385 /* Inform the window about the update */
386 SetWindowPos(window
, 0 /* InsertAfter, ignored */,
387 0, 0, 0, 0, /* Pos, Size, ignored */
388 SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
);
391 /*****************************************************************************
392 * IDirectDraw7::SetCooperativeLevel
394 * Sets the cooperative level for the DirectDraw object, and the window
395 * assigned to it. The cooperative level determines the general behavior
396 * of the DirectDraw application
398 * Warning: This is quite tricky, as it's not really documented which
399 * cooperative levels can be combined with each other. If a game fails
400 * after this function, try to check the cooperative levels passed on
401 * Windows, and if it returns something different.
403 * If you think that this function caused the failure because it writes a
404 * fixme, be sure to run again with a +ddraw trace.
406 * What is known about cooperative levels (See the ddraw modes test):
407 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
408 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
409 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
410 * DDSCL_FULLSCREEN can be activated
411 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
413 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
414 * DDSCL_SETFOCUSWINDOW (partially)
416 * Unhandled flags, which should be implemented
417 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
418 * expect any difference to a normal window for wine)
419 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
420 * rendering (Possible test case: Half-life)
422 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
424 * These seem not really imporant for wine
425 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX,
429 * DD_OK if the cooperative level was set successfully
430 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
431 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
432 * (Probably others too, have to investigate)
434 *****************************************************************************/
435 static HRESULT WINAPI
436 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7
*iface
,
440 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
444 FIXME("(%p)->(%p,%08x)\n",This
,hwnd
,cooplevel
);
445 DDRAW_dump_cooperativelevel(cooplevel
);
447 /* Get the old window */
448 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
, &window
);
451 ERR("IWineD3DDevice::GetHWND failed, hr = %08x\n", hr
);
455 /* Tests suggest that we need one of them: */
456 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
460 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
461 return DDERR_INVALIDPARAMS
;
464 /* Handle those levels first which set various hwnds */
465 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
467 /* This isn't compatible with a lot of flags */
468 if(cooplevel
& ( DDSCL_MULTITHREADED
|
473 DDSCL_SETDEVICEWINDOW
|
478 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
479 return DDERR_INVALIDPARAMS
;
481 else if( (This
->cooperative_level
& DDSCL_FULLSCREEN
) && window
)
483 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
484 return DDERR_HWNDALREADYSET
;
487 This
->focuswindow
= hwnd
;
488 /* Won't use the hwnd param for anything else */
491 /* Use the focus window for drawing too */
492 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, This
->focuswindow
);
494 /* Destroy the device window, if we have one */
495 if(This
->devicewindow
)
497 DestroyWindow(This
->devicewindow
);
498 This
->devicewindow
= NULL
;
501 /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
502 if(cooplevel
& DDSCL_NORMAL
)
504 /* Can't coexist with fullscreen or exclusive */
505 if(cooplevel
& (DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
) )
507 TRACE("(%p) DDSCL_NORMAL is not compative with DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE\n", This
);
508 return DDERR_INVALIDPARAMS
;
511 /* Switching from fullscreen? */
512 if(This
->cooperative_level
& DDSCL_FULLSCREEN
)
514 /* Restore the display mode */
515 IDirectDraw7_RestoreDisplayMode(iface
);
518 IDirectDrawImpl_RestoreWindow(This
, window
);
520 This
->cooperative_level
&= ~DDSCL_FULLSCREEN
;
521 This
->cooperative_level
&= ~DDSCL_EXCLUSIVE
;
522 This
->cooperative_level
&= ~DDSCL_ALLOWMODEX
;
525 /* Don't override focus windows or private device windows */
527 !(This
->focuswindow
) &&
528 !(This
->devicewindow
) &&
531 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
534 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
537 else if(cooplevel
& DDSCL_FULLSCREEN
)
539 /* Needs DDSCL_EXCLUSIVE */
540 if(!(cooplevel
& DDSCL_EXCLUSIVE
) )
542 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This
);
543 return DDERR_INVALIDPARAMS
;
548 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
549 return DDERR_INVALIDPARAMS;
553 /* Switch from normal to full screen mode? */
554 if(This
->cooperative_level
& DDSCL_NORMAL
)
556 This
->cooperative_level
&= ~DDSCL_NORMAL
;
557 IWineD3DDevice_SetFullscreen(This
->wineD3DDevice
,
561 /* Don't override focus windows or private device windows */
563 !(This
->focuswindow
) &&
564 !(This
->devicewindow
) &&
567 /* On a window change, restore the old window and set the new one */
571 IDirectDrawImpl_RestoreWindow(This
, window
);
572 IDirectDrawImpl_SetupFullscreenWindow(This
, hwnd
);
574 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
577 else if(cooplevel
& DDSCL_EXCLUSIVE
)
579 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This
);
580 return DDERR_INVALIDPARAMS
;
583 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
585 /* Don't create a device window if a focus window is set */
586 if( !(This
->focuswindow
) )
588 HWND devicewindow
= CreateWindowExA(0, This
->classname
, "DDraw device window",
590 GetSystemMetrics(SM_CXSCREEN
),
591 GetSystemMetrics(SM_CYSCREEN
),
592 NULL
, NULL
, GetModuleHandleA(0), NULL
);
594 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
595 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
597 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, devicewindow
);
598 This
->devicewindow
= devicewindow
;
602 /* Unhandled flags */
603 if(cooplevel
& DDSCL_ALLOWREBOOT
)
604 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
605 if(cooplevel
& DDSCL_ALLOWMODEX
)
606 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
607 if(cooplevel
& DDSCL_MULTITHREADED
)
608 FIXME("(%p) Unhandled flag DDSCL_MULTITHREADED, Uh Oh...\n", This
);
609 if(cooplevel
& DDSCL_FPUSETUP
)
610 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
611 if(cooplevel
& DDSCL_FPUPRESERVE
)
612 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This
);
614 /* Store the cooperative_level */
615 This
->cooperative_level
|= cooplevel
;
616 TRACE("SetCooperativeLevel retuning DD_OK\n");
620 /*****************************************************************************
621 * IDirectDraw7::SetDisplayMode
623 * Sets the display screen resolution, color depth and refresh frequency
624 * when in fullscreen mode (in theory).
625 * Possible return values listed in the SDK suggest that this method fails
626 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
627 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
628 * It seems to be valid to pass 0 for With and Height, this has to be tested
629 * It could mean that the current video mode should be left as-is. (But why
633 * Height, Width: Screen dimension
634 * BPP: Color depth in Bits per pixel
635 * Refreshrate: Screen refresh rate
641 *****************************************************************************/
642 static HRESULT WINAPI
643 IDirectDrawImpl_SetDisplayMode(IDirectDraw7
*iface
,
650 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
651 WINED3DDISPLAYMODE Mode
;
652 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
654 if( !Width
|| !Height
)
656 ERR("Width=%d, Height=%d, what to do?\n", Width
, Height
);
657 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
661 /* Check the exclusive mode
662 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
663 return DDERR_NOEXCLUSIVEMODE;
664 * This is WRONG. Don't know if the SDK is completely
665 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
666 * is returned, but Half-Life 1.1.1.1 (Steam version)
671 Mode
.Height
= Height
;
672 Mode
.RefreshRate
= RefreshRate
;
675 case 8: Mode
.Format
= WINED3DFMT_P8
; break;
676 case 15: Mode
.Format
= WINED3DFMT_X1R5G5B5
; break;
677 case 16: Mode
.Format
= WINED3DFMT_R5G6B5
; break;
678 case 24: Mode
.Format
= WINED3DFMT_R8G8B8
; break;
679 case 32: Mode
.Format
= WINED3DFMT_A8R8G8B8
; break;
682 /* TODO: The possible return values from msdn suggest that
683 * the screen mode can't be changed if a surface is locked
684 * or some drawing is in progress
687 /* TODO: Lose the primary surface */
688 return IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
689 0, /* First swapchain */
694 /*****************************************************************************
695 * IDirectDraw7::RestoreDisplayMode
697 * Restores the display mode to what it was at creation time. Basically.
699 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
700 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
701 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
702 * -> DD_1 is released. The screen should be left at 1024x768x32.
703 * -> DD_2 is released. The screen should be set to 1400x1050x32
704 * This case is unhandled right now, but Empire Earth does it this way.
705 * (But perhaps there is something in SetCooperativeLevel to prevent this)
707 * The msdn says that this method resets the display mode to what it was before
708 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
712 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
714 *****************************************************************************/
715 static HRESULT WINAPI
716 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7
*iface
)
718 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
719 TRACE("(%p)\n", This
);
721 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This
, IDirectDraw7
),
729 /*****************************************************************************
730 * IDirectDraw7::GetCaps
732 * Returns the drives capabilities
734 * Used for version 1, 2, 4 and 7
737 * DriverCaps: Structure to write the Hardware accelerated caps to
738 * HelCaps: Structure to write the emulation caps to
741 * This implementation returns DD_OK only
743 *****************************************************************************/
744 static HRESULT WINAPI
745 IDirectDrawImpl_GetCaps(IDirectDraw7
*iface
,
749 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
750 TRACE("(%p)->(%p,%p)\n", This
, DriverCaps
, HELCaps
);
752 /* One structure must be != NULL */
753 if( (!DriverCaps
) && (!HELCaps
) )
755 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This
);
756 return DDERR_INVALIDPARAMS
;
761 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &This
->caps
);
764 TRACE("Driver Caps :\n");
765 DDRAW_dump_DDCAPS(DriverCaps
);
771 DD_STRUCT_COPY_BYSIZE(HELCaps
, &This
->caps
);
774 TRACE("HEL Caps :\n");
775 DDRAW_dump_DDCAPS(HELCaps
);
782 /*****************************************************************************
783 * IDirectDraw7::Compact
785 * No idea what it does, MSDN says it's not implemented.
788 * DD_OK, but this is unchecked
790 *****************************************************************************/
791 static HRESULT WINAPI
792 IDirectDrawImpl_Compact(IDirectDraw7
*iface
)
794 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
795 TRACE("(%p)\n", This
);
800 /*****************************************************************************
801 * IDirectDraw7::GetDisplayMode
803 * Returns information about the current display mode
805 * Exists in Version 1, 2, 4 and 7
808 * DDSD: Address of a surface description structure to write the info to
813 *****************************************************************************/
814 static HRESULT WINAPI
815 IDirectDrawImpl_GetDisplayMode(IDirectDraw7
*iface
,
816 DDSURFACEDESC2
*DDSD
)
818 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
820 WINED3DDISPLAYMODE Mode
;
822 TRACE("(%p)->(%p): Relay\n", This
, DDSD
);
824 /* This seems sane */
827 return DDERR_INVALIDPARAMS
;
830 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
831 * so one method can be used for all versions (Hopefully)
833 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
838 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This
, hr
);
843 memset(DDSD
, 0, Size
);
846 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
847 DDSD
->dwWidth
= Mode
.Width
;
848 DDSD
->dwHeight
= Mode
.Height
;
849 DDSD
->u2
.dwRefreshRate
= 60;
850 DDSD
->ddsCaps
.dwCaps
= 0;
851 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
852 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
853 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
857 TRACE("Returning surface desc :\n");
858 DDRAW_dump_surface_desc(DDSD
);
864 /*****************************************************************************
865 * IDirectDraw7::GetFourCCCodes
867 * Returns an array of supported FourCC codes.
869 * Exists in Version 1, 2, 4 and 7
872 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
873 * of enumerated codes
874 * Codes: Pointer to an array of DWORDs where the supported codes are written
878 * Always returns DD_OK, as it's a stub for now
880 *****************************************************************************/
881 static HRESULT WINAPI
882 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7
*iface
,
883 DWORD
*NumCodes
, DWORD
*Codes
)
885 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
886 FIXME("(%p)->(%p, %p): Stub!\n", This
, NumCodes
, Codes
);
888 if(NumCodes
) *NumCodes
= 0;
893 /*****************************************************************************
894 * IDirectDraw7::GetMonitorFrequency
896 * Returns the monitor's frequency
898 * Exists in Version 1, 2, 4 and 7
901 * Freq: Pointer to a DWORD to write the frequency to
904 * Always returns DD_OK
906 *****************************************************************************/
907 static HRESULT WINAPI
908 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7
*iface
,
911 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
912 TRACE("(%p)->(%p)\n", This
, Freq
);
914 /* Ideally this should be in WineD3D, as it concerns the screen setup,
915 * but for now this should make the games happy
921 /*****************************************************************************
922 * IDirectDraw7::GetVerticalBlankStatus
924 * Returns the Vertical blank status of the monitor. This should be in WineD3D
925 * too basically, but as it's a semi stub, I didn't create a function there
928 * status: Pointer to a BOOL to be filled with the vertical blank status
932 * DDERR_INVALIDPARAMS if status is NULL
934 *****************************************************************************/
935 static HRESULT WINAPI
936 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7
*iface
,
939 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
940 TRACE("(%p)->(%p)\n", This
, status
);
942 /* This looks sane, the MSDN suggests it too */
943 if(!status
) return DDERR_INVALIDPARAMS
;
945 *status
= This
->fake_vblank
;
946 This
->fake_vblank
= !This
->fake_vblank
;
950 /*****************************************************************************
951 * IDirectDraw7::GetAvailableVidMem
953 * Returns the total and free video memory
956 * Caps: Specifies the memory type asked for
957 * total: Pointer to a DWORD to be filled with the total memory
958 * free: Pointer to a DWORD to be filled with the free memory
962 * DDERR_INVALIDPARAMS of free and total are NULL
964 *****************************************************************************/
965 static HRESULT WINAPI
966 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
968 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
969 TRACE("(%p)->(%p, %p, %p)\n", This
, Caps
, total
, free
);
973 TRACE("(%p) Asked for memory with description: ", This
);
974 DDRAW_dump_DDSCAPS2(Caps
);
978 /* Todo: System memory vs local video memory vs non-local video memory
979 * The MSDN also mentions differences between texture memory and other
980 * resources, but that's not important
983 if( (!total
) && (!free
) ) return DDERR_INVALIDPARAMS
;
985 if(total
) *total
= This
->total_vidmem
;
986 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
991 /*****************************************************************************
992 * IDirectDraw7::Initialize
994 * Initializes a DirectDraw interface.
997 * GUID: Interface identifier. Well, don't know what this is really good
1001 * Returns DD_OK on the first call,
1002 * DDERR_ALREADYINITIALIZED on repeated calls
1004 *****************************************************************************/
1005 static HRESULT WINAPI
1006 IDirectDrawImpl_Initialize(IDirectDraw7
*iface
,
1009 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1010 TRACE("(%p)->(%s): No-op\n", This
, debugstr_guid(Guid
));
1012 if(This
->initialized
)
1014 return DDERR_ALREADYINITIALIZED
;
1022 /*****************************************************************************
1023 * IDirectDraw7::FlipToGDISurface
1025 * "Makes the surface that the GDI writes to the primary surface"
1026 * Looks like some windows specific thing we don't have to care about.
1027 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1028 * show error boxes ;)
1029 * Well, just return DD_OK.
1032 * Always returns DD_OK
1034 *****************************************************************************/
1035 static HRESULT WINAPI
1036 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7
*iface
)
1038 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1039 TRACE("(%p)\n", This
);
1044 /*****************************************************************************
1045 * IDirectDraw7::WaitForVerticalBlank
1047 * This method allows applications to get in sync with the vertical blank
1049 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1050 * redraw the screen, most likely because of this stub
1053 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1054 * or DDWAITVB_BLOCKEND
1055 * h: Not used, according to MSDN
1058 * Always returns DD_OK
1060 *****************************************************************************/
1061 static HRESULT WINAPI
1062 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7
*iface
,
1066 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1067 FIXME("(%p)->(%x,%p): Stub\n", This
, Flags
, h
);
1069 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1070 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1071 return DDERR_UNSUPPORTED
; /* unchecked */
1076 /*****************************************************************************
1077 * IDirectDraw7::GetScanLine
1079 * Returns the scan line that is being drawn on the monitor
1082 * Scanline: Address to write the scan line value to
1085 * Always returns DD_OK
1087 *****************************************************************************/
1088 static HRESULT WINAPI
IDirectDrawImpl_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1090 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1091 static BOOL hide
= FALSE
;
1092 WINED3DDISPLAYMODE Mode
;
1094 /* This function is called often, so print the fixme only once */
1097 FIXME("(%p)->(%p): Semi-Stub\n", This
, Scanline
);
1101 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1105 /* Fake the line sweeping of the monitor */
1106 /* FIXME: We should synchronize with a source to keep the refresh rate */
1107 *Scanline
= This
->cur_scanline
++;
1108 /* Assume 20 scan lines in the vertical blank */
1109 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1110 This
->cur_scanline
= 0;
1115 /*****************************************************************************
1116 * IDirectDraw7::TestCooperativeLevel
1118 * Informs the application about the state of the video adapter, depending
1119 * on the cooperative level
1122 * DD_OK if the device is in a sane state
1123 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1124 * if the state is not correct(See below)
1126 *****************************************************************************/
1127 static HRESULT WINAPI
1128 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7
*iface
)
1130 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1132 TRACE("(%p)\n", This
);
1134 /* Description from MSDN:
1135 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1136 * away from the app with e.g. alt-tab. Windowed apps receive
1137 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1138 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1139 * when the video mode has changed
1142 hr
= IWineD3DDevice_TestCooperativeLevel(This
->wineD3DDevice
);
1144 /* Fix the result value. These values are mapped from their
1149 case WINED3DERR_DEVICELOST
:
1150 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
1152 return DDERR_NOEXCLUSIVEMODE
;
1156 return DDERR_EXCLUSIVEMODEALREADYSET
;
1159 case WINED3DERR_DEVICENOTRESET
:
1165 case WINED3DERR_DRIVERINTERNALERROR
:
1167 ERR("(%p) Unexpected return value %08x from wineD3D, " \
1168 " returning DD_OK\n", This
, hr
);
1174 /*****************************************************************************
1175 * IDirectDraw7::GetGDISurface
1177 * Returns the surface that GDI is treating as the primary surface.
1178 * For Wine this is the front buffer
1181 * GDISurface: Address to write the surface pointer to
1184 * DD_OK if the surface was found
1185 * DDERR_NOTFOUND if the GDI surface wasn't found
1187 *****************************************************************************/
1188 static HRESULT WINAPI
1189 IDirectDrawImpl_GetGDISurface(IDirectDraw7
*iface
,
1190 IDirectDrawSurface7
**GDISurface
)
1192 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1193 IWineD3DSurface
*Surf
;
1194 IDirectDrawSurface7
*ddsurf
;
1197 TRACE("(%p)->(%p)\n", This
, GDISurface
);
1199 /* Get the back buffer from the wineD3DDevice and search its
1200 * attached surfaces for the front buffer
1202 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1204 0, /* first back buffer*/
1205 WINED3DBACKBUFFER_TYPE_MONO
,
1208 if( (hr
!= D3D_OK
) ||
1211 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1212 return DDERR_NOTFOUND
;
1215 /* GetBackBuffer AddRef()ed the surface, release it */
1216 IWineD3DSurface_Release(Surf
);
1218 IWineD3DSurface_GetParent(Surf
,
1219 (IUnknown
**) &ddsurf
);
1220 IDirectDrawSurface7_Release(ddsurf
); /* For the GetParent */
1222 /* Find the front buffer */
1223 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1224 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1229 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr
);
1232 /* The AddRef is OK this time */
1236 /*****************************************************************************
1237 * IDirectDrawImpl_EnumDisplayModesCB
1239 * Callback function for IDirectDraw7::EnumDisplayModes. Translates
1240 * the wineD3D values to ddraw values and calls the application callback
1243 * device: The IDirectDraw7 interface to the current device
1244 * With, Height, Pixelformat, Refresh: Enumerated display mode
1245 * context: the context pointer passed to IWineD3DDevice::EnumDisplayModes
1248 * The return value from the application callback
1250 *****************************************************************************/
1251 static HRESULT WINAPI
1252 IDirectDrawImpl_EnumDisplayModesCB(IUnknown
*pDevice
,
1255 WINED3DFORMAT Pixelformat
,
1259 DDSURFACEDESC2 callback_sd
;
1260 EnumDisplayModesCBS
*cbs
= (EnumDisplayModesCBS
*) context
;
1262 memset(&callback_sd
, 0, sizeof(callback_sd
));
1263 callback_sd
.dwSize
= sizeof(callback_sd
);
1264 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1266 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
1269 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
1270 callback_sd
.u2
.dwRefreshRate
= 60.0;
1273 callback_sd
.dwHeight
= Height
;
1274 callback_sd
.dwWidth
= Width
;
1276 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, Pixelformat
);
1277 return cbs
->callback(&callback_sd
, cbs
->context
);
1280 /*****************************************************************************
1281 * IDirectDraw7::EnumDisplayModes
1283 * Enumerates the supported Display modes. The modes can be filtered with
1284 * the DDSD parameter.
1287 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1288 * DDSD: Surface description to filter the modes
1289 * Context: Pointer passed back to the callback function
1290 * cb: Application-provided callback function
1294 * DDERR_INVALIDPARAMS if the callback wasn't set
1296 *****************************************************************************/
1297 static HRESULT WINAPI
1298 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7
*iface
,
1300 DDSURFACEDESC2
*DDSD
,
1302 LPDDENUMMODESCALLBACK2 cb
)
1304 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1305 UINT Width
= 0, Height
= 0;
1306 WINED3DFORMAT pixelformat
= WINED3DFMT_UNKNOWN
;
1307 EnumDisplayModesCBS cbs
;
1309 TRACE("(%p)->(%p,%p,%p): Relay\n", This
, DDSD
, Context
, cb
);
1311 /* This looks sane */
1312 if(!cb
) return DDERR_INVALIDPARAMS
;
1314 /* The private callback structure */
1316 cbs
.context
= Context
;
1320 if (DDSD
->dwFlags
& DDSD_WIDTH
)
1321 Width
= DDSD
->dwWidth
;
1322 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
1323 Height
= DDSD
->dwHeight
;
1324 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1325 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1328 return IWineD3DDevice_EnumDisplayModes(This
->wineD3DDevice
,
1330 Width
, Height
, pixelformat
,
1332 IDirectDrawImpl_EnumDisplayModesCB
);
1335 /*****************************************************************************
1336 * IDirectDraw7::EvaluateMode
1338 * Used with IDirectDraw7::StartModeTest to test video modes.
1339 * EvaluateMode is used to pass or fail a mode, and continue with the next
1343 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1344 * Timeout: Returns the amount of seconds left before the mode would have
1345 * been failed automatically
1348 * This implementation always DD_OK, because it's a stub
1350 *****************************************************************************/
1351 static HRESULT WINAPI
1352 IDirectDrawImpl_EvaluateMode(IDirectDraw7
*iface
,
1356 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1357 FIXME("(%p)->(%d,%p): Stub!\n", This
, Flags
, Timeout
);
1359 /* When implementing this, implement it in WineD3D */
1364 /*****************************************************************************
1365 * IDirectDraw7::GetDeviceIdentifier
1367 * Returns the device identifier, which gives information about the driver
1368 * Our device identifier is defined at the beginning of this file.
1371 * DDDI: Address for the returned structure
1372 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1375 * On success it returns DD_OK
1376 * DDERR_INVALIDPARAMS if DDDI is NULL
1378 *****************************************************************************/
1379 static HRESULT WINAPI
1380 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7
*iface
,
1381 DDDEVICEIDENTIFIER2
*DDDI
,
1384 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1385 TRACE("(%p)->(%p,%08x)\n", This
, DDDI
, Flags
);
1388 return DDERR_INVALIDPARAMS
;
1390 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1391 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1392 * to any modern hardware, nor is it interesting for Wine, so ignore it
1395 *DDDI
= deviceidentifier
;
1399 /*****************************************************************************
1400 * IDirectDraw7::GetSurfaceFromDC
1402 * Returns the Surface for a GDI device context handle.
1403 * Is this related to IDirectDrawSurface::GetDC ???
1406 * hdc: hdc to return the surface for
1407 * Surface: Address to write the surface pointer to
1410 * Always returns DD_OK because it's a stub
1412 *****************************************************************************/
1413 static HRESULT WINAPI
1414 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7
*iface
,
1416 IDirectDrawSurface7
**Surface
)
1418 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1419 FIXME("(%p)->(%p,%p): Stub!\n", This
, hdc
, Surface
);
1421 /* Implementation idea if needed: Loop through all surfaces and compare
1422 * their hdc with hdc. Implement it in WineD3D! */
1423 return DDERR_NOTFOUND
;
1426 /*****************************************************************************
1427 * IDirectDraw7::RestoreAllSurfaces
1429 * Calls the restore method of all surfaces
1434 * Always returns DD_OK because it's a stub
1436 *****************************************************************************/
1437 static HRESULT WINAPI
1438 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7
*iface
)
1440 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1441 FIXME("(%p): Stub\n", This
);
1443 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1444 * get their parent and call their restore method. Do not implement
1445 * it in WineD3D, as restoring a surface means re-creating the
1451 /*****************************************************************************
1452 * IDirectDraw7::StartModeTest
1454 * Tests the specified video modes to update the system registry with
1455 * refresh rate information. StartModeTest starts the mode test,
1456 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1457 * isn't called within 15 seconds, the mode is failed automatically
1459 * As refresh rates are handled by the X server, I don't think this
1460 * Method is important
1463 * Modes: An array of mode specifications
1464 * NumModes: The number of modes in Modes
1465 * Flags: Some flags...
1468 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1469 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1472 *****************************************************************************/
1473 static HRESULT WINAPI
1474 IDirectDrawImpl_StartModeTest(IDirectDraw7
*iface
,
1479 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1480 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This
, Modes
, NumModes
, Flags
);
1482 /* This looks sane */
1483 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
1485 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1486 * As it is not, DDERR_TESTFINISHED is returned
1487 * (hopefully that's correct
1489 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1490 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1496 /*****************************************************************************
1497 * IDirectDrawImpl_RecreateSurfacesCallback
1499 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1500 * It re-recreates the WineD3DSurface. It's pretty straightforward
1502 *****************************************************************************/
1504 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
1505 DDSURFACEDESC2
*desc
,
1508 IDirectDrawSurfaceImpl
*surfImpl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1509 IDirectDrawSurface7
,
1511 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
1513 IParentImpl
*parImpl
= NULL
;
1514 IWineD3DSurface
*wineD3DSurface
;
1518 WINED3DSURFACE_DESC Desc
;
1519 WINED3DFORMAT Format
;
1520 WINED3DRESOURCETYPE Type
;
1525 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1526 DWORD MultiSampleQuality
;
1530 TRACE("(%p): Enumerated Surface %p\n", This
, surfImpl
);
1532 /* For the enumeration */
1533 IDirectDrawSurface7_Release(surf
);
1535 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
1537 /* Get the objects */
1538 wineD3DSurface
= surfImpl
->WineD3DSurface
;
1539 IWineD3DSurface_GetParent(wineD3DSurface
, &Parent
);
1540 IUnknown_Release(Parent
); /* For the getParent */
1542 /* Is the parent an IParent interface? */
1543 if(IUnknown_QueryInterface(Parent
, &IID_IParent
, &tmp
) == S_OK
)
1545 /* It is a IParent interface! */
1546 IUnknown_Release(Parent
); /* For the QueryInterface */
1547 parImpl
= ICOM_OBJECT(IParentImpl
, IParent
, Parent
);
1548 /* Release the reference the parent interface is holding */
1549 IWineD3DSurface_Release(wineD3DSurface
);
1553 /* Get the surface properties */
1554 Desc
.Format
= &Format
;
1556 Desc
.Usage
= &Usage
;
1559 Desc
.MultiSampleType
= &MultiSampleType
;
1560 Desc
.MultiSampleQuality
= &MultiSampleQuality
;
1561 Desc
.Width
= &Width
;
1562 Desc
.Height
= &Height
;
1564 hr
= IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
1565 if(hr
!= D3D_OK
) return hr
;
1567 /* Create the new surface */
1568 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1569 Width
, Height
, Format
,
1570 TRUE
/* Lockable */,
1571 FALSE
/* Discard */,
1572 surfImpl
->mipmap_level
,
1573 &surfImpl
->WineD3DSurface
,
1579 0 /* SharedHandle */,
1586 /* Update the IParent if it exists */
1589 parImpl
->child
= (IUnknown
*) surfImpl
->WineD3DSurface
;
1590 /* Add a reference for the IParent */
1591 IWineD3DSurface_AddRef(surfImpl
->WineD3DSurface
);
1593 /* TODO: Copy the surface content, except for render targets */
1595 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
1596 TRACE("Surface released successful, next surface\n");
1598 ERR("Something's still holding the old WineD3DSurface\n");
1600 surfImpl
->ImplType
= This
->ImplType
;
1602 return DDENUMRET_OK
;
1605 /*****************************************************************************
1606 * IDirectDrawImpl_RecreateAllSurfaces
1608 * A function, that converts all wineD3DSurfaces to the new implementation type
1609 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1610 * new WineD3DSurface, copies the content and releases the old surface
1612 *****************************************************************************/
1614 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl
*This
)
1616 DDSURFACEDESC2 desc
;
1617 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
1619 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
1621 /* Should happen almost never */
1622 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
1624 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
);
1626 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1628 memset(&desc
, 0, sizeof(desc
));
1629 desc
.dwSize
= sizeof(desc
);
1631 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This
, IDirectDraw7
),
1635 IDirectDrawImpl_RecreateSurfacesCallback
);
1638 /*****************************************************************************
1639 * D3D7CB_CreateSurface
1641 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1642 * correct mipmap sublevel, and returns it to WineD3D.
1643 * The surfaces are created already by IDirectDraw7::CreateSurface
1646 * With, Height: With and height of the surface
1647 * Format: The requested format
1648 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1649 * level: The mipmap level
1650 * Surface: Pointer to pass the created surface back at
1651 * SharedHandle: NULL
1656 *****************************************************************************/
1657 static HRESULT WINAPI
1658 D3D7CB_CreateSurface(IUnknown
*device
,
1659 UINT Width
, UINT Height
,
1660 WINED3DFORMAT Format
,
1661 DWORD Usage
, WINED3DPOOL Pool
, UINT level
,
1662 IWineD3DSurface
**Surface
,
1663 HANDLE
*SharedHandle
)
1665 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
1666 IDirectDrawSurfaceImpl
*surf
= This
->tex_root
;
1668 TRACE("(%p) call back. surf=%p\n", device
, surf
);
1670 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1671 for(i
= 0; i
< level
; i
++)
1672 surf
= surf
->next_complex
;
1674 /* Return the surface */
1675 *Surface
= surf
->WineD3DSurface
;
1677 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface
, surf
);
1681 /*****************************************************************************
1682 * IDirectDrawImpl_CreateNewSurface
1684 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1685 * with the passed parameters.
1688 * DDSD: Description of the surface to create
1689 * Surf: Address to store the interface pointer at
1694 *****************************************************************************/
1695 static HRESULT WINAPI
1696 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
,
1697 DDSURFACEDESC2
*pDDSD
,
1698 IDirectDrawSurfaceImpl
**ppSurf
,
1702 UINT Width
= 0, Height
= 0;
1703 WINED3DFORMAT Format
= WINED3DFMT_UNKNOWN
;
1704 WINED3DRESOURCETYPE ResType
= WINED3DRTYPE_SURFACE
;
1706 WINED3DSURFTYPE ImplType
= This
->ImplType
;
1707 WINED3DSURFACE_DESC Desc
;
1709 IParentImpl
*parImpl
= NULL
;
1710 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
1712 /* Dummies for GetDesc */
1713 WINED3DPOOL dummy_d3dpool
;
1714 WINED3DMULTISAMPLE_TYPE dummy_mst
;
1718 if (TRACE_ON(ddraw
))
1720 TRACE(" (%p) Requesting surface desc :\n", This
);
1721 DDRAW_dump_surface_desc(pDDSD
);
1724 /* Select the surface type, if it wasn't choosen yet */
1725 if(ImplType
== SURFACE_UNKNOWN
)
1727 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1728 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1730 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
1731 ImplType
= SURFACE_OPENGL
;
1734 /* Otherwise use GDI surfaces for now */
1737 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
1738 ImplType
= SURFACE_GDI
;
1741 /* Policy if all surface implementations are available:
1742 * First, check if a default type was set with winecfg. If not,
1743 * try Xrender surfaces, and use them if they work. Next, check if
1744 * accelerated OpenGL is available, and use GL surfaces in this
1745 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1746 * was created, always use OpenGL surfaces.
1748 * (Note: Xrender surfaces are not implemented for now, the
1749 * unaccelerated implementation uses GDI to render in Software)
1752 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1753 * be re-created. This could be done with IDirectDrawSurface7::Restore
1755 This
->ImplType
= ImplType
;
1759 if((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
1760 (This
->ImplType
!= SURFACE_OPENGL
) && DefaultSurfaceType
== SURFACE_UNKNOWN
)
1762 /* We have to change to OpenGL,
1763 * and re-create all WineD3DSurfaces
1765 ImplType
= SURFACE_OPENGL
;
1766 This
->ImplType
= ImplType
;
1767 TRACE("(%p) Re-creating all surfaces\n", This
);
1768 IDirectDrawImpl_RecreateAllSurfaces(This
);
1769 TRACE("(%p) Done recreating all surfaces\n", This
);
1771 else if(This
->ImplType
!= SURFACE_OPENGL
)
1773 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1774 /* Do not fail surface creation, only fail 3D device creation */
1778 /* Get the correct wined3d usage */
1779 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
1780 DDSCAPS_BACKBUFFER
|
1781 DDSCAPS_3DDEVICE
) )
1783 Usage
|= WINED3DUSAGE_RENDERTARGET
;
1785 pDDSD
->ddsCaps
.dwCaps
|= DDSCAPS_VIDEOMEMORY
|
1787 DDSCAPS_LOCALVIDMEM
;
1789 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_OVERLAY
))
1791 Usage
|= WINED3DUSAGE_OVERLAY
;
1793 if(This
->depthstencil
)
1795 /* The depth stencil creation callback sets this flag.
1796 * Set the WineD3D usage to let it know that it's a depth
1799 Usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
1801 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
1803 Pool
= WINED3DPOOL_SYSTEMMEM
;
1806 Format
= PixelFormat_DD2WineD3D(&pDDSD
->u4
.ddpfPixelFormat
);
1807 if(Format
== WINED3DFMT_UNKNOWN
)
1809 ERR("Unsupported / Unknown pixelformat\n");
1810 return DDERR_INVALIDPIXELFORMAT
;
1813 /* Create the Surface object */
1814 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
1817 ERR("(%p) Error allocating memory for a surface\n", This
);
1818 return DDERR_OUTOFVIDEOMEMORY
;
1820 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface7
, IDirectDrawSurface7_Vtbl
);
1821 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface3
, IDirectDrawSurface3_Vtbl
);
1822 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawGammaControl
, IDirectDrawGammaControl_Vtbl
);
1823 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture2
, IDirect3DTexture2_Vtbl
);
1824 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture
, IDirect3DTexture1_Vtbl
);
1826 (*ppSurf
)->version
= 7;
1827 (*ppSurf
)->ddraw
= This
;
1828 (*ppSurf
)->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
1829 (*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1830 DD_STRUCT_COPY_BYSIZE(&(*ppSurf
)->surface_desc
, pDDSD
);
1832 /* Surface attachments */
1833 (*ppSurf
)->next_attached
= NULL
;
1834 (*ppSurf
)->first_attached
= *ppSurf
;
1836 (*ppSurf
)->next_complex
= NULL
;
1837 (*ppSurf
)->first_complex
= *ppSurf
;
1839 /* Needed to re-create the surface on an implementation change */
1840 (*ppSurf
)->ImplType
= ImplType
;
1842 /* For D3DDevice creation */
1843 (*ppSurf
)->isRenderTarget
= FALSE
;
1845 /* A trace message for debugging */
1846 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This
, *ppSurf
);
1848 if(pDDSD
->ddsCaps
.dwCaps
& ( DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
) )
1850 /* Render targets and textures need a IParent interface,
1851 * because WineD3D will destroy them when the swapchain
1854 parImpl
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
));
1857 ERR("Out of memory when allocating memory for a IParent implementation\n");
1858 return DDERR_OUTOFMEMORY
;
1861 ICOM_INIT_INTERFACE(parImpl
, IParent
, IParent_Vtbl
);
1862 Parent
= (IUnknown
*) ICOM_INTERFACE(parImpl
, IParent
);
1863 TRACE("Using IParent interface %p as parent\n", parImpl
);
1867 /* Use the surface as parent */
1868 Parent
= (IUnknown
*) ICOM_INTERFACE(*ppSurf
, IDirectDrawSurface7
);
1869 TRACE("Using Surface interface %p as parent\n", *ppSurf
);
1872 /* Now create the WineD3D Surface */
1873 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1877 TRUE
/* Lockable */,
1878 FALSE
/* Discard */,
1880 &(*ppSurf
)->WineD3DSurface
,
1883 WINED3DMULTISAMPLE_NONE
,
1884 0 /* MultiSampleQuality */,
1885 0 /* SharedHandle */,
1891 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr
);
1895 /* Set the child of the parent implementation if it exists */
1898 parImpl
->child
= (IUnknown
*) (*ppSurf
)->WineD3DSurface
;
1899 /* The IParent releases the WineD3DSurface, and
1900 * the ddraw surface does that too. Hold a reference
1902 IWineD3DSurface_AddRef((*ppSurf
)->WineD3DSurface
);
1905 /* Increase the surface counter, and attach the surface */
1906 InterlockedIncrement(&This
->surfaces
);
1907 list_add_head(&This
->surface_list
, &(*ppSurf
)->surface_list_entry
);
1909 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1910 * But this could also be delegated to WineDDraw, as it keeps track of all its
1911 * resources. Not implemented for now, as there are more important things ;)
1914 /* Get the pixel format of the WineD3DSurface and store it.
1915 * Don't use the Format choosen above, WineD3D might have
1918 Desc
.Format
= &Format
;
1919 Desc
.Type
= &ResType
;
1920 Desc
.Usage
= &Usage
;
1921 Desc
.Pool
= &dummy_d3dpool
;
1922 Desc
.Size
= &dummy_uint
;
1923 Desc
.MultiSampleType
= &dummy_mst
;
1924 Desc
.MultiSampleQuality
= &dummy_dword
;
1925 Desc
.Width
= &Width
;
1926 Desc
.Height
= &Height
;
1928 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
1929 hr
= IWineD3DSurface_GetDesc((*ppSurf
)->WineD3DSurface
, &Desc
);
1932 ERR("IWineD3DSurface::GetDesc failed\n");
1933 IDirectDrawSurface7_Release( (IDirectDrawSurface7
*) *ppSurf
);
1937 if(Format
== WINED3DFMT_UNKNOWN
)
1939 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
1941 PixelFormat_WineD3DtoDD( &(*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
, Format
);
1943 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
1944 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
1945 * WineD3DDevice might not be useable for 3D yet, so an extra method was created
1947 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PITCH
;
1948 (*ppSurf
)->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch((*ppSurf
)->WineD3DSurface
);
1950 /* Application passed a color key? Set it! */
1951 if(pDDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
1953 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1955 &pDDSD
->u3
.ddckCKDestOverlay
);
1957 if(pDDSD
->dwFlags
& DDSD_CKDESTBLT
)
1959 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1961 &pDDSD
->ddckCKDestBlt
);
1963 if(pDDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
1965 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1967 &pDDSD
->ddckCKSrcOverlay
);
1969 if(pDDSD
->dwFlags
& DDSD_CKSRCBLT
)
1971 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1973 &pDDSD
->ddckCKSrcBlt
);
1975 if ( pDDSD
->dwFlags
& DDSD_LPSURFACE
)
1977 hr
= IWineD3DSurface_SetMem((*ppSurf
)->WineD3DSurface
, pDDSD
->lpSurface
);
1978 if(hr
!= WINED3D_OK
)
1980 /* No need for a trace here, wined3d does that for us */
1981 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf
), IDirectDrawSurface7
));
1989 /*****************************************************************************
1990 * IDirectDraw7::CreateSurface
1992 * Creates a new IDirectDrawSurface object and returns its interface.
1994 * The surface connections with wined3d are a bit tricky. Basically it works
1997 * |------------------------| |-----------------|
1998 * | DDraw surface | | WineD3DSurface |
2000 * | WineD3DSurface |-------------->| |
2001 * | Child |<------------->| Parent |
2002 * |------------------------| |-----------------|
2004 * The DDraw surface is the parent of the wined3d surface, and it releases
2005 * the WineD3DSurface when the ddraw surface is destroyed.
2007 * However, for all surfaces which can be in a container in WineD3D,
2008 * we have to do this. These surfaces are ususally complex surfaces,
2009 * so this concerns primary surfaces with a front and a back buffer,
2012 * |------------------------| |-----------------|
2013 * | DDraw surface | | Containter |
2015 * | Child |<------------->| Parent |
2016 * | Texture |<------------->| |
2017 * | WineD3DSurface |<----| | Levels |<--|
2018 * | Complex connection | | | | |
2019 * |------------------------| | |-----------------| |
2023 * | |------------------| | |-----------------| |
2024 * | | IParent | |-------->| WineD3DSurface | |
2026 * | | Child |<------------->| Parent | |
2027 * | | | | Container |<--|
2028 * | |------------------| |-----------------| |
2030 * | |----------------------| |
2031 * | | DDraw surface 2 | |
2033 * |<->| Complex root Child | |
2035 * | | WineD3DSurface |<----| |
2036 * | |----------------------| | |
2038 * | |---------------------| | |-----------------| |
2039 * | | IParent | |----->| WineD3DSurface | |
2041 * | | Child |<---------->| Parent | |
2042 * | |---------------------| | Container |<--|
2043 * | |-----------------| |
2045 * | ---More surfaces can follow--- |
2047 * The reason is that the IWineD3DSwapchain(render target container)
2048 * and the IWineD3DTexure(Texture container) release the parents
2049 * of their surface's children, but by releasing the complex root
2050 * the surfaces which are complexly attached to it are destroyed
2051 * too. See IDirectDrawSurface::Release for a more detailed
2055 * DDSD: Description of the surface to create
2056 * Surf: Address to store the interface pointer at
2057 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2058 * aggregation, so it has to be NULL
2062 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2063 * DDERR_* if an error occurs
2065 *****************************************************************************/
2066 static HRESULT WINAPI
2067 IDirectDrawImpl_CreateSurface(IDirectDraw7
*iface
,
2068 DDSURFACEDESC2
*DDSD
,
2069 IDirectDrawSurface7
**Surf
,
2072 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2073 IDirectDrawSurfaceImpl
*object
= NULL
;
2075 LONG extra_surfaces
= 0, i
;
2076 DDSURFACEDESC2 desc2
;
2078 WINED3DDISPLAYMODE Mode
;
2080 TRACE("(%p)->(%p,%p,%p)\n", This
, DDSD
, Surf
, UnkOuter
);
2082 /* Some checks before we start */
2083 if (TRACE_ON(ddraw
))
2085 TRACE(" (%p) Requesting surface desc :\n", This
);
2086 DDRAW_dump_surface_desc(DDSD
);
2089 if (UnkOuter
!= NULL
)
2091 FIXME("(%p) : outer != NULL?\n", This
);
2092 return CLASS_E_NOAGGREGATION
; /* unchecked */
2095 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2097 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2098 DDSD
->dwFlags
|= DDSD_CAPS
;
2100 if (DDSD
->ddsCaps
.dwCaps
== 0)
2102 /* This has been checked on real Windows */
2103 DDSD
->ddsCaps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
2106 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2108 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2109 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2112 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2114 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2115 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2116 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2119 if((DDSD
->ddsCaps
.dwCaps
& (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
)) == (DDSCAPS_FLIP
| DDSCAPS_PRIMARYSURFACE
) &&
2120 !(This
->cooperative_level
& DDSCL_EXCLUSIVE
))
2122 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This
);
2124 return DDERR_NOEXCLUSIVEMODE
;
2129 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2130 return E_POINTER
; /* unchecked */
2133 /* According to the msdn this flag is ignored by CreateSurface */
2134 if (DDSD
->dwSize
>= sizeof(DDSURFACEDESC2
))
2135 DDSD
->ddsCaps
.dwCaps2
&= ~DDSCAPS2_MIPMAPSUBLEVEL
;
2137 /* Modify some flags */
2138 memset(&desc2
, 0, sizeof(desc2
));
2139 desc2
.dwSize
= sizeof(desc2
); /* For the struct copy */
2140 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2141 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2142 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2144 /* Get the video mode from WineD3D - we will need it */
2145 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2146 0, /* Swapchain 0 */
2150 ERR("Failed to read display mode from wined3d\n");
2151 switch(This
->orig_bpp
)
2154 Mode
.Format
= WINED3DFMT_P8
;
2158 Mode
.Format
= WINED3DFMT_X1R5G5B5
;
2162 Mode
.Format
= WINED3DFMT_R5G6B5
;
2166 Mode
.Format
= WINED3DFMT_R8G8B8
;
2170 Mode
.Format
= WINED3DFMT_X8R8G8B8
;
2173 Mode
.Width
= This
->orig_width
;
2174 Mode
.Height
= This
->orig_height
;
2177 /* No pixelformat given? Use the current screen format */
2178 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2180 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2181 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2183 /* Wait: It could be a Z buffer */
2184 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2186 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glorious idea? */
2189 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D15S1
);
2192 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16
);
2195 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D24X8
);
2198 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32
);
2201 ERR("Unknown Z buffer bit depth\n");
2206 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2210 /* No Width or no Height? Use the current window size or
2211 * the original screen size
2213 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2214 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2218 /* Fallback: From WineD3D / original mode */
2219 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2220 desc2
.dwWidth
= Mode
.Width
;
2221 desc2
.dwHeight
= Mode
.Height
;
2223 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
2225 if( (hr
== D3D_OK
) && (window
!= 0) )
2228 if(GetWindowRect(window
, &rect
) )
2230 /* This is a hack until I find a better solution */
2231 if( (rect
.right
- rect
.left
) <= 1 ||
2232 (rect
.bottom
- rect
.top
) <= 1 )
2234 FIXME("Wanted to get surface dimensions from window %p, but it has only \
2235 a size of %dx%d. Using full screen dimensions\n",
2236 window
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
2240 /* Not sure if this is correct */
2241 desc2
.dwWidth
= rect
.right
- rect
.left
;
2242 desc2
.dwHeight
= rect
.bottom
- rect
.top
;
2243 TRACE("Using window %p's dimensions: %dx%d\n", window
, desc2
.dwWidth
, desc2
.dwHeight
);
2249 /* Mipmap count fixes */
2250 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2252 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2254 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2256 /* Mipmap count is given, nothing to do */
2260 /* Undocumented feature: Create sublevels until
2261 * either the width or the height is 1
2263 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2264 desc2
.dwWidth
: desc2
.dwHeight
;
2265 desc2
.u2
.dwMipMapCount
= 0;
2268 desc2
.u2
.dwMipMapCount
+= 1;
2275 /* Not-complex mipmap -> Mipmapcount = 1 */
2276 desc2
.u2
.dwMipMapCount
= 1;
2278 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2280 /* There's a mipmap count in the created surface in any case */
2281 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2283 /* If no mipmap is given, the texture has only one level */
2285 /* The first surface is a front buffer, the back buffer is created afterwards */
2286 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2288 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2291 /* Create the first surface */
2292 hr
= IDirectDrawImpl_CreateNewSurface(This
, &desc2
, &object
, 0);
2295 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr
);
2299 *Surf
= ICOM_INTERFACE(object
, IDirectDrawSurface7
);
2301 /* Create Additional surfaces if necessary
2302 * This applies to Primary surfaces which have a back buffer count
2303 * set, but not to mipmap textures. In case of Mipmap textures,
2304 * wineD3D takes care of the creation of additional surfaces
2306 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2308 extra_surfaces
= DDSD
->dwBackBufferCount
;
2309 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2310 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2312 /* Set the DDSCAPS2_MIPMAPSUBLEVEL flag on mipmap sublevels according to the msdn */
2313 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2315 desc2
.ddsCaps
.dwCaps2
|= DDSCAPS2_MIPMAPSUBLEVEL
;
2318 for(i
= 0; i
< extra_surfaces
; i
++)
2320 IDirectDrawSurfaceImpl
*object2
= NULL
;
2321 IDirectDrawSurfaceImpl
*iterator
;
2323 /* increase the mipmap level, but only if a mipmap is created
2324 * In this case, also halve the size
2326 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2329 if(desc2
.dwWidth
> 1) desc2
.dwWidth
/= 2;
2330 if(desc2
.dwHeight
> 1) desc2
.dwHeight
/= 2;
2333 hr
= IDirectDrawImpl_CreateNewSurface(This
,
2339 /* This destroys and possibly created surfaces too */
2340 IDirectDrawSurface_Release( ICOM_INTERFACE(object
, IDirectDrawSurface7
) );
2344 /* Add the new surface to the complex attachment list */
2345 object2
->first_complex
= object
;
2346 object2
->next_complex
= NULL
;
2348 while(iterator
->next_complex
) iterator
= iterator
->next_complex
;
2349 iterator
->next_complex
= object2
;
2351 /* Remove the (possible) back buffer cap from the new surface description,
2352 * because only one surface in the flipping chain is a back buffer, one
2353 * is a front buffer, the others are just primary surfaces.
2355 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2358 /* Addref the ddraw interface to keep an reference for each surface */
2359 IDirectDraw7_AddRef(iface
);
2360 object
->ifaceToRelease
= (IUnknown
*) iface
;
2362 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2363 * But attach the d3ddevice only if the currently created surface was
2364 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2365 * The only case I can think of where this doesn't apply is when a
2366 * 2D app was configured by the user to run with OpenGL and it didn't create
2367 * the render target as first surface. In this case the render target creation
2368 * will cause the 3D init.
2370 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
2371 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
2373 IDirectDrawSurfaceImpl
*target
= object
, *surface
;
2376 /* Search for the primary to use as render target */
2377 LIST_FOR_EACH(entry
, &This
->surface_list
)
2379 surface
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2380 if(surface
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2384 TRACE("Using primary %p as render target\n", target
);
2389 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
2390 hr
= IDirectDrawImpl_AttachD3DDevice(This
, target
->first_complex
);
2393 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr
);
2397 /* Create a WineD3DTexture if a texture was requested */
2398 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2401 WINED3DFORMAT Format
;
2402 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
2404 This
->tex_root
= object
;
2406 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2408 /* a mipmap is created, create enough levels */
2409 levels
= desc2
.u2
.dwMipMapCount
;
2413 /* No mipmap is created, create one level */
2417 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2418 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
2420 Pool
= WINED3DPOOL_SYSTEMMEM
;
2422 /* Should I forward the MANEGED cap to the managed pool ? */
2424 /* Get the format. It's set already by CreateNewSurface */
2425 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
2427 /* The surfaces are already created, the callback only
2428 * passes the IWineD3DSurface to WineD3D
2430 hr
= IWineD3DDevice_CreateTexture( This
->wineD3DDevice
,
2431 DDSD
->dwWidth
, DDSD
->dwHeight
,
2432 levels
, /* MipMapCount = Levels */
2436 &object
->wineD3DTexture
,
2437 0, /* SharedHandle */
2438 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2439 D3D7CB_CreateSurface
);
2440 This
->tex_root
= NULL
;
2446 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2447 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2450 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2451 const DDPIXELFORMAT
*provided
)
2453 /* Some flags must be present in both or neither for a match. */
2454 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2455 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2456 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2458 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2461 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2464 if (requested
->dwFlags
& DDPF_FOURCC
)
2465 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2468 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2469 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2470 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2473 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2474 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2475 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2478 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2479 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2482 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2483 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2485 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2488 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2489 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2496 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
,
2497 const DDSURFACEDESC2
* provided
)
2506 #define CMP(FLAG, FIELD) \
2507 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2508 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2510 static const struct compare_info compare
[] =
2512 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
2513 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
2515 CMP(CKDESTBLT
, ddckCKDestBlt
),
2516 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
2517 CMP(CKSRCBLT
, ddckCKSrcBlt
),
2518 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
2519 CMP(HEIGHT
, dwHeight
),
2520 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
2521 CMP(LPSURFACE
, lpSurface
),
2522 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
2523 CMP(PITCH
, u1
/* lPitch */),
2524 /* PIXELFORMAT: manual */
2525 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
2526 CMP(TEXTURESTAGE
, dwTextureStage
),
2527 CMP(WIDTH
, dwWidth
),
2528 /* ZBUFFERBITDEPTH: "obsolete" */
2535 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2538 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
2540 if (requested
->dwFlags
& compare
[i
].flag
2541 && memcmp((const char *)provided
+ compare
[i
].offset
,
2542 (const char *)requested
+ compare
[i
].offset
,
2543 compare
[i
].size
) != 0)
2547 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
2549 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
2550 &provided
->u4
.ddpfPixelFormat
))
2557 #undef DDENUMSURFACES_SEARCHTYPE
2558 #undef DDENUMSURFACES_MATCHTYPE
2560 /*****************************************************************************
2561 * IDirectDraw7::EnumSurfaces
2563 * Loops through all surfaces attached to this device and calls the
2564 * application callback. This can't be relayed to WineD3DDevice,
2565 * because some WineD3DSurfaces' parents are IParent objects
2568 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2569 * DDSD: Description to filter for
2570 * Context: Application-provided pointer, it's passed unmodified to the
2572 * Callback: Address to call for each surface
2575 * DDERR_INVALIDPARAMS if the callback is NULL
2578 *****************************************************************************/
2579 static HRESULT WINAPI
2580 IDirectDrawImpl_EnumSurfaces(IDirectDraw7
*iface
,
2582 DDSURFACEDESC2
*DDSD
,
2584 LPDDENUMSURFACESCALLBACK7 Callback
)
2586 /* The surface enumeration is handled by WineDDraw,
2587 * because it keeps track of all surfaces attached to
2588 * it. The filtering is done by our callback function,
2589 * because WineDDraw doesn't handle ddraw-like surface
2592 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2593 IDirectDrawSurfaceImpl
*surf
;
2595 DDSURFACEDESC2 desc
;
2596 struct list
*entry
, *entry2
;
2598 all
= Flags
& DDENUMSURFACES_ALL
;
2599 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
2601 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, DDSD
, Context
, Callback
);
2604 return DDERR_INVALIDPARAMS
;
2606 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2607 LIST_FOR_EACH_SAFE(entry
, entry2
, &This
->surface_list
)
2609 surf
= LIST_ENTRY(entry
, IDirectDrawSurfaceImpl
, surface_list_entry
);
2610 if (all
|| (nomatch
!= IDirectDrawImpl_DDSD_Match(DDSD
, &surf
->surface_desc
)))
2612 desc
= surf
->surface_desc
;
2613 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
2614 if(Callback( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, Context
) != DDENUMRET_OK
)
2621 /*****************************************************************************
2622 * D3D7CB_CreateRenderTarget
2624 * Callback called by WineD3D to create Surfaces for render target usage
2625 * This function takes the D3D target from the IDirectDrawImpl structure,
2626 * and returns the WineD3DSurface. To avoid double usage, the surface
2627 * is marked as render target afterwards
2630 * device: The WineD3DDevice's parent
2631 * Width, Height, Format: Dimensions and pixelformat of the render target
2632 * Ignored, because the surface already exists
2633 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2635 * ppSurface: Address to pass the surface pointer back at
2636 * pSharedHandle: Ignored
2639 * Always returns D3D_OK
2641 *****************************************************************************/
2642 static HRESULT WINAPI
2643 D3D7CB_CreateRenderTarget(IUnknown
*device
, UINT Width
, UINT Height
,
2644 WINED3DFORMAT Format
,
2645 WINED3DMULTISAMPLE_TYPE MultiSample
,
2646 DWORD MultisampleQuality
,
2648 IWineD3DSurface
** ppSurface
,
2649 HANDLE
* pSharedHandle
)
2651 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2652 IDirectDrawSurfaceImpl
*d3dSurface
= (IDirectDrawSurfaceImpl
*) This
->d3d_target
->first_complex
;
2653 TRACE("(%p) call back\n", device
);
2655 /* Loop through the complex chain and try to find unused primary surfaces */
2656 while(d3dSurface
->isRenderTarget
)
2658 d3dSurface
= d3dSurface
->next_complex
;
2659 if(!d3dSurface
) break;
2663 d3dSurface
= This
->d3d_target
;
2664 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
2667 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2669 *ppSurface
= d3dSurface
->WineD3DSurface
;
2670 d3dSurface
->isRenderTarget
= TRUE
;
2671 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface
, d3dSurface
);
2675 static HRESULT WINAPI
2676 D3D7CB_CreateDepthStencilSurface(IUnknown
*device
,
2679 WINED3DFORMAT Format
,
2680 WINED3DMULTISAMPLE_TYPE MultiSample
,
2681 DWORD MultisampleQuality
,
2683 IWineD3DSurface
** ppSurface
,
2684 HANDLE
* pSharedHandle
)
2686 /* Create a Depth Stencil surface to make WineD3D happy */
2687 HRESULT hr
= D3D_OK
;
2688 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2689 DDSURFACEDESC2 ddsd
;
2691 TRACE("(%p) call back\n", device
);
2695 /* Create a DirectDraw surface */
2696 memset(&ddsd
, 0, sizeof(ddsd
));
2697 ddsd
.dwSize
= sizeof(ddsd
);
2698 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2699 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2700 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2701 ddsd
.dwHeight
= Height
;
2702 ddsd
.dwWidth
= Width
;
2705 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, Format
);
2709 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
2712 This
->depthstencil
= TRUE
;
2713 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*) This
,
2715 (IDirectDrawSurface7
**) &This
->DepthStencilBuffer
,
2717 This
->depthstencil
= FALSE
;
2720 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This
, hr
);
2723 *ppSurface
= This
->DepthStencilBuffer
->WineD3DSurface
;
2727 /*****************************************************************************
2728 * D3D7CB_CreateAdditionalSwapChain
2730 * Callback function for WineD3D which creates a new WineD3DSwapchain
2731 * interface. It also creates an IParent interface to store that pointer,
2732 * so the WineD3DSwapchain has a parent and can be released when the D3D
2733 * device is destroyed
2734 *****************************************************************************/
2735 static HRESULT WINAPI
2736 D3D7CB_CreateAdditionalSwapChain(IUnknown
*device
,
2737 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
2738 IWineD3DSwapChain
** ppSwapChain
)
2740 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2741 IParentImpl
*object
= NULL
;
2742 HRESULT res
= D3D_OK
;
2743 IWineD3DSwapChain
*swapchain
;
2744 TRACE("(%p) call back\n", device
);
2746 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
2749 FIXME("Allocation of memory failed\n");
2750 *ppSwapChain
= NULL
;
2751 return DDERR_OUTOFVIDEOMEMORY
;
2754 ICOM_INIT_INTERFACE(object
, IParent
, IParent_Vtbl
);
2757 res
= IWineD3DDevice_CreateAdditionalSwapChain(This
->wineD3DDevice
,
2758 pPresentationParameters
,
2760 (IUnknown
*) ICOM_INTERFACE(object
, IParent
),
2761 D3D7CB_CreateRenderTarget
,
2762 D3D7CB_CreateDepthStencilSurface
);
2765 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
2766 HeapFree(GetProcessHeap(), 0 , object
);
2767 *ppSwapChain
= NULL
;
2771 *ppSwapChain
= swapchain
;
2772 object
->child
= (IUnknown
*) swapchain
;
2778 /*****************************************************************************
2779 * IDirectDrawImpl_AttachD3DDevice
2781 * Initializes the D3D capabilities of WineD3D
2784 * primary: The primary surface for D3D
2790 *****************************************************************************/
2791 static HRESULT WINAPI
2792 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
,
2793 IDirectDrawSurfaceImpl
*primary
)
2796 UINT BackBufferCount
= 0;
2799 WINED3DPRESENT_PARAMETERS localParameters
;
2800 BOOL isWindowed
, EnableAutoDepthStencil
;
2801 WINED3DFORMAT AutoDepthStencilFormat
;
2802 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
2803 WINED3DSWAPEFFECT SwapEffect
;
2804 DWORD Flags
, MultiSampleQuality
;
2805 UINT FullScreen_RefreshRateInHz
, PresentationInterval
;
2806 WINED3DDISPLAYMODE Mode
;
2808 TRACE("(%p)->(%p)\n", This
, primary
);
2810 /* Get the window */
2811 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
2815 ERR("IWineD3DDevice::GetHWND failed\n");
2819 /* If there's no window, create a hidden window. WineD3D needs it */
2822 window
= CreateWindowExA(0, This
->classname
, "Hidden D3D Window",
2824 GetSystemMetrics(SM_CXSCREEN
),
2825 GetSystemMetrics(SM_CYSCREEN
),
2826 NULL
, NULL
, GetModuleHandleA(0), NULL
);
2828 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2829 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This
, window
);
2830 This
->d3d_window
= window
;
2834 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This
, window
);
2837 /* use the surface description for the device parameters, not the
2838 * Device settings. The app might render to an offscreen surface
2840 Mode
.Width
= primary
->surface_desc
.dwWidth
;
2841 Mode
.Height
= primary
->surface_desc
.dwHeight
;
2842 Mode
.Format
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2844 if(primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2846 BackBufferCount
= primary
->surface_desc
.dwBackBufferCount
;
2849 /* Store the future Render Target surface */
2850 This
->d3d_target
= primary
;
2852 isWindowed
= !(This
->cooperative_level
& DDSCL_FULLSCREEN
);
2853 EnableAutoDepthStencil
= FALSE
;
2854 AutoDepthStencilFormat
= WINED3DFMT_D16
;
2855 MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2856 SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2858 MultiSampleQuality
= 0;
2859 FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
; /* Default rate: It's already set */
2860 PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2862 TRACE("Passing mode %d\n", Mode
.Format
);
2864 localParameters
.BackBufferWidth
= &Mode
.Width
;
2865 localParameters
.BackBufferHeight
= &Mode
.Height
;
2866 localParameters
.BackBufferFormat
= (WINED3DFORMAT
*) &Mode
.Format
;
2867 localParameters
.BackBufferCount
= (UINT
*) &BackBufferCount
;
2868 localParameters
.MultiSampleType
= &MultiSampleType
;
2869 localParameters
.MultiSampleQuality
= &MultiSampleQuality
;
2870 localParameters
.SwapEffect
= &SwapEffect
;
2871 localParameters
.hDeviceWindow
= &window
;
2872 localParameters
.Windowed
= &isWindowed
;
2873 localParameters
.EnableAutoDepthStencil
= &EnableAutoDepthStencil
;
2874 localParameters
.AutoDepthStencilFormat
= &AutoDepthStencilFormat
;
2875 localParameters
.Flags
= &Flags
;
2876 localParameters
.FullScreen_RefreshRateInHz
= &FullScreen_RefreshRateInHz
;
2877 localParameters
.PresentationInterval
= &PresentationInterval
;
2879 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2880 * recursive loop until ram or emulated video memory is full
2882 This
->d3d_initialized
= TRUE
;
2884 hr
= IWineD3DDevice_Init3D(This
->wineD3DDevice
,
2886 D3D7CB_CreateAdditionalSwapChain
);
2889 This
->wineD3DDevice
= NULL
;
2893 /* Create an Index Buffer parent */
2894 TRACE("(%p) Successfully initialized 3D\n", This
);
2898 /*****************************************************************************
2899 * DirectDrawCreateClipper (DDRAW.@)
2901 * Creates a new IDirectDrawClipper object.
2904 * Clipper: Address to write the interface pointer to
2905 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2909 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2910 * E_OUTOFMEMORY if allocating the object failed
2912 *****************************************************************************/
2914 DirectDrawCreateClipper(DWORD Flags
,
2915 IDirectDrawClipper
**Clipper
,
2918 IDirectDrawClipperImpl
* object
;
2919 TRACE("(%08x,%p,%p)\n", Flags
, Clipper
, UnkOuter
);
2921 if (UnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
2923 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2924 sizeof(IDirectDrawClipperImpl
));
2925 if (object
== NULL
) return E_OUTOFMEMORY
;
2927 ICOM_INIT_INTERFACE(object
, IDirectDrawClipper
, IDirectDrawClipper_Vtbl
);
2930 object
->ddraw_owner
= NULL
;
2932 *Clipper
= (IDirectDrawClipper
*) object
;
2936 /*****************************************************************************
2937 * IDirectDraw7::CreateClipper
2939 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
2941 *****************************************************************************/
2942 static HRESULT WINAPI
2943 IDirectDrawImpl_CreateClipper(IDirectDraw7
*iface
,
2945 IDirectDrawClipper
**Clipper
,
2948 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2949 TRACE("(%p)->(%x,%p,%p)\n", This
, Flags
, Clipper
, UnkOuter
);
2950 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
2953 /*****************************************************************************
2954 * IDirectDraw7::CreatePalette
2956 * Creates a new IDirectDrawPalette object
2959 * Flags: The flags for the new clipper
2960 * ColorTable: Color table to assign to the new clipper
2961 * Palette: Address to write the interface pointer to
2962 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2966 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2967 * E_OUTOFMEMORY if allocating the object failed
2969 *****************************************************************************/
2970 static HRESULT WINAPI
2971 IDirectDrawImpl_CreatePalette(IDirectDraw7
*iface
,
2973 PALETTEENTRY
*ColorTable
,
2974 IDirectDrawPalette
**Palette
,
2975 IUnknown
*pUnkOuter
)
2977 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2978 IDirectDrawPaletteImpl
*object
;
2979 HRESULT hr
= DDERR_GENERIC
;
2980 TRACE("(%p)->(%x,%p,%p,%p)\n", This
, Flags
, ColorTable
, Palette
, pUnkOuter
);
2982 if(pUnkOuter
!= NULL
)
2984 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
2985 return CLASS_E_NOAGGREGATION
;
2988 /* The refcount test shows that a cooplevel is required for this */
2989 if(!This
->cooperative_level
)
2991 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
2992 return DDERR_NOCOOPERATIVELEVELSET
;
2995 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
2998 ERR("Out of memory when allocating memory for a palette implementation\n");
2999 return E_OUTOFMEMORY
;
3002 ICOM_INIT_INTERFACE(object
, IDirectDrawPalette
, IDirectDrawPalette_Vtbl
);
3004 object
->ddraw_owner
= This
;
3006 hr
= IWineD3DDevice_CreatePalette(This
->wineD3DDevice
, Flags
, ColorTable
, &object
->wineD3DPalette
, (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawPalette
) );
3009 HeapFree(GetProcessHeap(), 0, object
);
3013 IDirectDraw7_AddRef(iface
);
3014 object
->ifaceToRelease
= (IUnknown
*) iface
;
3015 *Palette
= ICOM_INTERFACE(object
, IDirectDrawPalette
);
3019 /*****************************************************************************
3020 * IDirectDraw7::DuplicateSurface
3022 * Duplicates a surface. The surface memory points to the same memory as
3023 * the original surface, and it's released when the last surface referencing
3024 * it is released. I guess that's beyond Wine's surface management right now
3025 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3026 * test application to implement this)
3029 * Src: Address of the source surface
3030 * Dest: Address to write the new surface pointer to
3033 * See IDirectDraw7::CreateSurface
3035 *****************************************************************************/
3036 static HRESULT WINAPI
3037 IDirectDrawImpl_DuplicateSurface(IDirectDraw7
*iface
,
3038 IDirectDrawSurface7
*Src
,
3039 IDirectDrawSurface7
**Dest
)
3041 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3042 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Src
);
3044 FIXME("(%p)->(%p,%p)\n", This
, Surf
, Dest
);
3046 /* For now, simply create a new, independent surface */
3047 return IDirectDraw7_CreateSurface(iface
,
3048 &Surf
->surface_desc
,
3053 /*****************************************************************************
3054 * IDirectDraw7 VTable
3055 *****************************************************************************/
3056 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
=
3059 IDirectDrawImpl_QueryInterface
,
3060 IDirectDrawImpl_AddRef
,
3061 IDirectDrawImpl_Release
,
3062 /*** IDirectDraw ***/
3063 IDirectDrawImpl_Compact
,
3064 IDirectDrawImpl_CreateClipper
,
3065 IDirectDrawImpl_CreatePalette
,
3066 IDirectDrawImpl_CreateSurface
,
3067 IDirectDrawImpl_DuplicateSurface
,
3068 IDirectDrawImpl_EnumDisplayModes
,
3069 IDirectDrawImpl_EnumSurfaces
,
3070 IDirectDrawImpl_FlipToGDISurface
,
3071 IDirectDrawImpl_GetCaps
,
3072 IDirectDrawImpl_GetDisplayMode
,
3073 IDirectDrawImpl_GetFourCCCodes
,
3074 IDirectDrawImpl_GetGDISurface
,
3075 IDirectDrawImpl_GetMonitorFrequency
,
3076 IDirectDrawImpl_GetScanLine
,
3077 IDirectDrawImpl_GetVerticalBlankStatus
,
3078 IDirectDrawImpl_Initialize
,
3079 IDirectDrawImpl_RestoreDisplayMode
,
3080 IDirectDrawImpl_SetCooperativeLevel
,
3081 IDirectDrawImpl_SetDisplayMode
,
3082 IDirectDrawImpl_WaitForVerticalBlank
,
3083 /*** IDirectDraw2 ***/
3084 IDirectDrawImpl_GetAvailableVidMem
,
3085 /*** IDirectDraw7 ***/
3086 IDirectDrawImpl_GetSurfaceFromDC
,
3087 IDirectDrawImpl_RestoreAllSurfaces
,
3088 IDirectDrawImpl_TestCooperativeLevel
,
3089 IDirectDrawImpl_GetDeviceIdentifier
,
3090 /*** IDirectDraw7 ***/
3091 IDirectDrawImpl_StartModeTest
,
3092 IDirectDrawImpl_EvaluateMode