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 library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define DDRAW_INIT_GUID
25 #include "ddraw_private.h"
28 #include "wine/exception.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 static struct list global_ddraw_list
= LIST_INIT(global_ddraw_list
);
35 static HINSTANCE instance
;
37 /* value of ForceRefreshRate */
38 DWORD force_refresh_rate
= 0;
40 /* Structure for converting DirectDrawEnumerateA to DirectDrawEnumerateExA */
43 LPDDENUMCALLBACKA callback
;
47 /* Enumeration callback for converting DirectDrawEnumerateA to DirectDrawEnumerateExA */
48 static BOOL CALLBACK
enum_callback(GUID
*guid
, char *description
, char *driver_name
,
49 void *context
, HMONITOR monitor
)
51 const struct callback_info
*info
= context
;
53 return info
->callback(guid
, description
, driver_name
, info
->context
);
56 static void ddraw_enumerate_secondary_devices(struct wined3d
*wined3d
, LPDDENUMCALLBACKEXA callback
,
59 struct wined3d_adapter_identifier adapter_id
;
60 struct wined3d_output_desc output_desc
;
61 BOOL cont_enum
= TRUE
;
65 for (adapter
= 0; SUCCEEDED(hr
) && cont_enum
; adapter
++)
67 char DriverName
[512] = "", DriverDescription
[512] = "";
69 /* The Battle.net System Checker expects the GetAdapterIdentifier DeviceName to match the
70 * Driver Name, so obtain the DeviceName and GUID from D3D. */
71 memset(&adapter_id
, 0x0, sizeof(adapter_id
));
72 adapter_id
.device_name
= DriverName
;
73 adapter_id
.device_name_size
= sizeof(DriverName
);
74 adapter_id
.description
= DriverDescription
;
75 adapter_id
.description_size
= sizeof(DriverDescription
);
77 if (SUCCEEDED(hr
= wined3d_get_adapter_identifier(wined3d
, adapter
, 0x0, &adapter_id
)))
78 hr
= wined3d_get_output_desc(wined3d
, adapter
, &output_desc
);
79 wined3d_mutex_unlock();
82 TRACE("Interface %d: %s\n", adapter
, wine_dbgstr_guid(&adapter_id
.device_identifier
));
83 cont_enum
= callback(&adapter_id
.device_identifier
, adapter_id
.description
,
84 adapter_id
.device_name
, context
, output_desc
.monitor
);
89 /* Handle table functions */
90 BOOL
ddraw_handle_table_init(struct ddraw_handle_table
*t
, UINT initial_size
)
92 if (!(t
->entries
= heap_alloc_zero(initial_size
* sizeof(*t
->entries
))))
94 ERR("Failed to allocate handle table memory.\n");
97 t
->free_entries
= NULL
;
98 t
->table_size
= initial_size
;
104 void ddraw_handle_table_destroy(struct ddraw_handle_table
*t
)
106 heap_free(t
->entries
);
107 memset(t
, 0, sizeof(*t
));
110 DWORD
ddraw_allocate_handle(struct ddraw_handle_table
*t
, void *object
, enum ddraw_handle_type type
)
112 struct ddraw_handle_entry
*entry
;
116 DWORD idx
= t
->free_entries
- t
->entries
;
117 /* Use a free handle */
118 entry
= t
->free_entries
;
119 if (entry
->type
!= DDRAW_HANDLE_FREE
)
121 ERR("Handle %#x (%p) is in the free list, but has type %#x.\n", idx
, entry
->object
, entry
->type
);
122 return DDRAW_INVALID_HANDLE
;
124 t
->free_entries
= entry
->object
;
125 entry
->object
= object
;
131 if (!(t
->entry_count
< t
->table_size
))
134 UINT new_size
= t
->table_size
+ (t
->table_size
>> 1);
135 struct ddraw_handle_entry
*new_entries
;
137 if (!(new_entries
= heap_realloc(t
->entries
, new_size
* sizeof(*t
->entries
))))
139 ERR("Failed to grow the handle table.\n");
140 return DDRAW_INVALID_HANDLE
;
142 t
->entries
= new_entries
;
143 t
->table_size
= new_size
;
146 entry
= &t
->entries
[t
->entry_count
];
147 entry
->object
= object
;
150 return t
->entry_count
++;
153 void *ddraw_free_handle(struct ddraw_handle_table
*t
, DWORD handle
, enum ddraw_handle_type type
)
155 struct ddraw_handle_entry
*entry
;
158 if (handle
== DDRAW_INVALID_HANDLE
|| handle
>= t
->entry_count
)
160 WARN("Invalid handle %#x passed.\n", handle
);
164 entry
= &t
->entries
[handle
];
165 if (entry
->type
!= type
)
167 WARN("Handle %#x (%p) is not of type %#x.\n", handle
, entry
->object
, type
);
171 object
= entry
->object
;
172 entry
->object
= t
->free_entries
;
173 entry
->type
= DDRAW_HANDLE_FREE
;
174 t
->free_entries
= entry
;
179 void *ddraw_get_object(struct ddraw_handle_table
*t
, DWORD handle
, enum ddraw_handle_type type
)
181 struct ddraw_handle_entry
*entry
;
183 if (handle
== DDRAW_INVALID_HANDLE
|| handle
>= t
->entry_count
)
185 WARN("Invalid handle %#x passed.\n", handle
);
189 entry
= &t
->entries
[handle
];
190 if (entry
->type
!= type
)
192 WARN("Handle %#x (%p) is not of type %#x.\n", handle
, entry
->object
, type
);
196 return entry
->object
;
199 HRESULT WINAPI
GetSurfaceFromDC(HDC dc
, IDirectDrawSurface4
**surface
, HDC
*device_dc
)
203 TRACE("dc %p, surface %p, device_dc %p.\n", dc
, surface
, device_dc
);
215 wined3d_mutex_lock();
216 LIST_FOR_EACH_ENTRY(ddraw
, &global_ddraw_list
, struct ddraw
, ddraw_list_entry
)
218 if (FAILED(IDirectDraw4_GetSurfaceFromDC(&ddraw
->IDirectDraw4_iface
, dc
, surface
)))
221 *device_dc
= NULL
; /* FIXME */
222 wined3d_mutex_unlock();
225 wined3d_mutex_unlock();
230 return DDERR_NOTFOUND
;
233 /***********************************************************************
235 * Helper function for DirectDrawCreate and friends
236 * Creates a new DDraw interface with the given REFIID
238 * Interfaces that can be created:
239 * IDirectDraw, IDirectDraw2, IDirectDraw4, IDirectDraw7
240 * IDirect3D, IDirect3D2, IDirect3D3, IDirect3D7. (Does Windows return
241 * IDirect3D interfaces?)
244 * guid: ID of the requested driver, NULL for the default driver.
245 * The GUID can be queried with DirectDrawEnumerate(Ex)A/W
246 * DD: Used to return the pointer to the created object
247 * UnkOuter: For aggregation, which is unsupported. Must be NULL
248 * iid: requested version ID.
251 * DD_OK if the Interface was created successfully
252 * CLASS_E_NOAGGREGATION if UnkOuter is not NULL
253 * E_OUTOFMEMORY if some allocation failed
255 ***********************************************************************/
256 static HRESULT
DDRAW_Create(const GUID
*guid
, void **out
, IUnknown
*outer_unknown
, REFIID iid
)
258 enum wined3d_device_type device_type
;
263 TRACE("driver_guid %s, ddraw %p, outer_unknown %p, interface_iid %s.\n",
264 debugstr_guid(guid
), out
, outer_unknown
, debugstr_guid(iid
));
268 if (guid
== (GUID
*) DDCREATE_EMULATIONONLY
)
270 device_type
= WINED3D_DEVICE_TYPE_REF
;
272 else if (guid
== (GUID
*) DDCREATE_HARDWAREONLY
)
274 device_type
= WINED3D_DEVICE_TYPE_HAL
;
278 device_type
= WINED3D_DEVICE_TYPE_HAL
;
281 /* DDraw doesn't support aggregation, according to msdn */
282 if (outer_unknown
!= NULL
)
283 return CLASS_E_NOAGGREGATION
;
285 if (!IsEqualGUID(iid
, &IID_IDirectDraw7
))
286 flags
= WINED3D_LEGACY_FFP_LIGHTING
;
288 if (!(ddraw
= heap_alloc_zero(sizeof(*ddraw
))))
290 ERR("Out of memory when creating DirectDraw.\n");
291 return E_OUTOFMEMORY
;
294 if (FAILED(hr
= ddraw_init(ddraw
, flags
, device_type
)))
296 WARN("Failed to initialize ddraw object, hr %#x.\n", hr
);
301 hr
= IDirectDraw7_QueryInterface(&ddraw
->IDirectDraw7_iface
, iid
, out
);
302 IDirectDraw7_Release(&ddraw
->IDirectDraw7_iface
);
304 list_add_head(&global_ddraw_list
, &ddraw
->ddraw_list_entry
);
306 WARN("Failed to query interface %s from ddraw object %p.\n", debugstr_guid(iid
), ddraw
);
311 /***********************************************************************
312 * DirectDrawCreate (DDRAW.@)
314 * Creates legacy DirectDraw Interfaces. Can't create IDirectDraw7
315 * interfaces in theory
317 * Arguments, return values: See DDRAW_Create
319 ***********************************************************************/
320 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectDrawCreate(GUID
*driver_guid
, IDirectDraw
**ddraw
, IUnknown
*outer
)
324 TRACE("driver_guid %s, ddraw %p, outer %p.\n",
325 debugstr_guid(driver_guid
), ddraw
, outer
);
327 wined3d_mutex_lock();
328 hr
= DDRAW_Create(driver_guid
, (void **)ddraw
, outer
, &IID_IDirectDraw
);
329 wined3d_mutex_unlock();
333 if (FAILED(hr
= IDirectDraw_Initialize(*ddraw
, driver_guid
)))
334 IDirectDraw_Release(*ddraw
);
340 /***********************************************************************
341 * DirectDrawCreateEx (DDRAW.@)
343 * Only creates new IDirectDraw7 interfaces, supposed to fail if legacy
344 * interfaces are requested.
346 * Arguments, return values: See DDRAW_Create
348 ***********************************************************************/
349 HRESULT WINAPI DECLSPEC_HOTPATCH
DirectDrawCreateEx(GUID
*driver_guid
,
350 void **ddraw
, REFIID interface_iid
, IUnknown
*outer
)
354 TRACE("driver_guid %s, ddraw %p, interface_iid %s, outer %p.\n",
355 debugstr_guid(driver_guid
), ddraw
, debugstr_guid(interface_iid
), outer
);
357 if (!IsEqualGUID(interface_iid
, &IID_IDirectDraw7
))
358 return DDERR_INVALIDPARAMS
;
360 wined3d_mutex_lock();
361 hr
= DDRAW_Create(driver_guid
, ddraw
, outer
, interface_iid
);
362 wined3d_mutex_unlock();
366 IDirectDraw7
*ddraw7
= *(IDirectDraw7
**)ddraw
;
367 hr
= IDirectDraw7_Initialize(ddraw7
, driver_guid
);
369 IDirectDraw7_Release(ddraw7
);
375 /***********************************************************************
376 * DirectDrawEnumerateA (DDRAW.@)
378 * Enumerates legacy ddraw drivers, ascii version. We only have one
379 * driver, which relays to WineD3D. If we were sufficiently cool,
380 * we could offer various interfaces, which use a different default surface
381 * implementation, but I think it's better to offer this choice in
382 * winecfg, because some apps use the default driver, so we would need
383 * a winecfg option anyway, and there shouldn't be 2 ways to set one setting
386 * Callback: Callback function from the app
387 * Context: Argument to the call back.
391 * E_INVALIDARG if the Callback caused a page fault
394 ***********************************************************************/
395 HRESULT WINAPI
DirectDrawEnumerateA(LPDDENUMCALLBACKA callback
, void *context
)
397 struct callback_info info
;
399 TRACE("callback %p, context %p.\n", callback
, context
);
401 info
.callback
= callback
;
402 info
.context
= context
;
403 return DirectDrawEnumerateExA(enum_callback
, &info
, 0x0);
406 /***********************************************************************
407 * DirectDrawEnumerateExA (DDRAW.@)
409 * Enumerates DirectDraw7 drivers, ascii version. See
410 * the comments above DirectDrawEnumerateA for more details.
412 * The Flag member is not supported right now.
414 ***********************************************************************/
415 HRESULT WINAPI
DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA callback
, void *context
, DWORD flags
)
417 struct wined3d
*wined3d
;
419 TRACE("callback %p, context %p, flags %#x.\n", callback
, context
, flags
);
421 if (flags
& ~(DDENUM_ATTACHEDSECONDARYDEVICES
|
422 DDENUM_DETACHEDSECONDARYDEVICES
|
423 DDENUM_NONDISPLAYDEVICES
))
424 return DDERR_INVALIDPARAMS
;
426 if (flags
& ~DDENUM_ATTACHEDSECONDARYDEVICES
)
427 FIXME("flags 0x%08x not handled\n", flags
& ~DDENUM_ATTACHEDSECONDARYDEVICES
);
429 TRACE("Enumerating ddraw interfaces\n");
430 if (!(wined3d
= wined3d_create(DDRAW_WINED3D_FLAGS
)))
432 if (!(wined3d
= wined3d_create(DDRAW_WINED3D_FLAGS
| WINED3D_NO3D
)))
434 WARN("Failed to create a wined3d object.\n");
438 WARN("Created a wined3d object without 3D support.\n");
443 /* QuickTime expects the description "DirectDraw HAL" */
444 static CHAR driver_desc
[] = "DirectDraw HAL",
445 driver_name
[] = "display";
448 TRACE("Default interface: DirectDraw HAL\n");
449 cont_enum
= callback(NULL
, driver_desc
, driver_name
, context
, 0);
451 /* The Battle.net System Checker expects both a NULL device and a GUID-based device */
452 if (cont_enum
&& (flags
& DDENUM_ATTACHEDSECONDARYDEVICES
))
453 ddraw_enumerate_secondary_devices(wined3d
, callback
, context
);
457 wined3d_decref(wined3d
);
458 return DDERR_INVALIDPARAMS
;
462 wined3d_decref(wined3d
);
463 TRACE("End of enumeration\n");
467 /***********************************************************************
468 * DirectDrawEnumerateW (DDRAW.@)
470 * Enumerates legacy drivers, unicode version.
471 * This function is not implemented on Windows.
473 ***********************************************************************/
474 HRESULT WINAPI
DirectDrawEnumerateW(LPDDENUMCALLBACKW callback
, void *context
)
476 TRACE("callback %p, context %p.\n", callback
, context
);
479 return DDERR_INVALIDPARAMS
;
481 return DDERR_UNSUPPORTED
;
484 /***********************************************************************
485 * DirectDrawEnumerateExW (DDRAW.@)
487 * Enumerates DirectDraw7 drivers, unicode version.
488 * This function is not implemented on Windows.
490 ***********************************************************************/
491 HRESULT WINAPI
DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW callback
, void *context
, DWORD flags
)
493 TRACE("callback %p, context %p, flags %#x.\n", callback
, context
, flags
);
495 return DDERR_UNSUPPORTED
;
498 /***********************************************************************
499 * Classfactory implementation.
500 ***********************************************************************/
502 /***********************************************************************
503 * CF_CreateDirectDraw
505 * DDraw creation function for the class factory
508 * UnkOuter: Set to NULL
509 * iid: ID of the wanted interface
510 * obj: Address to pass the interface pointer back
513 * DD_OK / DDERR*, see DDRAW_Create
515 ***********************************************************************/
517 CF_CreateDirectDraw(IUnknown
* UnkOuter
, REFIID iid
,
522 TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter
, debugstr_guid(iid
), obj
);
524 wined3d_mutex_lock();
525 hr
= DDRAW_Create(NULL
, obj
, UnkOuter
, iid
);
526 wined3d_mutex_unlock();
531 /***********************************************************************
532 * CF_CreateDirectDraw
534 * Clipper creation function for the class factory
537 * UnkOuter: Set to NULL
538 * iid: ID of the wanted interface
539 * obj: Address to pass the interface pointer back
542 * DD_OK / DDERR*, see DDRAW_Create
544 ***********************************************************************/
546 CF_CreateDirectDrawClipper(IUnknown
* UnkOuter
, REFIID riid
,
550 IDirectDrawClipper
*Clip
;
552 TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter
, debugstr_guid(riid
), obj
);
554 wined3d_mutex_lock();
555 hr
= DirectDrawCreateClipper(0, &Clip
, UnkOuter
);
558 wined3d_mutex_unlock();
562 hr
= IDirectDrawClipper_QueryInterface(Clip
, riid
, obj
);
563 IDirectDrawClipper_Release(Clip
);
565 wined3d_mutex_unlock();
570 static const struct object_creation_info object_creation
[] =
572 { &CLSID_DirectDraw
, CF_CreateDirectDraw
},
573 { &CLSID_DirectDraw7
, CF_CreateDirectDraw
},
574 { &CLSID_DirectDrawClipper
, CF_CreateDirectDrawClipper
}
577 struct ddraw_class_factory
579 IClassFactory IClassFactory_iface
;
582 HRESULT (*pfnCreateInstance
)(IUnknown
*outer
, REFIID iid
, void **out
);
585 static inline struct ddraw_class_factory
*impl_from_IClassFactory(IClassFactory
*iface
)
587 return CONTAINING_RECORD(iface
, struct ddraw_class_factory
, IClassFactory_iface
);
590 /*******************************************************************************
591 * IDirectDrawClassFactory::QueryInterface
593 * QueryInterface for the class factory
596 * riid Reference to identifier of queried interface
597 * ppv Address to return the interface pointer at
601 * Failure: E_NOINTERFACE
603 *******************************************************************************/
604 static HRESULT WINAPI
ddraw_class_factory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **out
)
606 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
608 if (IsEqualGUID(riid
, &IID_IUnknown
)
609 || IsEqualGUID(riid
, &IID_IClassFactory
))
611 IClassFactory_AddRef(iface
);
616 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
618 return E_NOINTERFACE
;
621 /*******************************************************************************
622 * IDirectDrawClassFactory::AddRef
624 * AddRef for the class factory
629 *******************************************************************************/
630 static ULONG WINAPI
ddraw_class_factory_AddRef(IClassFactory
*iface
)
632 struct ddraw_class_factory
*factory
= impl_from_IClassFactory(iface
);
633 ULONG ref
= InterlockedIncrement(&factory
->ref
);
635 TRACE("%p increasing refcount to %u.\n", factory
, ref
);
640 /*******************************************************************************
641 * IDirectDrawClassFactory::Release
643 * Release for the class factory. If the refcount falls to 0, the object
649 *******************************************************************************/
650 static ULONG WINAPI
ddraw_class_factory_Release(IClassFactory
*iface
)
652 struct ddraw_class_factory
*factory
= impl_from_IClassFactory(iface
);
653 ULONG ref
= InterlockedDecrement(&factory
->ref
);
655 TRACE("%p decreasing refcount to %u.\n", factory
, ref
);
664 /*******************************************************************************
665 * IDirectDrawClassFactory::CreateInstance
667 * What is this? Seems to create DirectDraw objects...
670 * The usual things???
675 *******************************************************************************/
676 static HRESULT WINAPI
ddraw_class_factory_CreateInstance(IClassFactory
*iface
,
677 IUnknown
*outer_unknown
, REFIID riid
, void **out
)
679 struct ddraw_class_factory
*factory
= impl_from_IClassFactory(iface
);
681 TRACE("iface %p, outer_unknown %p, riid %s, out %p.\n",
682 iface
, outer_unknown
, debugstr_guid(riid
), out
);
684 return factory
->pfnCreateInstance(outer_unknown
, riid
, out
);
687 /*******************************************************************************
688 * IDirectDrawClassFactory::LockServer
696 * S_OK, because it's a stub
698 *******************************************************************************/
699 static HRESULT WINAPI
ddraw_class_factory_LockServer(IClassFactory
*iface
, BOOL dolock
)
701 FIXME("iface %p, dolock %#x stub!\n", iface
, dolock
);
706 /*******************************************************************************
707 * The class factory VTable
708 *******************************************************************************/
709 static const IClassFactoryVtbl IClassFactory_Vtbl
=
711 ddraw_class_factory_QueryInterface
,
712 ddraw_class_factory_AddRef
,
713 ddraw_class_factory_Release
,
714 ddraw_class_factory_CreateInstance
,
715 ddraw_class_factory_LockServer
718 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, void **out
)
720 struct ddraw_class_factory
*factory
;
723 TRACE("rclsid %s, riid %s, out %p.\n",
724 debugstr_guid(rclsid
), debugstr_guid(riid
), out
);
726 if (!IsEqualGUID(&IID_IClassFactory
, riid
)
727 && !IsEqualGUID(&IID_IUnknown
, riid
))
728 return E_NOINTERFACE
;
730 for (i
=0; i
< ARRAY_SIZE(object_creation
); i
++)
732 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
736 if (i
== ARRAY_SIZE(object_creation
))
738 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
739 return CLASS_E_CLASSNOTAVAILABLE
;
742 if (!(factory
= heap_alloc_zero(sizeof(*factory
))))
743 return E_OUTOFMEMORY
;
745 factory
->IClassFactory_iface
.lpVtbl
= &IClassFactory_Vtbl
;
748 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
755 /*******************************************************************************
756 * DllCanUnloadNow [DDRAW.@] Determines whether the DLL is in use.
762 HRESULT WINAPI
DllCanUnloadNow(void)
770 HRESULT WINAPI
DllRegisterServer(void)
772 return __wine_register_resources( instance
);
775 HRESULT WINAPI
DllUnregisterServer(void)
777 return __wine_unregister_resources( instance
);
780 /***********************************************************************
783 * Could be used to register DirectDraw drivers, if we have more than
784 * one. Also used to destroy any objects left at unload if the
785 * app didn't release them properly(Gothic 2, Diablo 2, Moto racer, ...)
787 ***********************************************************************/
788 BOOL WINAPI
DllMain(HINSTANCE inst
, DWORD reason
, void *reserved
)
792 case DLL_PROCESS_ATTACH
:
794 static HMODULE ddraw_self
;
798 /* Register the window class. This is used to create a hidden window
799 * for D3D rendering, if the application didn't pass one. It can also
800 * be used for creating a device window from SetCooperativeLevel(). */
801 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
802 wc
.lpfnWndProc
= DefWindowProcA
;
808 wc
.hbrBackground
= GetStockObject(BLACK_BRUSH
);
809 wc
.lpszMenuName
= NULL
;
810 wc
.lpszClassName
= DDRAW_WINDOW_CLASS_NAME
;
811 if (!RegisterClassA(&wc
))
813 ERR("Failed to register ddraw window class, last error %#x.\n", GetLastError());
817 /* On Windows one can force the refresh rate that DirectDraw uses by
818 * setting an override value in dxdiag. This is documented in KB315614
819 * (main article), KB230002, and KB217348. By comparing registry dumps
820 * before and after setting the override, we see that the override value
821 * is stored in HKLM\Software\Microsoft\DirectDraw\ForceRefreshRate as a
822 * DWORD that represents the refresh rate to force. We use this
823 * registry entry to modify the behavior of SetDisplayMode so that Wine
824 * users can override the refresh rate in a Windows-compatible way.
826 * dxdiag will not accept a refresh rate lower than 40 or higher than
827 * 120 so this value should be within that range. It is, of course,
828 * possible for a user to set the registry entry value directly so that
829 * assumption might not hold.
831 * There is no current mechanism for setting this value through the Wine
832 * GUI. It would be most appropriate to set this value through a dxdiag
833 * clone, but it may be sufficient to use winecfg.
835 * TODO: Create a mechanism for setting this value through the Wine GUI.
837 if ( !RegOpenKeyA( HKEY_LOCAL_MACHINE
, "Software\\Microsoft\\DirectDraw", &hkey
) )
839 DWORD type
, data
, size
;
842 if (!RegQueryValueExA(hkey
, "ForceRefreshRate", NULL
, &type
, (BYTE
*)&data
, &size
) && type
== REG_DWORD
)
844 TRACE("ForceRefreshRate set; overriding refresh rate to %d Hz\n", data
);
845 force_refresh_rate
= data
;
850 /* Prevent the ddraw module from being unloaded. When switching to
851 * exclusive mode, we replace the window proc of the ddraw window. If
852 * an application would unload ddraw from the WM_DESTROY handler for
853 * that window, it would return to unmapped memory and die. Apparently
854 * this is supposed to work on Windows. */
855 if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
| GET_MODULE_HANDLE_EX_FLAG_PIN
,
856 (const WCHAR
*)&ddraw_self
, &ddraw_self
))
857 ERR("Failed to get own module handle.\n");
860 DisableThreadLibraryCalls(inst
);
864 case DLL_PROCESS_DETACH
:
869 LIST_FOR_EACH_ENTRY(ddraw
, &global_ddraw_list
, struct ddraw
, ddraw_list_entry
)
871 struct ddraw_surface
*surface
;
873 WARN("DirectDraw object %p has reference counts {%u, %u, %u, %u, %u}.\n",
874 ddraw
, ddraw
->ref7
, ddraw
->ref4
, ddraw
->ref3
, ddraw
->ref2
, ddraw
->ref1
);
876 if (ddraw
->d3ddevice
)
877 WARN("DirectDraw object %p has Direct3D device %p attached.\n", ddraw
, ddraw
->d3ddevice
);
879 LIST_FOR_EACH_ENTRY(surface
, &ddraw
->surface_list
, struct ddraw_surface
, surface_list_entry
)
881 WARN("Surface %p has reference counts {%u, %u, %u, %u, %u, %u}.\n",
882 surface
, surface
->ref7
, surface
->ref4
, surface
->ref3
,
883 surface
->ref2
, surface
->ref1
, surface
->gamma_count
);
889 UnregisterClassA(DDRAW_WINDOW_CLASS_NAME
, inst
);