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 /* This is for cleanup if a broken app doesn't Release its objects */
66 IDirectDrawImpl
*ddraw_list
;
68 /*****************************************************************************
70 *****************************************************************************/
72 /*****************************************************************************
73 * IDirectDraw7::QueryInterface
75 * Queries different interfaces of the DirectDraw object. It can return
76 * IDirectDraw interfaces in version 1, 2, 4 and 7, and IDirect3D interfaces
77 * in version 1, 2, 3 and 7. An IDirect3DDevice can be created with this
79 * The returned interface is AddRef() before it's returned
81 * Rules for QueryInterface:
82 * http://msdn.microsoft.com/library/default.asp? \
83 * url=/library/en-us/com/html/6db17ed8-06e4-4bae-bc26-113176cc7e0e.asp
85 * Used for version 1, 2, 4 and 7
88 * refiid: Interface ID asked for
89 * obj: Used to return the interface pointer
92 * S_OK if an interface was found
93 * E_NOINTERFACE if the requested interface wasn't found
95 *****************************************************************************/
97 IDirectDrawImpl_QueryInterface(IDirectDraw7
*iface
,
101 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
103 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
105 /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
109 return DDERR_INVALIDPARAMS
;
111 /* Check DirectDraw Interfaces */
112 if ( IsEqualGUID( &IID_IUnknown
, refiid
) ||
113 IsEqualGUID( &IID_IDirectDraw7
, refiid
) )
115 *obj
= ICOM_INTERFACE(This
, IDirectDraw7
);
116 TRACE("(%p) Returning IDirectDraw7 interface at %p\n", This
, *obj
);
118 else if ( IsEqualGUID( &IID_IDirectDraw4
, refiid
) )
120 *obj
= ICOM_INTERFACE(This
, IDirectDraw4
);
121 TRACE("(%p) Returning IDirectDraw4 interface at %p\n", This
, *obj
);
123 else if ( IsEqualGUID( &IID_IDirectDraw2
, refiid
) )
125 *obj
= ICOM_INTERFACE(This
, IDirectDraw2
);
126 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This
, *obj
);
128 else if ( IsEqualGUID( &IID_IDirectDraw
, refiid
) )
130 *obj
= ICOM_INTERFACE(This
, IDirectDraw
);
131 TRACE("(%p) Returning IDirectDraw interface at %p\n", This
, *obj
);
135 else if ( IsEqualGUID( &IID_IDirect3D
, refiid
) ||
136 IsEqualGUID( &IID_IDirect3D2
, refiid
) ||
137 IsEqualGUID( &IID_IDirect3D3
, refiid
) ||
138 IsEqualGUID( &IID_IDirect3D7
, refiid
) )
140 /* Check the surface implementation */
141 if(This
->ImplType
== SURFACE_UNKNOWN
)
143 /* Apps may create the IDirect3D Interface before the primary surface.
144 * set the surface implementation */
145 This
->ImplType
= SURFACE_OPENGL
;
146 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This
);
148 else if(This
->ImplType
!= SURFACE_OPENGL
&& DefaultSurfaceType
== SURFACE_UNKNOWN
)
150 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This
);
151 ERR(" (%p) You may want to contact wine-devel for help\n", This
);
152 /* Should I assert(0) here??? */
154 else if(This
->ImplType
!= SURFACE_OPENGL
)
156 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
157 /* Do not abort here, only reject 3D Device creation */
160 if ( IsEqualGUID( &IID_IDirect3D
, refiid
) )
162 This
->d3dversion
= 1;
163 *obj
= ICOM_INTERFACE(This
, IDirect3D
);
164 TRACE(" returning Direct3D interface at %p.\n", *obj
);
166 else if ( IsEqualGUID( &IID_IDirect3D2
, refiid
) )
168 This
->d3dversion
= 2;
169 *obj
= ICOM_INTERFACE(This
, IDirect3D2
);
170 TRACE(" returning Direct3D2 interface at %p.\n", *obj
);
172 else if ( IsEqualGUID( &IID_IDirect3D3
, refiid
) )
174 This
->d3dversion
= 3;
175 *obj
= ICOM_INTERFACE(This
, IDirect3D3
);
176 TRACE(" returning Direct3D3 interface at %p.\n", *obj
);
178 else if(IsEqualGUID( &IID_IDirect3D7
, refiid
))
180 This
->d3dversion
= 7;
181 *obj
= ICOM_INTERFACE(This
, IDirect3D7
);
182 TRACE(" returning Direct3D7 interface at %p.\n", *obj
);
186 /* Unknown interface */
189 ERR("(%p)->(%s, %p): No interface found", This
, debugstr_guid(refiid
), obj
);
190 return E_NOINTERFACE
;
193 IUnknown_AddRef( (IUnknown
*) *obj
);
197 /*****************************************************************************
198 * IDirectDraw7::AddRef
200 * Increses the interfaces refcount. Used for version 1, 2, 4 and 7
202 * Returns: The new refcount
203 *****************************************************************************/
205 IDirectDrawImpl_AddRef(IDirectDraw7
*iface
)
207 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
208 ULONG ref
= InterlockedIncrement(&This
->ref
);
210 TRACE("(%p) : incrementing from %lu.\n", This
, ref
-1);
215 /*****************************************************************************
216 * IDirectDrawImpl_Destroy
218 * Destroys a ddraw object. This is to share code between normal Release
219 * and the dll unload cleanup code
222 * This: DirectDraw object to destroy
224 *****************************************************************************/
226 IDirectDrawImpl_Destroy(IDirectDrawImpl
*This
)
228 IDirectDrawImpl
*prev
;
230 TRACE("(%p)\n", This
);
232 /* Destroy the device window if we created one */
233 if(This
->devicewindow
!= 0)
235 TRACE(" (%p) Destroying the device window %p\n", This
, This
->devicewindow
);
236 DestroyWindow(This
->devicewindow
);
237 This
->devicewindow
= 0;
240 /* Unregister the window class */
241 UnregisterClassA(This
->classname
, 0);
243 /* Unchain it from the ddraw list */
244 if(ddraw_list
== This
)
246 ddraw_list
= This
->next
;
247 /* No need to search for a predecessor here */
251 for(prev
= ddraw_list
; prev
; prev
= prev
->next
)
252 if(prev
->next
== This
) break;
255 prev
->next
= This
->next
;
257 ERR("Didn't find the previous ddraw element in the list\n");
260 /* Release the attached WineD3D stuff */
261 IWineD3DDevice_Release(This
->wineD3DDevice
);
262 IWineD3D_Release(This
->wineD3D
);
264 /* Now free the object */
265 HeapFree(GetProcessHeap(), 0, This
);
267 /*****************************************************************************
268 * IDirectDraw7::Release
270 * Decreses the refcount. If the refcount falls to 0, the object is destroyed
272 * Returns: The new refcount
273 *****************************************************************************/
275 IDirectDrawImpl_Release(IDirectDraw7
*iface
)
277 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
278 ULONG ref
= InterlockedDecrement(&This
->ref
);
280 TRACE("(%p)->() decrementing from %lu.\n", This
, ref
+1);
284 /* No need to restore the display mode - it's done by SetCooperativeLevel */
286 IDirectDraw7_SetCooperativeLevel(ICOM_INTERFACE(This
, IDirectDraw7
),
290 /* This is for the dll cleanup code in DllMain() */
291 if(!This
->DoNotDestroy
)
292 IDirectDrawImpl_Destroy(This
);
298 /*****************************************************************************
299 * IDirectDraw methods
300 *****************************************************************************/
302 /*****************************************************************************
303 * IDirectDrawImpl_SetupExclusiveWindow
305 * Helper function that modifies a HWND's Style and ExStyle for proper
309 * This: Pointer to the DirectDraw implementation
310 * HWND: Window to setup
312 *****************************************************************************/
314 IDirectDrawImpl_SetupFullscreenWindow(IDirectDrawImpl
*This
,
318 /* Don't do anything if an original style is stored.
319 * That shouldn't happen
321 TRACE("(%p): Setting up window %p for exclusive mode\n", This
, window
);
322 if( (This
->style
!= 0) && (This
->exStyle
!= 0) )
324 ERR("(%p) Want to change the window parameters of HWND %p, but \
325 another style is stored for restauration afterwards\n", This
, window
);
328 /* Get the parameters and save them */
329 style
= GetWindowLongW(window
, GWL_STYLE
);
330 exStyle
= GetWindowLongW(window
, GWL_EXSTYLE
);
332 This
->exStyle
= exStyle
;
334 /* Filter out window decorations */
335 style
&= ~WS_CAPTION
;
336 style
&= ~WS_THICKFRAME
;
337 exStyle
&= ~WS_EX_WINDOWEDGE
;
338 exStyle
&= ~WS_EX_CLIENTEDGE
;
340 /* Make sure the window is managed, otherwise we won't get keyboard input */
341 style
|= WS_POPUP
| WS_SYSMENU
;
343 TRACE("Old style was %08lx,%08lx, setting to %08lx,%08lx\n",
344 This
->style
, This
->exStyle
, style
, exStyle
);
346 SetWindowLongW(window
, GWL_STYLE
, style
);
347 SetWindowLongW(window
, GWL_EXSTYLE
, exStyle
);
349 /* Inform the window about the update.
350 * TODO: Should I move it to 0/0 too?
352 SetWindowPos(window
, 0 /* InsertAfter, ignored */,
353 0, 0, 0, 0, /* Pos, Size, igored */
354 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
);
357 /*****************************************************************************
358 * IDirectDrawImpl_RestoreWindow
360 * Helper function that restores a windows' properties when taking it out
364 * This: Pointer to the DirectDraw implementation
365 * HWND: Window to setup
367 *****************************************************************************/
369 IDirectDrawImpl_RestoreWindow(IDirectDrawImpl
*This
,
372 if( (This
->style
== 0) && (This
->exStyle
== 0) )
374 /* This could be a DDSCL_NORMAL -> DDSCL_NORMAL
379 TRACE("(%p): Restoring window settings of window %p to %08lx, %08lx\n",
380 This
, window
, This
->style
, This
->exStyle
);
382 SetWindowLongW(window
, GWL_STYLE
, This
->style
);
383 SetWindowLongW(window
, GWL_EXSTYLE
, This
->exStyle
);
385 /* Delete the old values */
389 /* Inform the window about the update */
390 SetWindowPos(window
, 0 /* InsertAfter, ignored */,
391 0, 0, 0, 0, /* Pos, Size, igored */
392 SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOZORDER
);
395 /*****************************************************************************
396 * IDirectDraw7::SetCooperativeLevel
398 * Sets the cooerative level for the DirectDraw object, and the window
399 * assigned to it. The cooperative level determines the general behavior
400 * of the DirectDraw application
402 * Warning: This is quite tricky, as it's not really documented which
403 * cooperative levels can be combined with each other. If a game fails
404 * after this function, try to check the cooperative levels passed on
405 * Windows, and if it returns something different.
407 * If you think that this function caused the failure because it writes a
408 * fixme, be sure to run again with a +ddraw trace.
410 * What is known about cooperative levels(See the ddraw modes test):
411 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
412 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
413 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
414 * DDSCL_FULLSCREEN can be activated
415 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
417 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
418 * DDSCL_SETFOCUSWINDOW(partially)
420 * Unhandled flags, which should be implemented
421 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering(I don't
422 * expect any difference to a normal window for wine)
423 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create it's own window for
424 * rendering(Possible test case: Half-life)
426 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
428 * These seem not really imporant for wine
429 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX,
433 * DD_OK if the cooperative level was set successfully
434 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
435 * DDERR_HWNDALLREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
436 * (Propably others too, have to investigate)
438 *****************************************************************************/
439 static HRESULT WINAPI
440 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7
*iface
,
444 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
448 FIXME("(%p)->(%p,%08lx)\n",This
,hwnd
,cooplevel
);
449 DDRAW_dump_cooperativelevel(cooplevel
);
451 /* Get the old window */
452 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
, &window
);
455 ERR("IWineD3DDevice::GetHWND failed, hr = %08lx\n", hr
);
459 /* Tests suggest that we need one of them: */
460 if(!(cooplevel
& (DDSCL_SETFOCUSWINDOW
|
464 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
465 return DDERR_INVALIDPARAMS
;
468 /* Handle those levels first which set varios hwnds */
469 if(cooplevel
& DDSCL_SETFOCUSWINDOW
)
471 /* This isn't compatible with a lot of flags */
472 if(cooplevel
& ( DDSCL_MULTITHREADED
|
477 DDSCL_SETDEVICEWINDOW
|
482 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
483 return DDERR_INVALIDPARAMS
;
485 else if( (This
->cooperative_level
& DDSCL_FULLSCREEN
) && window
)
487 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
488 return DDERR_HWNDALREADYSET
;
491 This
->focuswindow
= hwnd
;
492 /* Won't use the hwnd param for anything else */
495 /* Use the focus window for drawing too */
496 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, This
->focuswindow
);
498 /* Destroy the device window, if we have one */
499 if(This
->devicewindow
)
501 DestroyWindow(This
->devicewindow
);
502 This
->devicewindow
= NULL
;
505 /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
506 if(cooplevel
& DDSCL_NORMAL
)
508 /* Can't coexist with fullscreen or exclusive */
509 if(cooplevel
& (DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
) )
511 TRACE("(%p) DDSCL_NORMAL is not compative with DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE\n", This
);
512 return DDERR_INVALIDPARAMS
;
515 /* Switching from fullscreen? */
516 if(This
->cooperative_level
& DDSCL_FULLSCREEN
)
518 /* Restore the display mode */
519 IDirectDraw7_RestoreDisplayMode(iface
);
522 IDirectDrawImpl_RestoreWindow(This
, window
);
524 This
->cooperative_level
&= ~DDSCL_FULLSCREEN
;
525 This
->cooperative_level
&= ~DDSCL_EXCLUSIVE
;
526 This
->cooperative_level
&= ~DDSCL_ALLOWMODEX
;
529 /* Don't override focus windows or private device windows */
531 !(This
->focuswindow
) &&
532 !(This
->devicewindow
) &&
535 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
538 else if(cooplevel
& DDSCL_FULLSCREEN
)
540 /* Needs DDSCL_EXCLUSIVE */
541 if(!(cooplevel
& DDSCL_EXCLUSIVE
) )
543 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This
);
544 return DDERR_INVALIDPARAMS
;
549 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
550 return DDERR_INVALIDPARAMS;
554 /* Switch from normal to full screen mode? */
555 if(This
->cooperative_level
& DDSCL_NORMAL
)
557 This
->cooperative_level
&= ~DDSCL_NORMAL
;
560 /* Don't override focus windows or private device windows */
562 !(This
->focuswindow
) &&
563 !(This
->devicewindow
) &&
566 /* On a window change, restore the old window and set the new one */
570 IDirectDrawImpl_RestoreWindow(This
, window
);
571 IDirectDrawImpl_SetupFullscreenWindow(This
, hwnd
);
573 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, hwnd
);
576 else if(cooplevel
& DDSCL_EXCLUSIVE
)
578 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This
);
579 return DDERR_INVALIDPARAMS
;
582 if(cooplevel
& DDSCL_CREATEDEVICEWINDOW
)
584 /* Don't create a device window if a focus window is set */
585 if( !(This
->focuswindow
) )
587 HWND devicewindow
= CreateWindowExA(0, This
->classname
, "DDraw device window",
589 GetSystemMetrics(SM_CXSCREEN
),
590 GetSystemMetrics(SM_CYSCREEN
),
591 NULL
, NULL
, GetModuleHandleA(0), NULL
);
593 ShowWindow(devicewindow
, SW_SHOW
); /* Just to be sure */
594 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This
, devicewindow
);
596 IWineD3DDevice_SetHWND(This
->wineD3DDevice
, devicewindow
);
597 This
->devicewindow
= devicewindow
;
601 /* Unhandled flags */
602 if(cooplevel
& DDSCL_ALLOWREBOOT
)
603 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This
);
604 if(cooplevel
& DDSCL_ALLOWMODEX
)
605 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This
);
606 if(cooplevel
& DDSCL_MULTITHREADED
)
607 FIXME("(%p) Unhandled flag DDSCL_MULTITHREADED, Uh Oh...\n", This
);
608 if(cooplevel
& DDSCL_FPUSETUP
)
609 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This
);
610 if(cooplevel
& DDSCL_FPUPRESERVE
)
611 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This
);
613 /* Store the cooperative_level */
614 This
->cooperative_level
|= cooplevel
;
615 TRACE("SetCooperativeLevel retuning DD_OK\n");
619 /*****************************************************************************
620 * IDirectDraw7::SetDisplayMode
622 * Sets the display screen resolution, color depth and refresh frequency
623 * when in fullscreen mode(in theory).
624 * Possible return values listed in the SDK suggest that this method fails
625 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
626 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
627 * It seems to be valid to pass 0 for With and Height, this has to be tested
628 * It could mean that the current video mode should be left as-is. (But why
632 * Height, Width: Screen dimension
633 * BPP: Color depth in Bits per pixel
634 * Refreshrate: Screen refresh rate
640 *****************************************************************************/
641 static HRESULT WINAPI
642 IDirectDrawImpl_SetDisplayMode(IDirectDraw7
*iface
,
649 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
650 WINED3DDISPLAYMODE Mode
;
651 TRACE("(%p)->(%ld,%ld,%ld,%ld,%lx: Relay!\n", This
, Width
, Height
, BPP
, RefreshRate
, Flags
);
653 if( !Width
|| !Height
)
655 ERR("Width=%ld, Height=%ld, what to do?\n", Width
, Height
);
656 /* It looks like Need for speed Posche Unleashed expects DD_OK here */
660 /* Check the exclusive mode
661 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
662 return DDERR_NOEXCLUSIVEMODE;
663 * This is WRONG. Don't know if the SDK is completely
664 * wrong and if there are any coditions when DDERR_NOEXCLUSIVE
665 * is returned, but Half-Life 1.1.1.1(Steam version)
670 Mode
.Height
= Height
;
671 Mode
.RefreshRate
= RefreshRate
;
674 case 8: Mode
.Format
= WINED3DFMT_P8
; break;
675 case 15: Mode
.Format
= WINED3DFMT_X1R5G5B5
; break;
676 case 16: Mode
.Format
= WINED3DFMT_R5G6B5
; break;
677 case 24: Mode
.Format
= WINED3DFMT_R8G8B8
; break;
678 case 32: Mode
.Format
= WINED3DFMT_A8R8G8B8
; break;
681 /* TODO: The possible return values from msdn suggest that
682 * the screen mode can't be changed if a surface is locked
683 * or some drawing is in progress
686 /* TODO: Lose the primary surface */
687 return IWineD3DDevice_SetDisplayMode(This
->wineD3DDevice
,
688 0, /* First swapchain */
693 /*****************************************************************************
694 * IDirectDraw7::RestoreDisplayMode
696 * Restores the display mode to what it was at creation time. Basically.
698 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
699 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
700 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
701 * -> DD_1 is released. The screen should be left at 1024x768x32.
702 * -> DD_2 is released. The screen should be set to 1400x1050x32
703 * This case is unhandled right now, but Empire Earth does it this way.
704 * (But perhaps there is something in SetCooperativeLevel to prevent this)
706 * The msdn says that this method resets the display mode to what it was before
707 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
711 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
713 *****************************************************************************/
714 static HRESULT WINAPI
715 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7
*iface
)
717 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
718 TRACE("(%p)\n", This
);
720 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This
, IDirectDraw7
),
728 /*****************************************************************************
729 * IDirectDraw7::GetCaps
731 * Returns the drives capatiblities
733 * Used for version 1, 2, 4 and 7
736 * DriverCaps: Structure to write the Hardware accellerated caps to
737 * HelCaps: Structure to write the emulation caps to
740 * This implementation returnd DD_OK only
742 *****************************************************************************/
743 static HRESULT WINAPI
744 IDirectDrawImpl_GetCaps(IDirectDraw7
*iface
,
748 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
749 TRACE("(%p)->(%p,%p)\n", This
, DriverCaps
, HELCaps
);
751 /* One structure must be != NULL */
752 if( (!DriverCaps
) && (!HELCaps
) )
754 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This
);
755 return DDERR_INVALIDPARAMS
;
760 DD_STRUCT_COPY_BYSIZE(DriverCaps
, &This
->caps
);
763 TRACE("Driver Caps :\n");
764 DDRAW_dump_DDCAPS(DriverCaps
);
770 DD_STRUCT_COPY_BYSIZE(HELCaps
, &This
->caps
);
773 TRACE("HEL Caps :\n");
774 DDRAW_dump_DDCAPS(HELCaps
);
781 /*****************************************************************************
782 * IDirectDraw7::Compact
784 * No idea what it does, MSDN says it's not implemented.
787 * DD_OK, but this is unchecked
789 *****************************************************************************/
790 static HRESULT WINAPI
791 IDirectDrawImpl_Compact(IDirectDraw7
*iface
)
793 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
794 TRACE("(%p)\n", This
);
799 /*****************************************************************************
800 * IDirectDraw7::GetDisplayMode
802 * Returns information about the current display mode
804 * Exists in Version 1, 2, 4 and 7
807 * DDSD: Address of a surface description structure to write the info to
812 *****************************************************************************/
813 static HRESULT WINAPI
814 IDirectDrawImpl_GetDisplayMode(IDirectDraw7
*iface
,
815 DDSURFACEDESC2
*DDSD
)
817 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
819 WINED3DDISPLAYMODE Mode
;
821 TRACE("(%p)->(%p): Relay\n", This
, DDSD
);
823 /* This seems sane */
826 return DDERR_INVALIDPARAMS
;
829 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
830 * so one method can be used for all versions (Hopefully)
832 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
837 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08lx\n", This
, hr
);
842 memset(DDSD
, 0, Size
);
845 DDSD
->dwFlags
|= DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
| DDSD_PITCH
| DDSD_REFRESHRATE
;
846 DDSD
->dwWidth
= Mode
.Width
;
847 DDSD
->dwHeight
= Mode
.Height
;
848 DDSD
->u2
.dwRefreshRate
= 60;
849 DDSD
->ddsCaps
.dwCaps
= 0;
850 DDSD
->u4
.ddpfPixelFormat
.dwSize
= sizeof(DDSD
->u4
.ddpfPixelFormat
);
851 PixelFormat_WineD3DtoDD(&DDSD
->u4
.ddpfPixelFormat
, Mode
.Format
);
852 DDSD
->u1
.lPitch
= Mode
.Width
* DDSD
->u4
.ddpfPixelFormat
.u1
.dwRGBBitCount
/ 8;
856 TRACE("Returning surface desc :\n");
857 DDRAW_dump_surface_desc(DDSD
);
863 /*****************************************************************************
864 * IDirectDraw7::GetFourCCCodes
866 * Returns an array of supported FourCC codes.
868 * Exists in Version 1, 2, 4 and 7
871 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
872 * of enumerated codes
873 * Codes: Pointer to an array of DWORDs where the supported codes are wriiten
877 * Always returns DD_OK, as it's a stub for now
879 *****************************************************************************/
880 static HRESULT WINAPI
881 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7
*iface
,
882 DWORD
*NumCodes
, DWORD
*Codes
)
884 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
885 FIXME("(%p)->(%p, %p): Stub!\n", This
, NumCodes
, Codes
);
887 if(NumCodes
) *NumCodes
= 0;
892 /*****************************************************************************
893 * IDirectDraw7::GetMonitorFrequency
895 * Returns the monitor's frequency
897 * Exists in Version 1, 2, 4 and 7
900 * Freq: Pointer to a DWORD to write the frequency to
903 * Always returns DD_OK
905 *****************************************************************************/
906 static HRESULT WINAPI
907 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7
*iface
,
910 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
911 TRACE("(%p)->(%p)\n", This
, Freq
);
913 /* Ideally this should be in WineD3D, as it concernes the screen setup,
914 * but for now this should make the games happy
920 /*****************************************************************************
921 * IDirectDraw7::GetVerticalBlankStatus
923 * Returns the Vertical blank status of the monitor. This should be in WineD3D
924 * too basically, but as it's a semi stub, I didn't create a function there
927 * status: Pointer to a BOOL to be filled with the vertical blank status
931 * DDERR_INVALIDPARAMS if status is NULL
933 *****************************************************************************/
934 static HRESULT WINAPI
935 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7
*iface
,
938 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
939 TRACE("(%p)->(%p)\n", This
, status
);
941 /* This looks sane, the MSDN suggests it too */
942 if(!status
) return DDERR_INVALIDPARAMS
;
944 *status
= This
->fake_vblank
;
945 This
->fake_vblank
= !This
->fake_vblank
;
949 /*****************************************************************************
950 * IDirectDraw7::GetAvailableVidMem
952 * Returns the total and free video memory
955 * Caps: Specifies the memory type asked for
956 * total: Pointer to a DWORD to be filled with the total memory
957 * free: Pointer to a DWORD to be filled with the free memory
961 * DDERR_INVALIDPARAMS of free and total are NULL
963 *****************************************************************************/
964 static HRESULT WINAPI
965 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7
*iface
, DDSCAPS2
*Caps
, DWORD
*total
, DWORD
*free
)
967 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
968 TRACE("(%p)->(%p, %p, %p)\n", This
, Caps
, total
, free
);
972 TRACE("(%p) Asked for memory with description: ", This
);
973 DDRAW_dump_DDSCAPS2(Caps
);
977 /* Todo: System memory vs local video memory vs non-local video memory
978 * The MSDN also mentiones differences between texture memory and other
979 * resources, but that's not important
982 if( (!total
) && (!free
) ) return DDERR_INVALIDPARAMS
;
984 if(total
) *total
= This
->total_vidmem
;
985 if(free
) *free
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
990 /*****************************************************************************
991 * IDirectDraw7::Initialize
993 * Initializes a DirectDraw interface.
996 * GUID: Interface identifier. Well, don't know what this is really good
1000 * Returns DD_OK on the first call,
1001 * DDERR_ALREADYINITIALIZED on repeated calls
1003 *****************************************************************************/
1004 static HRESULT WINAPI
1005 IDirectDrawImpl_Initialize(IDirectDraw7
*iface
,
1008 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1009 TRACE("(%p)->(%s): No-op\n", This
, debugstr_guid(Guid
));
1011 if(This
->initialized
)
1013 return DDERR_ALREADYINITIALIZED
;
1021 /*****************************************************************************
1022 * IDirectDraw7::FlipToGDISurface
1024 * "Makes the surface that the GDI writes to the primary surface"
1025 * Looks like some windows specific thing we don't have to care about.
1026 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
1027 * show error boxes ;)
1028 * Well, just return DD_OK.
1031 * Always returns DD_OK
1033 *****************************************************************************/
1034 static HRESULT WINAPI
1035 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7
*iface
)
1037 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1038 TRACE("(%p)\n", This
);
1043 /*****************************************************************************
1044 * IDirectDraw7::WaitForVerticalBlank
1046 * This method allows applications to get in sync with the vertical blank
1048 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
1049 * redraw the screen, most likely because of this stub
1052 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
1053 * or DDWAITVB_BLOCKEND
1054 * h: Not used, according to MSDN
1057 * Always returns DD_OK
1059 *****************************************************************************/
1060 static HRESULT WINAPI
1061 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7
*iface
,
1065 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1066 FIXME("(%p)->(%lx,%p): Stub\n", This
, Flags
, h
);
1068 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
1069 if(Flags
& DDWAITVB_BLOCKBEGINEVENT
)
1070 return DDERR_UNSUPPORTED
; /* unchecked */
1075 /*****************************************************************************
1076 * IDirectDraw7::GetScanLine
1078 * Returns the scan line that is beeing drawn on the monitor
1081 * Scanline: Address to write the scan line value to
1084 * Always returns DD_OK
1086 *****************************************************************************/
1087 static HRESULT WINAPI
IDirectDrawImpl_GetScanLine(IDirectDraw7
*iface
, DWORD
*Scanline
)
1089 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1090 static BOOL hide
= FALSE
;
1091 WINED3DDISPLAYMODE Mode
;
1093 /* This function is called often, so print the fixme only once */
1096 FIXME("(%p)->(%p): Semi-Stub\n", This
, Scanline
);
1100 IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
1104 /* Fake the line sweeping of the monitor */
1105 /* FIXME: We should synchronize with a source to keep the refresh rate */
1106 *Scanline
= This
->cur_scanline
++;
1107 /* Assume 20 scan lines in the vertical blank */
1108 if (This
->cur_scanline
>= Mode
.Height
+ 20)
1109 This
->cur_scanline
= 0;
1114 /*****************************************************************************
1115 * IDirectDraw7::TestCooperativeLevel
1117 * Informs the application about the state of the video adapter, depending
1118 * on the cooperative level
1121 * DD_OK if the device is in a sane state
1122 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1123 * if the state is not correct(See below)
1125 *****************************************************************************/
1126 static HRESULT WINAPI
1127 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7
*iface
)
1129 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1131 TRACE("(%p)\n", This
);
1133 /* Description from MSDN:
1134 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1135 * away from the app with e.g. alt-tab. Windowed apps receive
1136 * DDERR_EXCLUSIVEMODEALREADYSET if another application created an
1137 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1138 * when the video mode has changed
1141 hr
= IWineD3DDevice_TestCooperativeLevel(This
->wineD3DDevice
);
1143 /* Fix the result value. These values are mapped from their
1148 case WINED3DERR_DEVICELOST
:
1149 if(This
->cooperative_level
& DDSCL_EXCLUSIVE
)
1151 return DDERR_NOEXCLUSIVEMODE
;
1155 return DDERR_EXCLUSIVEMODEALREADYSET
;
1158 case WINED3DERR_DEVICENOTRESET
:
1164 case WINED3DERR_DRIVERINTERNALERROR
:
1166 ERR("(%p) Unexpected return value %08lx from wineD3D, " \
1167 " returning DD_OK\n", This
, hr
);
1173 /*****************************************************************************
1174 * IDirectDraw7::GetGDISurface
1176 * Returns the surface that GDI is treating as the primary surface.
1177 * For Wine this is the front buffer
1180 * GDISurface: Address to write the surface pointer to
1183 * DD_OK if the surface was found
1184 * DDERR_NOTFOUND if the GDI surface wasn't found
1186 *****************************************************************************/
1187 static HRESULT WINAPI
1188 IDirectDrawImpl_GetGDISurface(IDirectDraw7
*iface
,
1189 IDirectDrawSurface7
**GDISurface
)
1191 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1192 IWineD3DSurface
*Surf
;
1193 IDirectDrawSurface7
*ddsurf
;
1196 TRACE("(%p)->(%p)\n", This
, GDISurface
);
1198 /* Get the back buffer from the wineD3DDevice and search it's
1199 * attached surfaces for the front buffer
1201 hr
= IWineD3DDevice_GetBackBuffer(This
->wineD3DDevice
,
1203 0, /* first back buffer*/
1204 WINED3DBACKBUFFER_TYPE_MONO
,
1207 if( (hr
!= D3D_OK
) ||
1210 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1211 return DDERR_NOTFOUND
;
1214 /* GetBackBuffer AddRef()ed the surface, release it */
1215 IWineD3DSurface_Release(Surf
);
1217 IWineD3DSurface_GetParent(Surf
,
1218 (IUnknown
**) &ddsurf
);
1219 IDirectDrawSurface7_Release(ddsurf
); /* For the GetParent */
1221 /* Find the front buffer */
1222 ddsCaps
.dwCaps
= DDSCAPS_FRONTBUFFER
;
1223 hr
= IDirectDrawSurface7_GetAttachedSurface(ddsurf
,
1228 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %lx\n", hr
);
1231 /* The AddRef is OK this time */
1235 /*****************************************************************************
1236 * IDirectDrawImpl_EnumDisplayModesCB
1238 * Callback function for IDirectDraw7::EnumDisplayModes. Translates
1239 * the wineD3D values to ddraw values and calls the application callback
1242 * device: The IDirectDraw7 interface to the current device
1243 * With, Height, Pixelformat, Refresh: Enumerated display mode
1244 * context: the context pointer passed to IWineD3DDevice::EnumDisplayModes
1247 * The return value from the application callback
1249 *****************************************************************************/
1250 static HRESULT WINAPI
1251 IDirectDrawImpl_EnumDisplayModesCB(IUnknown
*pDevice
,
1254 WINED3DFORMAT Pixelformat
,
1258 DDSURFACEDESC2 callback_sd
;
1259 EnumDisplayModesCBS
*cbs
= (EnumDisplayModesCBS
*) context
;
1261 memset(&callback_sd
, 0, sizeof(callback_sd
));
1262 callback_sd
.dwSize
= sizeof(callback_sd
);
1263 callback_sd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1265 callback_sd
.dwFlags
= DDSD_HEIGHT
|DDSD_WIDTH
|DDSD_PIXELFORMAT
|DDSD_PITCH
;
1268 callback_sd
.dwFlags
|= DDSD_REFRESHRATE
;
1269 callback_sd
.u2
.dwRefreshRate
= 60.0;
1272 callback_sd
.dwHeight
= Height
;
1273 callback_sd
.dwWidth
= Width
;
1275 PixelFormat_WineD3DtoDD(&callback_sd
.u4
.ddpfPixelFormat
, Pixelformat
);
1276 return cbs
->callback(&callback_sd
, cbs
->context
);
1279 /*****************************************************************************
1280 * IDirectDraw7::EnumDisplayModes
1282 * Enumerates the supported Display modes. The modes can be filtered with
1283 * the DDSD paramter.
1286 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1287 * DDSD: Surface description to filter the modes
1288 * Context: Pointer passed back to the callback function
1289 * cb: Application-provided callback function
1293 * DDERR_INVALIDPARAMS if the callback wasn't set
1295 *****************************************************************************/
1296 static HRESULT WINAPI
1297 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7
*iface
,
1299 DDSURFACEDESC2
*DDSD
,
1301 LPDDENUMMODESCALLBACK2 cb
)
1303 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1304 UINT Width
= 0, Height
= 0;
1305 WINED3DFORMAT pixelformat
= WINED3DFMT_UNKNOWN
;
1306 EnumDisplayModesCBS cbs
;
1308 TRACE("(%p)->(%p,%p,%p): Relay\n", This
, DDSD
, Context
, cb
);
1310 /* This looks sane */
1311 if(!cb
) return DDERR_INVALIDPARAMS
;
1313 /* The private callback structure */
1315 cbs
.context
= Context
;
1319 if (DDSD
->dwFlags
& DDSD_WIDTH
)
1320 Width
= DDSD
->dwWidth
;
1321 if (DDSD
->dwFlags
& DDSD_HEIGHT
)
1322 Width
= DDSD
->dwHeight
;
1323 if ((DDSD
->dwFlags
& DDSD_PIXELFORMAT
) && (DDSD
->u4
.ddpfPixelFormat
.dwFlags
& DDPF_RGB
) )
1324 pixelformat
= PixelFormat_DD2WineD3D(&DDSD
->u4
.ddpfPixelFormat
);
1327 return IWineD3DDevice_EnumDisplayModes(This
->wineD3DDevice
,
1329 Width
, Height
, pixelformat
,
1331 IDirectDrawImpl_EnumDisplayModesCB
);
1334 /*****************************************************************************
1335 * IDirectDraw7::EvaluateMode
1337 * Used with IDirectDraw7::StartModeTest to test video modes.
1338 * EvaluateMode is used to pass or fail a mode, and continue with the next
1342 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1343 * Timeout: Returns the amount of secounds left before the mode would have
1344 * been failed automatically
1347 * This implementation always DD_OK, because it's a stub
1349 *****************************************************************************/
1350 static HRESULT WINAPI
1351 IDirectDrawImpl_EvaluateMode(IDirectDraw7
*iface
,
1355 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1356 FIXME("(%p)->(%ld,%p): Stub!\n", This
, Flags
, Timeout
);
1358 /* When implementing this, implement it in WineD3D */
1363 /*****************************************************************************
1364 * IDirectDraw7::GetDeviceIdentifier
1366 * Returns the device identifier, which gives information about the driver
1367 * Our device identifier is defined at the beginning of this file.
1370 * DDDI: Address for the returned structure
1371 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1374 * On success it returns DD_OK
1375 * DDERR_INVALIDPARAMS if DDDI is NULL;
1377 *****************************************************************************/
1378 static HRESULT WINAPI
1379 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7
*iface
,
1380 DDDEVICEIDENTIFIER2
*DDDI
,
1383 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1384 TRACE("(%p)->(%p,%08lx) \n", This
, DDDI
, Flags
);
1387 return DDERR_INVALIDPARAMS
;
1389 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1390 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1391 * to any modern hardware, nor is it interesting for Wine, so ignore it
1394 *DDDI
= deviceidentifier
;
1398 /*****************************************************************************
1399 * IDirectDraw7::GetSurfaceFromDC
1401 * Returns the Surface for a GDI device context handle.
1402 * Is this related to IDirectDrawSurface::GetDC ???
1405 * hdc: hdc to return the surface for
1406 * Surface: Address to write the surface pointer to
1409 * Always returns DD_OK because it's a stub
1411 *****************************************************************************/
1412 static HRESULT WINAPI
1413 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7
*iface
,
1415 IDirectDrawSurface7
**Surface
)
1417 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1418 FIXME("(%p)->(%p,%p): Stub!\n", This
, hdc
, Surface
);
1420 /* Implementation idea if needed: Loop through all surfaces and compare
1421 * their hdc with hdc. Implement it in WineD3D! */
1422 return DDERR_NOTFOUND
;
1425 /*****************************************************************************
1426 * IDirectDraw7::RestoreAllSurfaces
1428 * Calls the restore method of all surfaces
1433 * Always returns DD_OK because it's a stub
1435 *****************************************************************************/
1436 static HRESULT WINAPI
1437 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7
*iface
)
1439 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1440 FIXME("(%p): Stub\n", This
);
1442 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1443 * get their parent and call their restore method. Do not implement
1444 * it in WineD3D, as restoring a surface means re-creating the
1450 /*****************************************************************************
1451 * IDirectDraw7::StartModeTest
1453 * Tests the specified video modes to update the system registry with
1454 * refresh rate information. StartModeTest starts the mode test,
1455 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1456 * isn't called withhin 15 secounds, the mode is failed automatically
1458 * As refresh rates are handled by the X server, I don't think this
1459 * Methos is important
1462 * Modes: An array of mode specifications
1463 * NumModes: The number of modes in Modes
1464 * Flags: Some flags...
1467 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1468 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1471 *****************************************************************************/
1472 static HRESULT WINAPI
1473 IDirectDrawImpl_StartModeTest(IDirectDraw7
*iface
,
1478 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
1479 WARN("(%p)->(%p, %ld, %lx): Semi-Stub, most likely harmless\n", This
, Modes
, NumModes
, Flags
);
1481 /* This looks sane */
1482 if( (!Modes
) || (NumModes
== 0) ) return DDERR_INVALIDPARAMS
;
1484 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1485 * As it is not, DDERR_TESTFINISHED is returned
1486 * (hopefully that's correct
1488 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1489 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1495 /*****************************************************************************
1496 * IDirectDrawImpl_RecreateSurfacesCallback
1498 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1499 * It re-recreates the WineD3DSurface. It's pretty steightforward
1501 *****************************************************************************/
1503 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7
*surf
,
1504 DDSURFACEDESC2
*desc
,
1507 IDirectDrawSurfaceImpl
*surfImpl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
,
1508 IDirectDrawSurface7
,
1510 IDirectDrawImpl
*This
= surfImpl
->ddraw
;
1512 IParentImpl
*parImpl
= NULL
;
1513 IWineD3DSurface
*wineD3DSurface
;
1517 WINED3DSURFACE_DESC Desc
;
1518 WINED3DFORMAT Format
;
1519 WINED3DRESOURCETYPE Type
;
1524 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
1525 DWORD MultiSampleQuality
;
1529 TRACE("(%p): Enumerated Surface %p\n", This
, surfImpl
);
1531 /* For the enumeration */
1532 IDirectDrawSurface7_Release(surf
);
1534 if(surfImpl
->ImplType
== This
->ImplType
) return DDENUMRET_OK
; /* Continue */
1536 /* Get the objects */
1537 wineD3DSurface
= surfImpl
->WineD3DSurface
;
1538 IWineD3DSurface_GetParent(wineD3DSurface
, &Parent
);
1539 IUnknown_Release(Parent
); /* For the getParent */
1541 /* Is the parent an IParent interface? */
1542 if(IUnknown_QueryInterface(Parent
, &IID_IParent
, &tmp
) == S_OK
)
1544 /* It is a IParent interface! */
1545 IUnknown_Release(Parent
); /* For the QueryInterface */
1546 parImpl
= ICOM_OBJECT(IParentImpl
, IParent
, Parent
);
1547 /* Release the reference the parent interface is holding */
1548 IWineD3DSurface_Release(wineD3DSurface
);
1552 /* Get the surface properties */
1553 Desc
.Format
= &Format
;
1555 Desc
.Usage
= &Usage
;
1558 Desc
.MultiSampleType
= &MultiSampleType
;
1559 Desc
.MultiSampleQuality
= &MultiSampleQuality
;
1560 Desc
.Width
= &Width
;
1561 Desc
.Height
= &Height
;
1563 hr
= IWineD3DSurface_GetDesc(wineD3DSurface
, &Desc
);
1564 if(hr
!= D3D_OK
) return hr
;
1566 /* Create the new surface */
1567 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1568 Width
, Height
, Format
,
1569 TRUE
/* Lockable */,
1570 FALSE
/* Discard */,
1571 surfImpl
->mipmap_level
,
1572 &surfImpl
->WineD3DSurface
,
1578 0 /* SharedHandle */,
1585 /* Update the IParent if it exists */
1588 parImpl
->child
= (IUnknown
*) surfImpl
->WineD3DSurface
;
1589 /* Add a reference for the IParent */
1590 IWineD3DSurface_AddRef(surfImpl
->WineD3DSurface
);
1592 /* TODO: Copy the surface content, except for render targets */
1594 if(IWineD3DSurface_Release(wineD3DSurface
) == 0)
1595 TRACE("Surface released successfull, next surface\n");
1597 ERR("Something's still holding the old WineD3DSurface\n");
1599 surfImpl
->ImplType
= This
->ImplType
;
1601 return DDENUMRET_OK
;
1604 /*****************************************************************************
1605 * IDirectDrawImpl_RecreateAllSurfaces
1607 * A function, that converts all wineD3DSurfaces to the new implementation type
1608 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1609 * new WineD3DSurface, copys the content and releases the old surface
1611 *****************************************************************************/
1613 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl
*This
)
1615 DDSURFACEDESC2 desc
;
1616 TRACE("(%p): Switch to implementation %d\n", This
, This
->ImplType
);
1618 if(This
->ImplType
!= SURFACE_OPENGL
&& This
->d3d_initialized
)
1620 /* Should happen almost never */
1621 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This
);
1623 IWineD3DDevice_Uninit3D(This
->wineD3DDevice
);
1625 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1627 memset(&desc
, 0, sizeof(desc
));
1628 desc
.dwSize
= sizeof(desc
);
1630 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This
, IDirectDraw7
),
1634 IDirectDrawImpl_RecreateSurfacesCallback
);
1637 /*****************************************************************************
1638 * D3D7CB_CreateSurface
1640 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1641 * correct mipmap sublevel, and returns it to WineD3D.
1642 * The surfaces are created already by IDirectDraw7::CreateSurface
1645 * With, Height: With and height of the surface
1646 * Format: The requested format
1647 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1648 * level: The mipmap level
1649 * Surface: Pointer to pass the created surface back at
1650 * SharedHandle: NULL
1655 *****************************************************************************/
1656 static HRESULT WINAPI
1657 D3D7CB_CreateSurface(IUnknown
*device
,
1658 UINT Width
, UINT Height
,
1659 WINED3DFORMAT Format
,
1660 DWORD Usage
, WINED3DPOOL Pool
, UINT level
,
1661 IWineD3DSurface
**Surface
,
1662 HANDLE
*SharedHandle
)
1664 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
1665 IDirectDrawSurfaceImpl
*surf
= This
->tex_root
;
1667 TRACE("(%p) call back. surf=%p\n", device
, surf
);
1669 /* Find the wanted mipmap. There are enought mipmaps in the chain */
1670 for(i
= 0; i
< level
; i
++)
1671 surf
= surf
->next_complex
;
1673 /* Return the surface */
1674 *Surface
= surf
->WineD3DSurface
;
1676 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface
, surf
);
1680 /*****************************************************************************
1681 * IDirectDrawImpl_CreateNewSurface
1683 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1684 * with the passed parameters.
1687 * DDSD: Description of the surface to create
1688 * Surf: Address to store the interface pointer at
1693 *****************************************************************************/
1694 static HRESULT WINAPI
1695 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl
*This
,
1696 DDSURFACEDESC2
*pDDSD
,
1697 IDirectDrawSurfaceImpl
**ppSurf
,
1701 UINT Width
= 0, Height
= 0;
1702 WINED3DFORMAT Format
= WINED3DFMT_UNKNOWN
;
1703 WINED3DRESOURCETYPE ResType
= WINED3DRTYPE_SURFACE
;
1705 WINED3DSURFTYPE ImplType
= This
->ImplType
;
1706 WINED3DSURFACE_DESC Desc
;
1708 IParentImpl
*parImpl
= NULL
;
1709 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
1711 /* Dummies for GetDesc */
1712 WINED3DPOOL dummy_d3dpool
;
1713 WINED3DMULTISAMPLE_TYPE dummy_mst
;
1717 if (TRACE_ON(ddraw
))
1719 TRACE(" (%p) Requesting surface desc :\n", This
);
1720 DDRAW_dump_surface_desc(pDDSD
);
1723 /* Select the surface type, if it wasn't choosen yet */
1724 if(ImplType
== SURFACE_UNKNOWN
)
1726 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1727 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
)
1729 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This
);
1730 ImplType
= SURFACE_OPENGL
;
1733 /* Otherwise use GDI surfaces for now */
1736 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This
);
1737 ImplType
= SURFACE_GDI
;
1740 /* Policy if all surface implementations are available:
1741 * First, check if a default type was set with winecfg. If not,
1742 * try Xrender surfaces, and use them if they work. Next, check if
1743 * accellerated OpenGL is available, and use GL surfaces in this
1744 * case. If all fails, use GDI surfaces. If a 3DDEVICE surface
1745 * was created, always use OpenGL surfaces.
1747 * (Note: Xrender surfaces are not implemented by now, the
1748 * unaccellerated implementation uses GDI to render in Software)
1751 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1752 * be re-created. This could be done with IDirectDrawSurface7::Restore
1754 This
->ImplType
= ImplType
;
1758 if((pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_3DDEVICE
) &&
1759 (This
->ImplType
!= SURFACE_OPENGL
) && DefaultSurfaceType
== SURFACE_UNKNOWN
)
1761 /* We have to change to OpenGL,
1762 * and re-create all WineD3DSurfaces
1764 ImplType
= SURFACE_OPENGL
;
1765 This
->ImplType
= ImplType
;
1766 TRACE("(%p) Re-creating all surfaces\n", This
);
1767 IDirectDrawImpl_RecreateAllSurfaces(This
);
1768 TRACE("(%p) Done recreating all surfaces\n", This
);
1770 else if(This
->ImplType
!= SURFACE_OPENGL
)
1772 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1773 /* Do not fail surface creation, only fail 3D device creation */
1777 /* Get the surface parameters */
1778 if ( pDDSD
->dwFlags
& DDSD_LPSURFACE
)
1780 ERR("(%p) Using a passed surface pointer is not yet supported\n", This
);
1784 /* Get the correct wined3d usage */
1785 if (pDDSD
->ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
|
1786 DDSCAPS_BACKBUFFER
|
1787 DDSCAPS_3DDEVICE
) )
1789 Usage
|= WINED3DUSAGE_RENDERTARGET
;
1791 if(This
->depthstencil
)
1793 /* The depth stencil creation callback sets this flag.
1794 * Set the WineD3D usage to let it know that it's a depth
1797 Usage
|= WINED3DUSAGE_DEPTHSTENCIL
;
1799 if(pDDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
1801 Pool
= WINED3DPOOL_SYSTEMMEM
;
1804 Format
= PixelFormat_DD2WineD3D(&pDDSD
->u4
.ddpfPixelFormat
);
1805 if(Format
== WINED3DFMT_UNKNOWN
)
1807 ERR("Unsupported / Unknown pixelformat\n");
1808 return DDERR_INVALIDPIXELFORMAT
;
1811 /* Create the Surface object */
1812 *ppSurf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawSurfaceImpl
));
1815 ERR("(%p) Error allocating memory for a surface\n", This
);
1816 return DDERR_OUTOFVIDEOMEMORY
;
1818 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface7
, IDirectDrawSurface7_Vtbl
);
1819 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawSurface3
, IDirectDrawSurface3_Vtbl
);
1820 ICOM_INIT_INTERFACE(*ppSurf
, IDirectDrawGammaControl
, IDirectDrawGammaControl_Vtbl
);
1821 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture2
, IDirect3DTexture2_Vtbl
);
1822 ICOM_INIT_INTERFACE(*ppSurf
, IDirect3DTexture
, IDirect3DTexture1_Vtbl
);
1824 (*ppSurf
)->version
= 7;
1825 (*ppSurf
)->ddraw
= This
;
1826 (*ppSurf
)->surface_desc
.dwSize
= sizeof(DDSURFACEDESC2
);
1827 (*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
1828 DD_STRUCT_COPY_BYSIZE(&(*ppSurf
)->surface_desc
, pDDSD
);
1830 /* Surface attachments */
1831 (*ppSurf
)->next_attached
= NULL
;
1832 (*ppSurf
)->first_attached
= *ppSurf
;
1834 (*ppSurf
)->next_complex
= NULL
;
1835 (*ppSurf
)->first_complex
= *ppSurf
;
1837 /* Needed to re-create the surface on an implementation change */
1838 (*ppSurf
)->ImplType
= ImplType
;
1840 /* For D3DDevice creation */
1841 (*ppSurf
)->isRenderTarget
= FALSE
;
1843 /* A trace message for debugging */
1844 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This
, *ppSurf
);
1846 if(pDDSD
->ddsCaps
.dwCaps
& ( DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
| DDSCAPS_3DDEVICE
) )
1848 /* Render targets and textures need a IParent interface,
1849 * because WineD3D will destroy them when the swapchain
1852 parImpl
= HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl
));
1855 ERR("Out of memory when allocating memory for a IParent implementation\n");
1856 return DDERR_OUTOFMEMORY
;
1859 ICOM_INIT_INTERFACE(parImpl
, IParent
, IParent_Vtbl
);
1860 Parent
= (IUnknown
*) ICOM_INTERFACE(parImpl
, IParent
);
1861 TRACE("Using IParent interface %p as parent\n", parImpl
);
1865 /* Use the surface as parent */
1866 Parent
= (IUnknown
*) ICOM_INTERFACE(*ppSurf
, IDirectDrawSurface7
);
1867 TRACE("Using Surface interface %p as parent\n", *ppSurf
);
1870 /* Now create the WineD3D Surface */
1871 hr
= IWineD3DDevice_CreateSurface(This
->wineD3DDevice
,
1875 TRUE
/* Lockable */,
1876 FALSE
/* Discard */,
1878 &(*ppSurf
)->WineD3DSurface
,
1881 WINED3DMULTISAMPLE_NONE
,
1882 0 /* MultiSampleQuality */,
1883 0 /* SharedHandle */,
1889 ERR("IWineD3DDevice::CreateSurface failed. hr = %08lx\n", hr
);
1893 /* Set the child of the parent implementation if it exists */
1896 parImpl
->child
= (IUnknown
*) (*ppSurf
)->WineD3DSurface
;
1897 /* The IParent releases the WineD3DSurface, and
1898 * the ddraw surface does that too. Hold an reference
1900 IWineD3DSurface_AddRef((*ppSurf
)->WineD3DSurface
);
1903 /* Increase the surface counter, and attach the surface */
1904 InterlockedIncrement(&This
->surfaces
);
1905 if(This
->surface_list
)
1907 This
->surface_list
->prev
= *ppSurf
;
1909 (*ppSurf
)->next
= This
->surface_list
;
1910 This
->surface_list
= *ppSurf
;
1912 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1913 * But this could also be delegated to WineDDraw, as it keeps track of all it's
1914 * resources. Not implemented for now, as there are more important things ;)
1917 /* Get the pixel format of the WineD3DSurface and store it.
1918 * Don't use the Format choosen above, WineD3D might have
1921 Desc
.Format
= &Format
;
1922 Desc
.Type
= &ResType
;
1923 Desc
.Usage
= &Usage
;
1924 Desc
.Pool
= &dummy_d3dpool
;
1925 Desc
.Size
= &dummy_uint
;
1926 Desc
.MultiSampleType
= &dummy_mst
;
1927 Desc
.MultiSampleQuality
= &dummy_dword
;
1928 Desc
.Width
= &Width
;
1929 Desc
.Height
= &Height
;
1931 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
1932 hr
= IWineD3DSurface_GetDesc((*ppSurf
)->WineD3DSurface
, &Desc
);
1935 ERR("IWineD3DSurface::GetDesc failed\n");
1936 IDirectDrawSurface7_Release( (IDirectDrawSurface7
*) *ppSurf
);
1940 if(Format
== WINED3DFMT_UNKNOWN
)
1942 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
1944 PixelFormat_WineD3DtoDD( &(*ppSurf
)->surface_desc
.u4
.ddpfPixelFormat
, Format
);
1946 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
1947 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
1948 * WineD3DDevice might not be useable for 3D yet, so an extra method was created
1950 (*ppSurf
)->surface_desc
.dwFlags
|= DDSD_PITCH
;
1951 (*ppSurf
)->surface_desc
.u1
.lPitch
= IWineD3DSurface_GetPitch((*ppSurf
)->WineD3DSurface
);
1953 /* Application passed a color key? Set it! */
1954 if(pDDSD
->dwFlags
& DDSD_CKDESTOVERLAY
)
1956 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1958 &pDDSD
->u3
.ddckCKDestOverlay
);
1960 if(pDDSD
->dwFlags
& DDSD_CKDESTBLT
)
1962 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1964 &pDDSD
->ddckCKDestBlt
);
1966 if(pDDSD
->dwFlags
& DDSD_CKSRCOVERLAY
)
1968 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1970 &pDDSD
->ddckCKSrcOverlay
);
1972 if(pDDSD
->dwFlags
& DDSD_CKSRCBLT
)
1974 IWineD3DSurface_SetColorKey((*ppSurf
)->WineD3DSurface
,
1976 &pDDSD
->ddckCKSrcBlt
);
1982 /*****************************************************************************
1983 * IDirectDraw7::CreateSurface
1985 * Creates a new IDirectDrawSurface object and returns it's interface.
1987 * The surface connections with wined3d are a bit tricky. Basically it works
1990 * |------------------------| |-----------------|
1991 * | DDraw surface | | WineD3DSurface |
1993 * | WineD3DSurface |-------------->| |
1994 * | Child |<------------->| Parent |
1995 * |------------------------| |-----------------|
1997 * The DDraw surface is the parent of the wined3d surface, and it releases
1998 * the WineD3DSurface when the ddraw surface is destroyed.
2000 * However, for all surfaces which can be in a container in WineD3D,
2001 * we have to do this. These surfaces are ususally compley surfaces,
2002 * so this concernes primary surfaces with a front and a back buffer,
2003 * and textures textures.
2005 * |------------------------| |-----------------|
2006 * | DDraw surface | | Containter |
2008 * | Child |<------------->| Parent |
2009 * | Texture |<------------->| |
2010 * | WineD3DSurface |<----| | Levels |<--|
2011 * | Complex connection | | | | |
2012 * |------------------------| | |-----------------| |
2016 * | |------------------| | |-----------------| |
2017 * | | IParent | |-------->| WineD3DSurface | |
2019 * | | Child |<------------->| Parent | |
2020 * | | | | Container |<--|
2021 * | |------------------| |-----------------| |
2023 * | |----------------------| |
2024 * | | DDraw surface 2 | |
2026 * |<->| Complex root Child | |
2028 * | | WineD3DSurface |<----| |
2029 * | |----------------------| | |
2031 * | |---------------------| | |-----------------| |
2032 * | | IParent | |----->| WineD3DSurface | |
2034 * | | Child |<---------->| Parent | |
2035 * | |---------------------| | Container |<--|
2036 * | |-----------------| |
2038 * | ---More surfaces can follow--- |
2040 * The reason is that the IWineD3DSwapchain(render target container)
2041 * and the IWineD3DTexure(Texture container) release the parents
2042 * of their surface's children, but by releasing the complex root
2043 * the surfaces which are complexly attached to it are destroyed
2044 * too. See IDirectDrawSurface::Release for a more detailed
2048 * DDSD: Description of the surface to create
2049 * Surf: Address to store the interface pointer at
2050 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
2051 * aggregation, so it has to be NULL
2055 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2056 * DDERR_* if an error occurs
2058 *****************************************************************************/
2059 static HRESULT WINAPI
2060 IDirectDrawImpl_CreateSurface(IDirectDraw7
*iface
,
2061 DDSURFACEDESC2
*DDSD
,
2062 IDirectDrawSurface7
**Surf
,
2065 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2066 IDirectDrawSurfaceImpl
*object
= NULL
;
2068 LONG extra_surfaces
= 0, i
;
2069 DDSURFACEDESC2 desc2
;
2071 WINED3DDISPLAYMODE Mode
;
2073 TRACE("(%p)->(%p,%p,%p)\n", This
, DDSD
, Surf
, UnkOuter
);
2075 /* Some checks before we start */
2076 if (TRACE_ON(ddraw
))
2078 TRACE(" (%p) Requesting surface desc :\n", This
);
2079 DDRAW_dump_surface_desc(DDSD
);
2082 if (UnkOuter
!= NULL
)
2084 FIXME("(%p) : outer != NULL?\n", This
);
2085 return CLASS_E_NOAGGREGATION
; /* unchecked */
2088 if (!(DDSD
->dwFlags
& DDSD_CAPS
))
2090 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2091 DDSD
->dwFlags
|= DDSD_CAPS
;
2093 if (DDSD
->ddsCaps
.dwCaps
== 0)
2095 /* This has been checked on real Windows */
2096 DDSD
->ddsCaps
.dwCaps
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
;
2099 if (DDSD
->ddsCaps
.dwCaps
& DDSCAPS_ALLOCONLOAD
)
2101 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2102 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2105 if ((DDSD
->dwFlags
& DDSD_LPSURFACE
) && (DDSD
->lpSurface
== NULL
))
2107 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2108 WARN("(%p) Null surface pointer specified, ignore it!\n", This
);
2109 DDSD
->dwFlags
&= ~DDSD_LPSURFACE
;
2114 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This
);
2115 return E_POINTER
; /* unchecked */
2118 /* Modify some flags */
2119 memset(&desc2
, 0, sizeof(desc2
));
2120 desc2
.dwSize
= sizeof(desc2
); /*For the struct copy */
2121 DD_STRUCT_COPY_BYSIZE(&desc2
, DDSD
);
2122 desc2
.dwSize
= sizeof(desc2
); /* To override a possibly smaller size */
2123 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
); /* Just to be sure */
2125 /* Get the video mode from WineD3D - we will need it */
2126 hr
= IWineD3DDevice_GetDisplayMode(This
->wineD3DDevice
,
2127 0, /* Swapchain 0 */
2131 ERR("Failed to read display mode from wined3d\n");
2132 switch(This
->orig_bpp
)
2135 Mode
.Format
= WINED3DFMT_P8
;
2139 Mode
.Format
= WINED3DFMT_X1R5G5B5
;
2143 Mode
.Format
= WINED3DFMT_R5G6B5
;
2147 Mode
.Format
= WINED3DFMT_R8G8B8
;
2151 Mode
.Format
= WINED3DFMT_X8R8G8B8
;
2154 Mode
.Width
= This
->orig_width
;
2155 Mode
.Height
= This
->orig_height
;
2158 /* No pixelformat given? Use the current screen format */
2159 if(!(desc2
.dwFlags
& DDSD_PIXELFORMAT
))
2161 desc2
.dwFlags
|= DDSD_PIXELFORMAT
;
2162 desc2
.u4
.ddpfPixelFormat
.dwSize
=sizeof(DDPIXELFORMAT
);
2164 /* Wait: It could be a Z buffer */
2165 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_ZBUFFER
)
2167 switch(desc2
.u2
.dwMipMapCount
) /* Who had this glourious idea? */
2170 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D15S1
);
2173 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D16
);
2176 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D24X8
);
2179 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, WINED3DFMT_D32
);
2182 ERR("Unknown Z buffer bit depth\n");
2187 PixelFormat_WineD3DtoDD(&desc2
.u4
.ddpfPixelFormat
, Mode
.Format
);
2191 /* No Width or no Height? Use the current window size or
2192 * the original screen size
2194 if(!(desc2
.dwFlags
& DDSD_WIDTH
) ||
2195 !(desc2
.dwFlags
& DDSD_HEIGHT
) )
2199 /* Fallback: From WineD3D / original mode */
2200 desc2
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
2201 desc2
.dwWidth
= Mode
.Width
;
2202 desc2
.dwHeight
= Mode
.Height
;
2204 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
2206 if( (hr
== D3D_OK
) && (window
!= 0) )
2209 if(GetWindowRect(window
, &rect
) )
2211 /* This is a hack until I find a better solution */
2212 if( (rect
.right
- rect
.left
) <= 1 ||
2213 (rect
.bottom
- rect
.top
) <= 1 )
2215 FIXME("Wanted to get surface dimensions from window %p, but it has only \
2216 a size of %ldx%ld. Using full screen dimensions\n",
2217 window
, rect
.right
- rect
.left
, rect
.bottom
- rect
.top
);
2221 /* Not sure if this is correct */
2222 desc2
.dwWidth
= rect
.right
- rect
.left
;
2223 desc2
.dwHeight
= rect
.bottom
- rect
.top
;
2224 TRACE("Using window %p's dimensions: %ldx%ld\n", window
, desc2
.dwWidth
, desc2
.dwHeight
);
2230 /* Mipmap count fixes */
2231 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2233 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_COMPLEX
)
2235 if(desc2
.dwFlags
& DDSD_MIPMAPCOUNT
)
2237 /* Mipmap count is given, nothing to do */
2241 /* Undocumented feature: Create sublevels until
2242 * eighter the width or the height is 1
2244 DWORD min
= desc2
.dwWidth
< desc2
.dwHeight
?
2245 desc2
.dwWidth
: desc2
.dwHeight
;
2246 desc2
.u2
.dwMipMapCount
= 0;
2249 desc2
.u2
.dwMipMapCount
+= 1;
2256 /* Not-complex mipmap -> Mipmapcount = 1 */
2257 desc2
.u2
.dwMipMapCount
= 1;
2259 extra_surfaces
= desc2
.u2
.dwMipMapCount
- 1;
2261 /* There's a mipmap count in the created surface in any case */
2262 desc2
.dwFlags
|= DDSD_MIPMAPCOUNT
;
2264 /* If no mipmap is given, the texture has only one level */
2266 /* The first surface is a front buffer, the back buffer is created afterwards */
2267 if( (desc2
.dwFlags
& DDSD_CAPS
) && (desc2
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
) )
2269 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_FRONTBUFFER
;
2272 /* Create the first surface */
2273 hr
= IDirectDrawImpl_CreateNewSurface(This
, &desc2
, &object
, 0);
2276 ERR("IDirectDrawImpl_CreateNewSurface failed with %08lx\n", hr
);
2280 *Surf
= ICOM_INTERFACE(object
, IDirectDrawSurface7
);
2282 /* Create Additional surfaces if necessary
2283 * This applies to Primary surfaces which have a back buffer count
2284 * set, but not to mipmap textures. In case of Mipmap textures,
2285 * wineD3D takes care of the creation of additional surfaces
2287 if(DDSD
->dwFlags
& DDSD_BACKBUFFERCOUNT
)
2289 extra_surfaces
= DDSD
->dwBackBufferCount
;
2290 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_FRONTBUFFER
; /* It's not a front buffer */
2291 desc2
.ddsCaps
.dwCaps
|= DDSCAPS_BACKBUFFER
;
2294 for(i
= 0; i
< extra_surfaces
; i
++)
2296 IDirectDrawSurfaceImpl
*object2
= NULL
;
2297 IDirectDrawSurfaceImpl
*iterator
;
2299 /* increase the mipmap level, but only if a mipmap is created
2300 * In this case, also half the size
2302 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2306 desc2
.dwHeight
/= 2;
2309 hr
= IDirectDrawImpl_CreateNewSurface(This
,
2315 /* This destroys and possibly created surfaces too */
2316 IDirectDrawSurface_Release( ICOM_INTERFACE(object
, IDirectDrawSurface7
) );
2320 /* Add the new surface to the complex attachment list */
2321 object2
->first_complex
= object
;
2322 object2
->next_complex
= NULL
;
2324 while(iterator
->next_complex
) iterator
= iterator
->next_complex
;
2325 iterator
->next_complex
= object2
;
2327 /* Remove the (possible) back buffer cap from the new surface description,
2328 * because only one surface in the flipping chain is a back buffer, one
2329 * is a front buffer, the others are just primary surfaces.
2331 desc2
.ddsCaps
.dwCaps
&= ~DDSCAPS_BACKBUFFER
;
2334 /* Addref the ddraw interface to keep an reference for each surface */
2335 IDirectDraw7_AddRef(iface
);
2337 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2338 * But attach the d3ddevice only if the currently created surface was
2339 * a primary surface(2D app in 3D mode) or a 3DDEVICE surface(3D app)
2340 * The only case I can think of where this doesn't apply is when a
2341 * 2D app was configured by the user to run with OpenGL and it didn't create
2342 * the render target as first surface. In this case the render target creation
2343 * will cause the 3D init.
2345 if( (This
->ImplType
== SURFACE_OPENGL
) && !(This
->d3d_initialized
) &&
2346 desc2
.ddsCaps
.dwCaps
& (DDSCAPS_PRIMARYSURFACE
| DDSCAPS_3DDEVICE
) )
2348 IDirectDrawSurfaceImpl
*target
= This
->surface_list
;
2350 /* Search for the primary to use as render target */
2353 if(target
->surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_PRIMARYSURFACE
)
2356 TRACE("Using primary %p as render target\n", target
);
2359 target
= target
->next
;
2361 /* If it's not found, use the just created DDSCAPS_3DDEVICE surface */
2367 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This
, target
);
2368 hr
= IDirectDrawImpl_AttachD3DDevice(This
, target
->first_complex
);
2371 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %lx\n", hr
);
2375 /* Create a WineD3DTexture if a texture was requested */
2376 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_TEXTURE
)
2379 WINED3DFORMAT Format
;
2380 WINED3DPOOL Pool
= WINED3DPOOL_DEFAULT
;
2382 This
->tex_root
= object
;
2384 if(desc2
.ddsCaps
.dwCaps
& DDSCAPS_MIPMAP
)
2386 /* a mipmap is created, create enought levels */
2387 levels
= desc2
.u2
.dwMipMapCount
;
2391 /* No mipmap is created, create one level */
2395 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2396 if(DDSD
->ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
)
2398 Pool
= WINED3DPOOL_SYSTEMMEM
;
2400 /* Should I forward the MANEGED cap to the managed pool ? */
2402 /* Get the format. It's set already by CreateNewSurface */
2403 Format
= PixelFormat_DD2WineD3D(&object
->surface_desc
.u4
.ddpfPixelFormat
);
2405 /* The surfaces are already created, the callback only
2406 * passes the IWineD3DSurface to WineD3D
2408 hr
= IWineD3DDevice_CreateTexture( This
->wineD3DDevice
,
2409 DDSD
->dwWidth
, DDSD
->dwHeight
,
2410 levels
, /* MipMapCount = Levels */
2414 &object
->wineD3DTexture
,
2415 0, /* SharedHandle */
2416 (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawSurface7
),
2417 D3D7CB_CreateSurface
);
2418 This
->tex_root
= NULL
;
2424 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2425 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2428 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT
*requested
,
2429 const DDPIXELFORMAT
*provided
)
2431 /* Some flags must be present in both or neither for a match. */
2432 static const DWORD must_match
= DDPF_PALETTEINDEXED1
| DDPF_PALETTEINDEXED2
2433 | DDPF_PALETTEINDEXED4
| DDPF_PALETTEINDEXED8
| DDPF_FOURCC
2434 | DDPF_ZBUFFER
| DDPF_STENCILBUFFER
;
2436 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2439 if ((requested
->dwFlags
& must_match
) != (provided
->dwFlags
& must_match
))
2442 if (requested
->dwFlags
& DDPF_FOURCC
)
2443 if (requested
->dwFourCC
!= provided
->dwFourCC
)
2446 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_ALPHA
2447 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2448 if (requested
->u1
.dwRGBBitCount
!= provided
->u1
.dwRGBBitCount
)
2451 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2452 |DDPF_LUMINANCE
|DDPF_BUMPDUDV
))
2453 if (requested
->u2
.dwRBitMask
!= provided
->u2
.dwRBitMask
)
2456 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_ZBUFFER
|DDPF_BUMPDUDV
))
2457 if (requested
->u3
.dwGBitMask
!= provided
->u3
.dwGBitMask
)
2460 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2461 if (requested
->dwFlags
& (DDPF_RGB
|DDPF_YUV
|DDPF_STENCILBUFFER
2463 if (requested
->u4
.dwBBitMask
!= provided
->u4
.dwBBitMask
)
2466 if (requested
->dwFlags
& (DDPF_ALPHAPIXELS
|DDPF_ZPIXELS
))
2467 if (requested
->u5
.dwRGBAlphaBitMask
!= provided
->u5
.dwRGBAlphaBitMask
)
2474 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2
* requested
,
2475 const DDSURFACEDESC2
* provided
)
2484 #define CMP(FLAG, FIELD) \
2485 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2486 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2488 static const struct compare_info compare
[] =
2490 CMP(ALPHABITDEPTH
, dwAlphaBitDepth
),
2491 CMP(BACKBUFFERCOUNT
, dwBackBufferCount
),
2493 CMP(CKDESTBLT
, ddckCKDestBlt
),
2494 CMP(CKDESTOVERLAY
, u3
/* ddckCKDestOverlay */),
2495 CMP(CKSRCBLT
, ddckCKSrcBlt
),
2496 CMP(CKSRCOVERLAY
, ddckCKSrcOverlay
),
2497 CMP(HEIGHT
, dwHeight
),
2498 CMP(LINEARSIZE
, u1
/* dwLinearSize */),
2499 CMP(LPSURFACE
, lpSurface
),
2500 CMP(MIPMAPCOUNT
, u2
/* dwMipMapCount */),
2501 CMP(PITCH
, u1
/* lPitch */),
2502 /* PIXELFORMAT: manual */
2503 CMP(REFRESHRATE
, u2
/* dwRefreshRate */),
2504 CMP(TEXTURESTAGE
, dwTextureStage
),
2505 CMP(WIDTH
, dwWidth
),
2506 /* ZBUFFERBITDEPTH: "obsolete" */
2513 if ((requested
->dwFlags
& provided
->dwFlags
) != requested
->dwFlags
)
2516 for (i
=0; i
< sizeof(compare
)/sizeof(compare
[0]); i
++)
2518 if (requested
->dwFlags
& compare
[i
].flag
2519 && memcmp((const char *)provided
+ compare
[i
].offset
,
2520 (const char *)requested
+ compare
[i
].offset
,
2521 compare
[i
].size
) != 0)
2525 if (requested
->dwFlags
& DDSD_PIXELFORMAT
)
2527 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested
->u4
.ddpfPixelFormat
,
2528 &provided
->u4
.ddpfPixelFormat
))
2535 #undef DDENUMSURFACES_SEARCHTYPE
2536 #undef DDENUMSURFACES_MATCHTYPE
2538 /*****************************************************************************
2539 * IDirectDraw7::EnumSurfaces
2541 * Loops through all surfaces attached to this device and calls the
2542 * application callback. This can't be relayed to WineD3DDevice,
2543 * because some WineD3DSurfaces' parents are IParent objects
2546 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2547 * DDSD: Description to filter for
2548 * Context: Application-provided pointer, it's passed unmodified to the
2550 * Callback: Address to call for each surface
2553 * DDERR_INVALIDPARAMS if the callback is NULL
2556 *****************************************************************************/
2557 static HRESULT WINAPI
2558 IDirectDrawImpl_EnumSurfaces(IDirectDraw7
*iface
,
2560 DDSURFACEDESC2
*DDSD
,
2562 LPDDENUMSURFACESCALLBACK7 Callback
)
2564 /* The surface enumeration is handled by WineDDraw,
2565 * because it keeps track of all surfaces attached to
2566 * it. The filtering is done by our callback function,
2567 * because WineDDraw doesn't handle ddraw-like surface
2570 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2571 IDirectDrawSurfaceImpl
*surf
;
2573 DDSURFACEDESC2 desc
;
2575 all
= Flags
& DDENUMSURFACES_ALL
;
2576 nomatch
= Flags
& DDENUMSURFACES_NOMATCH
;
2578 TRACE("(%p)->(%lx,%p,%p,%p)\n", This
, Flags
, DDSD
, Context
, Callback
);
2581 return DDERR_INVALIDPARAMS
;
2583 for(surf
= This
->surface_list
; surf
; surf
= surf
->next
)
2585 if (all
|| (nomatch
!= IDirectDrawImpl_DDSD_Match(DDSD
, &surf
->surface_desc
)))
2587 desc
= surf
->surface_desc
;
2588 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf
, IDirectDrawSurface7
));
2589 if(Callback( ICOM_INTERFACE(surf
, IDirectDrawSurface7
), &desc
, Context
) != DDENUMRET_OK
)
2596 /*****************************************************************************
2597 * D3D7CB_CreateRenderTarget
2599 * Callback called by WineD3D to create Surfaces for render target usage
2600 * This function takes the D3D target from the IDirectDrawImpl structure,
2601 * and returns the WineD3DSurface. To avoid double usage, the surface
2602 * is marked as render target afterwards
2605 * device: The WineD3DDevice's parent
2606 * Width, Height, Format: Dimesions and pixelformat of the render target
2607 * Ignored, because the surface already exists
2608 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2610 * ppSurface: Address to pass the surface pointer back at
2611 * pSharedHandle: Ignored
2614 * Always returns D3D_OK
2616 *****************************************************************************/
2617 static HRESULT WINAPI
2618 D3D7CB_CreateRenderTarget(IUnknown
*device
, UINT Width
, UINT Height
,
2619 WINED3DFORMAT Format
,
2620 WINED3DMULTISAMPLE_TYPE MultiSample
,
2621 DWORD MultisampleQuality
,
2623 IWineD3DSurface
** ppSurface
,
2624 HANDLE
* pSharedHandle
)
2626 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2627 IDirectDrawSurfaceImpl
*d3dSurface
= (IDirectDrawSurfaceImpl
*) This
->d3d_target
->first_complex
;
2628 TRACE("(%p) call back\n", device
);
2630 /* Loop through the complex chain and try to find unused primary surfaces */
2631 while(d3dSurface
->isRenderTarget
)
2633 d3dSurface
= d3dSurface
->next_complex
;
2634 if(!d3dSurface
) break;
2638 d3dSurface
= This
->d3d_target
;
2639 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This
);
2642 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2644 *ppSurface
= d3dSurface
->WineD3DSurface
;
2645 d3dSurface
->isRenderTarget
= TRUE
;
2646 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface
, d3dSurface
);
2650 static HRESULT WINAPI
2651 D3D7CB_CreateDepthStencilSurface(IUnknown
*device
,
2654 WINED3DFORMAT Format
,
2655 WINED3DMULTISAMPLE_TYPE MultiSample
,
2656 DWORD MultisampleQuality
,
2658 IWineD3DSurface
** ppSurface
,
2659 HANDLE
* pSharedHandle
)
2661 /* Create a Depth Stencil surface to make WineD3D happy */
2662 HRESULT hr
= D3D_OK
;
2663 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2664 DDSURFACEDESC2 ddsd
;
2666 TRACE("(%p) call back\n", device
);
2670 /* Create a DirectDraw surface */
2671 memset(&ddsd
, 0, sizeof(ddsd
));
2672 ddsd
.dwSize
= sizeof(ddsd
);
2673 ddsd
.u4
.ddpfPixelFormat
.dwSize
= sizeof(DDPIXELFORMAT
);
2674 ddsd
.dwFlags
= DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
2675 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
2676 ddsd
.dwHeight
= Height
;
2677 ddsd
.dwWidth
= Width
;
2680 PixelFormat_WineD3DtoDD(&ddsd
.u4
.ddpfPixelFormat
, Format
);
2684 ddsd
.dwFlags
^= DDSD_PIXELFORMAT
;
2687 This
->depthstencil
= TRUE
;
2688 hr
= IDirectDraw7_CreateSurface((IDirectDraw7
*) This
,
2690 (IDirectDrawSurface7
**) &This
->DepthStencilBuffer
,
2692 This
->depthstencil
= FALSE
;
2695 ERR(" (%p) Creating a DepthStencil Surface failed, result = %lx\n", This
, hr
);
2698 *ppSurface
= This
->DepthStencilBuffer
->WineD3DSurface
;
2702 /*****************************************************************************
2703 * D3D7CB_CreateAdditionalSwapChain
2705 * Callback function for WineD3D which creates a new WineD3DSwapchain
2706 * interface. It also creates a IParent interface to store that pointer,
2707 * so the WineD3DSwapchain has a parent and can be released when the D3D
2708 * device is destroyed
2709 *****************************************************************************/
2710 static HRESULT WINAPI
2711 D3D7CB_CreateAdditionalSwapChain(IUnknown
*device
,
2712 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
2713 IWineD3DSwapChain
** ppSwapChain
)
2715 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, device
);
2716 IParentImpl
*object
= NULL
;
2717 HRESULT res
= D3D_OK
;
2718 IWineD3DSwapChain
*swapchain
;
2719 TRACE("(%p) call back\n", device
);
2721 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IParentImpl
));
2724 FIXME("Allocation of memory failed\n");
2725 *ppSwapChain
= NULL
;
2726 return DDERR_OUTOFVIDEOMEMORY
;
2729 ICOM_INIT_INTERFACE(object
, IParent
, IParent_Vtbl
);
2732 res
= IWineD3DDevice_CreateAdditionalSwapChain(This
->wineD3DDevice
,
2733 pPresentationParameters
,
2735 (IUnknown
*) ICOM_INTERFACE(object
, IParent
),
2736 D3D7CB_CreateRenderTarget
,
2737 D3D7CB_CreateDepthStencilSurface
);
2740 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This
);
2741 HeapFree(GetProcessHeap(), 0 , object
);
2742 *ppSwapChain
= NULL
;
2746 *ppSwapChain
= swapchain
;
2747 object
->child
= (IUnknown
*) swapchain
;
2753 /*****************************************************************************
2754 * IDirectDrawImpl_AttachD3DDevice
2756 * Initializes the D3D capatiblities of WineD3D
2759 * primary: The primary surface for D3D
2765 *****************************************************************************/
2766 static HRESULT WINAPI
2767 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl
*This
,
2768 IDirectDrawSurfaceImpl
*primary
)
2771 UINT BackBufferCount
= 0;
2774 WINED3DPRESENT_PARAMETERS localParameters
;
2775 BOOL isWindowed
, EnableAutoDepthStencil
;
2776 WINED3DFORMAT AutoDepthStencilFormat
;
2777 WINED3DMULTISAMPLE_TYPE MultiSampleType
;
2778 WINED3DSWAPEFFECT SwapEffect
;
2779 DWORD Flags
, MultiSampleQuality
;
2780 UINT FullScreen_RefreshRateInHz
, PresentationInterval
;
2781 WINED3DDISPLAYMODE Mode
;
2783 TRACE("(%p)->(%p)\n", This
, primary
);
2785 /* Get the window */
2786 hr
= IWineD3DDevice_GetHWND(This
->wineD3DDevice
,
2790 ERR("IWineD3DDevice::GetHWND failed\n");
2794 /* If there's no window, create a hidden window. WineD3D needs it */
2797 window
= CreateWindowExA(0, This
->classname
, "Hidden D3D Window",
2799 GetSystemMetrics(SM_CXSCREEN
),
2800 GetSystemMetrics(SM_CYSCREEN
),
2801 NULL
, NULL
, GetModuleHandleA(0), NULL
);
2803 ShowWindow(window
, SW_HIDE
); /* Just to be sure */
2804 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This
, window
);
2805 This
->d3d_window
= window
;
2809 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This
, window
);
2812 /* use the surface description for the device parameters, not the
2813 * Device settings. The app might render to an offscreen surface
2815 Mode
.Width
= primary
->surface_desc
.dwWidth
;
2816 Mode
.Height
= primary
->surface_desc
.dwHeight
;
2817 Mode
.Format
= PixelFormat_DD2WineD3D(&primary
->surface_desc
.u4
.ddpfPixelFormat
);
2819 if(primary
->surface_desc
.dwFlags
& DDSD_BACKBUFFERCOUNT
)
2821 BackBufferCount
= primary
->surface_desc
.dwBackBufferCount
;
2824 /* Store the future Render Target surface */
2825 This
->d3d_target
= primary
;
2827 isWindowed
= !(This
->cooperative_level
& DDSCL_FULLSCREEN
);
2828 EnableAutoDepthStencil
= FALSE
;
2829 AutoDepthStencilFormat
= WINED3DFMT_D16
;
2830 MultiSampleType
= WINED3DMULTISAMPLE_NONE
;
2831 SwapEffect
= WINED3DSWAPEFFECT_COPY
;
2833 MultiSampleQuality
= 0;
2834 FullScreen_RefreshRateInHz
= WINED3DPRESENT_RATE_DEFAULT
; /* Default rate: It's allready set */
2835 PresentationInterval
= WINED3DPRESENT_INTERVAL_DEFAULT
;
2837 TRACE("Passing mode %d\n", Mode
.Format
);
2839 localParameters
.BackBufferWidth
= &Mode
.Width
;
2840 localParameters
.BackBufferHeight
= &Mode
.Height
;
2841 localParameters
.BackBufferFormat
= (WINED3DFORMAT
*) &Mode
.Format
;
2842 localParameters
.BackBufferCount
= (UINT
*) &BackBufferCount
;
2843 localParameters
.MultiSampleType
= &MultiSampleType
;
2844 localParameters
.MultiSampleQuality
= &MultiSampleQuality
;
2845 localParameters
.SwapEffect
= &SwapEffect
;
2846 localParameters
.hDeviceWindow
= &window
;
2847 localParameters
.Windowed
= &isWindowed
;
2848 localParameters
.EnableAutoDepthStencil
= &EnableAutoDepthStencil
;
2849 localParameters
.AutoDepthStencilFormat
= &AutoDepthStencilFormat
;
2850 localParameters
.Flags
= &Flags
;
2851 localParameters
.FullScreen_RefreshRateInHz
= &FullScreen_RefreshRateInHz
;
2852 localParameters
.PresentationInterval
= &PresentationInterval
;
2854 /* Set this NOW, otherwise creating the depth stencil surface will cause an
2855 * recursive loop until ram or emulated video memory is full
2857 This
->d3d_initialized
= TRUE
;
2859 hr
= IWineD3DDevice_Init3D(This
->wineD3DDevice
,
2861 D3D7CB_CreateAdditionalSwapChain
);
2864 This
->wineD3DDevice
= NULL
;
2868 /* Create an Index Buffer parent */
2869 TRACE("(%p) Successfully initialized 3D\n", This
);
2873 /*****************************************************************************
2874 * DirectDrawCreateClipper (DDRAW.@)
2876 * Creates a new IDirectDrawClipper object.
2879 * Clipper: Address to write the interface pointer to
2880 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2884 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2885 * E_OUTOFMEMORY if allocating the object failed
2887 *****************************************************************************/
2889 DirectDrawCreateClipper(DWORD Flags
,
2890 IDirectDrawClipper
**Clipper
,
2893 IDirectDrawClipperImpl
* object
;
2894 TRACE("(%08lx,%p,%p)\n", Flags
, Clipper
, UnkOuter
);
2896 if (UnkOuter
!= NULL
) return CLASS_E_NOAGGREGATION
;
2898 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2899 sizeof(IDirectDrawClipperImpl
));
2900 if (object
== NULL
) return E_OUTOFMEMORY
;
2902 ICOM_INIT_INTERFACE(object
, IDirectDrawClipper
, IDirectDrawClipper_Vtbl
);
2905 object
->ddraw_owner
= NULL
;
2907 *Clipper
= (IDirectDrawClipper
*) object
;
2911 /*****************************************************************************
2912 * IDirectDraw7::CreateClipper
2914 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
2916 *****************************************************************************/
2917 static HRESULT WINAPI
2918 IDirectDrawImpl_CreateClipper(IDirectDraw7
*iface
,
2920 IDirectDrawClipper
**Clipper
,
2923 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2924 TRACE("(%p)->(%lx,%p,%p)\n", This
, Flags
, Clipper
, UnkOuter
);
2925 return DirectDrawCreateClipper(Flags
, Clipper
, UnkOuter
);
2928 /*****************************************************************************
2929 * IDirectDraw7::CreatePalette
2931 * Creates a new IDirectDrawPalette object
2934 * Flags: The flags for the new clipper
2935 * ColorTable: Color table to assign to the new clipper
2936 * Palette: Address to write the interface pointer to
2937 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2941 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2942 * E_OUTOFMEMORY if allocating the object failed
2944 *****************************************************************************/
2945 static HRESULT WINAPI
2946 IDirectDrawImpl_CreatePalette(IDirectDraw7
*iface
,
2948 PALETTEENTRY
*ColorTable
,
2949 IDirectDrawPalette
**Palette
,
2950 IUnknown
*pUnkOuter
)
2952 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
2953 IDirectDrawPaletteImpl
*object
;
2954 HRESULT hr
= DDERR_GENERIC
;
2955 TRACE("(%p)->(%lx,%p,%p,%p)\n", This
, Flags
, ColorTable
, Palette
, pUnkOuter
);
2957 if(pUnkOuter
!= NULL
)
2959 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter
);
2960 return CLASS_E_NOAGGREGATION
;
2963 /* The refcount test shows that a cooplevel is required for this */
2964 if(!This
->cooperative_level
)
2966 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
2967 return DDERR_NOCOOPERATIVELEVELSET
;
2970 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl
));
2973 ERR("Out of memory when allocating memory for a palette implementation\n");
2974 return E_OUTOFMEMORY
;
2977 ICOM_INIT_INTERFACE(object
, IDirectDrawPalette
, IDirectDrawPalette_Vtbl
);
2979 object
->ddraw_owner
= This
;
2981 hr
= IWineD3DDevice_CreatePalette(This
->wineD3DDevice
, Flags
, ColorTable
, &object
->wineD3DPalette
, (IUnknown
*) ICOM_INTERFACE(object
, IDirectDrawPalette
) );
2984 HeapFree(GetProcessHeap(), 0, object
);
2988 IDirectDraw7_AddRef(iface
);
2989 *Palette
= ICOM_INTERFACE(object
, IDirectDrawPalette
);
2993 /*****************************************************************************
2994 * IDirectDraw7::DuplicateSurface
2996 * Duplicates a surface. The surface memory points to the same memory as
2997 * the original surface, and it's released when the last surface referring
2998 * it is released. I guess that's beyond Wines surface management right now
2999 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
3000 * test application to implement this)
3003 * Src: Address of the source surface
3004 * Dest: Address to write the new surface pointer to
3007 * See IDirectDraw7::CreateSurface
3009 *****************************************************************************/
3010 static HRESULT WINAPI
3011 IDirectDrawImpl_DuplicateSurface(IDirectDraw7
*iface
,
3012 IDirectDrawSurface7
*Src
,
3013 IDirectDrawSurface7
**Dest
)
3015 ICOM_THIS_FROM(IDirectDrawImpl
, IDirectDraw7
, iface
);
3016 IDirectDrawSurfaceImpl
*Surf
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, Src
);
3018 FIXME("(%p)->(%p,%p)\n", This
, Surf
, Dest
);
3020 /* For now, simply create a new, independent surface */
3021 return IDirectDraw7_CreateSurface(iface
,
3022 &Surf
->surface_desc
,
3027 /*****************************************************************************
3028 * IDirectDraw7 VTable
3029 *****************************************************************************/
3030 const IDirectDraw7Vtbl IDirectDraw7_Vtbl
=
3033 IDirectDrawImpl_QueryInterface
,
3034 IDirectDrawImpl_AddRef
,
3035 IDirectDrawImpl_Release
,
3036 /*** IDirectDraw ***/
3037 IDirectDrawImpl_Compact
,
3038 IDirectDrawImpl_CreateClipper
,
3039 IDirectDrawImpl_CreatePalette
,
3040 IDirectDrawImpl_CreateSurface
,
3041 IDirectDrawImpl_DuplicateSurface
,
3042 IDirectDrawImpl_EnumDisplayModes
,
3043 IDirectDrawImpl_EnumSurfaces
,
3044 IDirectDrawImpl_FlipToGDISurface
,
3045 IDirectDrawImpl_GetCaps
,
3046 IDirectDrawImpl_GetDisplayMode
,
3047 IDirectDrawImpl_GetFourCCCodes
,
3048 IDirectDrawImpl_GetGDISurface
,
3049 IDirectDrawImpl_GetMonitorFrequency
,
3050 IDirectDrawImpl_GetScanLine
,
3051 IDirectDrawImpl_GetVerticalBlankStatus
,
3052 IDirectDrawImpl_Initialize
,
3053 IDirectDrawImpl_RestoreDisplayMode
,
3054 IDirectDrawImpl_SetCooperativeLevel
,
3055 IDirectDrawImpl_SetDisplayMode
,
3056 IDirectDrawImpl_WaitForVerticalBlank
,
3057 /*** IDirectDraw2 ***/
3058 IDirectDrawImpl_GetAvailableVidMem
,
3059 /*** IDirectDraw7 ***/
3060 IDirectDrawImpl_GetSurfaceFromDC
,
3061 IDirectDrawImpl_RestoreAllSurfaces
,
3062 IDirectDrawImpl_TestCooperativeLevel
,
3063 IDirectDrawImpl_GetDeviceIdentifier
,
3064 /*** IDirectDraw7 ***/
3065 IDirectDrawImpl_StartModeTest
,
3066 IDirectDrawImpl_EvaluateMode