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);
429 This->cooperative_level &= ~DDSCL_FULLSCREEN;
430 This->cooperative_level &= ~DDSCL_EXCLUSIVE;
431 This->cooperative_level &= ~DDSCL_ALLOWMODEX;
434 /* Don't override focus windows or private device windows */
436 !(This->focuswindow) &&
437 !(This->devicewindow) &&
440 IWineD3DDevice_SetHWND(This->wineD3DDevice, hwnd);
443 IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
446 else if(cooplevel & DDSCL_FULLSCREEN)
448 /* Needs DDSCL_EXCLUSIVE */
449 if(!(cooplevel & DDSCL_EXCLUSIVE) )
451 TRACE("(%p) DDSCL_FULLSCREEN needs DDSCL_EXCLUSIVE\n", This);
452 return DDERR_INVALIDPARAMS;
457 TRACE("(%p) DDSCL_FULLSCREEN needs a HWND\n", This);
458 return DDERR_INVALIDPARAMS;
462 /* Switch from normal to full screen mode? */
463 if(This->cooperative_level & DDSCL_NORMAL)
465 This->cooperative_level &= ~DDSCL_NORMAL;
466 IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
470 /* Don't override focus windows or private device windows */
472 !(This->focuswindow) &&
473 !(This->devicewindow) &&
476 IWineD3DDevice_SetHWND(This->wineD3DDevice, hwnd);
479 else if(cooplevel & DDSCL_EXCLUSIVE)
481 TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN\n", This);
482 return DDERR_INVALIDPARAMS;
485 if(cooplevel & DDSCL_CREATEDEVICEWINDOW)
487 /* Don't create a device window if a focus window is set */
488 if( !(This->focuswindow) )
490 HWND devicewindow = CreateWindowExA(0, This->classname, "DDraw device window",
492 GetSystemMetrics(SM_CXSCREEN),
493 GetSystemMetrics(SM_CYSCREEN),
494 NULL, NULL, GetModuleHandleA(0), NULL);
496 ShowWindow(devicewindow, SW_SHOW); /* Just to be sure */
497 TRACE("(%p) Created a DDraw device window. HWND=%p\n", This, devicewindow);
499 IWineD3DDevice_SetHWND(This->wineD3DDevice, devicewindow);
500 This->devicewindow = devicewindow;
504 /* Unhandled flags */
505 if(cooplevel & DDSCL_ALLOWREBOOT)
506 WARN("(%p) Unhandled flag DDSCL_ALLOWREBOOT, harmless\n", This);
507 if(cooplevel & DDSCL_ALLOWMODEX)
508 WARN("(%p) Unhandled flag DDSCL_ALLOWMODEX, harmless\n", This);
509 if(cooplevel & DDSCL_MULTITHREADED)
510 FIXME("(%p) Unhandled flag DDSCL_MULTITHREADED, Uh Oh...\n", This);
511 if(cooplevel & DDSCL_FPUSETUP)
512 WARN("(%p) Unhandled flag DDSCL_FPUSETUP, harmless\n", This);
513 if(cooplevel & DDSCL_FPUPRESERVE)
514 WARN("(%p) Unhandled flag DDSCL_FPUPRESERVE, harmless\n", This);
516 /* Store the cooperative_level */
517 This->cooperative_level |= cooplevel;
518 TRACE("SetCooperativeLevel retuning DD_OK\n");
522 /*****************************************************************************
523 * IDirectDraw7::SetDisplayMode
525 * Sets the display screen resolution, color depth and refresh frequency
526 * when in fullscreen mode (in theory).
527 * Possible return values listed in the SDK suggest that this method fails
528 * when not in fullscreen mode, but this is wrong. Windows 2000 happily sets
529 * the display mode in DDSCL_NORMAL mode without an hwnd specified.
530 * It seems to be valid to pass 0 for With and Height, this has to be tested
531 * It could mean that the current video mode should be left as-is. (But why
535 * Height, Width: Screen dimension
536 * BPP: Color depth in Bits per pixel
537 * Refreshrate: Screen refresh rate
543 *****************************************************************************/
544 static HRESULT WINAPI
545 IDirectDrawImpl_SetDisplayMode(IDirectDraw7 *iface,
552 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
553 WINED3DDISPLAYMODE Mode;
554 TRACE("(%p)->(%d,%d,%d,%d,%x: Relay!\n", This, Width, Height, BPP, RefreshRate, Flags);
556 if( !Width || !Height )
558 ERR("Width=%d, Height=%d, what to do?\n", Width, Height);
559 /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
563 /* Check the exclusive mode
564 if(!(This->cooperative_level & DDSCL_EXCLUSIVE))
565 return DDERR_NOEXCLUSIVEMODE;
566 * This is WRONG. Don't know if the SDK is completely
567 * wrong and if there are any conditions when DDERR_NOEXCLUSIVE
568 * is returned, but Half-Life 1.1.1.1 (Steam version)
573 Mode.Height = Height;
574 Mode.RefreshRate = RefreshRate;
577 case 8: Mode.Format = WINED3DFMT_P8; break;
578 case 15: Mode.Format = WINED3DFMT_X1R5G5B5; break;
579 case 16: Mode.Format = WINED3DFMT_R5G6B5; break;
580 case 24: Mode.Format = WINED3DFMT_R8G8B8; break;
581 case 32: Mode.Format = WINED3DFMT_A8R8G8B8; break;
584 /* TODO: The possible return values from msdn suggest that
585 * the screen mode can't be changed if a surface is locked
586 * or some drawing is in progress
589 /* TODO: Lose the primary surface */
590 return IWineD3DDevice_SetDisplayMode(This->wineD3DDevice,
591 0, /* First swapchain */
596 /*****************************************************************************
597 * IDirectDraw7::RestoreDisplayMode
599 * Restores the display mode to what it was at creation time. Basically.
601 * A problem arises when there are 2 DirectDraw objects using the same hwnd:
602 * -> DD_1 finds the screen at 1400x1050x32 when created, sets it to 640x480x16
603 * -> DD_2 is created, finds the screen at 640x480x16, sets it to 1024x768x32
604 * -> DD_1 is released. The screen should be left at 1024x768x32.
605 * -> DD_2 is released. The screen should be set to 1400x1050x32
606 * This case is unhandled right now, but Empire Earth does it this way.
607 * (But perhaps there is something in SetCooperativeLevel to prevent this)
609 * The msdn says that this method resets the display mode to what it was before
610 * SetDisplayMode was called. What if SetDisplayModes is called 2 times??
614 * DDERR_NOEXCLUSIVE mode if the device isn't in fullscreen mode
616 *****************************************************************************/
617 static HRESULT WINAPI
618 IDirectDrawImpl_RestoreDisplayMode(IDirectDraw7 *iface)
620 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
621 TRACE("(%p)\n", This);
623 return IDirectDraw7_SetDisplayMode(ICOM_INTERFACE(This, IDirectDraw7),
631 /*****************************************************************************
632 * IDirectDraw7::GetCaps
634 * Returns the drives capabilities
636 * Used for version 1, 2, 4 and 7
639 * DriverCaps: Structure to write the Hardware accelerated caps to
640 * HelCaps: Structure to write the emulation caps to
643 * This implementation returns DD_OK only
645 *****************************************************************************/
646 static HRESULT WINAPI
647 IDirectDrawImpl_GetCaps(IDirectDraw7 *iface,
651 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
652 TRACE("(%p)->(%p,%p)\n", This, DriverCaps, HELCaps);
654 /* One structure must be != NULL */
655 if( (!DriverCaps) && (!HELCaps) )
657 ERR("(%p) Invalid params to IDirectDrawImpl_GetCaps\n", This);
658 return DDERR_INVALIDPARAMS;
663 DD_STRUCT_COPY_BYSIZE(DriverCaps, &This->caps);
666 TRACE("Driver Caps :\n");
667 DDRAW_dump_DDCAPS(DriverCaps);
673 DD_STRUCT_COPY_BYSIZE(HELCaps, &This->caps);
676 TRACE("HEL Caps :\n");
677 DDRAW_dump_DDCAPS(HELCaps);
684 /*****************************************************************************
685 * IDirectDraw7::Compact
687 * No idea what it does, MSDN says it's not implemented.
690 * DD_OK, but this is unchecked
692 *****************************************************************************/
693 static HRESULT WINAPI
694 IDirectDrawImpl_Compact(IDirectDraw7 *iface)
696 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
697 TRACE("(%p)\n", This);
702 /*****************************************************************************
703 * IDirectDraw7::GetDisplayMode
705 * Returns information about the current display mode
707 * Exists in Version 1, 2, 4 and 7
710 * DDSD: Address of a surface description structure to write the info to
715 *****************************************************************************/
716 static HRESULT WINAPI
717 IDirectDrawImpl_GetDisplayMode(IDirectDraw7 *iface,
718 DDSURFACEDESC2 *DDSD)
720 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
722 WINED3DDISPLAYMODE Mode;
724 TRACE("(%p)->(%p): Relay\n", This, DDSD);
726 /* This seems sane */
729 return DDERR_INVALIDPARAMS;
732 /* The necessary members of LPDDSURFACEDESC and LPDDSURFACEDESC2 are equal,
733 * so one method can be used for all versions (Hopefully)
735 hr = IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
740 ERR(" (%p) IWineD3DDevice::GetDisplayMode returned %08x\n", This, hr);
745 memset(DDSD, 0, Size);
748 DDSD->dwFlags |= DDSD_HEIGHT | DDSD_WIDTH | DDSD_PIXELFORMAT | DDSD_PITCH | DDSD_REFRESHRATE;
749 DDSD->dwWidth = Mode.Width;
750 DDSD->dwHeight = Mode.Height;
751 DDSD->u2.dwRefreshRate = 60;
752 DDSD->ddsCaps.dwCaps = 0;
753 DDSD->u4.ddpfPixelFormat.dwSize = sizeof(DDSD->u4.ddpfPixelFormat);
754 PixelFormat_WineD3DtoDD(&DDSD->u4.ddpfPixelFormat, Mode.Format);
755 DDSD->u1.lPitch = Mode.Width * DDSD->u4.ddpfPixelFormat.u1.dwRGBBitCount / 8;
759 TRACE("Returning surface desc :\n");
760 DDRAW_dump_surface_desc(DDSD);
766 /*****************************************************************************
767 * IDirectDraw7::GetFourCCCodes
769 * Returns an array of supported FourCC codes.
771 * Exists in Version 1, 2, 4 and 7
774 * NumCodes: Contains the number of Codes that Codes can carry. Returns the number
775 * of enumerated codes
776 * Codes: Pointer to an array of DWORDs where the supported codes are written
780 * Always returns DD_OK, as it's a stub for now
782 *****************************************************************************/
783 static HRESULT WINAPI
784 IDirectDrawImpl_GetFourCCCodes(IDirectDraw7 *iface,
785 DWORD *NumCodes, DWORD *Codes)
787 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
788 FIXME("(%p)->(%p, %p): Stub!\n", This, NumCodes, Codes);
790 if(NumCodes) *NumCodes = 0;
795 /*****************************************************************************
796 * IDirectDraw7::GetMonitorFrequency
798 * Returns the monitor's frequency
800 * Exists in Version 1, 2, 4 and 7
803 * Freq: Pointer to a DWORD to write the frequency to
806 * Always returns DD_OK
808 *****************************************************************************/
809 static HRESULT WINAPI
810 IDirectDrawImpl_GetMonitorFrequency(IDirectDraw7 *iface,
813 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
814 TRACE("(%p)->(%p)\n", This, Freq);
816 /* Ideally this should be in WineD3D, as it concerns the screen setup,
817 * but for now this should make the games happy
823 /*****************************************************************************
824 * IDirectDraw7::GetVerticalBlankStatus
826 * Returns the Vertical blank status of the monitor. This should be in WineD3D
827 * too basically, but as it's a semi stub, I didn't create a function there
830 * status: Pointer to a BOOL to be filled with the vertical blank status
834 * DDERR_INVALIDPARAMS if status is NULL
836 *****************************************************************************/
837 static HRESULT WINAPI
838 IDirectDrawImpl_GetVerticalBlankStatus(IDirectDraw7 *iface,
841 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
842 TRACE("(%p)->(%p)\n", This, status);
844 /* This looks sane, the MSDN suggests it too */
845 if(!status) return DDERR_INVALIDPARAMS;
847 *status = This->fake_vblank;
848 This->fake_vblank = !This->fake_vblank;
852 /*****************************************************************************
853 * IDirectDraw7::GetAvailableVidMem
855 * Returns the total and free video memory
858 * Caps: Specifies the memory type asked for
859 * total: Pointer to a DWORD to be filled with the total memory
860 * free: Pointer to a DWORD to be filled with the free memory
864 * DDERR_INVALIDPARAMS of free and total are NULL
866 *****************************************************************************/
867 static HRESULT WINAPI
868 IDirectDrawImpl_GetAvailableVidMem(IDirectDraw7 *iface, DDSCAPS2 *Caps, DWORD *total, DWORD *free)
870 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
871 TRACE("(%p)->(%p, %p, %p)\n", This, Caps, total, free);
875 TRACE("(%p) Asked for memory with description: ", This);
876 DDRAW_dump_DDSCAPS2(Caps);
880 /* Todo: System memory vs local video memory vs non-local video memory
881 * The MSDN also mentions differences between texture memory and other
882 * resources, but that's not important
885 if( (!total) && (!free) ) return DDERR_INVALIDPARAMS;
887 if(total) *total = This->total_vidmem;
888 if(free) *free = IWineD3DDevice_GetAvailableTextureMem(This->wineD3DDevice);
893 /*****************************************************************************
894 * IDirectDraw7::Initialize
896 * Initializes a DirectDraw interface.
899 * GUID: Interface identifier. Well, don't know what this is really good
903 * Returns DD_OK on the first call,
904 * DDERR_ALREADYINITIALIZED on repeated calls
906 *****************************************************************************/
907 static HRESULT WINAPI
908 IDirectDrawImpl_Initialize(IDirectDraw7 *iface,
911 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
912 TRACE("(%p)->(%s): No-op\n", This, debugstr_guid(Guid));
914 if(This->initialized)
916 return DDERR_ALREADYINITIALIZED;
924 /*****************************************************************************
925 * IDirectDraw7::FlipToGDISurface
927 * "Makes the surface that the GDI writes to the primary surface"
928 * Looks like some windows specific thing we don't have to care about.
929 * According to MSDN it permits GDI dialog boxes in FULLSCREEN mode. Good to
930 * show error boxes ;)
931 * Well, just return DD_OK.
934 * Always returns DD_OK
936 *****************************************************************************/
937 static HRESULT WINAPI
938 IDirectDrawImpl_FlipToGDISurface(IDirectDraw7 *iface)
940 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
941 TRACE("(%p)\n", This);
946 /*****************************************************************************
947 * IDirectDraw7::WaitForVerticalBlank
949 * This method allows applications to get in sync with the vertical blank
951 * The wormhole demo in the DirectX 7 sdk uses this call, and it doesn't
952 * redraw the screen, most likely because of this stub
955 * Flags: one of DDWAITVB_BLOCKBEGIN, DDWAITVB_BLOCKBEGINEVENT
956 * or DDWAITVB_BLOCKEND
957 * h: Not used, according to MSDN
960 * Always returns DD_OK
962 *****************************************************************************/
963 static HRESULT WINAPI
964 IDirectDrawImpl_WaitForVerticalBlank(IDirectDraw7 *iface,
968 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
969 FIXME("(%p)->(%x,%p): Stub\n", This, Flags, h);
971 /* MSDN says DDWAITVB_BLOCKBEGINEVENT is not supported */
972 if(Flags & DDWAITVB_BLOCKBEGINEVENT)
973 return DDERR_UNSUPPORTED; /* unchecked */
978 /*****************************************************************************
979 * IDirectDraw7::GetScanLine
981 * Returns the scan line that is being drawn on the monitor
984 * Scanline: Address to write the scan line value to
987 * Always returns DD_OK
989 *****************************************************************************/
990 static HRESULT WINAPI IDirectDrawImpl_GetScanLine(IDirectDraw7 *iface, DWORD *Scanline)
992 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
993 static BOOL hide = FALSE;
994 WINED3DDISPLAYMODE Mode;
996 /* This function is called often, so print the fixme only once */
999 FIXME("(%p)->(%p): Semi-Stub\n", This, Scanline);
1003 IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
1007 /* Fake the line sweeping of the monitor */
1008 /* FIXME: We should synchronize with a source to keep the refresh rate */
1009 *Scanline = This->cur_scanline++;
1010 /* Assume 20 scan lines in the vertical blank */
1011 if (This->cur_scanline >= Mode.Height + 20)
1012 This->cur_scanline = 0;
1017 /*****************************************************************************
1018 * IDirectDraw7::TestCooperativeLevel
1020 * Informs the application about the state of the video adapter, depending
1021 * on the cooperative level
1024 * DD_OK if the device is in a sane state
1025 * DDERR_NOEXCLUSIVEMODE or DDERR_EXCLUSIVEMODEALREADYSET
1026 * if the state is not correct(See below)
1028 *****************************************************************************/
1029 static HRESULT WINAPI
1030 IDirectDrawImpl_TestCooperativeLevel(IDirectDraw7 *iface)
1032 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1034 TRACE("(%p)\n", This);
1036 /* Description from MSDN:
1037 * For fullscreen apps return DDERR_NOEXCLUSIVEMODE if the user switched
1038 * away from the app with e.g. alt-tab. Windowed apps receive
1039 * DDERR_EXCLUSIVEMODEALREADYSET if another application created a
1040 * DirectDraw object in exclusive mode. DDERR_WRONGMODE is returned,
1041 * when the video mode has changed
1044 hr = IWineD3DDevice_TestCooperativeLevel(This->wineD3DDevice);
1046 /* Fix the result value. These values are mapped from their
1051 case WINED3DERR_DEVICELOST:
1052 if(This->cooperative_level & DDSCL_EXCLUSIVE)
1054 return DDERR_NOEXCLUSIVEMODE;
1058 return DDERR_EXCLUSIVEMODEALREADYSET;
1061 case WINED3DERR_DEVICENOTRESET:
1067 case WINED3DERR_DRIVERINTERNALERROR:
1069 ERR("(%p) Unexpected return value %08x from wineD3D, "
1070 " returning DD_OK\n", This, hr);
1076 /*****************************************************************************
1077 * IDirectDraw7::GetGDISurface
1079 * Returns the surface that GDI is treating as the primary surface.
1080 * For Wine this is the front buffer
1083 * GDISurface: Address to write the surface pointer to
1086 * DD_OK if the surface was found
1087 * DDERR_NOTFOUND if the GDI surface wasn't found
1089 *****************************************************************************/
1090 static HRESULT WINAPI
1091 IDirectDrawImpl_GetGDISurface(IDirectDraw7 *iface,
1092 IDirectDrawSurface7 **GDISurface)
1094 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1095 IWineD3DSurface *Surf;
1096 IDirectDrawSurface7 *ddsurf;
1099 TRACE("(%p)->(%p)\n", This, GDISurface);
1101 /* Get the back buffer from the wineD3DDevice and search its
1102 * attached surfaces for the front buffer
1104 hr = IWineD3DDevice_GetBackBuffer(This->wineD3DDevice,
1106 0, /* first back buffer*/
1107 WINED3DBACKBUFFER_TYPE_MONO,
1110 if( (hr != D3D_OK) ||
1113 ERR("IWineD3DDevice::GetBackBuffer failed\n");
1114 return DDERR_NOTFOUND;
1117 /* GetBackBuffer AddRef()ed the surface, release it */
1118 IWineD3DSurface_Release(Surf);
1120 IWineD3DSurface_GetParent(Surf,
1121 (IUnknown **) &ddsurf);
1122 IDirectDrawSurface7_Release(ddsurf); /* For the GetParent */
1124 /* Find the front buffer */
1125 ddsCaps.dwCaps = DDSCAPS_FRONTBUFFER;
1126 hr = IDirectDrawSurface7_GetAttachedSurface(ddsurf,
1131 ERR("IDirectDrawSurface7::GetAttachedSurface failed, hr = %x\n", hr);
1134 /* The AddRef is OK this time */
1138 /*****************************************************************************
1139 * IDirectDraw7::EnumDisplayModes
1141 * Enumerates the supported Display modes. The modes can be filtered with
1142 * the DDSD parameter.
1145 * Flags: can be DDEDM_REFRESHRATES and DDEDM_STANDARDVGAMODES
1146 * DDSD: Surface description to filter the modes
1147 * Context: Pointer passed back to the callback function
1148 * cb: Application-provided callback function
1152 * DDERR_INVALIDPARAMS if the callback wasn't set
1154 *****************************************************************************/
1155 static HRESULT WINAPI
1156 IDirectDrawImpl_EnumDisplayModes(IDirectDraw7 *iface,
1158 DDSURFACEDESC2 *DDSD,
1160 LPDDENUMMODESCALLBACK2 cb)
1162 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1163 unsigned int modenum = 0;
1164 WINED3DFORMAT pixelformat = WINED3DFMT_UNKNOWN;
1165 WINED3DDISPLAYMODE mode;
1166 DDSURFACEDESC2 callback_sd;
1168 TRACE("(%p)->(%p,%p,%p): Relay\n", This, DDSD, Context, cb);
1170 /* This looks sane */
1171 if(!cb) return DDERR_INVALIDPARAMS;
1175 if ((DDSD->dwFlags & DDSD_PIXELFORMAT) && (DDSD->u4.ddpfPixelFormat.dwFlags & DDPF_RGB) )
1176 pixelformat = PixelFormat_DD2WineD3D(&DDSD->u4.ddpfPixelFormat);
1179 while(IWineD3D_EnumAdapterModes(This->wineD3D,
1180 WINED3DADAPTER_DEFAULT,
1183 &mode) == WINED3D_OK) {
1186 if(DDSD->dwFlags & DDSD_WIDTH && mode.Width != DDSD->dwWidth) continue;
1187 if(DDSD->dwFlags & DDSD_HEIGHT && mode.Height != DDSD->dwHeight) continue;
1190 memset(&callback_sd, 0, sizeof(callback_sd));
1191 callback_sd.dwSize = sizeof(callback_sd);
1192 callback_sd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1194 callback_sd.dwFlags = DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|DDSD_PITCH;
1195 if(Flags & DDEDM_REFRESHRATES)
1197 callback_sd.dwFlags |= DDSD_REFRESHRATE;
1198 callback_sd.u2.dwRefreshRate = mode.RefreshRate;
1201 callback_sd.dwWidth = mode.Width;
1202 callback_sd.dwHeight = mode.Height;
1204 PixelFormat_WineD3DtoDD(&callback_sd.u4.ddpfPixelFormat, mode.Format);
1206 TRACE("Enumerating %dx%d@%d\n", callback_sd.dwWidth, callback_sd.dwHeight, callback_sd.u4.ddpfPixelFormat.u1.dwRGBBitCount);
1208 if(cb(&callback_sd, Context) == DDENUMRET_CANCEL)
1210 TRACE("Application asked to terminate the enumeration\n");
1214 TRACE("End of enumeration\n");
1218 /*****************************************************************************
1219 * IDirectDraw7::EvaluateMode
1221 * Used with IDirectDraw7::StartModeTest to test video modes.
1222 * EvaluateMode is used to pass or fail a mode, and continue with the next
1226 * Flags: DDEM_MODEPASSED or DDEM_MODEFAILED
1227 * Timeout: Returns the amount of seconds left before the mode would have
1228 * been failed automatically
1231 * This implementation always DD_OK, because it's a stub
1233 *****************************************************************************/
1234 static HRESULT WINAPI
1235 IDirectDrawImpl_EvaluateMode(IDirectDraw7 *iface,
1239 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1240 FIXME("(%p)->(%d,%p): Stub!\n", This, Flags, Timeout);
1242 /* When implementing this, implement it in WineD3D */
1247 /*****************************************************************************
1248 * IDirectDraw7::GetDeviceIdentifier
1250 * Returns the device identifier, which gives information about the driver
1251 * Our device identifier is defined at the beginning of this file.
1254 * DDDI: Address for the returned structure
1255 * Flags: Can be DDGDI_GETHOSTIDENTIFIER
1258 * On success it returns DD_OK
1259 * DDERR_INVALIDPARAMS if DDDI is NULL
1261 *****************************************************************************/
1262 static HRESULT WINAPI
1263 IDirectDrawImpl_GetDeviceIdentifier(IDirectDraw7 *iface,
1264 DDDEVICEIDENTIFIER2 *DDDI,
1267 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1268 TRACE("(%p)->(%p,%08x)\n", This, DDDI, Flags);
1271 return DDERR_INVALIDPARAMS;
1273 /* The DDGDI_GETHOSTIDENTIFIER returns the information about the 2D
1274 * host adapter, if there's a secondary 3D adapter. This doesn't apply
1275 * to any modern hardware, nor is it interesting for Wine, so ignore it
1278 *DDDI = deviceidentifier;
1282 /*****************************************************************************
1283 * IDirectDraw7::GetSurfaceFromDC
1285 * Returns the Surface for a GDI device context handle.
1286 * Is this related to IDirectDrawSurface::GetDC ???
1289 * hdc: hdc to return the surface for
1290 * Surface: Address to write the surface pointer to
1293 * Always returns DD_OK because it's a stub
1295 *****************************************************************************/
1296 static HRESULT WINAPI
1297 IDirectDrawImpl_GetSurfaceFromDC(IDirectDraw7 *iface,
1299 IDirectDrawSurface7 **Surface)
1301 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1302 FIXME("(%p)->(%p,%p): Stub!\n", This, hdc, Surface);
1304 /* Implementation idea if needed: Loop through all surfaces and compare
1305 * their hdc with hdc. Implement it in WineD3D! */
1306 return DDERR_NOTFOUND;
1309 /*****************************************************************************
1310 * IDirectDraw7::RestoreAllSurfaces
1312 * Calls the restore method of all surfaces
1317 * Always returns DD_OK because it's a stub
1319 *****************************************************************************/
1320 static HRESULT WINAPI
1321 IDirectDrawImpl_RestoreAllSurfaces(IDirectDraw7 *iface)
1323 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1324 FIXME("(%p): Stub\n", This);
1326 /* This isn't hard to implement: Enumerate all WineD3D surfaces,
1327 * get their parent and call their restore method. Do not implement
1328 * it in WineD3D, as restoring a surface means re-creating the
1334 /*****************************************************************************
1335 * IDirectDraw7::StartModeTest
1337 * Tests the specified video modes to update the system registry with
1338 * refresh rate information. StartModeTest starts the mode test,
1339 * EvaluateMode is used to fail or pass a mode. If EvaluateMode
1340 * isn't called within 15 seconds, the mode is failed automatically
1342 * As refresh rates are handled by the X server, I don't think this
1343 * Method is important
1346 * Modes: An array of mode specifications
1347 * NumModes: The number of modes in Modes
1348 * Flags: Some flags...
1351 * Returns DDERR_TESTFINISHED if flags contains DDSMT_ISTESTREQUIRED,
1352 * if no modes are passed, DDERR_INVALIDPARAMS is returned,
1355 *****************************************************************************/
1356 static HRESULT WINAPI
1357 IDirectDrawImpl_StartModeTest(IDirectDraw7 *iface,
1362 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1363 WARN("(%p)->(%p, %d, %x): Semi-Stub, most likely harmless\n", This, Modes, NumModes, Flags);
1365 /* This looks sane */
1366 if( (!Modes) || (NumModes == 0) ) return DDERR_INVALIDPARAMS;
1368 /* DDSMT_ISTESTREQUIRED asks if a mode test is necessary.
1369 * As it is not, DDERR_TESTFINISHED is returned
1370 * (hopefully that's correct
1372 if(Flags & DDSMT_ISTESTREQUIRED) return DDERR_TESTFINISHED;
1373 * well, that value doesn't (yet) exist in the wine headers, so ignore it
1379 /*****************************************************************************
1380 * IDirectDrawImpl_RecreateSurfacesCallback
1382 * Enumeration callback for IDirectDrawImpl_RecreateAllSurfaces.
1383 * It re-recreates the WineD3DSurface. It's pretty straightforward
1385 *****************************************************************************/
1387 IDirectDrawImpl_RecreateSurfacesCallback(IDirectDrawSurface7 *surf,
1388 DDSURFACEDESC2 *desc,
1391 IDirectDrawSurfaceImpl *surfImpl = ICOM_OBJECT(IDirectDrawSurfaceImpl,
1392 IDirectDrawSurface7,
1394 IDirectDrawImpl *This = surfImpl->ddraw;
1396 IParentImpl *parImpl = NULL;
1397 IWineD3DSurface *wineD3DSurface;
1401 WINED3DSURFACE_DESC Desc;
1402 WINED3DFORMAT Format;
1403 WINED3DRESOURCETYPE Type;
1408 WINED3DMULTISAMPLE_TYPE MultiSampleType;
1409 DWORD MultiSampleQuality;
1413 TRACE("(%p): Enumerated Surface %p\n", This, surfImpl);
1415 /* For the enumeration */
1416 IDirectDrawSurface7_Release(surf);
1418 if(surfImpl->ImplType == This->ImplType) return DDENUMRET_OK; /* Continue */
1420 /* Get the objects */
1421 wineD3DSurface = surfImpl->WineD3DSurface;
1422 IWineD3DSurface_GetParent(wineD3DSurface, &Parent);
1423 IUnknown_Release(Parent); /* For the getParent */
1425 /* Is the parent an IParent interface? */
1426 if(IUnknown_QueryInterface(Parent, &IID_IParent, &tmp) == S_OK)
1428 /* It is a IParent interface! */
1429 IUnknown_Release(Parent); /* For the QueryInterface */
1430 parImpl = ICOM_OBJECT(IParentImpl, IParent, Parent);
1431 /* Release the reference the parent interface is holding */
1432 IWineD3DSurface_Release(wineD3DSurface);
1436 /* Get the surface properties */
1437 Desc.Format = &Format;
1439 Desc.Usage = &Usage;
1442 Desc.MultiSampleType = &MultiSampleType;
1443 Desc.MultiSampleQuality = &MultiSampleQuality;
1444 Desc.Width = &Width;
1445 Desc.Height = &Height;
1447 hr = IWineD3DSurface_GetDesc(wineD3DSurface, &Desc);
1448 if(hr != D3D_OK) return hr;
1450 /* Create the new surface */
1451 hr = IWineD3DDevice_CreateSurface(This->wineD3DDevice,
1452 Width, Height, Format,
1453 TRUE /* Lockable */,
1454 FALSE /* Discard */,
1455 surfImpl->mipmap_level,
1456 &surfImpl->WineD3DSurface,
1462 0 /* SharedHandle */,
1469 /* Update the IParent if it exists */
1472 parImpl->child = (IUnknown *) surfImpl->WineD3DSurface;
1473 /* Add a reference for the IParent */
1474 IWineD3DSurface_AddRef(surfImpl->WineD3DSurface);
1476 /* TODO: Copy the surface content, except for render targets */
1478 if(IWineD3DSurface_Release(wineD3DSurface) == 0)
1479 TRACE("Surface released successful, next surface\n");
1481 ERR("Something's still holding the old WineD3DSurface\n");
1483 surfImpl->ImplType = This->ImplType;
1485 return DDENUMRET_OK;
1488 /*****************************************************************************
1489 * IDirectDrawImpl_RecreateAllSurfaces
1491 * A function, that converts all wineD3DSurfaces to the new implementation type
1492 * It enumerates all surfaces with IWineD3DDevice::EnumSurfaces, creates a
1493 * new WineD3DSurface, copies the content and releases the old surface
1495 *****************************************************************************/
1497 IDirectDrawImpl_RecreateAllSurfaces(IDirectDrawImpl *This)
1499 DDSURFACEDESC2 desc;
1500 TRACE("(%p): Switch to implementation %d\n", This, This->ImplType);
1502 if(This->ImplType != SURFACE_OPENGL && This->d3d_initialized)
1504 /* Should happen almost never */
1505 FIXME("(%p) Switching to non-opengl surfaces with d3d started. Is this a bug?\n", This);
1507 IWineD3DDevice_Uninit3D(This->wineD3DDevice, D3D7CB_DestroyDepthStencilSurface, D3D7CB_DestroySwapChain);
1509 /* Contrary: D3D starting is handled by the caller, because it knows the render target */
1511 memset(&desc, 0, sizeof(desc));
1512 desc.dwSize = sizeof(desc);
1514 return IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(This, IDirectDraw7),
1518 IDirectDrawImpl_RecreateSurfacesCallback);
1521 /*****************************************************************************
1522 * D3D7CB_CreateSurface
1524 * Callback function for IDirect3DDevice_CreateTexture. It searches for the
1525 * correct mipmap sublevel, and returns it to WineD3D.
1526 * The surfaces are created already by IDirectDraw7::CreateSurface
1529 * With, Height: With and height of the surface
1530 * Format: The requested format
1531 * Usage, Pool: D3DUSAGE and D3DPOOL of the surface
1532 * level: The mipmap level
1533 * Surface: Pointer to pass the created surface back at
1534 * SharedHandle: NULL
1539 *****************************************************************************/
1540 static HRESULT WINAPI
1541 D3D7CB_CreateSurface(IUnknown *device,
1542 IUnknown *pSuperior,
1543 UINT Width, UINT Height,
1544 WINED3DFORMAT Format,
1545 DWORD Usage, WINED3DPOOL Pool, UINT level,
1546 IWineD3DSurface **Surface,
1547 HANDLE *SharedHandle)
1549 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
1550 IDirectDrawSurfaceImpl *surf = This->tex_root;
1552 TRACE("(%p) call back. surf=%p\n", device, surf);
1554 /* Find the wanted mipmap. There are enough mipmaps in the chain */
1555 for(i = 0; i < level; i++)
1556 surf = surf->next_complex;
1558 /* Return the surface */
1559 *Surface = surf->WineD3DSurface;
1561 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *Surface, surf);
1565 ULONG WINAPI D3D7CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
1566 IUnknown* swapChainParent;
1567 TRACE("(%p) call back\n", pSwapChain);
1569 IWineD3DSwapChain_GetParent(pSwapChain, &swapChainParent);
1570 IUnknown_Release(swapChainParent);
1571 return IUnknown_Release(swapChainParent);
1574 ULONG WINAPI D3D7CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
1575 IUnknown* surfaceParent;
1576 TRACE("(%p) call back\n", pSurface);
1578 IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
1579 IUnknown_Release(surfaceParent);
1580 return IUnknown_Release(surfaceParent);
1583 /*****************************************************************************
1584 * IDirectDrawImpl_CreateNewSurface
1586 * A helper function for IDirectDraw7::CreateSurface. It creates a new surface
1587 * with the passed parameters.
1590 * DDSD: Description of the surface to create
1591 * Surf: Address to store the interface pointer at
1596 *****************************************************************************/
1597 static HRESULT WINAPI
1598 IDirectDrawImpl_CreateNewSurface(IDirectDrawImpl *This,
1599 DDSURFACEDESC2 *pDDSD,
1600 IDirectDrawSurfaceImpl **ppSurf,
1604 UINT Width = 0, Height = 0;
1605 WINED3DFORMAT Format = WINED3DFMT_UNKNOWN;
1606 WINED3DRESOURCETYPE ResType = WINED3DRTYPE_SURFACE;
1608 WINED3DSURFTYPE ImplType = This->ImplType;
1609 WINED3DSURFACE_DESC Desc;
1611 IParentImpl *parImpl = NULL;
1612 WINED3DPOOL Pool = WINED3DPOOL_DEFAULT;
1614 /* Dummies for GetDesc */
1615 WINED3DPOOL dummy_d3dpool;
1616 WINED3DMULTISAMPLE_TYPE dummy_mst;
1620 if (TRACE_ON(ddraw))
1622 TRACE(" (%p) Requesting surface desc :\n", This);
1623 DDRAW_dump_surface_desc(pDDSD);
1626 /* Select the surface type, if it wasn't choosen yet */
1627 if(ImplType == SURFACE_UNKNOWN)
1629 /* Use GL Surfaces if a D3DDEVICE Surface is requested */
1630 if(pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE)
1632 TRACE("(%p) Choosing GL surfaces because a 3DDEVICE Surface was requested\n", This);
1633 ImplType = SURFACE_OPENGL;
1636 /* Otherwise use GDI surfaces for now */
1639 TRACE("(%p) Choosing GDI surfaces for 2D rendering\n", This);
1640 ImplType = SURFACE_GDI;
1643 /* Policy if all surface implementations are available:
1644 * First, check if a default type was set with winecfg. If not,
1645 * try Xrender surfaces, and use them if they work. Next, check if
1646 * accelerated OpenGL is available, and use GL surfaces in this
1647 * case. If all else fails, use GDI surfaces. If a 3DDEVICE surface
1648 * was created, always use OpenGL surfaces.
1650 * (Note: Xrender surfaces are not implemented for now, the
1651 * unaccelerated implementation uses GDI to render in Software)
1654 /* Store the type. If it needs to be changed, all WineD3DSurfaces have to
1655 * be re-created. This could be done with IDirectDrawSurface7::Restore
1657 This->ImplType = ImplType;
1661 if((pDDSD->ddsCaps.dwCaps & DDSCAPS_3DDEVICE ) &&
1662 (This->ImplType != SURFACE_OPENGL ) && DefaultSurfaceType == SURFACE_UNKNOWN)
1664 /* We have to change to OpenGL,
1665 * and re-create all WineD3DSurfaces
1667 ImplType = SURFACE_OPENGL;
1668 This->ImplType = ImplType;
1669 TRACE("(%p) Re-creating all surfaces\n", This);
1670 IDirectDrawImpl_RecreateAllSurfaces(This);
1671 TRACE("(%p) Done recreating all surfaces\n", This);
1673 else if(This->ImplType != SURFACE_OPENGL)
1675 WARN("The application requests a 3D capable surface, but a non-opengl surface was set in the registry\n");
1676 /* Do not fail surface creation, only fail 3D device creation */
1680 /* Get the correct wined3d usage */
1681 if (pDDSD->ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE |
1682 DDSCAPS_BACKBUFFER |
1683 DDSCAPS_3DDEVICE ) )
1685 Usage |= WINED3DUSAGE_RENDERTARGET;
1687 pDDSD->ddsCaps.dwCaps |= DDSCAPS_VIDEOMEMORY |
1689 DDSCAPS_LOCALVIDMEM;
1691 if (pDDSD->ddsCaps.dwCaps & (DDSCAPS_OVERLAY))
1693 Usage |= WINED3DUSAGE_OVERLAY;
1695 if(This->depthstencil)
1697 /* The depth stencil creation callback sets this flag.
1698 * Set the WineD3D usage to let it know that it's a depth
1701 Usage |= WINED3DUSAGE_DEPTHSTENCIL;
1703 if(pDDSD->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
1705 Pool = WINED3DPOOL_SYSTEMMEM;
1707 else if(pDDSD->ddsCaps.dwCaps2 & DDSCAPS2_TEXTUREMANAGE)
1709 Pool = WINED3DPOOL_MANAGED;
1712 Format = PixelFormat_DD2WineD3D(&pDDSD->u4.ddpfPixelFormat);
1713 if(Format == WINED3DFMT_UNKNOWN)
1715 ERR("Unsupported / Unknown pixelformat\n");
1716 return DDERR_INVALIDPIXELFORMAT;
1719 /* Create the Surface object */
1720 *ppSurf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawSurfaceImpl));
1723 ERR("(%p) Error allocating memory for a surface\n", This);
1724 return DDERR_OUTOFVIDEOMEMORY;
1726 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawSurface7, IDirectDrawSurface7_Vtbl);
1727 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawSurface3, IDirectDrawSurface3_Vtbl);
1728 ICOM_INIT_INTERFACE(*ppSurf, IDirectDrawGammaControl, IDirectDrawGammaControl_Vtbl);
1729 ICOM_INIT_INTERFACE(*ppSurf, IDirect3DTexture2, IDirect3DTexture2_Vtbl);
1730 ICOM_INIT_INTERFACE(*ppSurf, IDirect3DTexture, IDirect3DTexture1_Vtbl);
1732 (*ppSurf)->version = 7;
1733 (*ppSurf)->ddraw = This;
1734 (*ppSurf)->surface_desc.dwSize = sizeof(DDSURFACEDESC2);
1735 (*ppSurf)->surface_desc.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
1736 DD_STRUCT_COPY_BYSIZE(&(*ppSurf)->surface_desc, pDDSD);
1738 /* Surface attachments */
1739 (*ppSurf)->next_attached = NULL;
1740 (*ppSurf)->first_attached = *ppSurf;
1742 (*ppSurf)->next_complex = NULL;
1743 (*ppSurf)->first_complex = *ppSurf;
1745 /* Needed to re-create the surface on an implementation change */
1746 (*ppSurf)->ImplType = ImplType;
1748 /* For D3DDevice creation */
1749 (*ppSurf)->isRenderTarget = FALSE;
1751 /* A trace message for debugging */
1752 TRACE("(%p) Created IDirectDrawSurface implementation structure at %p\n", This, *ppSurf);
1754 if(pDDSD->ddsCaps.dwCaps & ( DDSCAPS_PRIMARYSURFACE | DDSCAPS_TEXTURE | DDSCAPS_3DDEVICE) )
1756 /* Render targets and textures need a IParent interface,
1757 * because WineD3D will destroy them when the swapchain
1760 parImpl = HeapAlloc(GetProcessHeap(), 0, sizeof(IParentImpl));
1763 ERR("Out of memory when allocating memory for a IParent implementation\n");
1764 return DDERR_OUTOFMEMORY;
1767 ICOM_INIT_INTERFACE(parImpl, IParent, IParent_Vtbl);
1768 Parent = (IUnknown *) ICOM_INTERFACE(parImpl, IParent);
1769 TRACE("Using IParent interface %p as parent\n", parImpl);
1773 /* Use the surface as parent */
1774 Parent = (IUnknown *) ICOM_INTERFACE(*ppSurf, IDirectDrawSurface7);
1775 TRACE("Using Surface interface %p as parent\n", *ppSurf);
1778 /* Now create the WineD3D Surface */
1779 hr = IWineD3DDevice_CreateSurface(This->wineD3DDevice,
1783 TRUE /* Lockable */,
1784 FALSE /* Discard */,
1786 &(*ppSurf)->WineD3DSurface,
1789 WINED3DMULTISAMPLE_NONE,
1790 0 /* MultiSampleQuality */,
1791 0 /* SharedHandle */,
1797 ERR("IWineD3DDevice::CreateSurface failed. hr = %08x\n", hr);
1801 /* Set the child of the parent implementation if it exists */
1804 parImpl->child = (IUnknown *) (*ppSurf)->WineD3DSurface;
1805 /* The IParent releases the WineD3DSurface, and
1806 * the ddraw surface does that too. Hold a reference
1808 IWineD3DSurface_AddRef((*ppSurf)->WineD3DSurface);
1811 /* Increase the surface counter, and attach the surface */
1812 InterlockedIncrement(&This->surfaces);
1813 list_add_head(&This->surface_list, &(*ppSurf)->surface_list_entry);
1815 /* Here we could store all created surfaces in the DirectDrawImpl structure,
1816 * But this could also be delegated to WineDDraw, as it keeps track of all its
1817 * resources. Not implemented for now, as there are more important things ;)
1820 /* Get the pixel format of the WineD3DSurface and store it.
1821 * Don't use the Format choosen above, WineD3D might have
1824 Desc.Format = &Format;
1825 Desc.Type = &ResType;
1826 Desc.Usage = &Usage;
1827 Desc.Pool = &dummy_d3dpool;
1828 Desc.Size = &dummy_uint;
1829 Desc.MultiSampleType = &dummy_mst;
1830 Desc.MultiSampleQuality = &dummy_dword;
1831 Desc.Width = &Width;
1832 Desc.Height = &Height;
1834 (*ppSurf)->surface_desc.dwFlags |= DDSD_PIXELFORMAT;
1835 hr = IWineD3DSurface_GetDesc((*ppSurf)->WineD3DSurface, &Desc);
1838 ERR("IWineD3DSurface::GetDesc failed\n");
1839 IDirectDrawSurface7_Release( (IDirectDrawSurface7 *) *ppSurf);
1843 if(Format == WINED3DFMT_UNKNOWN)
1845 FIXME("IWineD3DSurface::GetDesc returned WINED3DFMT_UNKNOWN\n");
1847 PixelFormat_WineD3DtoDD( &(*ppSurf)->surface_desc.u4.ddpfPixelFormat, Format);
1849 /* Anno 1602 stores the pitch right after surface creation, so make sure it's there.
1850 * I can't LockRect() the surface here because if OpenGL surfaces are in use, the
1851 * WineD3DDevice might not be useable for 3D yet, so an extra method was created
1853 (*ppSurf)->surface_desc.dwFlags |= DDSD_PITCH;
1854 (*ppSurf)->surface_desc.u1.lPitch = IWineD3DSurface_GetPitch((*ppSurf)->WineD3DSurface);
1856 /* Application passed a color key? Set it! */
1857 if(pDDSD->dwFlags & DDSD_CKDESTOVERLAY)
1859 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1861 &pDDSD->u3.ddckCKDestOverlay);
1863 if(pDDSD->dwFlags & DDSD_CKDESTBLT)
1865 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1867 &pDDSD->ddckCKDestBlt);
1869 if(pDDSD->dwFlags & DDSD_CKSRCOVERLAY)
1871 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1873 &pDDSD->ddckCKSrcOverlay);
1875 if(pDDSD->dwFlags & DDSD_CKSRCBLT)
1877 IWineD3DSurface_SetColorKey((*ppSurf)->WineD3DSurface,
1879 &pDDSD->ddckCKSrcBlt);
1881 if ( pDDSD->dwFlags & DDSD_LPSURFACE)
1883 hr = IWineD3DSurface_SetMem((*ppSurf)->WineD3DSurface, pDDSD->lpSurface);
1884 if(hr != WINED3D_OK)
1886 /* No need for a trace here, wined3d does that for us */
1887 IDirectDrawSurface7_Release(ICOM_INTERFACE((*ppSurf), IDirectDrawSurface7));
1895 /*****************************************************************************
1896 * IDirectDraw7::CreateSurface
1898 * Creates a new IDirectDrawSurface object and returns its interface.
1900 * The surface connections with wined3d are a bit tricky. Basically it works
1903 * |------------------------| |-----------------|
1904 * | DDraw surface | | WineD3DSurface |
1906 * | WineD3DSurface |-------------->| |
1907 * | Child |<------------->| Parent |
1908 * |------------------------| |-----------------|
1910 * The DDraw surface is the parent of the wined3d surface, and it releases
1911 * the WineD3DSurface when the ddraw surface is destroyed.
1913 * However, for all surfaces which can be in a container in WineD3D,
1914 * we have to do this. These surfaces are ususally complex surfaces,
1915 * so this concerns primary surfaces with a front and a back buffer,
1918 * |------------------------| |-----------------|
1919 * | DDraw surface | | Containter |
1921 * | Child |<------------->| Parent |
1922 * | Texture |<------------->| |
1923 * | WineD3DSurface |<----| | Levels |<--|
1924 * | Complex connection | | | | |
1925 * |------------------------| | |-----------------| |
1929 * | |------------------| | |-----------------| |
1930 * | | IParent | |-------->| WineD3DSurface | |
1932 * | | Child |<------------->| Parent | |
1933 * | | | | Container |<--|
1934 * | |------------------| |-----------------| |
1936 * | |----------------------| |
1937 * | | DDraw surface 2 | |
1939 * |<->| Complex root Child | |
1941 * | | WineD3DSurface |<----| |
1942 * | |----------------------| | |
1944 * | |---------------------| | |-----------------| |
1945 * | | IParent | |----->| WineD3DSurface | |
1947 * | | Child |<---------->| Parent | |
1948 * | |---------------------| | Container |<--|
1949 * | |-----------------| |
1951 * | ---More surfaces can follow--- |
1953 * The reason is that the IWineD3DSwapchain(render target container)
1954 * and the IWineD3DTexure(Texture container) release the parents
1955 * of their surface's children, but by releasing the complex root
1956 * the surfaces which are complexly attached to it are destroyed
1957 * too. See IDirectDrawSurface::Release for a more detailed
1961 * DDSD: Description of the surface to create
1962 * Surf: Address to store the interface pointer at
1963 * UnkOuter: Basically for aggregation support, but ddraw doesn't support
1964 * aggregation, so it has to be NULL
1968 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
1969 * DDERR_* if an error occurs
1971 *****************************************************************************/
1972 static HRESULT WINAPI
1973 IDirectDrawImpl_CreateSurface(IDirectDraw7 *iface,
1974 DDSURFACEDESC2 *DDSD,
1975 IDirectDrawSurface7 **Surf,
1978 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
1979 IDirectDrawSurfaceImpl *object = NULL;
1981 LONG extra_surfaces = 0, i;
1982 DDSURFACEDESC2 desc2;
1984 WINED3DDISPLAYMODE Mode;
1986 TRACE("(%p)->(%p,%p,%p)\n", This, DDSD, Surf, UnkOuter);
1988 /* Some checks before we start */
1989 if (TRACE_ON(ddraw))
1991 TRACE(" (%p) Requesting surface desc :\n", This);
1992 DDRAW_dump_surface_desc(DDSD);
1995 if (UnkOuter != NULL)
1997 FIXME("(%p) : outer != NULL?\n", This);
1998 return CLASS_E_NOAGGREGATION; /* unchecked */
2001 if (!(DDSD->dwFlags & DDSD_CAPS))
2003 /* DVIDEO.DLL does forget the DDSD_CAPS flag ... *sigh* */
2004 DDSD->dwFlags |= DDSD_CAPS;
2006 if (DDSD->ddsCaps.dwCaps == 0)
2008 /* This has been checked on real Windows */
2009 DDSD->ddsCaps.dwCaps = DDSCAPS_LOCALVIDMEM | DDSCAPS_VIDEOMEMORY;
2012 if (DDSD->ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD)
2014 /* If the surface is of the 'alloconload' type, ignore the LPSURFACE field */
2015 DDSD->dwFlags &= ~DDSD_LPSURFACE;
2018 if ((DDSD->dwFlags & DDSD_LPSURFACE) && (DDSD->lpSurface == NULL))
2020 /* Frank Herbert's Dune specifies a null pointer for the surface, ignore the LPSURFACE field */
2021 WARN("(%p) Null surface pointer specified, ignore it!\n", This);
2022 DDSD->dwFlags &= ~DDSD_LPSURFACE;
2025 if((DDSD->ddsCaps.dwCaps & (DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE)) == (DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE) &&
2026 !(This->cooperative_level & DDSCL_EXCLUSIVE))
2028 TRACE("(%p): Attempt to create a flipable primary surface without DDSCL_EXCLUSIVE set\n", This);
2030 return DDERR_NOEXCLUSIVEMODE;
2035 FIXME("(%p) You want to get back a surface? Don't give NULL ptrs!\n", This);
2036 return E_POINTER; /* unchecked */
2039 /* According to the msdn this flag is ignored by CreateSurface */
2040 if (DDSD->dwSize >= sizeof(DDSURFACEDESC2))
2041 DDSD->ddsCaps.dwCaps2 &= ~DDSCAPS2_MIPMAPSUBLEVEL;
2043 /* Modify some flags */
2044 memset(&desc2, 0, sizeof(desc2));
2045 desc2.dwSize = sizeof(desc2); /* For the struct copy */
2046 DD_STRUCT_COPY_BYSIZE(&desc2, DDSD);
2047 desc2.dwSize = sizeof(desc2); /* To override a possibly smaller size */
2048 desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT); /* Just to be sure */
2050 /* Get the video mode from WineD3D - we will need it */
2051 hr = IWineD3DDevice_GetDisplayMode(This->wineD3DDevice,
2052 0, /* Swapchain 0 */
2056 ERR("Failed to read display mode from wined3d\n");
2057 switch(This->orig_bpp)
2060 Mode.Format = WINED3DFMT_P8;
2064 Mode.Format = WINED3DFMT_X1R5G5B5;
2068 Mode.Format = WINED3DFMT_R5G6B5;
2072 Mode.Format = WINED3DFMT_R8G8B8;
2076 Mode.Format = WINED3DFMT_X8R8G8B8;
2079 Mode.Width = This->orig_width;
2080 Mode.Height = This->orig_height;
2083 /* No pixelformat given? Use the current screen format */
2084 if(!(desc2.dwFlags & DDSD_PIXELFORMAT))
2086 desc2.dwFlags |= DDSD_PIXELFORMAT;
2087 desc2.u4.ddpfPixelFormat.dwSize=sizeof(DDPIXELFORMAT);
2089 /* Wait: It could be a Z buffer */
2090 if(desc2.ddsCaps.dwCaps & DDSCAPS_ZBUFFER)
2092 switch(desc2.u2.dwMipMapCount) /* Who had this glorious idea? */
2095 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D15S1);
2098 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D16);
2101 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D24X8);
2104 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, WINED3DFMT_D32);
2107 ERR("Unknown Z buffer bit depth\n");
2112 PixelFormat_WineD3DtoDD(&desc2.u4.ddpfPixelFormat, Mode.Format);
2116 /* No Width or no Height? Use the current window size or
2117 * the original screen size
2119 if(!(desc2.dwFlags & DDSD_WIDTH) ||
2120 !(desc2.dwFlags & DDSD_HEIGHT) )
2124 /* Fallback: From WineD3D / original mode */
2125 desc2.dwFlags |= DDSD_WIDTH | DDSD_HEIGHT;
2126 desc2.dwWidth = Mode.Width;
2127 desc2.dwHeight = Mode.Height;
2129 hr = IWineD3DDevice_GetHWND(This->wineD3DDevice,
2131 if( (hr == D3D_OK) && (window != 0) )
2134 if(GetWindowRect(window, &rect) )
2136 /* This is a hack until I find a better solution */
2137 if( (rect.right - rect.left) <= 1 ||
2138 (rect.bottom - rect.top) <= 1 )
2140 FIXME("Wanted to get surface dimensions from window %p, but it has only "
2141 "a size of %dx%d. Using full screen dimensions\n",
2142 window, rect.right - rect.left, rect.bottom - rect.top);
2146 /* Not sure if this is correct */
2147 desc2.dwWidth = rect.right - rect.left;
2148 desc2.dwHeight = rect.bottom - rect.top;
2149 TRACE("Using window %p's dimensions: %dx%d\n", window, desc2.dwWidth, desc2.dwHeight);
2155 /* Mipmap count fixes */
2156 if(desc2.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2158 if(desc2.ddsCaps.dwCaps & DDSCAPS_COMPLEX)
2160 if(desc2.dwFlags & DDSD_MIPMAPCOUNT)
2162 /* Mipmap count is given, nothing to do */
2166 /* Undocumented feature: Create sublevels until
2167 * either the width or the height is 1
2169 DWORD min = desc2.dwWidth < desc2.dwHeight ?
2170 desc2.dwWidth : desc2.dwHeight;
2171 desc2.u2.dwMipMapCount = 0;
2174 desc2.u2.dwMipMapCount += 1;
2181 /* Not-complex mipmap -> Mipmapcount = 1 */
2182 desc2.u2.dwMipMapCount = 1;
2184 extra_surfaces = desc2.u2.dwMipMapCount - 1;
2186 /* There's a mipmap count in the created surface in any case */
2187 desc2.dwFlags |= DDSD_MIPMAPCOUNT;
2189 /* If no mipmap is given, the texture has only one level */
2191 /* The first surface is a front buffer, the back buffer is created afterwards */
2192 if( (desc2.dwFlags & DDSD_CAPS) && (desc2.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) )
2194 desc2.ddsCaps.dwCaps |= DDSCAPS_FRONTBUFFER;
2197 /* Create the first surface */
2198 hr = IDirectDrawImpl_CreateNewSurface(This, &desc2, &object, 0);
2201 ERR("IDirectDrawImpl_CreateNewSurface failed with %08x\n", hr);
2205 *Surf = ICOM_INTERFACE(object, IDirectDrawSurface7);
2207 /* Create Additional surfaces if necessary
2208 * This applies to Primary surfaces which have a back buffer count
2209 * set, but not to mipmap textures. In case of Mipmap textures,
2210 * wineD3D takes care of the creation of additional surfaces
2212 if(DDSD->dwFlags & DDSD_BACKBUFFERCOUNT)
2214 extra_surfaces = DDSD->dwBackBufferCount;
2215 desc2.ddsCaps.dwCaps &= ~DDSCAPS_FRONTBUFFER; /* It's not a front buffer */
2216 desc2.ddsCaps.dwCaps |= DDSCAPS_BACKBUFFER;
2218 /* Set the DDSCAPS2_MIPMAPSUBLEVEL flag on mipmap sublevels according to the msdn */
2219 if(DDSD->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2221 desc2.ddsCaps.dwCaps2 |= DDSCAPS2_MIPMAPSUBLEVEL;
2224 for(i = 0; i < extra_surfaces; i++)
2226 IDirectDrawSurfaceImpl *object2 = NULL;
2227 IDirectDrawSurfaceImpl *iterator;
2229 /* increase the mipmap level, but only if a mipmap is created
2230 * In this case, also halve the size
2232 if(DDSD->ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2235 if(desc2.dwWidth > 1) desc2.dwWidth /= 2;
2236 if(desc2.dwHeight > 1) desc2.dwHeight /= 2;
2239 hr = IDirectDrawImpl_CreateNewSurface(This,
2245 /* This destroys and possibly created surfaces too */
2246 IDirectDrawSurface_Release( ICOM_INTERFACE(object, IDirectDrawSurface7) );
2250 /* Add the new surface to the complex attachment list */
2251 object2->first_complex = object;
2252 object2->next_complex = NULL;
2254 while(iterator->next_complex) iterator = iterator->next_complex;
2255 iterator->next_complex = object2;
2257 /* Remove the (possible) back buffer cap from the new surface description,
2258 * because only one surface in the flipping chain is a back buffer, one
2259 * is a front buffer, the others are just primary surfaces.
2261 desc2.ddsCaps.dwCaps &= ~DDSCAPS_BACKBUFFER;
2264 /* Addref the ddraw interface to keep an reference for each surface */
2265 IDirectDraw7_AddRef(iface);
2266 object->ifaceToRelease = (IUnknown *) iface;
2268 /* If the implementation is OpenGL and there's no d3ddevice, attach a d3ddevice
2269 * But attach the d3ddevice only if the currently created surface was
2270 * a primary surface (2D app in 3D mode) or a 3DDEVICE surface (3D app)
2271 * The only case I can think of where this doesn't apply is when a
2272 * 2D app was configured by the user to run with OpenGL and it didn't create
2273 * the render target as first surface. In this case the render target creation
2274 * will cause the 3D init.
2276 if( (This->ImplType == SURFACE_OPENGL) && !(This->d3d_initialized) &&
2277 desc2.ddsCaps.dwCaps & (DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE) )
2279 IDirectDrawSurfaceImpl *target = object, *surface;
2282 /* Search for the primary to use as render target */
2283 LIST_FOR_EACH(entry, &This->surface_list)
2285 surface = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
2286 if(surface->surface_desc.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
2290 TRACE("Using primary %p as render target\n", target);
2295 TRACE("(%p) Attaching a D3DDevice, rendertarget = %p\n", This, target);
2296 hr = IDirectDrawImpl_AttachD3DDevice(This, target->first_complex);
2299 ERR("IDirectDrawImpl_AttachD3DDevice failed, hr = %x\n", hr);
2303 /* Create a WineD3DTexture if a texture was requested */
2304 if(DDSD->ddsCaps.dwCaps & DDSCAPS_TEXTURE)
2307 WINED3DFORMAT Format;
2308 WINED3DPOOL Pool = WINED3DPOOL_DEFAULT;
2310 This->tex_root = object;
2312 if(desc2.ddsCaps.dwCaps & DDSCAPS_MIPMAP)
2314 /* a mipmap is created, create enough levels */
2315 levels = desc2.u2.dwMipMapCount;
2319 /* No mipmap is created, create one level */
2323 /* DDSCAPS_SYSTEMMEMORY textures are in WINED3DPOOL_SYSTEMMEM */
2324 if(DDSD->ddsCaps.dwCaps & DDSCAPS_SYSTEMMEMORY)
2326 Pool = WINED3DPOOL_SYSTEMMEM;
2328 /* Should I forward the MANEGED cap to the managed pool ? */
2330 /* Get the format. It's set already by CreateNewSurface */
2331 Format = PixelFormat_DD2WineD3D(&object->surface_desc.u4.ddpfPixelFormat);
2333 /* The surfaces are already created, the callback only
2334 * passes the IWineD3DSurface to WineD3D
2336 hr = IWineD3DDevice_CreateTexture( This->wineD3DDevice,
2337 DDSD->dwWidth, DDSD->dwHeight,
2338 levels, /* MipMapCount = Levels */
2342 &object->wineD3DTexture,
2343 0, /* SharedHandle */
2344 (IUnknown *) ICOM_INTERFACE(object, IDirectDrawSurface7),
2345 D3D7CB_CreateSurface );
2346 This->tex_root = NULL;
2352 #define DDENUMSURFACES_SEARCHTYPE (DDENUMSURFACES_CANBECREATED|DDENUMSURFACES_DOESEXIST)
2353 #define DDENUMSURFACES_MATCHTYPE (DDENUMSURFACES_ALL|DDENUMSURFACES_MATCH|DDENUMSURFACES_NOMATCH)
2356 Main_DirectDraw_DDPIXELFORMAT_Match(const DDPIXELFORMAT *requested,
2357 const DDPIXELFORMAT *provided)
2359 /* Some flags must be present in both or neither for a match. */
2360 static const DWORD must_match = DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2
2361 | DDPF_PALETTEINDEXED4 | DDPF_PALETTEINDEXED8 | DDPF_FOURCC
2362 | DDPF_ZBUFFER | DDPF_STENCILBUFFER;
2364 if ((requested->dwFlags & provided->dwFlags) != requested->dwFlags)
2367 if ((requested->dwFlags & must_match) != (provided->dwFlags & must_match))
2370 if (requested->dwFlags & DDPF_FOURCC)
2371 if (requested->dwFourCC != provided->dwFourCC)
2374 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_ZBUFFER|DDPF_ALPHA
2375 |DDPF_LUMINANCE|DDPF_BUMPDUDV))
2376 if (requested->u1.dwRGBBitCount != provided->u1.dwRGBBitCount)
2379 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_STENCILBUFFER
2380 |DDPF_LUMINANCE|DDPF_BUMPDUDV))
2381 if (requested->u2.dwRBitMask != provided->u2.dwRBitMask)
2384 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_ZBUFFER|DDPF_BUMPDUDV))
2385 if (requested->u3.dwGBitMask != provided->u3.dwGBitMask)
2388 /* I could be wrong about the bumpmapping. MSDN docs are vague. */
2389 if (requested->dwFlags & (DDPF_RGB|DDPF_YUV|DDPF_STENCILBUFFER
2391 if (requested->u4.dwBBitMask != provided->u4.dwBBitMask)
2394 if (requested->dwFlags & (DDPF_ALPHAPIXELS|DDPF_ZPIXELS))
2395 if (requested->u5.dwRGBAlphaBitMask != provided->u5.dwRGBAlphaBitMask)
2402 IDirectDrawImpl_DDSD_Match(const DDSURFACEDESC2* requested,
2403 const DDSURFACEDESC2* provided)
2412 #define CMP(FLAG, FIELD) \
2413 { DDSD_##FLAG, offsetof(DDSURFACEDESC2, FIELD), \
2414 sizeof(((DDSURFACEDESC2 *)(NULL))->FIELD) }
2416 static const struct compare_info compare[] =
2418 CMP(ALPHABITDEPTH, dwAlphaBitDepth),
2419 CMP(BACKBUFFERCOUNT, dwBackBufferCount),
2421 CMP(CKDESTBLT, ddckCKDestBlt),
2422 CMP(CKDESTOVERLAY, u3 /* ddckCKDestOverlay */),
2423 CMP(CKSRCBLT, ddckCKSrcBlt),
2424 CMP(CKSRCOVERLAY, ddckCKSrcOverlay),
2425 CMP(HEIGHT, dwHeight),
2426 CMP(LINEARSIZE, u1 /* dwLinearSize */),
2427 CMP(LPSURFACE, lpSurface),
2428 CMP(MIPMAPCOUNT, u2 /* dwMipMapCount */),
2429 CMP(PITCH, u1 /* lPitch */),
2430 /* PIXELFORMAT: manual */
2431 CMP(REFRESHRATE, u2 /* dwRefreshRate */),
2432 CMP(TEXTURESTAGE, dwTextureStage),
2433 CMP(WIDTH, dwWidth),
2434 /* ZBUFFERBITDEPTH: "obsolete" */
2441 if ((requested->dwFlags & provided->dwFlags) != requested->dwFlags)
2444 for (i=0; i < sizeof(compare)/sizeof(compare[0]); i++)
2446 if (requested->dwFlags & compare[i].flag
2447 && memcmp((const char *)provided + compare[i].offset,
2448 (const char *)requested + compare[i].offset,
2449 compare[i].size) != 0)
2453 if (requested->dwFlags & DDSD_PIXELFORMAT)
2455 if (!Main_DirectDraw_DDPIXELFORMAT_Match(&requested->u4.ddpfPixelFormat,
2456 &provided->u4.ddpfPixelFormat))
2463 #undef DDENUMSURFACES_SEARCHTYPE
2464 #undef DDENUMSURFACES_MATCHTYPE
2466 /*****************************************************************************
2467 * IDirectDraw7::EnumSurfaces
2469 * Loops through all surfaces attached to this device and calls the
2470 * application callback. This can't be relayed to WineD3DDevice,
2471 * because some WineD3DSurfaces' parents are IParent objects
2474 * Flags: Some filtering flags. See IDirectDrawImpl_EnumSurfacesCallback
2475 * DDSD: Description to filter for
2476 * Context: Application-provided pointer, it's passed unmodified to the
2478 * Callback: Address to call for each surface
2481 * DDERR_INVALIDPARAMS if the callback is NULL
2484 *****************************************************************************/
2485 static HRESULT WINAPI
2486 IDirectDrawImpl_EnumSurfaces(IDirectDraw7 *iface,
2488 DDSURFACEDESC2 *DDSD,
2490 LPDDENUMSURFACESCALLBACK7 Callback)
2492 /* The surface enumeration is handled by WineDDraw,
2493 * because it keeps track of all surfaces attached to
2494 * it. The filtering is done by our callback function,
2495 * because WineDDraw doesn't handle ddraw-like surface
2498 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2499 IDirectDrawSurfaceImpl *surf;
2501 DDSURFACEDESC2 desc;
2502 struct list *entry, *entry2;
2504 all = Flags & DDENUMSURFACES_ALL;
2505 nomatch = Flags & DDENUMSURFACES_NOMATCH;
2507 TRACE("(%p)->(%x,%p,%p,%p)\n", This, Flags, DDSD, Context, Callback);
2510 return DDERR_INVALIDPARAMS;
2512 /* Use the _SAFE enumeration, the app may destroy enumerated surfaces */
2513 LIST_FOR_EACH_SAFE(entry, entry2, &This->surface_list)
2515 surf = LIST_ENTRY(entry, IDirectDrawSurfaceImpl, surface_list_entry);
2516 if (all || (nomatch != IDirectDrawImpl_DDSD_Match(DDSD, &surf->surface_desc)))
2518 desc = surf->surface_desc;
2519 IDirectDrawSurface7_AddRef(ICOM_INTERFACE(surf, IDirectDrawSurface7));
2520 if(Callback( ICOM_INTERFACE(surf, IDirectDrawSurface7), &desc, Context) != DDENUMRET_OK)
2527 /*****************************************************************************
2528 * D3D7CB_CreateRenderTarget
2530 * Callback called by WineD3D to create Surfaces for render target usage
2531 * This function takes the D3D target from the IDirectDrawImpl structure,
2532 * and returns the WineD3DSurface. To avoid double usage, the surface
2533 * is marked as render target afterwards
2536 * device: The WineD3DDevice's parent
2537 * Width, Height, Format: Dimensions and pixelformat of the render target
2538 * Ignored, because the surface already exists
2539 * MultiSample, MultisampleQuality, Lockable: Ignored for the same reason
2541 * ppSurface: Address to pass the surface pointer back at
2542 * pSharedHandle: Ignored
2545 * Always returns D3D_OK
2547 *****************************************************************************/
2548 static HRESULT WINAPI
2549 D3D7CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior,
2550 UINT Width, UINT Height,
2551 WINED3DFORMAT Format,
2552 WINED3DMULTISAMPLE_TYPE MultiSample,
2553 DWORD MultisampleQuality,
2555 IWineD3DSurface** ppSurface,
2556 HANDLE* pSharedHandle)
2558 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2559 IDirectDrawSurfaceImpl *d3dSurface = (IDirectDrawSurfaceImpl *) This->d3d_target->first_complex;
2560 TRACE("(%p) call back\n", device);
2562 /* Loop through the complex chain and try to find unused primary surfaces */
2563 while(d3dSurface->isRenderTarget)
2565 d3dSurface = d3dSurface->next_complex;
2566 if(!d3dSurface) break;
2570 d3dSurface = This->d3d_target;
2571 ERR(" (%p) : No DirectDrawSurface found to create the back buffer. Using the front buffer as back buffer. Uncertain consequences\n", This);
2574 /* TODO: Return failure if the dimensions do not match, but this shouldn't happen */
2576 *ppSurface = d3dSurface->WineD3DSurface;
2577 d3dSurface->isRenderTarget = TRUE;
2578 TRACE("Returning wineD3DSurface %p, it belongs to surface %p\n", *ppSurface, d3dSurface);
2582 static HRESULT WINAPI
2583 D3D7CB_CreateDepthStencilSurface(IUnknown *device,
2584 IUnknown *pSuperior,
2587 WINED3DFORMAT Format,
2588 WINED3DMULTISAMPLE_TYPE MultiSample,
2589 DWORD MultisampleQuality,
2591 IWineD3DSurface** ppSurface,
2592 HANDLE* pSharedHandle)
2594 /* Create a Depth Stencil surface to make WineD3D happy */
2595 HRESULT hr = D3D_OK;
2596 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2597 DDSURFACEDESC2 ddsd;
2599 TRACE("(%p) call back\n", device);
2603 /* Create a DirectDraw surface */
2604 memset(&ddsd, 0, sizeof(ddsd));
2605 ddsd.dwSize = sizeof(ddsd);
2606 ddsd.u4.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);
2607 ddsd.dwFlags = DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
2608 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
2609 ddsd.dwHeight = Height;
2610 ddsd.dwWidth = Width;
2613 PixelFormat_WineD3DtoDD(&ddsd.u4.ddpfPixelFormat, Format);
2617 ddsd.dwFlags ^= DDSD_PIXELFORMAT;
2620 This->depthstencil = TRUE;
2621 hr = IDirectDraw7_CreateSurface((IDirectDraw7 *) This,
2623 (IDirectDrawSurface7 **) &This->DepthStencilBuffer,
2625 This->depthstencil = FALSE;
2628 ERR(" (%p) Creating a DepthStencil Surface failed, result = %x\n", This, hr);
2631 *ppSurface = This->DepthStencilBuffer->WineD3DSurface;
2635 /*****************************************************************************
2636 * D3D7CB_CreateAdditionalSwapChain
2638 * Callback function for WineD3D which creates a new WineD3DSwapchain
2639 * interface. It also creates an IParent interface to store that pointer,
2640 * so the WineD3DSwapchain has a parent and can be released when the D3D
2641 * device is destroyed
2642 *****************************************************************************/
2643 static HRESULT WINAPI
2644 D3D7CB_CreateAdditionalSwapChain(IUnknown *device,
2645 WINED3DPRESENT_PARAMETERS* pPresentationParameters,
2646 IWineD3DSwapChain ** ppSwapChain)
2648 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, device);
2649 IParentImpl *object = NULL;
2650 HRESULT res = D3D_OK;
2651 IWineD3DSwapChain *swapchain;
2652 TRACE("(%p) call back\n", device);
2654 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IParentImpl));
2657 FIXME("Allocation of memory failed\n");
2658 *ppSwapChain = NULL;
2659 return DDERR_OUTOFVIDEOMEMORY;
2662 ICOM_INIT_INTERFACE(object, IParent, IParent_Vtbl);
2665 res = IWineD3DDevice_CreateAdditionalSwapChain(This->wineD3DDevice,
2666 pPresentationParameters,
2668 (IUnknown*) ICOM_INTERFACE(object, IParent),
2669 D3D7CB_CreateRenderTarget,
2670 D3D7CB_CreateDepthStencilSurface);
2673 FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
2674 HeapFree(GetProcessHeap(), 0 , object);
2675 *ppSwapChain = NULL;
2679 *ppSwapChain = swapchain;
2680 object->child = (IUnknown *) swapchain;
2686 /*****************************************************************************
2687 * IDirectDrawImpl_AttachD3DDevice
2689 * Initializes the D3D capabilities of WineD3D
2692 * primary: The primary surface for D3D
2698 *****************************************************************************/
2699 static HRESULT WINAPI
2700 IDirectDrawImpl_AttachD3DDevice(IDirectDrawImpl *This,
2701 IDirectDrawSurfaceImpl *primary)
2706 WINED3DPRESENT_PARAMETERS localParameters;
2708 TRACE("(%p)->(%p)\n", This, primary);
2710 /* Get the window */
2711 hr = IWineD3DDevice_GetHWND(This->wineD3DDevice,
2715 ERR("IWineD3DDevice::GetHWND failed\n");
2719 /* If there's no window, create a hidden window. WineD3D needs it */
2722 window = CreateWindowExA(0, This->classname, "Hidden D3D Window",
2724 GetSystemMetrics(SM_CXSCREEN),
2725 GetSystemMetrics(SM_CYSCREEN),
2726 NULL, NULL, GetModuleHandleA(0), NULL);
2728 ShowWindow(window, SW_HIDE); /* Just to be sure */
2729 WARN("(%p) No window for the Direct3DDevice, created a hidden window. HWND=%p\n", This, window);
2730 This->d3d_window = window;
2734 TRACE("(%p) Using existing window %p for Direct3D rendering\n", This, window);
2737 /* Store the future Render Target surface */
2738 This->d3d_target = primary;
2740 /* Use the surface description for the device parameters, not the
2741 * Device settings. The app might render to an offscreen surface
2743 localParameters.BackBufferWidth = primary->surface_desc.dwWidth;
2744 localParameters.BackBufferHeight = primary->surface_desc.dwHeight;
2745 localParameters.BackBufferFormat = PixelFormat_DD2WineD3D(&primary->surface_desc.u4.ddpfPixelFormat);
2746 localParameters.BackBufferCount = (primary->surface_desc.dwFlags & DDSD_BACKBUFFERCOUNT) ? primary->surface_desc.dwBackBufferCount : 0;
2747 localParameters.MultiSampleType = WINED3DMULTISAMPLE_NONE;
2748 localParameters.MultiSampleQuality = 0;
2749 localParameters.SwapEffect = WINED3DSWAPEFFECT_COPY;
2750 localParameters.hDeviceWindow = window;
2751 localParameters.Windowed = !(This->cooperative_level & DDSCL_FULLSCREEN);
2752 localParameters.EnableAutoDepthStencil = FALSE;
2753 localParameters.AutoDepthStencilFormat = WINED3DFMT_D16;
2754 localParameters.Flags = 0;
2755 localParameters.FullScreen_RefreshRateInHz = WINED3DPRESENT_RATE_DEFAULT; /* Default rate: It's already set */
2756 localParameters.PresentationInterval = WINED3DPRESENT_INTERVAL_DEFAULT;
2758 TRACE("Passing mode %d\n", localParameters.BackBufferFormat);
2760 /* Set this NOW, otherwise creating the depth stencil surface will cause a
2761 * recursive loop until ram or emulated video memory is full
2763 This->d3d_initialized = TRUE;
2765 hr = IWineD3DDevice_Init3D(This->wineD3DDevice,
2767 D3D7CB_CreateAdditionalSwapChain);
2770 This->wineD3DDevice = NULL;
2774 /* Create an Index Buffer parent */
2775 TRACE("(%p) Successfully initialized 3D\n", This);
2779 /*****************************************************************************
2780 * DirectDrawCreateClipper (DDRAW.@)
2782 * Creates a new IDirectDrawClipper object.
2785 * Clipper: Address to write the interface pointer to
2786 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2790 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2791 * E_OUTOFMEMORY if allocating the object failed
2793 *****************************************************************************/
2795 DirectDrawCreateClipper(DWORD Flags,
2796 IDirectDrawClipper **Clipper,
2799 IDirectDrawClipperImpl* object;
2800 TRACE("(%08x,%p,%p)\n", Flags, Clipper, UnkOuter);
2802 if (UnkOuter != NULL) return CLASS_E_NOAGGREGATION;
2804 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2805 sizeof(IDirectDrawClipperImpl));
2806 if (object == NULL) return E_OUTOFMEMORY;
2808 ICOM_INIT_INTERFACE(object, IDirectDrawClipper, IDirectDrawClipper_Vtbl);
2811 object->ddraw_owner = NULL;
2813 *Clipper = (IDirectDrawClipper *) object;
2817 /*****************************************************************************
2818 * IDirectDraw7::CreateClipper
2820 * Creates a DDraw clipper. See DirectDrawCreateClipper for details
2822 *****************************************************************************/
2823 static HRESULT WINAPI
2824 IDirectDrawImpl_CreateClipper(IDirectDraw7 *iface,
2826 IDirectDrawClipper **Clipper,
2829 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2830 TRACE("(%p)->(%x,%p,%p)\n", This, Flags, Clipper, UnkOuter);
2831 return DirectDrawCreateClipper(Flags, Clipper, UnkOuter);
2834 /*****************************************************************************
2835 * IDirectDraw7::CreatePalette
2837 * Creates a new IDirectDrawPalette object
2840 * Flags: The flags for the new clipper
2841 * ColorTable: Color table to assign to the new clipper
2842 * Palette: Address to write the interface pointer to
2843 * UnkOuter: For aggregation support, which ddraw doesn't have. Has to be
2847 * CLASS_E_NOAGGREGATION if UnkOuter != NULL
2848 * E_OUTOFMEMORY if allocating the object failed
2850 *****************************************************************************/
2851 static HRESULT WINAPI
2852 IDirectDrawImpl_CreatePalette(IDirectDraw7 *iface,
2854 PALETTEENTRY *ColorTable,
2855 IDirectDrawPalette **Palette,
2856 IUnknown *pUnkOuter)
2858 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2859 IDirectDrawPaletteImpl *object;
2860 HRESULT hr = DDERR_GENERIC;
2861 TRACE("(%p)->(%x,%p,%p,%p)\n", This, Flags, ColorTable, Palette, pUnkOuter);
2863 if(pUnkOuter != NULL)
2865 WARN("pUnkOuter is %p, returning CLASS_E_NOAGGREGATION\n", pUnkOuter);
2866 return CLASS_E_NOAGGREGATION;
2869 /* The refcount test shows that a cooplevel is required for this */
2870 if(!This->cooperative_level)
2872 WARN("No cooperative level set, returning DDERR_NOCOOPERATIVELEVELSET\n");
2873 return DDERR_NOCOOPERATIVELEVELSET;
2876 object = HeapAlloc(GetProcessHeap(), 0, sizeof(IDirectDrawPaletteImpl));
2879 ERR("Out of memory when allocating memory for a palette implementation\n");
2880 return E_OUTOFMEMORY;
2883 ICOM_INIT_INTERFACE(object, IDirectDrawPalette, IDirectDrawPalette_Vtbl);
2885 object->ddraw_owner = This;
2887 hr = IWineD3DDevice_CreatePalette(This->wineD3DDevice, Flags, ColorTable, &object->wineD3DPalette, (IUnknown *) ICOM_INTERFACE(object, IDirectDrawPalette) );
2890 HeapFree(GetProcessHeap(), 0, object);
2894 IDirectDraw7_AddRef(iface);
2895 object->ifaceToRelease = (IUnknown *) iface;
2896 *Palette = ICOM_INTERFACE(object, IDirectDrawPalette);
2900 /*****************************************************************************
2901 * IDirectDraw7::DuplicateSurface
2903 * Duplicates a surface. The surface memory points to the same memory as
2904 * the original surface, and it's released when the last surface referencing
2905 * it is released. I guess that's beyond Wine's surface management right now
2906 * (Idea: create a new DDraw surface with the same WineD3DSurface. I need a
2907 * test application to implement this)
2910 * Src: Address of the source surface
2911 * Dest: Address to write the new surface pointer to
2914 * See IDirectDraw7::CreateSurface
2916 *****************************************************************************/
2917 static HRESULT WINAPI
2918 IDirectDrawImpl_DuplicateSurface(IDirectDraw7 *iface,
2919 IDirectDrawSurface7 *Src,
2920 IDirectDrawSurface7 **Dest)
2922 ICOM_THIS_FROM(IDirectDrawImpl, IDirectDraw7, iface);
2923 IDirectDrawSurfaceImpl *Surf = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, Src);
2925 FIXME("(%p)->(%p,%p)\n", This, Surf, Dest);
2927 /* For now, simply create a new, independent surface */
2928 return IDirectDraw7_CreateSurface(iface,
2929 &Surf->surface_desc,
2934 /*****************************************************************************
2935 * IDirectDraw7 VTable
2936 *****************************************************************************/
2937 const IDirectDraw7Vtbl IDirectDraw7_Vtbl =
2940 IDirectDrawImpl_QueryInterface,
2941 IDirectDrawImpl_AddRef,
2942 IDirectDrawImpl_Release,
2943 /*** IDirectDraw ***/
2944 IDirectDrawImpl_Compact,
2945 IDirectDrawImpl_CreateClipper,
2946 IDirectDrawImpl_CreatePalette,
2947 IDirectDrawImpl_CreateSurface,
2948 IDirectDrawImpl_DuplicateSurface,
2949 IDirectDrawImpl_EnumDisplayModes,
2950 IDirectDrawImpl_EnumSurfaces,
2951 IDirectDrawImpl_FlipToGDISurface,
2952 IDirectDrawImpl_GetCaps,
2953 IDirectDrawImpl_GetDisplayMode,
2954 IDirectDrawImpl_GetFourCCCodes,
2955 IDirectDrawImpl_GetGDISurface,
2956 IDirectDrawImpl_GetMonitorFrequency,
2957 IDirectDrawImpl_GetScanLine,
2958 IDirectDrawImpl_GetVerticalBlankStatus,
2959 IDirectDrawImpl_Initialize,
2960 IDirectDrawImpl_RestoreDisplayMode,
2961 IDirectDrawImpl_SetCooperativeLevel,
2962 IDirectDrawImpl_SetDisplayMode,
2963 IDirectDrawImpl_WaitForVerticalBlank,
2964 /*** IDirectDraw2 ***/
2965 IDirectDrawImpl_GetAvailableVidMem,
2966 /*** IDirectDraw7 ***/
2967 IDirectDrawImpl_GetSurfaceFromDC,
2968 IDirectDrawImpl_RestoreAllSurfaces,
2969 IDirectDrawImpl_TestCooperativeLevel,
2970 IDirectDrawImpl_GetDeviceIdentifier,
2971 /*** IDirectDraw7 ***/
2972 IDirectDrawImpl_StartModeTest,
2973 IDirectDrawImpl_EvaluateMode