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_IDirectDraw3, refiid ) )
122 *obj = ICOM_INTERFACE(This, IDirectDraw3);
123 TRACE("(%p) Returning IDirectDraw3 interface at %p\n", This, *obj);
125 else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
127 *obj = ICOM_INTERFACE(This, IDirectDraw2);
128 TRACE("(%p) Returning IDirectDraw2 interface at %p\n", This, *obj);
130 else if ( IsEqualGUID( &IID_IDirectDraw, refiid ) )
132 *obj = ICOM_INTERFACE(This, IDirectDraw);
133 TRACE("(%p) Returning IDirectDraw interface at %p\n", This, *obj);
137 * The refcount unit test revealed that an IDirect3D7 interface can only be queried
138 * from a DirectDraw object that was created as an IDirectDraw7 interface. No idea
139 * who had this idea and why. The older interfaces can query and IDirect3D version
140 * because they are all created as IDirectDraw(1). This isn't really crucial behavior,
141 * and messy to implement with the common creation function, so it has been left out here.
143 else if ( IsEqualGUID( &IID_IDirect3D , refiid ) ||
144 IsEqualGUID( &IID_IDirect3D2 , refiid ) ||
145 IsEqualGUID( &IID_IDirect3D3 , refiid ) ||
146 IsEqualGUID( &IID_IDirect3D7 , refiid ) )
148 /* Check the surface implementation */
149 if(This->ImplType == SURFACE_UNKNOWN)
151 /* Apps may create the IDirect3D Interface before the primary surface.
152 * set the surface implementation */
153 This->ImplType = SURFACE_OPENGL;
154 TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This);
156 else if(This->ImplType != SURFACE_OPENGL && DefaultSurfaceType == SURFACE_UNKNOWN)
158 ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This);
159 ERR(" (%p) You may want to contact wine-devel for help\n", This);
160 /* Should I assert(0) here??? */
162 else if(This->ImplType != SURFACE_OPENGL)
164 WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
165 /* Do not abort here, only reject 3D Device creation */
168 if ( IsEqualGUID( &IID_IDirect3D , refiid ) )
170 This->d3dversion = 1;
171 *obj = ICOM_INTERFACE(This, IDirect3D);
172 TRACE(" returning Direct3D interface at %p.\n", *obj);
174 else if ( IsEqualGUID( &IID_IDirect3D2 , refiid ) )
176 This->d3dversion = 2;
177 *obj = ICOM_INTERFACE(This, IDirect3D2);
178 TRACE(" returning Direct3D2 interface at %p.\n", *obj);
180 else if ( IsEqualGUID( &IID_IDirect3D3 , refiid ) )
182 This->d3dversion = 3;
183 *obj = ICOM_INTERFACE(This, IDirect3D3);
184 TRACE(" returning Direct3D3 interface at %p.\n", *obj);
186 else if(IsEqualGUID( &IID_IDirect3D7 , refiid ))
188 This->d3dversion = 7;
189 *obj = ICOM_INTERFACE(This, IDirect3D7);
190 TRACE(" returning Direct3D7 interface at %p.\n", *obj);
194 /* Unknown interface */
197 ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
198 return E_NOINTERFACE;
201 IUnknown_AddRef( (IUnknown *) *obj );
205 /*****************************************************************************
206 * IDirectDraw7::AddRef
208 * Increases the interfaces refcount, basically
210 * DDraw refcounting is a bit tricky. The different DirectDraw interface
211 * versions have individual refcounts, but the IDirect3D interfaces do not.
212 * All interfaces are from one object, that means calling QueryInterface on an
213 * IDirectDraw7 interface for an IDirectDraw4 interface does not create a new
214 * IDirectDrawImpl object.
216 * That means all AddRef and Release implementations of IDirectDrawX work
217 * with their own counter, and IDirect3DX::AddRef thunk to IDirectDraw (1),
218 * except of IDirect3D7 which thunks to IDirectDraw7
220 * Returns: The new refcount
222 *****************************************************************************/
224 IDirectDrawImpl_AddRef(IDirectDraw7 *iface)
226 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
227 ULONG ref = InterlockedIncrement(&This->ref7);
229 TRACE("(%p) : incrementing IDirectDraw7 refcount from %u.\n", This, ref -1);
231 if(ref == 1) InterlockedIncrement(&This->numIfaces);
236 /*****************************************************************************
237 * IDirectDrawImpl_Destroy
239 * Destroys a ddraw object if all refcounts are 0. This is to share code
240 * between the IDirectDrawX::Release functions
243 * This: DirectDraw object to destroy
245 *****************************************************************************/
247 IDirectDrawImpl_Destroy(IDirectDrawImpl *This)
249 /* Clear the cooplevel to restore window and display mode */
250 IDirectDraw7_SetCooperativeLevel(ICOM_INTERFACE(This, IDirectDraw7),
254 /* Destroy the device window if we created one */
255 if(This->devicewindow != 0)
257 TRACE(" (%p) Destroying the device window %p\n", This, This->devicewindow);
258 DestroyWindow(This->devicewindow);
259 This->devicewindow = 0;
262 /* Unregister the window class */
263 UnregisterClassA(This->classname, 0);
265 remove_ddraw_object(This);
267 /* Release the attached WineD3D stuff */
268 IWineD3DDevice_Release(This->wineD3DDevice);
269 IWineD3D_Release(This->wineD3D);
271 /* Now free the object */
272 HeapFree(GetProcessHeap(), 0, This);
275 /*****************************************************************************
276 * IDirectDraw7::Release
278 * Decreases the refcount. If the refcount falls to 0, the object is destroyed
280 * Returns: The new refcount
281 *****************************************************************************/
283 IDirectDrawImpl_Release(IDirectDraw7 *iface)
285 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
286 ULONG ref = InterlockedDecrement(&This->ref7);
288 TRACE("(%p)->() decrementing IDirectDraw7 refcount from %u.\n", This, ref +1);
292 ULONG ifacecount = InterlockedDecrement(&This->numIfaces);
293 if(ifacecount == 0) IDirectDrawImpl_Destroy(This);
299 /*****************************************************************************
300 * IDirectDraw methods
301 *****************************************************************************/
303 /*****************************************************************************
304 * IDirectDraw7::SetCooperativeLevel
306 * Sets the cooperative level for the DirectDraw object, and the window
307 * assigned to it. The cooperative level determines the general behavior
308 * of the DirectDraw application
310 * Warning: This is quite tricky, as it's not really documented which
311 * cooperative levels can be combined with each other. If a game fails
312 * after this function, try to check the cooperative levels passed on
313 * Windows, and if it returns something different.
315 * If you think that this function caused the failure because it writes a
316 * fixme, be sure to run again with a +ddraw trace.
318 * What is known about cooperative levels (See the ddraw modes test):
319 * DDSCL_EXCLUSIVE and DDSCL_FULLSCREEN must be used with each other
320 * DDSCL_NORMAL is not compatible with DDSCL_EXCLUSIVE or DDSCL_FULLSCREEN
321 * DDSCL_SETFOCUSWINDOW can be passed only in DDSCL_NORMAL mode, but after that
322 * DDSCL_FULLSCREEN can be activated
323 * DDSCL_SETFOCUSWINDOW may only be used with DDSCL_NOWINDOWCHANGES
325 * Handled flags: DDSCL_NORMAL, DDSCL_FULLSCREEN, DDSCL_EXCLUSIVE,
326 * DDSCL_SETFOCUSWINDOW (partially)
328 * Unhandled flags, which should be implemented
329 * DDSCL_SETDEVICEWINDOW: Sets a window specially used for rendering (I don't
330 * expect any difference to a normal window for wine)
331 * DDSCL_CREATEDEVICEWINDOW: Tells ddraw to create its own window for
332 * rendering (Possible test case: Half-life)
334 * Unsure about these: DDSCL_FPUSETUP DDSCL_FPURESERVE
336 * These seem not really imporant for wine
337 * DDSCL_ALLOWREBOOT, DDSCL_NOWINDOWCHANGES, DDSCL_ALLOWMODEX,
341 * DD_OK if the cooperative level was set successfully
342 * DDERR_INVALIDPARAMS if the passed cooperative level combination is invalid
343 * DDERR_HWNDALREADYSET if DDSCL_SETFOCUSWINDOW is passed in exclusive mode
344 * (Probably others too, have to investigate)
346 *****************************************************************************/
347 static HRESULT WINAPI
348 IDirectDrawImpl_SetCooperativeLevel(IDirectDraw7 *iface,
352 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
356 FIXME("(%p)->(%p,%08x)\n",This,hwnd,cooplevel);
357 DDRAW_dump_cooperativelevel(cooplevel);
359 /* Get the old window */
360 hr = IWineD3DDevice_GetHWND(This->wineD3DDevice, &window);
363 ERR("IWineD3DDevice::GetHWND failed, hr = %08x\n", hr);
367 /* Tests suggest that we need one of them: */
368 if(!(cooplevel & (DDSCL_SETFOCUSWINDOW |
372 TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
373 return DDERR_INVALIDPARAMS;
376 /* Handle those levels first which set various hwnds */
377 if(cooplevel & DDSCL_SETFOCUSWINDOW)
379 /* This isn't compatible with a lot of flags */
380 if(cooplevel & ( DDSCL_MULTITHREADED |
385 DDSCL_SETDEVICEWINDOW |
390 TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
391 return DDERR_INVALIDPARAMS;
393 else if( (This->cooperative_level & DDSCL_FULLSCREEN) && window)
395 TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
396 return DDERR_HWNDALREADYSET;
399 This->focuswindow = hwnd;
400 /* Won't use the hwnd param for anything else */
403 /* Use the focus window for drawing too */
404 IWineD3DDevice_SetHWND(This->wineD3DDevice, This->focuswindow);
406 /* Destroy the device window, if we have one */
407 if(This->devicewindow)
409 DestroyWindow(This->devicewindow);
410 This->devicewindow = NULL;
413 /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
414 if(cooplevel & DDSCL_NORMAL)
416 /* Can't coexist with fullscreen or exclusive */
417 if(cooplevel & (DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) )
419 TRACE("(%p) DDSCL_NORMAL is not compative with DDSCL_FULLSCREEN or DDSCL_EXCLUSIVE\n", This);
420 return DDERR_INVALIDPARAMS;
423 /* Switching from fullscreen? */
424 if(This->cooperative_level & DDSCL_FULLSCREEN)
426 /* Restore the display mode */
427 IDirectDraw7_RestoreDisplayMode(iface);
430 IWineD3DDevice_RestoreWindow(This->wineD3DDevice, window);
432 This->cooperative_level &= ~DDSCL_FULLSCREEN;
433 This->cooperative_level &= ~DDSCL_EXCLUSIVE;
434 This->cooperative_level &= ~DDSCL_ALLOWMODEX;
437 /* Don't override focus windows or private device windows */
439 !(This->focuswindow) &&
440 !(This->devicewindow) &&
443 IWineD3DDevice_SetHWND(This->wineD3DDevice, hwnd);
446 IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
449 else if(cooplevel & DDSCL_FULLSCREEN)
451 /* Needs DDSCL_EXCLUSIVE */
452 if(!(cooplevel & DDSCL_EXCLUSIVE) )
454 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This);
455 return DDERR_INVALIDPARAMS;
460 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
461 return DDERR_INVALIDPARAMS;
465 /* Switch from normal to full screen mode? */
466 if(This->cooperative_level & DDSCL_NORMAL)
468 This->cooperative_level &= ~DDSCL_NORMAL;
469 IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
473 /* Don't override focus windows or private device windows */
475 !(This->focuswindow) &&
476 !(This->devicewindow) &&
479 /* On a window change, restore the old window and set the new one */
483 IWineD3DDevice_RestoreWindow(This->wineD3DDevice, window);
484 IWineD3DDevice_SetupFullscreenWindow(This->wineD3DDevice, hwnd);
486 IWineD3DDevice_SetHWND(This->wineD3DDevice, hwnd);
489 else if(cooplevel & DDSCL_EXCLUSIVE)
491 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This);
492 return DDERR_INVALIDPARAMS;
495 if(cooplevel & DDSCL_CREATEDEVICEWINDOW)
497 /* Don't create a device window if a focus window is set */
498 if( !(This->focuswindow) )
500 HWND devicewindow = CreateWindowExA(0, This->classname, "DDraw device window",
502 GetSystemMetrics(SM_CXSCREEN),
503 GetSystemMetrics(SM_CYSCREEN),
504 NULL, NULL, GetModuleHandleA(0), NULL);
506 ShowWindow(devicewindow, SW_SHOW); /* Just to be sure */
507 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This, devicewindow);
509 IWineD3DDevice_SetHWND(This->wineD3DDevice, devicewindow);
510 This->devicewindow = devicewindow;
514 /* Unhandled flags */
515 if(cooplevel & DDSCL_ALLOWREBOOT)
516 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This);
517 if(cooplevel & DDSCL_ALLOWMODEX)
518 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This);
519 if(cooplevel & DDSCL_MULTITHREADED)
520 FIXME("(%p) Unhandled flag DDSCL_MULTITHREADED, Uh Oh...\n", This);
521 if(cooplevel & DDSCL_FPUSETUP)
522 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This);
523 if(cooplevel & DDSCL_FPUPRESERVE)
524 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This);
526 /* Store the cooperative_level */
527 This->cooperative_level |= cooplevel;
528 TRACE("SetCooperativeLevel retuning DD_OK\n");
532 /*****************************************************************************
533 * IDirectDraw7::SetDisplayMode
535 * Sets the display screen resolution, color depth and refresh frequency
536 * when in fullscreen mode (in theory).
537 * Possible return values listed in the SDK suggest that this method fails
538 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
539 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
540 * It seems to be valid to pass 0 for With and Height, this has to be tested
541 * It could mean that the current video mode should be left as-is. (But why
545 * Height, Width: Screen dimension
546 * BPP: Color depth in Bits per pixel
547 * Refreshrate: Screen refresh rate
553 *****************************************************************************/
554 static HRESULT WINAPI
555 IDirectDrawImpl_SetDisplayMode(IDirectDraw7 *iface,
562 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
563 WINED3DDISPLAYMODE Mode;
564 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This, Width, Height, BPP, RefreshRate, Flags);
566 if( !Width || !Height )
568 ERR("Width=%d, Height=%d, what to do?\n", Width, Height);
569 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
573 /* Check the exclusive mode
574 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
575 return DDERR_NOEXCLUSIVEMODE;
576 * This is WRONG. Don't know if the SDK is completely
577 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
578 * is returned, but Half-Life 1.1.1.1 (Steam version)
583 Mode.Height = Height;
584 Mode.RefreshRate = RefreshRate;
587 case 8: Mode.Format = WINED3DFMT_P8; break;
588 case 15: Mode.Format = WINED3DFMT_X1R5G5B5; break;
589 case 16: Mode.Format = WINED3DFMT_R5G6B5; break;
590 case 24: Mode.Format = WINED3DFMT_R8G8B8; break;
591 case 32: Mode.Format = WINED3DFMT_A8R8G8B8; break;
594 /* TODO: The possible return values from msdn suggest that
595 * the screen mode can't be changed if a surface is locked
596 * or some drawing is in progress
599 /* TODO: Lose the primary surface */
600 return IWineD3DDevice_SetDisplayMode(This->wineD3DDevice,
601 0, /* First swapchain */
606 /*****************************************************************************
607 * IDirectDraw7::RestoreDisplayMode
609 * Restores the display mode to what it was at creation time. Basically.
611 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
612 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
613 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
614 * -> DD_1 is released. The screen should be left at 1024x768x32.
615 * -> DD_2 is released. The screen should be set to 1400x1050x32
616 * This case is unhandled right now, but Empire Earth does it this way.
617 * (But perhaps there is something in SetCooperativeLevel to prevent this)
619 * The msdn says that this method resets the display mode to what it was before
620 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
624 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
626 *****************************************************************************/
627 static HRESULT WINAPI
628 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7 *iface)
630 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
631 TRACE("(%p)\n", This);
633 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This, IDirectDraw7),
641 /*****************************************************************************
642 * IDirectDraw7::GetCaps
644 * Returns the drives capabilities
646 * Used for version 1, 2, 4 and 7
649 * DriverCaps: Structure to write the Hardware accelerated caps to
650 * HelCaps: Structure to write the emulation caps to
653 * This implementation returns DD_OK only
655 *****************************************************************************/
656 static HRESULT WINAPI
657 IDirectDrawImpl_GetCaps(IDirectDraw7 *iface,
661 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
662 TRACE("(%p)->(%p,%p)\n", This, DriverCaps, HELCaps);
664 /* One structure must be != NULL */
665 if( (!DriverCaps) && (!HELCaps) )
667 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This);
668 return DDERR_INVALIDPARAMS;
673 DD_STRUCT_COPY_BYSIZE(DriverCaps, &This->caps);
676 TRACE("Driver Caps :\n");
677 DDRAW_dump_DDCAPS(DriverCaps);
683 DD_STRUCT_COPY_BYSIZE(HELCaps, &This->caps);
686 TRACE("HEL Caps :\n");
687 DDRAW_dump_DDCAPS(HELCaps);
694 /*****************************************************************************
695 * IDirectDraw7::Compact
697 * No idea what it does, MSDN says it's not implemented.
700 * DD_OK, but this is unchecked
702 *****************************************************************************/
703 static HRESULT WINAPI
704 IDirectDrawImpl_Compact(IDirectDraw7 *iface)
706 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
707 TRACE("(%p)\n", This);
712 /*****************************************************************************
713 * IDirectDraw7::GetDisplayMode
715 * Returns information about the current display mode
717 * Exists in Version 1, 2, 4 and 7
720 * DDSD: Address of a surface description structure to write the info to
725 *****************************************************************************/
726 static HRESULT WINAPI
727 IDirectDrawImpl_GetDisplayMode(IDirectDraw7 *iface,
728 DDSURFACEDESC2 *DDSD)
730 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
732 WINED3DDISPLAYMODE Mode;
734 TRACE("(%p)->(%p): Relay\n", This, DDSD);
736 /* This seems sane */
739 return DDERR_INVALIDPARAMS;
742 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
743 * so one method can be used for all versions (Hopefully)
745 hr = IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
750 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This, hr);
755 memset(DDSD, 0, Size);
758 DDSD->dwFlags |= DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_PITCH | DDSD_REFRESHRATE;
759 DDSD->dwWidth = Mode.Width;
760 DDSD->dwHeight = Mode.Height;
761 DDSD->u2.dwRefreshRate = 60;
762 DDSD->ddsCaps.dwCaps = 0;
763 DDSD->u4.ddpfPixelFormat.dwSize = sizeof(DDSD->u4.ddpfPixelFormat);
764 PixelFormat_WineD3DtoDD(&DDSD->u4.ddpfPixelFormat, Mode.Format);
765 DDSD->u1.lPitch = Mode.Width * DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount / 8;
769 TRACE("Returning surface desc :\n");
770 DDRAW_dump_surface_desc(DDSD);
776 /*****************************************************************************
777 * IDirectDraw7::GetFourCCCodes
779 * Returns an array of supported FourCC codes.
781 * Exists in Version 1, 2, 4 and 7
784 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
785 * of enumerated codes
786 * Codes: Pointer to an array of DWORDs where the supported codes are written
790 * Always returns DD_OK, as it's a stub for now
792 *****************************************************************************/
793 static HRESULT WINAPI
794 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7 *iface,
795 DWORD *NumCodes, DWORD *Codes)
797 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
798 FIXME("(%p)->(%p, %p): Stub!\n", This, NumCodes, Codes);
800 if(NumCodes) *NumCodes = 0;
805 /*****************************************************************************
806 * IDirectDraw7::GetMonitorFrequency
808 * Returns the monitor's frequency
810 * Exists in Version 1, 2, 4 and 7
813 * Freq: Pointer to a DWORD to write the frequency to
816 * Always returns DD_OK
818 *****************************************************************************/
819 static HRESULT WINAPI
820 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7 *iface,
823 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
824 TRACE("(%p)->(%p)\n", This, Freq);
826 /* Ideally this should be in WineD3D, as it concerns the screen setup,
827 * but for now this should make the games happy
833 /*****************************************************************************
834 * IDirectDraw7::GetVerticalBlankStatus
836 * Returns the Vertical blank status of the monitor. This should be in WineD3D
837 * too basically, but as it's a semi stub, I didn't create a function there
840 * status: Pointer to a BOOL to be filled with the vertical blank status
844 * DDERR_INVALIDPARAMS if status is NULL
846 *****************************************************************************/
847 static HRESULT WINAPI
848 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7 *iface,
851 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
852 TRACE("(%p)->(%p)\n", This, status);
854 /* This looks sane, the MSDN suggests it too */
855 if(!status) return DDERR_INVALIDPARAMS;
857 *status = This->fake_vblank;
858 This->fake_vblank = !This->fake_vblank;
862 /*****************************************************************************
863 * IDirectDraw7::GetAvailableVidMem
865 * Returns the total and free video memory
868 * Caps: Specifies the memory type asked for
869 * total: Pointer to a DWORD to be filled with the total memory
870 * free: Pointer to a DWORD to be filled with the free memory
874 * DDERR_INVALIDPARAMS of free and total are NULL
876 *****************************************************************************/
877 static HRESULT WINAPI
878 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *Caps, DWORD *total, DWORD *free)
880 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
881 TRACE("(%p)->(%p, %p, %p)\n", This, Caps, total, free);
885 TRACE("(%p) Asked for memory with description: ", This);
886 DDRAW_dump_DDSCAPS2(Caps);
890 /* Todo: System memory vs local video memory vs non-local video memory
891 * The MSDN also mentions differences between texture memory and other
892 * resources, but that's not important
895 if( (!total) && (!free) ) return DDERR_INVALIDPARAMS;
897 if(total) *total = This->total_vidmem;
898 if(free) *free = IWineD3DDevice_GetAvailableTextureMem(This->wineD3DDevice);
903 /*****************************************************************************
904 * IDirectDraw7::Initialize
906 * Initializes a DirectDraw interface.
909 * GUID: Interface identifier. Well, don't know what this is really good
913 * Returns DD_OK on the first call,
914 * DDERR_ALREADYINITIALIZED on repeated calls
916 *****************************************************************************/
917 static HRESULT WINAPI
918 IDirectDrawImpl_Initialize(IDirectDraw7 *iface,
921 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
922 TRACE("(%p)->(%s): No-op\n", This, debugstr_guid(Guid));
924 if(This->initialized)
926 return DDERR_ALREADYINITIALIZED;
934 /*****************************************************************************
935 * IDirectDraw7::FlipToGDISurface
937 * "Makes the surface that the GDI writes to the primary surface"
938 * Looks like some windows specific thing we don't have to care about.
939 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
940 * show error boxes ;)
941 * Well, just return DD_OK.
944 * Always returns DD_OK
946 *****************************************************************************/
947 static HRESULT WINAPI
948 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7 *iface)
950 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
951 TRACE("(%p)\n", This);
956 /*****************************************************************************
957 * IDirectDraw7::WaitForVerticalBlank
959 * This method allows applications to get in sync with the vertical blank
961 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
962 * redraw the screen, most likely because of this stub
965 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
966 * or DDWAITVB_BLOCKEND
967 * h: Not used, according to MSDN
970 * Always returns DD_OK
972 *****************************************************************************/
973 static HRESULT WINAPI
974 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7 *iface,
978 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
979 FIXME("(%p)->(%x,%p): Stub\n", This, Flags, h);
981 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
982 if(Flags & DDWAITVB_BLOCKBEGINEVENT)
983 return DDERR_UNSUPPORTED; /* unchecked */
988 /*****************************************************************************
989 * IDirectDraw7::GetScanLine
991 * Returns the scan line that is being drawn on the monitor
994 * Scanline: Address to write the scan line value to
997 * Always returns DD_OK
999 *****************************************************************************/
1000 static HRESULT WINAPI IDirectDrawImpl_GetScanLine(IDirectDraw7 *iface, DWORD *Scanline)
1002 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1003 static BOOL hide = FALSE;
1004 WINED3DDISPLAYMODE Mode;
1006 /* This function is called often, so print the fixme only once */
1009 FIXME("(%p)->(%p): Semi-Stub\n", This, Scanline);
1013 IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
1017 /* Fake the line sweeping of the monitor */
1018 /* FIXME: We should synchronize with a source to keep the refresh rate */
1019 *Scanline = This->cur_scanline++;
1020 /* Assume 20 scan lines in the vertical blank */
1021 if (This->cur_scanline >= Mode.Height + 20)
1022 This->cur_scanline = 0;
1027 /*****************************************************************************
1028 * IDirectDraw7::TestCooperativeLevel
1030 * Informs the application about the state of the video adapter, depending
1031 * on the cooperative level
1034 * DD_OK if the device is in a sane state
1035 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1036 * if the state is not correct(See below)
1038 *****************************************************************************/
1039 static HRESULT WINAPI
1040 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7 *iface)
1042 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1044 TRACE("(%p)\n", This);
1046 /* Description from MSDN:
1047 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1048 * away from the app with e.g. alt-tab. Windowed apps receive
1049 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1050 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1051 * when the video mode has changed
1054 hr = IWineD3DDevice_TestCooperativeLevel(This->wineD3DDevice);
1056 /* Fix the result value. These values are mapped from their
1061 case WINED3DERR_DEVICELOST:
1062 if(This->cooperative_level & DDSCL_EXCLUSIVE)
1064 return DDERR_NOEXCLUSIVEMODE;
1068 return DDERR_EXCLUSIVEMODEALREADYSET;
1071 case WINED3DERR_DEVICENOTRESET:
1077 case WINED3DERR_DRIVERINTERNALERROR:
1079 ERR("(%p) Unexpected return value %08x from wineD3D, "
1080 " returning DD_OK\n", This, hr);
1086 /*****************************************************************************
1087 * IDirectDraw7::GetGDISurface
1089 * Returns the surface that GDI is treating as the primary surface.
1090 * For Wine this is the front buffer
1093 * GDISurface: Address to write the surface pointer to
1096 * DD_OK if the surface was found
1097 * DDERR_NOTFOUND if the GDI surface wasn't found
1099 *****************************************************************************/
1100 static HRESULT WINAPI
1101 IDirectDrawImpl_GetGDISurface(IDirectDraw7 *iface,
1102 IDirectDrawSurface7 **GDISurface)
1104 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1105 IWineD3DSurface *Surf;
1106 IDirectDrawSurface7 *ddsurf;
1109 TRACE("(%p)->(%p)\n", This, GDISurface);
1111 /* Get the back buffer from the wineD3DDevice and search its
1112 * attached surfaces for the front buffer
1114 hr = IWineD3DDevice_GetBackBuffer(This->wineD3DDevice,
1116 0, /* first back buffer*/
1117 WINED3DBACKBUFFER_TYPE_MONO,
1120 if( (hr != D3D_OK) ||
1123 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1124 return DDERR_NOTFOUND;
1127 /* GetBackBuffer AddRef()ed the surface, release it */
1128 IWineD3DSurface_Release(Surf);
1130 IWineD3DSurface_GetParent(Surf,
1131 (IUnknown **) &ddsurf);
1132 IDirectDrawSurface7_Release(ddsurf); /* For the GetParent */
1134 /* Find the front buffer */
1135 ddsCaps.dwCaps = DDSCAPS_FRONTBUFFER;
1136 hr = IDirectDrawSurface7_GetAttachedSurface(ddsurf,
1141 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr);
1144 /* The AddRef is OK this time */
1148 /*****************************************************************************
1149 * IDirectDrawImpl_EnumDisplayModesCB
1151 * Callback function for IDirectDraw7::EnumDisplayModes. Translates
1152 * the wineD3D values to ddraw values and calls the application callback
1155 * device: The IDirectDraw7 interface to the current device
1156 * With, Height, Pixelformat, Refresh: Enumerated display mode
1157 * context: the context pointer passed to IWineD3DDevice::EnumDisplayModes
1160 * The return value from the application callback
1162 *****************************************************************************/
1163 static HRESULT WINAPI
1164 IDirectDrawImpl_EnumDisplayModesCB(IUnknown *pDevice,
1167 WINED3DFORMAT Pixelformat,
1171 DDSURFACEDESC2 callback_sd;
1172 EnumDisplayModesCBS *cbs = (EnumDisplayModesCBS *) context;
1174 memset(&callback_sd, 0, sizeof(callback_sd));
1175 callback_sd.dwSize = sizeof(callback_sd);
1176 callback_sd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1178 callback_sd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH;
1181 callback_sd.dwFlags |= DDSD_REFRESHRATE;
1182 callback_sd.u2.dwRefreshRate = 60.0;
1185 callback_sd.dwHeight = Height;
1186 callback_sd.dwWidth = Width;
1188 PixelFormat_WineD3DtoDD(&callback_sd.u4.ddpfPixelFormat, Pixelformat);
1189 return cbs->callback(&callback_sd, cbs->context);
1192 /*****************************************************************************
1193 * IDirectDraw7::EnumDisplayModes
1195 * Enumerates the supported Display modes. The modes can be filtered with
1196 * the DDSD parameter.
1199 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1200 * DDSD: Surface description to filter the modes
1201 * Context: Pointer passed back to the callback function
1202 * cb: Application-provided callback function
1206 * DDERR_INVALIDPARAMS if the callback wasn't set
1208 *****************************************************************************/
1209 static HRESULT WINAPI
1210 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7 *iface,
1212 DDSURFACEDESC2 *DDSD,
1214 LPDDENUMMODESCALLBACK2 cb)
1216 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1217 UINT Width = 0, Height = 0;
1218 WINED3DFORMAT pixelformat = WINED3DFMT_UNKNOWN;
1219 EnumDisplayModesCBS cbs;
1221 TRACE("(%p)->(%p,%p,%p): Relay\n", This, DDSD, Context, cb);
1223 /* This looks sane */
1224 if(!cb) return DDERR_INVALIDPARAMS;
1226 /* The private callback structure */
1228 cbs.context = Context;
1232 if (DDSD->dwFlags & DDSD_WIDTH)
1233 Width = DDSD->dwWidth;
1234 if (DDSD->dwFlags & DDSD_HEIGHT)
1235 Height = DDSD->dwHeight;
1236 if ((DDSD->dwFlags & DDSD_PIXELFORMAT) && (DDSD->u4.ddpfPixelFormat.dwFlags & DDPF_RGB) )
1237 pixelformat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1240 return IWineD3DDevice_EnumDisplayModes(This->wineD3DDevice,
1242 Width, Height, pixelformat,
1244 IDirectDrawImpl_EnumDisplayModesCB);
1247 /*****************************************************************************
1248 * IDirectDraw7::EvaluateMode
1250 * Used with IDirectDraw7::StartModeTest to test video modes.
1251 * EvaluateMode is used to pass or fail a mode, and continue with the next
1255 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1256 * Timeout: Returns the amount of seconds left before the mode would have
1257 * been failed automatically
1260 * This implementation always DD_OK, because it's a stub
1262 *****************************************************************************/
1263 static HRESULT WINAPI
1264 IDirectDrawImpl_EvaluateMode(IDirectDraw7 *iface,
1268 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1269 FIXME("(%p)->(%d,%p): Stub!\n", This, Flags, Timeout);
1271 /* When implementing this, implement it in WineD3D */
1276 /*****************************************************************************
1277 * IDirectDraw7::GetDeviceIdentifier
1279 * Returns the device identifier, which gives information about the driver
1280 * Our device identifier is defined at the beginning of this file.
1283 * DDDI: Address for the returned structure
1284 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1287 * On success it returns DD_OK
1288 * DDERR_INVALIDPARAMS if DDDI is NULL
1290 *****************************************************************************/
1291 static HRESULT WINAPI
1292 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7 *iface,
1293 DDDEVICEIDENTIFIER2 *DDDI,
1296 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1297 TRACE("(%p)->(%p,%08x)\n", This, DDDI, Flags);
1300 return DDERR_INVALIDPARAMS;
1302 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1303 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1304 * to any modern hardware, nor is it interesting for Wine, so ignore it
1307 *DDDI = deviceidentifier;
1311 /*****************************************************************************
1312 * IDirectDraw7::GetSurfaceFromDC
1314 * Returns the Surface for a GDI device context handle.
1315 * Is this related to IDirectDrawSurface::GetDC ???
1318 * hdc: hdc to return the surface for
1319 * Surface: Address to write the surface pointer to
1322 * Always returns DD_OK because it's a stub
1324 *****************************************************************************/
1325 static HRESULT WINAPI
1326 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7 *iface,
1328 IDirectDrawSurface7 **Surface)
1330 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1331 FIXME("(%p)->(%p,%p): Stub!\n", This, hdc, Surface);
1333 /* Implementation idea if needed: Loop through all surfaces and compare
1334 * their hdc with hdc. Implement it in WineD3D! */
1335 return DDERR_NOTFOUND;
1338 /*****************************************************************************
1339 * IDirectDraw7::RestoreAllSurfaces
1341 * Calls the restore method of all surfaces
1346 * Always returns DD_OK because it's a stub
1348 *****************************************************************************/
1349 static HRESULT WINAPI
1350 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7 *iface)
1352 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1353 FIXME("(%p): Stub\n", This);
1355 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1356 * get their parent and call their restore method. Do not implement
1357 * it in WineD3D, as restoring a surface means re-creating the
1363 /*****************************************************************************
1364 * IDirectDraw7::StartModeTest
1366 * Tests the specified video modes to update the system registry with
1367 * refresh rate information. StartModeTest starts the mode test,
1368 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1369 * isn't called within 15 seconds, the mode is failed automatically
1371 * As refresh rates are handled by the X server, I don't think this
1372 * Method is important
1375 * Modes: An array of mode specifications
1376 * NumModes: The number of modes in Modes
1377 * Flags: Some flags...
1380 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1381 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1384 *****************************************************************************/
1385 static HRESULT WINAPI
1386 IDirectDrawImpl_StartModeTest(IDirectDraw7 *iface,
1391 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1392 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This, Modes, NumModes, Flags);
1394 /* This looks sane */
1395 if( (!Modes) || (NumModes == 0) ) return DDERR_INVALIDPARAMS;
1397 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1398 * As it is not, DDERR_TESTFINISHED is returned
1399 * (hopefully that's correct
1401 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1402 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1408 /*****************************************************************************
1409 * IDirectDrawImpl_RecreateSurfacesCallback
1411 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1412 * It re-recreates the WineD3DSurface. It's pretty straightforward
1414 *****************************************************************************/
1416 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
1417 DDSURFACEDESC2 *desc,
1420 IDirectDrawSurfaceImpl *surfImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1421 IDirectDrawSurface7,
1423 IDirectDrawImpl *This = surfImpl->ddraw;
1425 IParentImpl *parImpl = NULL;
1426 IWineD3DSurface *wineD3DSurface;
1430 WINED3DSURFACE_DESC Desc;
1431 WINED3DFORMAT Format;
1432 WINED3DRESOURCETYPE Type;
1437 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1438 DWORD MultiSampleQuality;
1442 TRACE("(%p): Enumerated Surface %p\n", This, surfImpl);
1444 /* For the enumeration */
1445 IDirectDrawSurface7_Release(surf);
1447 if(surfImpl->ImplType == This->ImplType) return DDENUMRET_OK; /* Continue */
1449 /* Get the objects */
1450 wineD3DSurface = surfImpl->WineD3DSurface;
1451 IWineD3DSurface_GetParent(wineD3DSurface, &Parent);
1452 IUnknown_Release(Parent); /* For the getParent */
1454 /* Is the parent an IParent interface? */
1455 if(IUnknown_QueryInterface(Parent, &IID_IParent, &tmp) == S_OK)
1457 /* It is a IParent interface! */
1458 IUnknown_Release(Parent); /* For the QueryInterface */
1459 parImpl = ICOM_OBJECT(IParentImpl, IParent, Parent);
1460 /* Release the reference the parent interface is holding */
1461 IWineD3DSurface_Release(wineD3DSurface);
1465 /* Get the surface properties */
1466 Desc.Format = &Format;
1468 Desc.Usage = &Usage;
1471 Desc.MultiSampleType = &MultiSampleType;
1472 Desc.MultiSampleQuality = &MultiSampleQuality;
1473 Desc.Width = &Width;
1474 Desc.Height = &Height;
1476 hr = IWineD3DSurface_GetDesc(wineD3DSurface, &Desc);
1477 if(hr != D3D_OK) return hr;
1479 /* Create the new surface */
1480 hr = IWineD3DDevice_CreateSurface(This->wineD3DDevice,
1481 Width, Height, Format,
1482 TRUE /* Lockable */,
1483 FALSE /* Discard */,
1484 surfImpl->mipmap_level,
1485 &surfImpl->WineD3DSurface,
1491 0 /* SharedHandle */,
1498 /* Update the IParent if it exists */
1501 parImpl->child = (IUnknown *) surfImpl->WineD3DSurface;
1502 /* Add a reference for the IParent */
1503 IWineD3DSurface_AddRef(surfImpl->WineD3DSurface);
1505 /* TODO: Copy the surface content, except for render targets */
1507 if(IWineD3DSurface_Release(wineD3DSurface) == 0)
1508 TRACE("Surface released successful, next surface\n");
1510 ERR("Something's still holding the old WineD3DSurface\n");
1512 surfImpl->ImplType = This->ImplType;
1514 return DDENUMRET_OK;
1517 /*****************************************************************************
1518 * IDirectDrawImpl_RecreateAllSurfaces
1520 * A function, that converts all wineD3DSurfaces to the new implementation type
1521 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1522 * new WineD3DSurface, copies the content and releases the old surface
1524 *****************************************************************************/
1526 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl *This)
1528 DDSURFACEDESC2 desc;
1529 TRACE("(%p): Switch to implementation %d\n", This, This->ImplType);
1531 if(This->ImplType != SURFACE_OPENGL && This->d3d_initialized)
1533 /* Should happen almost never */
1534 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This);
1536 IWineD3DDevice_Uninit3D(This->wineD3DDevice, D3D7CB_DestroyDepthStencilSurface, D3D7CB_DestroySwapChain);
1538 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1540 memset(&desc, 0, sizeof(desc));
1541 desc.dwSize = sizeof(desc);
1543 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This, IDirectDraw7),
1547 IDirectDrawImpl_RecreateSurfacesCallback);
1550 /*****************************************************************************
1551 * D3D7CB_CreateSurface
1553 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1554 * correct mipmap sublevel, and returns it to WineD3D.
1555 * The surfaces are created already by IDirectDraw7::CreateSurface
1558 * With, Height: With and height of the surface
1559 * Format: The requested format
1560 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1561 * level: The mipmap level
1562 * Surface: Pointer to pass the created surface back at
1563 * SharedHandle: NULL
1568 *****************************************************************************/
1569 static HRESULT WINAPI
1570 D3D7CB_CreateSurface(IUnknown *device,
1571 IUnknown *pSuperior,
1572 UINT Width, UINT Height,
1573 WINED3DFORMAT Format,
1574 DWORD Usage, WINED3DPOOL Pool, UINT level,
1575 IWineD3DSurface **Surface,
1576 HANDLE *SharedHandle)
1578 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
1579 IDirectDrawSurfaceImpl *surf = This->tex_root;
1581 TRACE("(%p) call back. surf=%p\n", device, surf);
1583 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1584 for(i = 0; i < level; i++)
1585 surf = surf->next_complex;
1587 /* Return the surface */
1588 *Surface = surf->WineD3DSurface;
1590 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface, surf);
1594 ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
1595 IUnknown* swapChainParent;
1596 TRACE("(%p) call back\n", pSwapChain);
1598 IWineD3DSwapChain_GetParent(pSwapChain, &swapChainParent);
1599 IUnknown_Release(swapChainParent);
1600 return IUnknown_Release(swapChainParent);
1603 ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
1604 IUnknown* surfaceParent;
1605 TRACE("(%p) call back\n", pSurface);
1607 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1608 IUnknown_Release(surfaceParent);
1609 return IUnknown_Release(surfaceParent);
1612 /*****************************************************************************
1613 * IDirectDrawImpl_CreateNewSurface
1615 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1616 * with the passed parameters.
1619 * DDSD: Description of the surface to create
1620 * Surf: Address to store the interface pointer at
1625 *****************************************************************************/
1626 static HRESULT WINAPI
1627 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl *This,
1628 DDSURFACEDESC2 *pDDSD,
1629 IDirectDrawSurfaceImpl **ppSurf,
1633 UINT Width = 0, Height = 0;
1634 WINED3DFORMAT Format = WINED3DFMT_UNKNOWN;
1635 WINED3DRESOURCETYPE ResType = WINED3DRTYPE_SURFACE;
1637 WINED3DSURFTYPE ImplType = This->ImplType;
1638 WINED3DSURFACE_DESC Desc;
1640 IParentImpl *parImpl = NULL;
1641 WINED3DPOOL Pool = WINED3DPOOL_DEFAULT;
1643 /* Dummies for GetDesc */
1644 WINED3DPOOL dummy_d3dpool;
1645 WINED3DMULTISAMPLE_TYPE dummy_mst;
1649 if (TRACE_ON(ddraw))
1651 TRACE(" (%p) Requesting surface desc :\n", This);
1652 DDRAW_dump_surface_desc(pDDSD);
1655 /* Select the surface type, if it wasn't choosen yet */
1656 if(ImplType == SURFACE_UNKNOWN)
1658 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1659 if(pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE)
1661 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This);
1662 ImplType = SURFACE_OPENGL;
1665 /* Otherwise use GDI surfaces for now */
1668 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This);
1669 ImplType = SURFACE_GDI;
1672 /* Policy if all surface implementations are available:
1673 * First, check if a default type was set with winecfg. If not,
1674 * try Xrender surfaces, and use them if they work. Next, check if
1675 * accelerated OpenGL is available, and use GL surfaces in this
1676 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1677 * was created, always use OpenGL surfaces.
1679 * (Note: Xrender surfaces are not implemented for now, the
1680 * unaccelerated implementation uses GDI to render in Software)
1683 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1684 * be re-created. This could be done with IDirectDrawSurface7::Restore
1686 This->ImplType = ImplType;
1690 if((pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE ) &&
1691 (This->ImplType != SURFACE_OPENGL ) && DefaultSurfaceType == SURFACE_UNKNOWN)
1693 /* We have to change to OpenGL,
1694 * and re-create all WineD3DSurfaces
1696 ImplType = SURFACE_OPENGL;
1697 This->ImplType = ImplType;
1698 TRACE("(%p) Re-creating all surfaces\n", This);
1699 IDirectDrawImpl_RecreateAllSurfaces(This);
1700 TRACE("(%p) Done recreating all surfaces\n", This);
1702 else if(This->ImplType != SURFACE_OPENGL)
1704 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1705 /* Do not fail surface creation, only fail 3D device creation */
1709 /* Get the correct wined3d usage */
1710 if (pDDSD->ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
1711 DDSCAPS_BACKBUFFER |
1712 DDSCAPS_3DDEVICE ) )
1714 Usage |= WINED3DUSAGE_RENDERTARGET;
1716 pDDSD->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY |
1718 DDSCAPS_LOCALVIDMEM;
1720 if (pDDSD->ddsCaps.dwCaps & (DDSCAPS_OVERLAY))
1722 Usage |= WINED3DUSAGE_OVERLAY;
1724 if(This->depthstencil)
1726 /* The depth stencil creation callback sets this flag.
1727 * Set the WineD3D usage to let it know that it's a depth
1730 Usage |= WINED3DUSAGE_DEPTHSTENCIL;
1732 if(pDDSD->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
1734 Pool = WINED3DPOOL_SYSTEMMEM;
1736 else if(pDDSD->ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
1738 Pool = WINED3DPOOL_MANAGED;
1741 Format = PixelFormat_DD2WineD3D(&pDDSD->u4.ddpfPixelFormat);
1742 if(Format == WINED3DFMT_UNKNOWN)
1744 ERR("Unsupported / Unknown pixelformat\n");
1745 return DDERR_INVALIDPIXELFORMAT;
1748 /* Create the Surface object */
1749 *ppSurf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawSurfaceImpl));
1752 ERR("(%p) Error allocating memory for a surface\n", This);
1753 return DDERR_OUTOFVIDEOMEMORY;
1755 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawSurface7, IDirectDrawSurface7_Vtbl);
1756 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawSurface3, IDirectDrawSurface3_Vtbl);
1757 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawGammaControl, IDirectDrawGammaControl_Vtbl);
1758 ICOM_INIT_INTERFACE(*ppSurf, IDirect3DTexture2, IDirect3DTexture2_Vtbl);
1759 ICOM_INIT_INTERFACE(*ppSurf, IDirect3DTexture, IDirect3DTexture1_Vtbl);
1761 (*ppSurf)->version = 7;
1762 (*ppSurf)->ddraw = This;
1763 (*ppSurf)->surface_desc.dwSize = sizeof(DDSURFACEDESC2);
1764 (*ppSurf)->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1765 DD_STRUCT_COPY_BYSIZE(&(*ppSurf)->surface_desc, pDDSD);
1767 /* Surface attachments */
1768 (*ppSurf)->next_attached = NULL;
1769 (*ppSurf)->first_attached = *ppSurf;
1771 (*ppSurf)->next_complex = NULL;
1772 (*ppSurf)->first_complex = *ppSurf;
1774 /* Needed to re-create the surface on an implementation change */
1775 (*ppSurf)->ImplType = ImplType;
1777 /* For D3DDevice creation */
1778 (*ppSurf)->isRenderTarget = FALSE;
1780 /* A trace message for debugging */
1781 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This, *ppSurf);
1783 if(pDDSD->ddsCaps.dwCaps & ( DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE) )
1785 /* Render targets and textures need a IParent interface,
1786 * because WineD3D will destroy them when the swapchain
1789 parImpl = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl));
1792 ERR("Out of memory when allocating memory for a IParent implementation\n");
1793 return DDERR_OUTOFMEMORY;
1796 ICOM_INIT_INTERFACE(parImpl, IParent, IParent_Vtbl);
1797 Parent = (IUnknown *) ICOM_INTERFACE(parImpl, IParent);
1798 TRACE("Using IParent interface %p as parent\n", parImpl);
1802 /* Use the surface as parent */
1803 Parent = (IUnknown *) ICOM_INTERFACE(*ppSurf, IDirectDrawSurface7);
1804 TRACE("Using Surface interface %p as parent\n", *ppSurf);
1807 /* Now create the WineD3D Surface */
1808 hr = IWineD3DDevice_CreateSurface(This->wineD3DDevice,
1812 TRUE /* Lockable */,
1813 FALSE /* Discard */,
1815 &(*ppSurf)->WineD3DSurface,
1818 WINED3DMULTISAMPLE_NONE,
1819 0 /* MultiSampleQuality */,
1820 0 /* SharedHandle */,
1826 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr);
1830 /* Set the child of the parent implementation if it exists */
1833 parImpl->child = (IUnknown *) (*ppSurf)->WineD3DSurface;
1834 /* The IParent releases the WineD3DSurface, and
1835 * the ddraw surface does that too. Hold a reference
1837 IWineD3DSurface_AddRef((*ppSurf)->WineD3DSurface);
1840 /* Increase the surface counter, and attach the surface */
1841 InterlockedIncrement(&This->surfaces);
1842 list_add_head(&This->surface_list, &(*ppSurf)->surface_list_entry);
1844 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1845 * But this could also be delegated to WineDDraw, as it keeps track of all its
1846 * resources. Not implemented for now, as there are more important things ;)
1849 /* Get the pixel format of the WineD3DSurface and store it.
1850 * Don't use the Format choosen above, WineD3D might have
1853 Desc.Format = &Format;
1854 Desc.Type = &ResType;
1855 Desc.Usage = &Usage;
1856 Desc.Pool = &dummy_d3dpool;
1857 Desc.Size = &dummy_uint;
1858 Desc.MultiSampleType = &dummy_mst;
1859 Desc.MultiSampleQuality = &dummy_dword;
1860 Desc.Width = &Width;
1861 Desc.Height = &Height;
1863 (*ppSurf)->surface_desc.dwFlags |= DDSD_PIXELFORMAT;
1864 hr = IWineD3DSurface_GetDesc((*ppSurf)->WineD3DSurface, &Desc);
1867 ERR("IWineD3DSurface::GetDesc failed\n");
1868 IDirectDrawSurface7_Release( (IDirectDrawSurface7 *) *ppSurf);
1872 if(Format == WINED3DFMT_UNKNOWN)
1874 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
1876 PixelFormat_WineD3DtoDD( &(*ppSurf)->surface_desc.u4.ddpfPixelFormat, Format);
1878 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
1879 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
1880 * WineD3DDevice might not be useable for 3D yet, so an extra method was created
1882 (*ppSurf)->surface_desc.dwFlags |= DDSD_PITCH;
1883 (*ppSurf)->surface_desc.u1.lPitch = IWineD3DSurface_GetPitch((*ppSurf)->WineD3DSurface);
1885 /* Application passed a color key? Set it! */
1886 if(pDDSD->dwFlags & DDSD_CKDESTOVERLAY)
1888 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1890 &pDDSD->u3.ddckCKDestOverlay);
1892 if(pDDSD->dwFlags & DDSD_CKDESTBLT)
1894 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1896 &pDDSD->ddckCKDestBlt);
1898 if(pDDSD->dwFlags & DDSD_CKSRCOVERLAY)
1900 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1902 &pDDSD->ddckCKSrcOverlay);
1904 if(pDDSD->dwFlags & DDSD_CKSRCBLT)
1906 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1908 &pDDSD->ddckCKSrcBlt);
1910 if ( pDDSD->dwFlags & DDSD_LPSURFACE)
1912 hr = IWineD3DSurface_SetMem((*ppSurf)->WineD3DSurface, pDDSD->lpSurface);
1913 if(hr != WINED3D_OK)
1915 /* No need for a trace here, wined3d does that for us */
1916 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf), IDirectDrawSurface7));
1924 /*****************************************************************************
1925 * IDirectDraw7::CreateSurface
1927 * Creates a new IDirectDrawSurface object and returns its interface.
1929 * The surface connections with wined3d are a bit tricky. Basically it works
1932 * |------------------------| |-----------------|
1933 * | DDraw surface | | WineD3DSurface |
1935 * | WineD3DSurface |-------------->| |
1936 * | Child |<------------->| Parent |
1937 * |------------------------| |-----------------|
1939 * The DDraw surface is the parent of the wined3d surface, and it releases
1940 * the WineD3DSurface when the ddraw surface is destroyed.
1942 * However, for all surfaces which can be in a container in WineD3D,
1943 * we have to do this. These surfaces are ususally complex surfaces,
1944 * so this concerns primary surfaces with a front and a back buffer,
1947 * |------------------------| |-----------------|
1948 * | DDraw surface | | Containter |
1950 * | Child |<------------->| Parent |
1951 * | Texture |<------------->| |
1952 * | WineD3DSurface |<----| | Levels |<--|
1953 * | Complex connection | | | | |
1954 * |------------------------| | |-----------------| |
1958 * | |------------------| | |-----------------| |
1959 * | | IParent | |-------->| WineD3DSurface | |
1961 * | | Child |<------------->| Parent | |
1962 * | | | | Container |<--|
1963 * | |------------------| |-----------------| |
1965 * | |----------------------| |
1966 * | | DDraw surface 2 | |
1968 * |<->| Complex root Child | |
1970 * | | WineD3DSurface |<----| |
1971 * | |----------------------| | |
1973 * | |---------------------| | |-----------------| |
1974 * | | IParent | |----->| WineD3DSurface | |
1976 * | | Child |<---------->| Parent | |
1977 * | |---------------------| | Container |<--|
1978 * | |-----------------| |
1980 * | ---More surfaces can follow--- |
1982 * The reason is that the IWineD3DSwapchain(render target container)
1983 * and the IWineD3DTexure(Texture container) release the parents
1984 * of their surface's children, but by releasing the complex root
1985 * the surfaces which are complexly attached to it are destroyed
1986 * too. See IDirectDrawSurface::Release for a more detailed
1990 * DDSD: Description of the surface to create
1991 * Surf: Address to store the interface pointer at
1992 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
1993 * aggregation, so it has to be NULL
1997 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
1998 * DDERR_* if an error occurs
2000 *****************************************************************************/
2001 static HRESULT WINAPI
2002 IDirectDrawImpl_CreateSurface(IDirectDraw7 *iface,
2003 DDSURFACEDESC2 *DDSD,
2004 IDirectDrawSurface7 **Surf,
2007 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2008 IDirectDrawSurfaceImpl *object = NULL;
2010 LONG extra_surfaces = 0, i;
2011 DDSURFACEDESC2 desc2;
2013 WINED3DDISPLAYMODE Mode;
2015 TRACE("(%p)->(%p,%p,%p)\n", This, DDSD, Surf, UnkOuter);
2017 /* Some checks before we start */
2018 if (TRACE_ON(ddraw))
2020 TRACE(" (%p) Requesting surface desc :\n", This);
2021 DDRAW_dump_surface_desc(DDSD);
2024 if (UnkOuter != NULL)
2026 FIXME("(%p) : outer != NULL?\n", This);
2027 return CLASS_E_NOAGGREGATION; /* unchecked */
2030 if (!(DDSD->dwFlags & DDSD_CAPS))
2032 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2033 DDSD->dwFlags |= DDSD_CAPS;
2035 if (DDSD->ddsCaps.dwCaps == 0)
2037 /* This has been checked on real Windows */
2038 DDSD->ddsCaps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
2041 if (DDSD->ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD)
2043 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2044 DDSD->dwFlags &= ~DDSD_LPSURFACE;
2047 if ((DDSD->dwFlags & DDSD_LPSURFACE) && (DDSD->lpSurface == NULL))
2049 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2050 WARN("(%p) Null surface pointer specified, ignore it!\n", This);
2051 DDSD->dwFlags &= ~DDSD_LPSURFACE;
2054 if((DDSD->ddsCaps.dwCaps & (DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE)) == (DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE) &&
2055 !(This->cooperative_level & DDSCL_EXCLUSIVE))
2057 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This);
2059 return DDERR_NOEXCLUSIVEMODE;
2064 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This);
2065 return E_POINTER; /* unchecked */
2068 /* According to the msdn this flag is ignored by CreateSurface */
2069 if (DDSD->dwSize >= sizeof(DDSURFACEDESC2))
2070 DDSD->ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
2072 /* Modify some flags */
2073 memset(&desc2, 0, sizeof(desc2));
2074 desc2.dwSize = sizeof(desc2); /* For the struct copy */
2075 DD_STRUCT_COPY_BYSIZE(&desc2, DDSD);
2076 desc2.dwSize = sizeof(desc2); /* To override a possibly smaller size */
2077 desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT); /* Just to be sure */
2079 /* Get the video mode from WineD3D - we will need it */
2080 hr = IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
2081 0, /* Swapchain 0 */
2085 ERR("Failed to read display mode from wined3d\n");
2086 switch(This->orig_bpp)
2089 Mode.Format = WINED3DFMT_P8;
2093 Mode.Format = WINED3DFMT_X1R5G5B5;
2097 Mode.Format = WINED3DFMT_R5G6B5;
2101 Mode.Format = WINED3DFMT_R8G8B8;
2105 Mode.Format = WINED3DFMT_X8R8G8B8;
2108 Mode.Width = This->orig_width;
2109 Mode.Height = This->orig_height;
2112 /* No pixelformat given? Use the current screen format */
2113 if(!(desc2.dwFlags & DDSD_PIXELFORMAT))
2115 desc2.dwFlags |= DDSD_PIXELFORMAT;
2116 desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT);
2118 /* Wait: It could be a Z buffer */
2119 if(desc2.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
2121 switch(desc2.u2.dwMipMapCount) /* Who had this glorious idea? */
2124 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D15S1);
2127 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D16);
2130 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D24X8);
2133 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D32);
2136 ERR("Unknown Z buffer bit depth\n");
2141 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, Mode.Format);
2145 /* No Width or no Height? Use the current window size or
2146 * the original screen size
2148 if(!(desc2.dwFlags & DDSD_WIDTH) ||
2149 !(desc2.dwFlags & DDSD_HEIGHT) )
2153 /* Fallback: From WineD3D / original mode */
2154 desc2.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
2155 desc2.dwWidth = Mode.Width;
2156 desc2.dwHeight = Mode.Height;
2158 hr = IWineD3DDevice_GetHWND(This->wineD3DDevice,
2160 if( (hr == D3D_OK) && (window != 0) )
2163 if(GetWindowRect(window, &rect) )
2165 /* This is a hack until I find a better solution */
2166 if( (rect.right - rect.left) <= 1 ||
2167 (rect.bottom - rect.top) <= 1 )
2169 FIXME("Wanted to get surface dimensions from window %p, but it has only "
2170 "a size of %dx%d. Using full screen dimensions\n",
2171 window, rect.right - rect.left, rect.bottom - rect.top);
2175 /* Not sure if this is correct */
2176 desc2.dwWidth = rect.right - rect.left;
2177 desc2.dwHeight = rect.bottom - rect.top;
2178 TRACE("Using window %p's dimensions: %dx%d\n", window, desc2.dwWidth, desc2.dwHeight);
2184 /* Mipmap count fixes */
2185 if(desc2.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2187 if(desc2.ddsCaps.dwCaps & DDSCAPS_COMPLEX)
2189 if(desc2.dwFlags & DDSD_MIPMAPCOUNT)
2191 /* Mipmap count is given, nothing to do */
2195 /* Undocumented feature: Create sublevels until
2196 * either the width or the height is 1
2198 DWORD min = desc2.dwWidth < desc2.dwHeight ?
2199 desc2.dwWidth : desc2.dwHeight;
2200 desc2.u2.dwMipMapCount = 0;
2203 desc2.u2.dwMipMapCount += 1;
2210 /* Not-complex mipmap -> Mipmapcount = 1 */
2211 desc2.u2.dwMipMapCount = 1;
2213 extra_surfaces = desc2.u2.dwMipMapCount - 1;
2215 /* There's a mipmap count in the created surface in any case */
2216 desc2.dwFlags |= DDSD_MIPMAPCOUNT;
2218 /* If no mipmap is given, the texture has only one level */
2220 /* The first surface is a front buffer, the back buffer is created afterwards */
2221 if( (desc2.dwFlags & DDSD_CAPS) && (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) )
2223 desc2.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
2226 /* Create the first surface */
2227 hr = IDirectDrawImpl_CreateNewSurface(This, &desc2, &object, 0);
2230 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr);
2234 *Surf = ICOM_INTERFACE(object, IDirectDrawSurface7);
2236 /* Create Additional surfaces if necessary
2237 * This applies to Primary surfaces which have a back buffer count
2238 * set, but not to mipmap textures. In case of Mipmap textures,
2239 * wineD3D takes care of the creation of additional surfaces
2241 if(DDSD->dwFlags & DDSD_BACKBUFFERCOUNT)
2243 extra_surfaces = DDSD->dwBackBufferCount;
2244 desc2.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; /* It's not a front buffer */
2245 desc2.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
2247 /* Set the DDSCAPS2_MIPMAPSUBLEVEL flag on mipmap sublevels according to the msdn */
2248 if(DDSD->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2250 desc2.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
2253 for(i = 0; i < extra_surfaces; i++)
2255 IDirectDrawSurfaceImpl *object2 = NULL;
2256 IDirectDrawSurfaceImpl *iterator;
2258 /* increase the mipmap level, but only if a mipmap is created
2259 * In this case, also halve the size
2261 if(DDSD->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2264 if(desc2.dwWidth > 1) desc2.dwWidth /= 2;
2265 if(desc2.dwHeight > 1) desc2.dwHeight /= 2;
2268 hr = IDirectDrawImpl_CreateNewSurface(This,
2274 /* This destroys and possibly created surfaces too */
2275 IDirectDrawSurface_Release( ICOM_INTERFACE(object, IDirectDrawSurface7) );
2279 /* Add the new surface to the complex attachment list */
2280 object2->first_complex = object;
2281 object2->next_complex = NULL;
2283 while(iterator->next_complex) iterator = iterator->next_complex;
2284 iterator->next_complex = object2;
2286 /* Remove the (possible) back buffer cap from the new surface description,
2287 * because only one surface in the flipping chain is a back buffer, one
2288 * is a front buffer, the others are just primary surfaces.
2290 desc2.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER;
2293 /* Addref the ddraw interface to keep an reference for each surface */
2294 IDirectDraw7_AddRef(iface);
2295 object->ifaceToRelease = (IUnknown *) iface;
2297 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2298 * But attach the d3ddevice only if the currently created surface was
2299 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2300 * The only case I can think of where this doesn't apply is when a
2301 * 2D app was configured by the user to run with OpenGL and it didn't create
2302 * the render target as first surface. In this case the render target creation
2303 * will cause the 3D init.
2305 if( (This->ImplType == SURFACE_OPENGL) && !(This->d3d_initialized) &&
2306 desc2.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) )
2308 IDirectDrawSurfaceImpl *target = object, *surface;
2311 /* Search for the primary to use as render target */
2312 LIST_FOR_EACH(entry, &This->surface_list)
2314 surface = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
2315 if(surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
2319 TRACE("Using primary %p as render target\n", target);
2324 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This, target);
2325 hr = IDirectDrawImpl_AttachD3DDevice(This, target->first_complex);
2328 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr);
2332 /* Create a WineD3DTexture if a texture was requested */
2333 if(DDSD->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
2336 WINED3DFORMAT Format;
2337 WINED3DPOOL Pool = WINED3DPOOL_DEFAULT;
2339 This->tex_root = object;
2341 if(desc2.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2343 /* a mipmap is created, create enough levels */
2344 levels = desc2.u2.dwMipMapCount;
2348 /* No mipmap is created, create one level */
2352 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2353 if(DDSD->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
2355 Pool = WINED3DPOOL_SYSTEMMEM;
2357 /* Should I forward the MANEGED cap to the managed pool ? */
2359 /* Get the format. It's set already by CreateNewSurface */
2360 Format = PixelFormat_DD2WineD3D(&object->surface_desc.u4.ddpfPixelFormat);
2362 /* The surfaces are already created, the callback only
2363 * passes the IWineD3DSurface to WineD3D
2365 hr = IWineD3DDevice_CreateTexture( This->wineD3DDevice,
2366 DDSD->dwWidth, DDSD->dwHeight,
2367 levels, /* MipMapCount = Levels */
2371 &object->wineD3DTexture,
2372 0, /* SharedHandle */
2373 (IUnknown *) ICOM_INTERFACE(object, IDirectDrawSurface7),
2374 D3D7CB_CreateSurface );
2375 This->tex_root = NULL;
2381 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2382 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2385 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT *requested,
2386 const DDPIXELFORMAT *provided)
2388 /* Some flags must be present in both or neither for a match. */
2389 static const DWORD must_match = DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2
2390 | DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_FOURCC
2391 | DDPF_ZBUFFER | DDPF_STENCILBUFFER;
2393 if ((requested->dwFlags & provided->dwFlags) != requested->dwFlags)
2396 if ((requested->dwFlags & must_match) != (provided->dwFlags & must_match))
2399 if (requested->dwFlags & DDPF_FOURCC)
2400 if (requested->dwFourCC != provided->dwFourCC)
2403 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_ZBUFFER|DDPF_ALPHA
2404 |DDPF_LUMINANCE|DDPF_BUMPDUDV))
2405 if (requested->u1.dwRGBBitCount != provided->u1.dwRGBBitCount)
2408 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_STENCILBUFFER
2409 |DDPF_LUMINANCE|DDPF_BUMPDUDV))
2410 if (requested->u2.dwRBitMask != provided->u2.dwRBitMask)
2413 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_ZBUFFER|DDPF_BUMPDUDV))
2414 if (requested->u3.dwGBitMask != provided->u3.dwGBitMask)
2417 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2418 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_STENCILBUFFER
2420 if (requested->u4.dwBBitMask != provided->u4.dwBBitMask)
2423 if (requested->dwFlags & (DDPF_ALPHAPIXELS|DDPF_ZPIXELS))
2424 if (requested->u5.dwRGBAlphaBitMask != provided->u5.dwRGBAlphaBitMask)
2431 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2* requested,
2432 const DDSURFACEDESC2* provided)
2441 #define CMP(FLAG, FIELD) \
2442 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2443 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2445 static const struct compare_info compare[] =
2447 CMP(ALPHABITDEPTH, dwAlphaBitDepth),
2448 CMP(BACKBUFFERCOUNT, dwBackBufferCount),
2450 CMP(CKDESTBLT, ddckCKDestBlt),
2451 CMP(CKDESTOVERLAY, u3 /* ddckCKDestOverlay */),
2452 CMP(CKSRCBLT, ddckCKSrcBlt),
2453 CMP(CKSRCOVERLAY, ddckCKSrcOverlay),
2454 CMP(HEIGHT, dwHeight),
2455 CMP(LINEARSIZE, u1 /* dwLinearSize */),
2456 CMP(LPSURFACE, lpSurface),
2457 CMP(MIPMAPCOUNT, u2 /* dwMipMapCount */),
2458 CMP(PITCH, u1 /* lPitch */),
2459 /* PIXELFORMAT: manual */
2460 CMP(REFRESHRATE, u2 /* dwRefreshRate */),
2461 CMP(TEXTURESTAGE, dwTextureStage),
2462 CMP(WIDTH, dwWidth),
2463 /* ZBUFFERBITDEPTH: "obsolete" */
2470 if ((requested->dwFlags & provided->dwFlags) != requested->dwFlags)
2473 for (i=0; i < sizeof(compare)/sizeof(compare[0]); i++)
2475 if (requested->dwFlags & compare[i].flag
2476 && memcmp((const char *)provided + compare[i].offset,
2477 (const char *)requested + compare[i].offset,
2478 compare[i].size) != 0)
2482 if (requested->dwFlags & DDSD_PIXELFORMAT)
2484 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested->u4.ddpfPixelFormat,
2485 &provided->u4.ddpfPixelFormat))
2492 #undef DDENUMSURFACES_SEARCHTYPE
2493 #undef DDENUMSURFACES_MATCHTYPE
2495 /*****************************************************************************
2496 * IDirectDraw7::EnumSurfaces
2498 * Loops through all surfaces attached to this device and calls the
2499 * application callback. This can't be relayed to WineD3DDevice,
2500 * because some WineD3DSurfaces' parents are IParent objects
2503 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2504 * DDSD: Description to filter for
2505 * Context: Application-provided pointer, it's passed unmodified to the
2507 * Callback: Address to call for each surface
2510 * DDERR_INVALIDPARAMS if the callback is NULL
2513 *****************************************************************************/
2514 static HRESULT WINAPI
2515 IDirectDrawImpl_EnumSurfaces(IDirectDraw7 *iface,
2517 DDSURFACEDESC2 *DDSD,
2519 LPDDENUMSURFACESCALLBACK7 Callback)
2521 /* The surface enumeration is handled by WineDDraw,
2522 * because it keeps track of all surfaces attached to
2523 * it. The filtering is done by our callback function,
2524 * because WineDDraw doesn't handle ddraw-like surface
2527 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2528 IDirectDrawSurfaceImpl *surf;
2530 DDSURFACEDESC2 desc;
2531 struct list *entry, *entry2;
2533 all = Flags & DDENUMSURFACES_ALL;
2534 nomatch = Flags & DDENUMSURFACES_NOMATCH;
2536 TRACE("(%p)->(%x,%p,%p,%p)\n", This, Flags, DDSD, Context, Callback);
2539 return DDERR_INVALIDPARAMS;
2541 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2542 LIST_FOR_EACH_SAFE(entry, entry2, &This->surface_list)
2544 surf = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
2545 if (all || (nomatch != IDirectDrawImpl_DDSD_Match(DDSD, &surf->surface_desc)))
2547 desc = surf->surface_desc;
2548 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
2549 if(Callback( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, Context) != DDENUMRET_OK)
2556 /*****************************************************************************
2557 * D3D7CB_CreateRenderTarget
2559 * Callback called by WineD3D to create Surfaces for render target usage
2560 * This function takes the D3D target from the IDirectDrawImpl structure,
2561 * and returns the WineD3DSurface. To avoid double usage, the surface
2562 * is marked as render target afterwards
2565 * device: The WineD3DDevice's parent
2566 * Width, Height, Format: Dimensions and pixelformat of the render target
2567 * Ignored, because the surface already exists
2568 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2570 * ppSurface: Address to pass the surface pointer back at
2571 * pSharedHandle: Ignored
2574 * Always returns D3D_OK
2576 *****************************************************************************/
2577 static HRESULT WINAPI
2578 D3D7CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior,
2579 UINT Width, UINT Height,
2580 WINED3DFORMAT Format,
2581 WINED3DMULTISAMPLE_TYPE MultiSample,
2582 DWORD MultisampleQuality,
2584 IWineD3DSurface** ppSurface,
2585 HANDLE* pSharedHandle)
2587 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2588 IDirectDrawSurfaceImpl *d3dSurface = (IDirectDrawSurfaceImpl *) This->d3d_target->first_complex;
2589 TRACE("(%p) call back\n", device);
2591 /* Loop through the complex chain and try to find unused primary surfaces */
2592 while(d3dSurface->isRenderTarget)
2594 d3dSurface = d3dSurface->next_complex;
2595 if(!d3dSurface) break;
2599 d3dSurface = This->d3d_target;
2600 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This);
2603 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2605 *ppSurface = d3dSurface->WineD3DSurface;
2606 d3dSurface->isRenderTarget = TRUE;
2607 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface, d3dSurface);
2611 static HRESULT WINAPI
2612 D3D7CB_CreateDepthStencilSurface(IUnknown *device,
2613 IUnknown *pSuperior,
2616 WINED3DFORMAT Format,
2617 WINED3DMULTISAMPLE_TYPE MultiSample,
2618 DWORD MultisampleQuality,
2620 IWineD3DSurface** ppSurface,
2621 HANDLE* pSharedHandle)
2623 /* Create a Depth Stencil surface to make WineD3D happy */
2624 HRESULT hr = D3D_OK;
2625 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2626 DDSURFACEDESC2 ddsd;
2628 TRACE("(%p) call back\n", device);
2632 /* Create a DirectDraw surface */
2633 memset(&ddsd, 0, sizeof(ddsd));
2634 ddsd.dwSize = sizeof(ddsd);
2635 ddsd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
2636 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
2637 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2638 ddsd.dwHeight = Height;
2639 ddsd.dwWidth = Width;
2642 PixelFormat_WineD3DtoDD(&ddsd.u4.ddpfPixelFormat, Format);
2646 ddsd.dwFlags ^= DDSD_PIXELFORMAT;
2649 This->depthstencil = TRUE;
2650 hr = IDirectDraw7_CreateSurface((IDirectDraw7 *) This,
2652 (IDirectDrawSurface7 **) &This->DepthStencilBuffer,
2654 This->depthstencil = FALSE;
2657 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This, hr);
2660 *ppSurface = This->DepthStencilBuffer->WineD3DSurface;
2664 /*****************************************************************************
2665 * D3D7CB_CreateAdditionalSwapChain
2667 * Callback function for WineD3D which creates a new WineD3DSwapchain
2668 * interface. It also creates an IParent interface to store that pointer,
2669 * so the WineD3DSwapchain has a parent and can be released when the D3D
2670 * device is destroyed
2671 *****************************************************************************/
2672 static HRESULT WINAPI
2673 D3D7CB_CreateAdditionalSwapChain(IUnknown *device,
2674 WINED3DPRESENT_PARAMETERS* pPresentationParameters,
2675 IWineD3DSwapChain ** ppSwapChain)
2677 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2678 IParentImpl *object = NULL;
2679 HRESULT res = D3D_OK;
2680 IWineD3DSwapChain *swapchain;
2681 TRACE("(%p) call back\n", device);
2683 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IParentImpl));
2686 FIXME("Allocation of memory failed\n");
2687 *ppSwapChain = NULL;
2688 return DDERR_OUTOFVIDEOMEMORY;
2691 ICOM_INIT_INTERFACE(object, IParent, IParent_Vtbl);
2694 res = IWineD3DDevice_CreateAdditionalSwapChain(This->wineD3DDevice,
2695 pPresentationParameters,
2697 (IUnknown*) ICOM_INTERFACE(object, IParent),
2698 D3D7CB_CreateRenderTarget,
2699 D3D7CB_CreateDepthStencilSurface);
2702 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
2703 HeapFree(GetProcessHeap(), 0 , object);
2704 *ppSwapChain = NULL;
2708 *ppSwapChain = swapchain;
2709 object->child = (IUnknown *) swapchain;
2715 /*****************************************************************************
2716 * IDirectDrawImpl_AttachD3DDevice
2718 * Initializes the D3D capabilities of WineD3D
2721 * primary: The primary surface for D3D
2727 *****************************************************************************/
2728 static HRESULT WINAPI
2729 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl *This,
2730 IDirectDrawSurfaceImpl *primary)
2733 UINT BackBufferCount = 0;
2736 WINED3DPRESENT_PARAMETERS localParameters;
2737 BOOL isWindowed, EnableAutoDepthStencil;
2738 WINED3DFORMAT AutoDepthStencilFormat;
2739 WINED3DMULTISAMPLE_TYPE MultiSampleType;
2740 WINED3DSWAPEFFECT SwapEffect;
2741 DWORD Flags, MultiSampleQuality;
2742 UINT FullScreen_RefreshRateInHz, PresentationInterval;
2743 WINED3DDISPLAYMODE Mode;
2745 TRACE("(%p)->(%p)\n", This, primary);
2747 /* Get the window */
2748 hr = IWineD3DDevice_GetHWND(This->wineD3DDevice,
2752 ERR("IWineD3DDevice::GetHWND failed\n");
2756 /* If there's no window, create a hidden window. WineD3D needs it */
2759 window = CreateWindowExA(0, This->classname, "Hidden D3D Window",
2761 GetSystemMetrics(SM_CXSCREEN),
2762 GetSystemMetrics(SM_CYSCREEN),
2763 NULL, NULL, GetModuleHandleA(0), NULL);
2765 ShowWindow(window, SW_HIDE); /* Just to be sure */
2766 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This, window);
2767 This->d3d_window = window;
2771 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This, window);
2774 /* use the surface description for the device parameters, not the
2775 * Device settings. The app might render to an offscreen surface
2777 Mode.Width = primary->surface_desc.dwWidth;
2778 Mode.Height = primary->surface_desc.dwHeight;
2779 Mode.Format = PixelFormat_DD2WineD3D(&primary->surface_desc.u4.ddpfPixelFormat);
2781 if(primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT)
2783 BackBufferCount = primary->surface_desc.dwBackBufferCount;
2786 /* Store the future Render Target surface */
2787 This->d3d_target = primary;
2789 isWindowed = !(This->cooperative_level & DDSCL_FULLSCREEN);
2790 EnableAutoDepthStencil = FALSE;
2791 AutoDepthStencilFormat = WINED3DFMT_D16;
2792 MultiSampleType = WINED3DMULTISAMPLE_NONE;
2793 SwapEffect = WINED3DSWAPEFFECT_COPY;
2795 MultiSampleQuality = 0;
2796 FullScreen_RefreshRateInHz = WINED3DPRESENT_RATE_DEFAULT; /* Default rate: It's already set */
2797 PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT;
2799 TRACE("Passing mode %d\n", Mode.Format);
2801 localParameters.BackBufferWidth = &Mode.Width;
2802 localParameters.BackBufferHeight = &Mode.Height;
2803 localParameters.BackBufferFormat = (WINED3DFORMAT *) &Mode.Format;
2804 localParameters.BackBufferCount = (UINT *) &BackBufferCount;
2805 localParameters.MultiSampleType = &MultiSampleType;
2806 localParameters.MultiSampleQuality = &MultiSampleQuality;
2807 localParameters.SwapEffect = &SwapEffect;
2808 localParameters.hDeviceWindow = &window;
2809 localParameters.Windowed = &isWindowed;
2810 localParameters.EnableAutoDepthStencil = &EnableAutoDepthStencil;
2811 localParameters.AutoDepthStencilFormat = &AutoDepthStencilFormat;
2812 localParameters.Flags = &Flags;
2813 localParameters.FullScreen_RefreshRateInHz = &FullScreen_RefreshRateInHz;
2814 localParameters.PresentationInterval = &PresentationInterval;
2816 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2817 * recursive loop until ram or emulated video memory is full
2819 This->d3d_initialized = TRUE;
2821 hr = IWineD3DDevice_Init3D(This->wineD3DDevice,
2823 D3D7CB_CreateAdditionalSwapChain);
2826 This->wineD3DDevice = NULL;
2830 /* Create an Index Buffer parent */
2831 TRACE("(%p) Successfully initialized 3D\n", This);
2835 /*****************************************************************************
2836 * DirectDrawCreateClipper (DDRAW.@)
2838 * Creates a new IDirectDrawClipper object.
2841 * Clipper: Address to write the interface pointer to
2842 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2846 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2847 * E_OUTOFMEMORY if allocating the object failed
2849 *****************************************************************************/
2851 DirectDrawCreateClipper(DWORD Flags,
2852 IDirectDrawClipper **Clipper,
2855 IDirectDrawClipperImpl* object;
2856 TRACE("(%08x,%p,%p)\n", Flags, Clipper, UnkOuter);
2858 if (UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
2860 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2861 sizeof(IDirectDrawClipperImpl));
2862 if (object == NULL) return E_OUTOFMEMORY;
2864 ICOM_INIT_INTERFACE(object, IDirectDrawClipper, IDirectDrawClipper_Vtbl);
2867 object->ddraw_owner = NULL;
2869 *Clipper = (IDirectDrawClipper *) object;
2873 /*****************************************************************************
2874 * IDirectDraw7::CreateClipper
2876 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
2878 *****************************************************************************/
2879 static HRESULT WINAPI
2880 IDirectDrawImpl_CreateClipper(IDirectDraw7 *iface,
2882 IDirectDrawClipper **Clipper,
2885 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2886 TRACE("(%p)->(%x,%p,%p)\n", This, Flags, Clipper, UnkOuter);
2887 return DirectDrawCreateClipper(Flags, Clipper, UnkOuter);
2890 /*****************************************************************************
2891 * IDirectDraw7::CreatePalette
2893 * Creates a new IDirectDrawPalette object
2896 * Flags: The flags for the new clipper
2897 * ColorTable: Color table to assign to the new clipper
2898 * Palette: Address to write the interface pointer to
2899 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2903 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2904 * E_OUTOFMEMORY if allocating the object failed
2906 *****************************************************************************/
2907 static HRESULT WINAPI
2908 IDirectDrawImpl_CreatePalette(IDirectDraw7 *iface,
2910 PALETTEENTRY *ColorTable,
2911 IDirectDrawPalette **Palette,
2912 IUnknown *pUnkOuter)
2914 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2915 IDirectDrawPaletteImpl *object;
2916 HRESULT hr = DDERR_GENERIC;
2917 TRACE("(%p)->(%x,%p,%p,%p)\n", This, Flags, ColorTable, Palette, pUnkOuter);
2919 if(pUnkOuter != NULL)
2921 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter);
2922 return CLASS_E_NOAGGREGATION;
2925 /* The refcount test shows that a cooplevel is required for this */
2926 if(!This->cooperative_level)
2928 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
2929 return DDERR_NOCOOPERATIVELEVELSET;
2932 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl));
2935 ERR("Out of memory when allocating memory for a palette implementation\n");
2936 return E_OUTOFMEMORY;
2939 ICOM_INIT_INTERFACE(object, IDirectDrawPalette, IDirectDrawPalette_Vtbl);
2941 object->ddraw_owner = This;
2943 hr = IWineD3DDevice_CreatePalette(This->wineD3DDevice, Flags, ColorTable, &object->wineD3DPalette, (IUnknown *) ICOM_INTERFACE(object, IDirectDrawPalette) );
2946 HeapFree(GetProcessHeap(), 0, object);
2950 IDirectDraw7_AddRef(iface);
2951 object->ifaceToRelease = (IUnknown *) iface;
2952 *Palette = ICOM_INTERFACE(object, IDirectDrawPalette);
2956 /*****************************************************************************
2957 * IDirectDraw7::DuplicateSurface
2959 * Duplicates a surface. The surface memory points to the same memory as
2960 * the original surface, and it's released when the last surface referencing
2961 * it is released. I guess that's beyond Wine's surface management right now
2962 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
2963 * test application to implement this)
2966 * Src: Address of the source surface
2967 * Dest: Address to write the new surface pointer to
2970 * See IDirectDraw7::CreateSurface
2972 *****************************************************************************/
2973 static HRESULT WINAPI
2974 IDirectDrawImpl_DuplicateSurface(IDirectDraw7 *iface,
2975 IDirectDrawSurface7 *Src,
2976 IDirectDrawSurface7 **Dest)
2978 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2979 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Src);
2981 FIXME("(%p)->(%p,%p)\n", This, Surf, Dest);
2983 /* For now, simply create a new, independent surface */
2984 return IDirectDraw7_CreateSurface(iface,
2985 &Surf->surface_desc,
2990 /*****************************************************************************
2991 * IDirectDraw7 VTable
2992 *****************************************************************************/
2993 const IDirectDraw7Vtbl IDirectDraw7_Vtbl =
2996 IDirectDrawImpl_QueryInterface,
2997 IDirectDrawImpl_AddRef,
2998 IDirectDrawImpl_Release,
2999 /*** IDirectDraw ***/
3000 IDirectDrawImpl_Compact,
3001 IDirectDrawImpl_CreateClipper,
3002 IDirectDrawImpl_CreatePalette,
3003 IDirectDrawImpl_CreateSurface,
3004 IDirectDrawImpl_DuplicateSurface,
3005 IDirectDrawImpl_EnumDisplayModes,
3006 IDirectDrawImpl_EnumSurfaces,
3007 IDirectDrawImpl_FlipToGDISurface,
3008 IDirectDrawImpl_GetCaps,
3009 IDirectDrawImpl_GetDisplayMode,
3010 IDirectDrawImpl_GetFourCCCodes,
3011 IDirectDrawImpl_GetGDISurface,
3012 IDirectDrawImpl_GetMonitorFrequency,
3013 IDirectDrawImpl_GetScanLine,
3014 IDirectDrawImpl_GetVerticalBlankStatus,
3015 IDirectDrawImpl_Initialize,
3016 IDirectDrawImpl_RestoreDisplayMode,
3017 IDirectDrawImpl_SetCooperativeLevel,
3018 IDirectDrawImpl_SetDisplayMode,
3019 IDirectDrawImpl_WaitForVerticalBlank,
3020 /*** IDirectDraw2 ***/
3021 IDirectDrawImpl_GetAvailableVidMem,
3022 /*** IDirectDraw7 ***/
3023 IDirectDrawImpl_GetSurfaceFromDC,
3024 IDirectDrawImpl_RestoreAllSurfaces,
3025 IDirectDrawImpl_TestCooperativeLevel,
3026 IDirectDrawImpl_GetDeviceIdentifier,
3027 /*** IDirectDraw7 ***/
3028 IDirectDrawImpl_StartModeTest,
3029 IDirectDrawImpl_EvaluateMode