1 /* DirectDraw Base Functions
3 * Copyright 1997-1999 Marcus Meissner
4 * Copyright 1998 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 * Copyright 2006 Stefan Dösinger
7 * Copyright 2008 Denver Gingerich
9 * This file contains the (internal) driver registration functions,
10 * driver enumeration APIs and DirectDraw creation functions.
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
29 #include "wine/debug.h"
42 #include "wine/exception.h"
48 #define DDRAW_INIT_GUID
49 #include "ddraw_private.h"
51 static typeof(WineDirect3DCreate
) *pWineDirect3DCreate
;
53 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
55 /* The configured default surface */
56 WINED3DSURFTYPE DefaultSurfaceType
= SURFACE_UNKNOWN
;
58 /* DDraw list and critical section */
59 static struct list global_ddraw_list
= LIST_INIT(global_ddraw_list
);
61 static CRITICAL_SECTION_DEBUG ddraw_cs_debug
=
64 { &ddraw_cs_debug
.ProcessLocksList
,
65 &ddraw_cs_debug
.ProcessLocksList
},
66 0, 0, { (DWORD_PTR
)(__FILE__
": ddraw_cs") }
68 CRITICAL_SECTION ddraw_cs
= { &ddraw_cs_debug
, -1, 0, 0, 0, 0 };
70 /* value of ForceRefreshRate */
71 DWORD force_refresh_rate
= 0;
74 * Helper Function for DDRAW_Create and DirectDrawCreateClipper for
75 * lazy loading of the Wine D3D driver.
82 BOOL
LoadWineD3D(void)
84 static HMODULE hWineD3D
= (HMODULE
) -1;
85 if (hWineD3D
== (HMODULE
) -1)
87 hWineD3D
= LoadLibraryA("wined3d");
90 pWineDirect3DCreate
= (typeof(WineDirect3DCreate
) *)GetProcAddress(hWineD3D
, "WineDirect3DCreate");
91 pWineDirect3DCreateClipper
= (typeof(WineDirect3DCreateClipper
) *) GetProcAddress(hWineD3D
, "WineDirect3DCreateClipper");
95 return hWineD3D
!= NULL
;
98 /***********************************************************************
100 * Helper function for DirectDrawCreate and friends
101 * Creates a new DDraw interface with the given REFIID
103 * Interfaces that can be created:
104 * IDirectDraw, IDirectDraw2, IDirectDraw4, IDirectDraw7
105 * IDirect3D, IDirect3D2, IDirect3D3, IDirect3D7. (Does Windows return
106 * IDirect3D interfaces?)
109 * guid: ID of the requested driver, NULL for the default driver.
110 * The GUID can be queried with DirectDrawEnumerate(Ex)A/W
111 * DD: Used to return the pointer to the created object
112 * UnkOuter: For aggregation, which is unsupported. Must be NULL
113 * iid: requested version ID.
116 * DD_OK if the Interface was created successfully
117 * CLASS_E_NOAGGREGATION if UnkOuter is not NULL
118 * E_OUTOFMEMORY if some allocation failed
120 ***********************************************************************/
122 DDRAW_Create(const GUID
*guid
,
127 IDirectDrawImpl
*This
= NULL
;
129 IWineD3D
*wineD3D
= NULL
;
130 IWineD3DDevice
*wineD3DDevice
= NULL
;
132 WINED3DDEVTYPE devicetype
;
134 TRACE("(%s,%p,%p)\n", debugstr_guid(guid
), DD
, UnkOuter
);
138 /* We don't care about this guids. Well, there's no special guid anyway
141 if (guid
== (GUID
*) DDCREATE_EMULATIONONLY
)
143 /* Use the reference device id. This doesn't actually change anything,
144 * WineD3D always uses OpenGL for D3D rendering. One could make it request
147 devicetype
= WINED3DDEVTYPE_REF
;
149 else if(guid
== (GUID
*) DDCREATE_HARDWAREONLY
)
151 devicetype
= WINED3DDEVTYPE_HAL
;
158 /* DDraw doesn't support aggregation, according to msdn */
159 if (UnkOuter
!= NULL
)
160 return CLASS_E_NOAGGREGATION
;
162 /* DirectDraw creation comes here */
163 This
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectDrawImpl
));
166 ERR("Out of memory when creating DirectDraw\n");
167 return E_OUTOFMEMORY
;
171 * IDirectDraw and IDirect3D are the same object,
172 * QueryInterface is used to get other interfaces.
174 ICOM_INIT_INTERFACE(This
, IDirectDraw
, IDirectDraw1_Vtbl
);
175 ICOM_INIT_INTERFACE(This
, IDirectDraw2
, IDirectDraw2_Vtbl
);
176 ICOM_INIT_INTERFACE(This
, IDirectDraw3
, IDirectDraw3_Vtbl
);
177 ICOM_INIT_INTERFACE(This
, IDirectDraw4
, IDirectDraw4_Vtbl
);
178 ICOM_INIT_INTERFACE(This
, IDirectDraw7
, IDirectDraw7_Vtbl
);
179 ICOM_INIT_INTERFACE(This
, IDirect3D
, IDirect3D1_Vtbl
);
180 ICOM_INIT_INTERFACE(This
, IDirect3D2
, IDirect3D2_Vtbl
);
181 ICOM_INIT_INTERFACE(This
, IDirect3D3
, IDirect3D3_Vtbl
);
182 ICOM_INIT_INTERFACE(This
, IDirect3D7
, IDirect3D7_Vtbl
);
183 This
->device_parent_vtbl
= &ddraw_wined3d_device_parent_vtbl
;
185 /* See comments in IDirectDrawImpl_CreateNewSurface for a description
187 * Read from a registry key, should add a winecfg option later
189 This
->ImplType
= DefaultSurfaceType
;
191 /* Get the current screen settings */
193 This
->orig_bpp
= GetDeviceCaps(hDC
, BITSPIXEL
) * GetDeviceCaps(hDC
, PLANES
);
195 This
->orig_width
= GetSystemMetrics(SM_CXSCREEN
);
196 This
->orig_height
= GetSystemMetrics(SM_CYSCREEN
);
200 ERR("Couldn't load WineD3D - OpenGL libs not present?\n");
201 hr
= DDERR_NODIRECTDRAWSUPPORT
;
205 /* Initialize WineD3D
207 * All Rendering (2D and 3D) is relayed to WineD3D,
208 * but DirectDraw specific management, like DDSURFACEDESC and DDPIXELFORMAT
209 * structure handling is handled in this lib.
211 wineD3D
= pWineDirect3DCreate(7 /* DXVersion */, (IUnknown
*) This
/* Parent */);
214 ERR("Failed to initialise WineD3D\n");
218 This
->wineD3D
= wineD3D
;
219 TRACE("WineD3D created at %p\n", wineD3D
);
221 /* Initialized member...
223 * It is set to false at creation time, and set to true in
224 * IDirectDraw7::Initialize. Its sole purpose is to return DD_OK on
225 * initialize only once
227 This
->initialized
= FALSE
;
229 /* Initialize WineD3DDevice
231 * It is used for screen setup, surface and palette creation
232 * When a Direct3DDevice7 is created, the D3D capabilities of WineD3D are
235 hr
= IWineD3D_CreateDevice(wineD3D
, 0 /* D3D_ADAPTER_DEFAULT */, devicetype
, NULL
/* FocusWindow, don't know yet */,
236 0 /* BehaviorFlags */, (IUnknown
*)ICOM_INTERFACE(This
, IDirectDraw7
),
237 (IWineD3DDeviceParent
*)&This
->device_parent_vtbl
, &wineD3DDevice
);
240 ERR("Failed to create a wineD3DDevice, result = %x\n", hr
);
243 This
->wineD3DDevice
= wineD3DDevice
;
244 TRACE("wineD3DDevice created at %p\n", This
->wineD3DDevice
);
246 /* Register the window class
248 * It is used to create a hidden window for D3D
249 * rendering, if the application didn't pass one.
250 * It can also be used for Creating a device window
251 * from SetCooperativeLevel
253 * The name: DDRAW_<address>. The classname is
254 * 32 bit long, so a 64 bit address will fit nicely
255 * (Will this be compiled for 64 bit anyway?)
258 sprintf(This
->classname
, "DDRAW_%p", This
);
260 memset(&This
->wnd_class
, 0, sizeof(This
->wnd_class
));
261 This
->wnd_class
.style
= CS_HREDRAW
| CS_VREDRAW
;
262 This
->wnd_class
.lpfnWndProc
= DefWindowProcA
;
263 This
->wnd_class
.cbClsExtra
= 0;
264 This
->wnd_class
.cbWndExtra
= 0;
265 This
->wnd_class
.hInstance
= GetModuleHandleA(0);
266 This
->wnd_class
.hIcon
= 0;
267 This
->wnd_class
.hCursor
= 0;
268 This
->wnd_class
.hbrBackground
= GetStockObject(BLACK_BRUSH
);
269 This
->wnd_class
.lpszMenuName
= NULL
;
270 This
->wnd_class
.lpszClassName
= This
->classname
;
271 if(!RegisterClassA(&This
->wnd_class
))
273 ERR("RegisterClassA failed!\n");
277 /* Get the amount of video memory */
278 This
->total_vidmem
= IWineD3DDevice_GetAvailableTextureMem(This
->wineD3DDevice
);
280 list_init(&This
->surface_list
);
281 list_add_head(&global_ddraw_list
, &This
->ddraw_list_entry
);
283 /* Call QueryInterface to get the pointer to the requested interface. This also initializes
284 * The required refcount
286 hr
= IDirectDraw7_QueryInterface( ICOM_INTERFACE(This
, IDirectDraw7
), iid
, DD
);
287 if(SUCCEEDED(hr
)) return DD_OK
;
290 /* Let's hope we never need this ;) */
291 if(wineD3DDevice
) IWineD3DDevice_Release(wineD3DDevice
);
292 if(wineD3D
) IWineD3D_Release(wineD3D
);
293 if(This
) HeapFree(GetProcessHeap(), 0, This
->decls
);
294 HeapFree(GetProcessHeap(), 0, This
);
298 /***********************************************************************
299 * DirectDrawCreate (DDRAW.@)
301 * Creates legacy DirectDraw Interfaces. Can't create IDirectDraw7
302 * interfaces in theory
304 * Arguments, return values: See DDRAW_Create
306 ***********************************************************************/
308 DirectDrawCreate(GUID
*GUID
,
313 TRACE("(%s,%p,%p)\n", debugstr_guid(GUID
), DD
, UnkOuter
);
315 EnterCriticalSection(&ddraw_cs
);
316 hr
= DDRAW_Create(GUID
, (void **) DD
, UnkOuter
, &IID_IDirectDraw
);
317 LeaveCriticalSection(&ddraw_cs
);
321 /***********************************************************************
322 * DirectDrawCreateEx (DDRAW.@)
324 * Only creates new IDirectDraw7 interfaces, supposed to fail if legacy
325 * interfaces are requested.
327 * Arguments, return values: See DDRAW_Create
329 ***********************************************************************/
331 DirectDrawCreateEx(GUID
*GUID
,
337 TRACE("(%s,%p,%s,%p)\n", debugstr_guid(GUID
), DD
, debugstr_guid(iid
), UnkOuter
);
339 if (!IsEqualGUID(iid
, &IID_IDirectDraw7
))
340 return DDERR_INVALIDPARAMS
;
342 EnterCriticalSection(&ddraw_cs
);
343 hr
= DDRAW_Create(GUID
, DD
, UnkOuter
, iid
);
344 LeaveCriticalSection(&ddraw_cs
);
348 /***********************************************************************
349 * DirectDrawEnumerateA (DDRAW.@)
351 * Enumerates legacy ddraw drivers, ascii version. We only have one
352 * driver, which relays to WineD3D. If we were sufficiently cool,
353 * we could offer various interfaces, which use a different default surface
354 * implementation, but I think it's better to offer this choice in
355 * winecfg, because some apps use the default driver, so we would need
356 * a winecfg option anyway, and there shouldn't be 2 ways to set one setting
359 * Callback: Callback function from the app
360 * Context: Argument to the call back.
364 * E_INVALIDARG if the Callback caused a page fault
367 ***********************************************************************/
369 DirectDrawEnumerateA(LPDDENUMCALLBACKA Callback
,
374 TRACE(" Enumerating default DirectDraw HAL interface\n");
375 /* We only have one driver */
378 static CHAR driver_desc
[] = "DirectDraw HAL",
379 driver_name
[] = "display";
381 stop
= !Callback(NULL
, driver_desc
, driver_name
, Context
);
389 TRACE(" End of enumeration\n");
393 /***********************************************************************
394 * DirectDrawEnumerateExA (DDRAW.@)
396 * Enumerates DirectDraw7 drivers, ascii version. See
397 * the comments above DirectDrawEnumerateA for more details.
399 * The Flag member is not supported right now.
401 ***********************************************************************/
403 DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA Callback
,
408 TRACE("Enumerating default DirectDraw HAL interface\n");
410 /* We only have one driver by now */
413 static CHAR driver_desc
[] = "DirectDraw HAL",
414 driver_name
[] = "display";
416 /* QuickTime expects the description "DirectDraw HAL" */
417 stop
= !Callback(NULL
, driver_desc
, driver_name
, Context
, 0);
425 TRACE("End of enumeration\n");
429 /***********************************************************************
430 * DirectDrawEnumerateW (DDRAW.@)
432 * Enumerates legacy drivers, unicode version. See
433 * the comments above DirectDrawEnumerateA for more details.
435 * The Flag member is not supported right now.
437 ***********************************************************************/
439 /***********************************************************************
440 * DirectDrawEnumerateExW (DDRAW.@)
442 * Enumerates DirectDraw7 drivers, unicode version. See
443 * the comments above DirectDrawEnumerateA for more details.
445 * The Flag member is not supported right now.
447 ***********************************************************************/
449 /***********************************************************************
450 * Classfactory implementation.
451 ***********************************************************************/
453 /***********************************************************************
454 * CF_CreateDirectDraw
456 * DDraw creation function for the class factory
459 * UnkOuter: Set to NULL
460 * iid: ID of the wanted interface
461 * obj: Address to pass the interface pointer back
464 * DD_OK / DDERR*, see DDRAW_Create
466 ***********************************************************************/
468 CF_CreateDirectDraw(IUnknown
* UnkOuter
, REFIID iid
,
473 TRACE("(%p,%s,%p)\n", UnkOuter
, debugstr_guid(iid
), obj
);
475 EnterCriticalSection(&ddraw_cs
);
476 hr
= DDRAW_Create(NULL
, obj
, UnkOuter
, iid
);
477 LeaveCriticalSection(&ddraw_cs
);
481 /***********************************************************************
482 * CF_CreateDirectDraw
484 * Clipper creation function for the class factory
487 * UnkOuter: Set to NULL
488 * iid: ID of the wanted interface
489 * obj: Address to pass the interface pointer back
492 * DD_OK / DDERR*, see DDRAW_Create
494 ***********************************************************************/
496 CF_CreateDirectDrawClipper(IUnknown
* UnkOuter
, REFIID riid
,
500 IDirectDrawClipper
*Clip
;
502 EnterCriticalSection(&ddraw_cs
);
503 hr
= DirectDrawCreateClipper(0, &Clip
, UnkOuter
);
506 LeaveCriticalSection(&ddraw_cs
);
510 hr
= IDirectDrawClipper_QueryInterface(Clip
, riid
, obj
);
511 IDirectDrawClipper_Release(Clip
);
513 LeaveCriticalSection(&ddraw_cs
);
517 static const struct object_creation_info object_creation
[] =
519 { &CLSID_DirectDraw
, CF_CreateDirectDraw
},
520 { &CLSID_DirectDraw7
, CF_CreateDirectDraw
},
521 { &CLSID_DirectDrawClipper
, CF_CreateDirectDrawClipper
}
524 /*******************************************************************************
525 * IDirectDrawClassFactory::QueryInterface
527 * QueryInterface for the class factory
530 * riid Reference to identifier of queried interface
531 * ppv Address to return the interface pointer at
535 * Failure: E_NOINTERFACE
537 *******************************************************************************/
538 static HRESULT WINAPI
539 IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory
*iface
,
543 ICOM_THIS_FROM(IClassFactoryImpl
, IClassFactory
, iface
);
545 TRACE("(%p)->(%s,%p)\n", This
, debugstr_guid(riid
), obj
);
547 if (IsEqualGUID(riid
, &IID_IUnknown
)
548 || IsEqualGUID(riid
, &IID_IClassFactory
))
550 IClassFactory_AddRef(iface
);
555 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),obj
);
556 return E_NOINTERFACE
;
559 /*******************************************************************************
560 * IDirectDrawClassFactory::AddRef
562 * AddRef for the class factory
567 *******************************************************************************/
569 IDirectDrawClassFactoryImpl_AddRef(IClassFactory
*iface
)
571 ICOM_THIS_FROM(IClassFactoryImpl
, IClassFactory
, iface
);
572 ULONG ref
= InterlockedIncrement(&This
->ref
);
574 TRACE("(%p)->() incrementing from %d.\n", This
, ref
- 1);
579 /*******************************************************************************
580 * IDirectDrawClassFactory::Release
582 * Release for the class factory. If the refcount falls to 0, the object
588 *******************************************************************************/
590 IDirectDrawClassFactoryImpl_Release(IClassFactory
*iface
)
592 ICOM_THIS_FROM(IClassFactoryImpl
, IClassFactory
, iface
);
593 ULONG ref
= InterlockedDecrement(&This
->ref
);
594 TRACE("(%p)->() decrementing from %d.\n", This
, ref
+1);
597 HeapFree(GetProcessHeap(), 0, This
);
603 /*******************************************************************************
604 * IDirectDrawClassFactory::CreateInstance
606 * What is this? Seems to create DirectDraw objects...
609 * The usual things???
614 *******************************************************************************/
615 static HRESULT WINAPI
616 IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory
*iface
,
621 ICOM_THIS_FROM(IClassFactoryImpl
, IClassFactory
, iface
);
623 TRACE("(%p)->(%p,%s,%p)\n",This
,UnkOuter
,debugstr_guid(riid
),obj
);
625 return This
->pfnCreateInstance(UnkOuter
, riid
, obj
);
628 /*******************************************************************************
629 * IDirectDrawClassFactory::LockServer
637 * S_OK, because it's a stub
639 *******************************************************************************/
640 static HRESULT WINAPI
641 IDirectDrawClassFactoryImpl_LockServer(IClassFactory
*iface
,BOOL dolock
)
643 ICOM_THIS_FROM(IClassFactoryImpl
, IClassFactory
, iface
);
644 FIXME("(%p)->(%d),stub!\n",This
,dolock
);
648 /*******************************************************************************
649 * The class factory VTable
650 *******************************************************************************/
651 static const IClassFactoryVtbl IClassFactory_Vtbl
=
653 IDirectDrawClassFactoryImpl_QueryInterface
,
654 IDirectDrawClassFactoryImpl_AddRef
,
655 IDirectDrawClassFactoryImpl_Release
,
656 IDirectDrawClassFactoryImpl_CreateInstance
,
657 IDirectDrawClassFactoryImpl_LockServer
660 /*******************************************************************************
661 * DllGetClassObject [DDRAW.@]
662 * Retrieves class object from a DLL object
665 * Docs say returns STDAPI
668 * rclsid [I] CLSID for the class object
669 * riid [I] Reference to identifier of interface for class object
670 * ppv [O] Address of variable to receive interface pointer for riid
674 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
677 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
680 IClassFactoryImpl
*factory
;
682 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
684 if ( !IsEqualGUID( &IID_IClassFactory
, riid
)
685 && ! IsEqualGUID( &IID_IUnknown
, riid
) )
686 return E_NOINTERFACE
;
688 for (i
=0; i
< sizeof(object_creation
)/sizeof(object_creation
[0]); i
++)
690 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
694 if (i
== sizeof(object_creation
)/sizeof(object_creation
[0]))
696 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
697 return CLASS_E_CLASSNOTAVAILABLE
;
700 factory
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*factory
));
701 if (factory
== NULL
) return E_OUTOFMEMORY
;
703 ICOM_INIT_INTERFACE(factory
, IClassFactory
, IClassFactory_Vtbl
);
706 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
708 *ppv
= ICOM_INTERFACE(factory
, IClassFactory
);
713 /*******************************************************************************
714 * DllCanUnloadNow [DDRAW.@] Determines whether the DLL is in use.
720 HRESULT WINAPI
DllCanUnloadNow(void)
723 FIXME("(void): stub\n");
725 EnterCriticalSection(&ddraw_cs
);
727 LeaveCriticalSection(&ddraw_cs
);
732 /*******************************************************************************
735 * Callback function for the EnumSurfaces call in DllMain.
736 * Dumps some surface info and releases the surface
739 * surf: The enumerated surface
740 * desc: it's description
741 * context: Pointer to the ddraw impl
745 *******************************************************************************/
746 static HRESULT WINAPI
747 DestroyCallback(IDirectDrawSurface7
*surf
,
748 DDSURFACEDESC2
*desc
,
751 IDirectDrawSurfaceImpl
*Impl
= ICOM_OBJECT(IDirectDrawSurfaceImpl
, IDirectDrawSurface7
, surf
);
752 IDirectDrawImpl
*ddraw
= context
;
755 ref
= IDirectDrawSurface7_Release(surf
); /* For the EnumSurfaces */
756 WARN("Surface %p has an reference count of %d\n", Impl
, ref
);
758 /* Skip surfaces which are attached somewhere or which are
759 * part of a complex compound. They will get released when destroying
762 if( (!Impl
->is_complex_root
) || (Impl
->first_attached
!= Impl
) )
764 /* Skip our depth stencil surface, it will be released with the render target */
765 if( Impl
== ddraw
->DepthStencilBuffer
)
768 /* Destroy the surface */
769 while(ref
) ref
= IDirectDrawSurface7_Release(surf
);
774 /***********************************************************************
777 * Reads a config key from the registry. Taken from WineD3D
779 ***********************************************************************/
780 static inline DWORD
get_config_key(HKEY defkey
, HKEY appkey
, const char* name
, char* buffer
, DWORD size
)
782 if (0 != appkey
&& !RegQueryValueExA( appkey
, name
, 0, NULL
, (LPBYTE
) buffer
, &size
)) return 0;
783 if (0 != defkey
&& !RegQueryValueExA( defkey
, name
, 0, NULL
, (LPBYTE
) buffer
, &size
)) return 0;
784 return ERROR_FILE_NOT_FOUND
;
787 /***********************************************************************
790 * Could be used to register DirectDraw drivers, if we have more than
791 * one. Also used to destroy any objects left at unload if the
792 * app didn't release them properly(Gothic 2, Diablo 2, Moto racer, ...)
794 ***********************************************************************/
796 DllMain(HINSTANCE hInstDLL
,
800 TRACE("(%p,%x,%p)\n", hInstDLL
, Reason
, lpv
);
801 if (Reason
== DLL_PROCESS_ATTACH
)
803 char buffer
[MAX_PATH
+10];
804 DWORD size
= sizeof(buffer
);
809 /* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
810 if ( RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\Direct3D", &hkey
) ) hkey
= 0;
812 len
= GetModuleFileNameA( 0, buffer
, MAX_PATH
);
813 if (len
&& len
< MAX_PATH
)
816 /* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
817 if (!RegOpenKeyA( HKEY_CURRENT_USER
, "Software\\Wine\\AppDefaults", &tmpkey
))
819 char *p
, *appname
= buffer
;
820 if ((p
= strrchr( appname
, '/' ))) appname
= p
+ 1;
821 if ((p
= strrchr( appname
, '\\' ))) appname
= p
+ 1;
822 strcat( appname
, "\\Direct3D" );
823 TRACE("appname = [%s]\n", appname
);
824 if (RegOpenKeyA( tmpkey
, appname
, &appkey
)) appkey
= 0;
825 RegCloseKey( tmpkey
);
829 if ( 0 != hkey
|| 0 != appkey
)
831 if ( !get_config_key( hkey
, appkey
, "DirectDrawRenderer", buffer
, size
) )
833 if (!strcmp(buffer
,"gdi"))
835 TRACE("Defaulting to GDI surfaces\n");
836 DefaultSurfaceType
= SURFACE_GDI
;
838 else if (!strcmp(buffer
,"opengl"))
840 TRACE("Defaulting to opengl surfaces\n");
841 DefaultSurfaceType
= SURFACE_OPENGL
;
845 ERR("Unknown default surface type. Supported are:\n gdi, opengl\n");
850 /* On Windows one can force the refresh rate that DirectDraw uses by
851 * setting an override value in dxdiag. This is documented in KB315614
852 * (main article), KB230002, and KB217348. By comparing registry dumps
853 * before and after setting the override, we see that the override value
854 * is stored in HKLM\Software\Microsoft\DirectDraw\ForceRefreshRate as a
855 * DWORD that represents the refresh rate to force. We use this
856 * registry entry to modify the behavior of SetDisplayMode so that Wine
857 * users can override the refresh rate in a Windows-compatible way.
859 * dxdiag will not accept a refresh rate lower than 40 or higher than
860 * 120 so this value should be within that range. It is, of course,
861 * possible for a user to set the registry entry value directly so that
862 * assumption might not hold.
864 * There is no current mechanism for setting this value through the Wine
865 * GUI. It would be most appropriate to set this value through a dxdiag
866 * clone, but it may be sufficient to use winecfg.
868 * TODO: Create a mechanism for setting this value through the Wine GUI.
870 if ( !RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\DirectDraw", &hkey
) )
874 if (!RegQueryValueExA( hkey
, "ForceRefreshRate", NULL
, &type
, (LPBYTE
)&data
, &size
) && type
== REG_DWORD
)
876 TRACE("ForceRefreshRate set; overriding refresh rate to %d Hz\n", data
);
877 force_refresh_rate
= data
;
882 DisableThreadLibraryCalls(hInstDLL
);
884 else if (Reason
== DLL_PROCESS_DETACH
)
886 if(!list_empty(&global_ddraw_list
))
888 struct list
*entry
, *entry2
;
889 WARN("There are still existing DirectDraw interfaces. Wine bug or buggy application?\n");
891 /* We remove elements from this loop */
892 LIST_FOR_EACH_SAFE(entry
, entry2
, &global_ddraw_list
)
897 IDirectDrawImpl
*ddraw
= LIST_ENTRY(entry
, IDirectDrawImpl
, ddraw_list_entry
);
899 WARN("DDraw %p has a refcount of %d\n", ddraw
, ddraw
->ref7
+ ddraw
->ref4
+ ddraw
->ref3
+ ddraw
->ref2
+ ddraw
->ref1
);
901 /* Add references to each interface to avoid freeing them unexpectedly */
902 IDirectDraw_AddRef(ICOM_INTERFACE(ddraw
, IDirectDraw
));
903 IDirectDraw2_AddRef(ICOM_INTERFACE(ddraw
, IDirectDraw2
));
904 IDirectDraw3_AddRef(ICOM_INTERFACE(ddraw
, IDirectDraw3
));
905 IDirectDraw4_AddRef(ICOM_INTERFACE(ddraw
, IDirectDraw4
));
906 IDirectDraw7_AddRef(ICOM_INTERFACE(ddraw
, IDirectDraw7
));
908 /* Does a D3D device exist? Destroy it
909 * TODO: Destroy all Vertex buffers, Lights, Materials
910 * and execute buffers too
914 WARN("DDraw %p has d3ddevice %p attached\n", ddraw
, ddraw
->d3ddevice
);
915 while(IDirect3DDevice7_Release(ICOM_INTERFACE(ddraw
->d3ddevice
, IDirect3DDevice7
)));
918 /* Try to release the objects
919 * Do an EnumSurfaces to find any hanging surfaces
921 memset(&desc
, 0, sizeof(desc
));
922 desc
.dwSize
= sizeof(desc
);
923 for(i
= 0; i
<= 1; i
++)
925 hr
= IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(ddraw
, IDirectDraw7
),
931 ERR("(%p) EnumSurfaces failed, prepare for trouble\n", ddraw
);
934 /* Check the surface count */
935 if(ddraw
->surfaces
> 0)
936 ERR("DDraw %p still has %d surfaces attached\n", ddraw
, ddraw
->surfaces
);
938 /* Release all hanging references to destroy the objects. This
939 * restores the screen mode too
941 while(IDirectDraw_Release(ICOM_INTERFACE(ddraw
, IDirectDraw
)));
942 while(IDirectDraw2_Release(ICOM_INTERFACE(ddraw
, IDirectDraw2
)));
943 while(IDirectDraw3_Release(ICOM_INTERFACE(ddraw
, IDirectDraw3
)));
944 while(IDirectDraw4_Release(ICOM_INTERFACE(ddraw
, IDirectDraw4
)));
945 while(IDirectDraw7_Release(ICOM_INTERFACE(ddraw
, IDirectDraw7
)));