2006-06-09 19:36:12 +02:00
|
|
|
/* DirectDraw Base Functions
|
2000-04-09 16:30:50 +02:00
|
|
|
*
|
|
|
|
* Copyright 1997-1999 Marcus Meissner
|
2006-06-09 19:36:12 +02:00
|
|
|
* Copyright 1998 Lionel Ulmer
|
2001-04-17 19:48:19 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2008-10-18 19:19:45 +02:00
|
|
|
* Copyright 2006 Stefan Dösinger
|
2008-03-10 17:44:38 +01:00
|
|
|
* Copyright 2008 Denver Gingerich
|
2001-01-04 23:44:55 +01:00
|
|
|
*
|
|
|
|
* This file contains the (internal) driver registration functions,
|
|
|
|
* driver enumeration APIs and DirectDraw creation functions.
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2004-04-07 05:59:41 +02:00
|
|
|
#include "wine/port.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2010-08-18 19:26:20 +02:00
|
|
|
#define DDRAW_INIT_GUID
|
|
|
|
#include "ddraw_private.h"
|
2010-12-07 12:42:08 +01:00
|
|
|
#include "rpcproxy.h"
|
2004-10-07 05:06:48 +02:00
|
|
|
|
2005-12-05 20:40:42 +01:00
|
|
|
#include "wine/exception.h"
|
2006-06-09 19:36:12 +02:00
|
|
|
#include "winreg.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2006-10-09 14:40:30 +02:00
|
|
|
static struct list global_ddraw_list = LIST_INIT(global_ddraw_list);
|
|
|
|
|
2010-12-07 12:42:08 +01:00
|
|
|
static HINSTANCE instance;
|
|
|
|
|
2008-03-10 17:44:38 +01:00
|
|
|
/* value of ForceRefreshRate */
|
|
|
|
DWORD force_refresh_rate = 0;
|
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
/* Structure for converting DirectDrawEnumerateA to DirectDrawEnumerateExA */
|
|
|
|
struct callback_info
|
|
|
|
{
|
|
|
|
LPDDENUMCALLBACKA callback;
|
|
|
|
void *context;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Enumeration callback for converting DirectDrawEnumerateA to DirectDrawEnumerateExA */
|
|
|
|
static HRESULT CALLBACK enum_callback(GUID *guid, char *description, char *driver_name,
|
|
|
|
void *context, HMONITOR monitor)
|
|
|
|
{
|
|
|
|
const struct callback_info *info = context;
|
|
|
|
|
|
|
|
return info->callback(guid, description, driver_name, info->context);
|
|
|
|
}
|
|
|
|
|
2010-07-29 12:56:57 +02:00
|
|
|
/* Handle table functions */
|
|
|
|
BOOL ddraw_handle_table_init(struct ddraw_handle_table *t, UINT initial_size)
|
|
|
|
{
|
|
|
|
t->entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, initial_size * sizeof(*t->entries));
|
|
|
|
if (!t->entries)
|
|
|
|
{
|
|
|
|
ERR("Failed to allocate handle table memory.\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
t->free_entries = NULL;
|
|
|
|
t->table_size = initial_size;
|
|
|
|
t->entry_count = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ddraw_handle_table_destroy(struct ddraw_handle_table *t)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, t->entries);
|
|
|
|
memset(t, 0, sizeof(*t));
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD ddraw_allocate_handle(struct ddraw_handle_table *t, void *object, enum ddraw_handle_type type)
|
|
|
|
{
|
|
|
|
struct ddraw_handle_entry *entry;
|
|
|
|
|
|
|
|
if (t->free_entries)
|
|
|
|
{
|
|
|
|
DWORD idx = t->free_entries - t->entries;
|
|
|
|
/* Use a free handle */
|
|
|
|
entry = t->free_entries;
|
|
|
|
if (entry->type != DDRAW_HANDLE_FREE)
|
|
|
|
{
|
|
|
|
ERR("Handle %#x (%p) is in the free list, but has type %#x.\n", idx, entry->object, entry->type);
|
|
|
|
return DDRAW_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
t->free_entries = entry->object;
|
|
|
|
entry->object = object;
|
|
|
|
entry->type = type;
|
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(t->entry_count < t->table_size))
|
|
|
|
{
|
|
|
|
/* Grow the table */
|
|
|
|
UINT new_size = t->table_size + (t->table_size >> 1);
|
|
|
|
struct ddraw_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
|
|
|
|
0, t->entries, new_size * sizeof(*t->entries));
|
|
|
|
if (!new_entries)
|
|
|
|
{
|
|
|
|
ERR("Failed to grow the handle table.\n");
|
|
|
|
return DDRAW_INVALID_HANDLE;
|
|
|
|
}
|
|
|
|
t->entries = new_entries;
|
|
|
|
t->table_size = new_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = &t->entries[t->entry_count];
|
|
|
|
entry->object = object;
|
|
|
|
entry->type = type;
|
|
|
|
|
|
|
|
return t->entry_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ddraw_free_handle(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type)
|
|
|
|
{
|
|
|
|
struct ddraw_handle_entry *entry;
|
|
|
|
void *object;
|
|
|
|
|
|
|
|
if (handle == DDRAW_INVALID_HANDLE || handle >= t->entry_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid handle %#x passed.\n", handle);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = &t->entries[handle];
|
|
|
|
if (entry->type != type)
|
|
|
|
{
|
|
|
|
WARN("Handle %#x (%p) is not of type %#x.\n", handle, entry->object, type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
object = entry->object;
|
|
|
|
entry->object = t->free_entries;
|
|
|
|
entry->type = DDRAW_HANDLE_FREE;
|
|
|
|
t->free_entries = entry;
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *ddraw_get_object(struct ddraw_handle_table *t, DWORD handle, enum ddraw_handle_type type)
|
|
|
|
{
|
|
|
|
struct ddraw_handle_entry *entry;
|
|
|
|
|
|
|
|
if (handle == DDRAW_INVALID_HANDLE || handle >= t->entry_count)
|
|
|
|
{
|
|
|
|
WARN("Invalid handle %#x passed.\n", handle);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = &t->entries[handle];
|
|
|
|
if (entry->type != type)
|
|
|
|
{
|
|
|
|
WARN("Handle %#x (%p) is not of type %#x.\n", handle, entry->object, type);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry->object;
|
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Helper function for DirectDrawCreate and friends
|
|
|
|
* Creates a new DDraw interface with the given REFIID
|
|
|
|
*
|
|
|
|
* Interfaces that can be created:
|
|
|
|
* IDirectDraw, IDirectDraw2, IDirectDraw4, IDirectDraw7
|
|
|
|
* IDirect3D, IDirect3D2, IDirect3D3, IDirect3D7. (Does Windows return
|
|
|
|
* IDirect3D interfaces?)
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* guid: ID of the requested driver, NULL for the default driver.
|
|
|
|
* The GUID can be queried with DirectDrawEnumerate(Ex)A/W
|
|
|
|
* DD: Used to return the pointer to the created object
|
|
|
|
* UnkOuter: For aggregation, which is unsupported. Must be NULL
|
|
|
|
* iid: requested version ID.
|
|
|
|
*
|
|
|
|
* Returns:
|
2006-06-23 18:18:02 +02:00
|
|
|
* DD_OK if the Interface was created successfully
|
2006-06-09 19:36:12 +02:00
|
|
|
* CLASS_E_NOAGGREGATION if UnkOuter is not NULL
|
|
|
|
* E_OUTOFMEMORY if some allocation failed
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static HRESULT
|
2007-04-21 23:16:34 +02:00
|
|
|
DDRAW_Create(const GUID *guid,
|
2006-06-09 19:36:12 +02:00
|
|
|
void **DD,
|
|
|
|
IUnknown *UnkOuter,
|
|
|
|
REFIID iid)
|
2003-06-04 22:13:21 +02:00
|
|
|
{
|
2011-12-12 20:53:59 +01:00
|
|
|
enum wined3d_device_type device_type;
|
2012-03-08 20:27:16 +01:00
|
|
|
struct ddraw *ddraw;
|
2010-08-19 18:57:48 +02:00
|
|
|
HRESULT hr;
|
2003-08-18 21:55:11 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("driver_guid %s, ddraw %p, outer_unknown %p, interface_iid %s.\n",
|
|
|
|
debugstr_guid(guid), DD, UnkOuter, debugstr_guid(iid));
|
2003-06-04 22:13:21 +02:00
|
|
|
|
2006-08-30 05:56:32 +02:00
|
|
|
*DD = NULL;
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/* We don't care about this guids. Well, there's no special guid anyway
|
|
|
|
* OK, we could
|
|
|
|
*/
|
|
|
|
if (guid == (GUID *) DDCREATE_EMULATIONONLY)
|
|
|
|
{
|
|
|
|
/* Use the reference device id. This doesn't actually change anything,
|
|
|
|
* WineD3D always uses OpenGL for D3D rendering. One could make it request
|
|
|
|
* indirect rendering
|
|
|
|
*/
|
2011-12-12 20:53:59 +01:00
|
|
|
device_type = WINED3D_DEVICE_TYPE_REF;
|
2003-06-04 22:13:21 +02:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
else if(guid == (GUID *) DDCREATE_HARDWAREONLY)
|
|
|
|
{
|
2011-12-12 20:53:59 +01:00
|
|
|
device_type = WINED3D_DEVICE_TYPE_HAL;
|
2004-07-30 20:54:32 +02:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
else
|
|
|
|
{
|
2011-12-12 20:53:59 +01:00
|
|
|
device_type = 0;
|
2004-07-30 20:54:32 +02:00
|
|
|
}
|
|
|
|
|
2006-06-23 18:18:02 +02:00
|
|
|
/* DDraw doesn't support aggregation, according to msdn */
|
2006-06-09 19:36:12 +02:00
|
|
|
if (UnkOuter != NULL)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2004-07-30 20:54:32 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/* DirectDraw creation comes here */
|
2012-03-08 20:27:16 +01:00
|
|
|
ddraw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw));
|
|
|
|
if (!ddraw)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
|
|
|
ERR("Out of memory when creating DirectDraw\n");
|
|
|
|
return E_OUTOFMEMORY;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
2000-10-15 02:23:09 +02:00
|
|
|
|
2012-03-08 20:27:16 +01:00
|
|
|
hr = ddraw_init(ddraw, device_type);
|
2010-08-19 18:57:48 +02:00
|
|
|
if (FAILED(hr))
|
2006-08-03 07:30:00 +02:00
|
|
|
{
|
2010-08-19 18:57:48 +02:00
|
|
|
WARN("Failed to initialize ddraw object, hr %#x.\n", hr);
|
2012-03-08 20:27:16 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, ddraw);
|
2010-08-19 18:57:48 +02:00
|
|
|
return hr;
|
2006-08-03 07:30:00 +02:00
|
|
|
}
|
|
|
|
|
2012-03-08 20:27:16 +01:00
|
|
|
hr = IDirectDraw7_QueryInterface(&ddraw->IDirectDraw7_iface, iid, DD);
|
|
|
|
IDirectDraw7_Release(&ddraw->IDirectDraw7_iface);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
list_add_head(&global_ddraw_list, &ddraw->ddraw_list_entry);
|
|
|
|
else
|
|
|
|
WARN("Failed to query interface %s from ddraw object %p.\n", debugstr_guid(iid), ddraw);
|
2010-08-19 18:57:48 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return hr;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* DirectDrawCreate (DDRAW.@)
|
|
|
|
*
|
|
|
|
* Creates legacy DirectDraw Interfaces. Can't create IDirectDraw7
|
|
|
|
* interfaces in theory
|
|
|
|
*
|
|
|
|
* Arguments, return values: See DDRAW_Create
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2012-11-07 21:41:12 +01:00
|
|
|
HRESULT WINAPI DECLSPEC_HOTPATCH DirectDrawCreate(GUID *driver_guid, IDirectDraw **ddraw, IUnknown *outer)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2007-05-21 01:12:36 +02:00
|
|
|
HRESULT hr;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-11-07 21:41:12 +01:00
|
|
|
TRACE("driver_guid %s, ddraw %p, outer %p.\n",
|
|
|
|
debugstr_guid(driver_guid), ddraw, outer);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2012-11-07 21:41:12 +01:00
|
|
|
hr = DDRAW_Create(driver_guid, (void **)ddraw, outer, &IID_IDirectDraw);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2011-09-18 21:05:28 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2012-11-07 21:41:12 +01:00
|
|
|
if (FAILED(hr = IDirectDraw_Initialize(*ddraw, driver_guid)))
|
|
|
|
IDirectDraw_Release(*ddraw);
|
2011-09-18 21:05:28 +02:00
|
|
|
}
|
|
|
|
|
2007-05-21 01:12:36 +02:00
|
|
|
return hr;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* DirectDrawCreateEx (DDRAW.@)
|
|
|
|
*
|
|
|
|
* Only creates new IDirectDraw7 interfaces, supposed to fail if legacy
|
|
|
|
* interfaces are requested.
|
|
|
|
*
|
|
|
|
* Arguments, return values: See DDRAW_Create
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2009-09-12 14:15:31 +02:00
|
|
|
HRESULT WINAPI DECLSPEC_HOTPATCH
|
2011-10-18 05:40:38 +02:00
|
|
|
DirectDrawCreateEx(GUID *guid,
|
|
|
|
LPVOID *dd,
|
2006-06-09 19:36:12 +02:00
|
|
|
REFIID iid,
|
|
|
|
IUnknown *UnkOuter)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2007-05-21 01:12:36 +02:00
|
|
|
HRESULT hr;
|
2010-08-19 18:57:50 +02:00
|
|
|
|
|
|
|
TRACE("driver_guid %s, ddraw %p, interface_iid %s, outer_unknown %p.\n",
|
2011-10-18 05:40:38 +02:00
|
|
|
debugstr_guid(guid), dd, debugstr_guid(iid), UnkOuter);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2011-10-18 05:40:38 +02:00
|
|
|
hr = DDRAW_Create(guid, dd, UnkOuter, iid);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2011-09-18 21:05:28 +02:00
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
2011-10-18 05:40:38 +02:00
|
|
|
IDirectDraw7 *ddraw7 = *(IDirectDraw7 **)dd;
|
|
|
|
hr = IDirectDraw7_Initialize(ddraw7, guid);
|
2011-09-18 21:05:28 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
IDirectDraw7_Release(ddraw7);
|
|
|
|
}
|
|
|
|
|
2007-05-21 01:12:36 +02:00
|
|
|
return hr;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* DirectDrawEnumerateA (DDRAW.@)
|
|
|
|
*
|
|
|
|
* Enumerates legacy ddraw drivers, ascii version. We only have one
|
|
|
|
* driver, which relays to WineD3D. If we were sufficiently cool,
|
|
|
|
* we could offer various interfaces, which use a different default surface
|
|
|
|
* implementation, but I think it's better to offer this choice in
|
|
|
|
* winecfg, because some apps use the default driver, so we would need
|
|
|
|
* a winecfg option anyway, and there shouldn't be 2 ways to set one setting
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* Callback: Callback function from the app
|
|
|
|
* Context: Argument to the call back.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DD_OK on success
|
|
|
|
* E_INVALIDARG if the Callback caused a page fault
|
|
|
|
*
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2012-09-17 22:17:40 +02:00
|
|
|
HRESULT WINAPI DirectDrawEnumerateA(LPDDENUMCALLBACKA callback, void *context)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2012-09-17 22:17:40 +02:00
|
|
|
struct callback_info info;
|
2006-08-18 20:06:07 +02:00
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
TRACE("callback %p, context %p.\n", callback, context);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
info.callback = callback;
|
|
|
|
info.context = context;
|
|
|
|
return DirectDrawEnumerateExA(enum_callback, &info, 0x0);
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DirectDrawEnumerateExA (DDRAW.@)
|
|
|
|
*
|
|
|
|
* Enumerates DirectDraw7 drivers, ascii version. See
|
|
|
|
* the comments above DirectDrawEnumerateA for more details.
|
|
|
|
*
|
|
|
|
* The Flag member is not supported right now.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2012-09-17 22:17:40 +02:00
|
|
|
HRESULT WINAPI DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA callback, void *context, DWORD flags)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-09-17 22:18:39 +02:00
|
|
|
struct wined3d *wined3d;
|
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
TRACE("callback %p, context %p, flags %#x.\n", callback, context, flags);
|
2009-10-08 16:04:08 +02:00
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
if (flags & ~(DDENUM_ATTACHEDSECONDARYDEVICES |
|
2009-10-08 16:04:08 +02:00
|
|
|
DDENUM_DETACHEDSECONDARYDEVICES |
|
|
|
|
DDENUM_NONDISPLAYDEVICES))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
2012-09-17 22:17:40 +02:00
|
|
|
if (flags)
|
|
|
|
FIXME("flags 0x%08x not handled\n", flags);
|
2009-10-08 16:04:08 +02:00
|
|
|
|
2012-09-17 22:18:39 +02:00
|
|
|
TRACE("Enumerating ddraw interfaces\n");
|
2013-05-30 10:05:33 +02:00
|
|
|
if (!(wined3d = wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS)))
|
2013-01-13 22:08:09 +01:00
|
|
|
{
|
2013-05-30 10:05:33 +02:00
|
|
|
if (!(wined3d = wined3d_create(7, WINED3D_LEGACY_DEPTH_BIAS | WINED3D_NO3D)))
|
2013-01-13 22:08:09 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create a wined3d object.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Created a wined3d object without 3D support.\n");
|
|
|
|
}
|
2003-01-13 19:30:47 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
__TRY
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2012-09-17 22:18:39 +02:00
|
|
|
/* QuickTime expects the description "DirectDraw HAL" */
|
2006-08-18 20:06:07 +02:00
|
|
|
static CHAR driver_desc[] = "DirectDraw HAL",
|
|
|
|
driver_name[] = "display";
|
2012-09-17 22:18:39 +02:00
|
|
|
struct wined3d_adapter_identifier adapter_id;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
UINT adapter = 0;
|
|
|
|
BOOL cont_enum;
|
|
|
|
|
|
|
|
/* The Battle.net System Checker expects both a NULL device and a GUID-based device */
|
|
|
|
TRACE("Default interface: DirectDraw HAL\n");
|
|
|
|
cont_enum = callback(NULL, driver_desc, driver_name, context, 0);
|
|
|
|
for (adapter = 0; SUCCEEDED(hr) && cont_enum; adapter++)
|
|
|
|
{
|
|
|
|
char DriverName[512] = "";
|
|
|
|
|
|
|
|
/* The Battle.net System Checker expects the GetAdapterIdentifier DeviceName to match the
|
|
|
|
* Driver Name, so obtain the DeviceName and GUID from D3D. */
|
|
|
|
memset(&adapter_id, 0x0, sizeof(adapter_id));
|
|
|
|
adapter_id.device_name = DriverName;
|
|
|
|
adapter_id.device_name_size = sizeof(DriverName);
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
hr = wined3d_get_adapter_identifier(wined3d, adapter, 0x0, &adapter_id);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
TRACE("Interface %d: %s\n", adapter, wine_dbgstr_guid(&adapter_id.device_identifier));
|
|
|
|
cont_enum = callback(&adapter_id.device_identifier, driver_desc,
|
|
|
|
adapter_id.device_name, context, 0);
|
|
|
|
}
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
__EXCEPT_PAGE_FAULT
|
|
|
|
{
|
2012-09-17 22:18:39 +02:00
|
|
|
wined3d_decref(wined3d);
|
2009-10-08 16:04:08 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
|
|
|
__ENDTRY;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2012-09-17 22:18:39 +02:00
|
|
|
wined3d_decref(wined3d);
|
2006-06-09 19:36:12 +02:00
|
|
|
TRACE("End of enumeration\n");
|
|
|
|
return DD_OK;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2000-04-15 22:44:21 +02:00
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* DirectDrawEnumerateW (DDRAW.@)
|
2001-01-04 23:44:55 +01:00
|
|
|
*
|
2009-10-08 16:04:00 +02:00
|
|
|
* Enumerates legacy drivers, unicode version.
|
|
|
|
* This function is not implemented on Windows.
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
***********************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
HRESULT WINAPI DirectDrawEnumerateW(LPDDENUMCALLBACKW callback, void *context)
|
2009-10-08 16:04:00 +02:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("callback %p, context %p.\n", callback, context);
|
2009-10-08 16:04:00 +02:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
if (!callback)
|
2009-10-08 16:04:00 +02:00
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
else
|
|
|
|
return DDERR_UNSUPPORTED;
|
|
|
|
}
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2000-05-24 01:38:32 +02:00
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* DirectDrawEnumerateExW (DDRAW.@)
|
2001-01-04 23:44:55 +01:00
|
|
|
*
|
2009-10-08 16:04:18 +02:00
|
|
|
* Enumerates DirectDraw7 drivers, unicode version.
|
|
|
|
* This function is not implemented on Windows.
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
***********************************************************************/
|
2010-08-19 18:57:50 +02:00
|
|
|
HRESULT WINAPI DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW callback, void *context, DWORD flags)
|
2009-10-08 16:04:18 +02:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("callback %p, context %p, flags %#x.\n", callback, context, flags);
|
2009-10-08 16:04:18 +02:00
|
|
|
|
|
|
|
return DDERR_UNSUPPORTED;
|
|
|
|
}
|
2000-10-23 01:47:09 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* Classfactory implementation.
|
|
|
|
***********************************************************************/
|
2000-10-23 01:47:09 +02:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CF_CreateDirectDraw
|
|
|
|
*
|
|
|
|
* DDraw creation function for the class factory
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* UnkOuter: Set to NULL
|
|
|
|
* iid: ID of the wanted interface
|
|
|
|
* obj: Address to pass the interface pointer back
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* DD_OK / DDERR*, see DDRAW_Create
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static HRESULT
|
|
|
|
CF_CreateDirectDraw(IUnknown* UnkOuter, REFIID iid,
|
|
|
|
void **obj)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(iid), obj);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2006-06-09 19:36:12 +02:00
|
|
|
hr = DDRAW_Create(NULL, obj, UnkOuter, iid);
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
return hr;
|
2000-05-13 03:28:49 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* CF_CreateDirectDraw
|
|
|
|
*
|
|
|
|
* Clipper creation function for the class factory
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* UnkOuter: Set to NULL
|
|
|
|
* iid: ID of the wanted interface
|
|
|
|
* obj: Address to pass the interface pointer back
|
|
|
|
*
|
|
|
|
* Returns
|
|
|
|
* DD_OK / DDERR*, see DDRAW_Create
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
static HRESULT
|
|
|
|
CF_CreateDirectDrawClipper(IUnknown* UnkOuter, REFIID riid,
|
|
|
|
void **obj)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
IDirectDrawClipper *Clip;
|
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("outer_unknown %p, riid %s, object %p.\n", UnkOuter, debugstr_guid(riid), obj);
|
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_lock();
|
2006-06-09 19:36:12 +02:00
|
|
|
hr = DirectDrawCreateClipper(0, &Clip, UnkOuter);
|
2007-05-21 01:12:36 +02:00
|
|
|
if (hr != DD_OK)
|
|
|
|
{
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
2007-05-21 01:12:36 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
hr = IDirectDrawClipper_QueryInterface(Clip, riid, obj);
|
|
|
|
IDirectDrawClipper_Release(Clip);
|
2007-05-21 01:12:36 +02:00
|
|
|
|
2011-11-13 19:52:24 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
static const struct object_creation_info object_creation[] =
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
{ &CLSID_DirectDraw, CF_CreateDirectDraw },
|
|
|
|
{ &CLSID_DirectDraw7, CF_CreateDirectDraw },
|
|
|
|
{ &CLSID_DirectDrawClipper, CF_CreateDirectDrawClipper }
|
2001-01-04 23:44:55 +01:00
|
|
|
};
|
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
struct ddraw_class_factory
|
2011-01-23 21:00:00 +01:00
|
|
|
{
|
|
|
|
IClassFactory IClassFactory_iface;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid, LPVOID *ppObj);
|
2012-04-25 21:24:21 +02:00
|
|
|
};
|
2011-01-23 21:00:00 +01:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
static inline struct ddraw_class_factory *impl_from_IClassFactory(IClassFactory *iface)
|
2011-01-23 21:00:00 +01:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct ddraw_class_factory, IClassFactory_iface);
|
2011-01-23 21:00:00 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectDrawClassFactory::QueryInterface
|
|
|
|
*
|
|
|
|
* QueryInterface for the class factory
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* riid Reference to identifier of queried interface
|
|
|
|
* ppv Address to return the interface pointer at
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: E_NOINTERFACE
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2012-04-25 21:24:21 +02:00
|
|
|
static HRESULT WINAPI ddraw_class_factory_QueryInterface(IClassFactory *iface, REFIID riid, void **out)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
2006-06-09 19:36:12 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IClassFactory))
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
IClassFactory_AddRef(iface);
|
2012-04-25 21:24:21 +02:00
|
|
|
*out = iface;
|
2006-06-09 19:36:12 +02:00
|
|
|
return S_OK;
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 20:31:36 +01:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2000-04-09 16:30:50 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectDrawClassFactory::AddRef
|
|
|
|
*
|
|
|
|
* AddRef for the class factory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2012-04-25 21:24:21 +02:00
|
|
|
static ULONG WINAPI ddraw_class_factory_AddRef(IClassFactory *iface)
|
2004-09-28 21:19:27 +02:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
struct ddraw_class_factory *factory = impl_from_IClassFactory(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&factory->ref);
|
2003-01-13 19:30:47 +01:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", factory, ref);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectDrawClassFactory::Release
|
|
|
|
*
|
|
|
|
* Release for the class factory. If the refcount falls to 0, the object
|
|
|
|
* is destroyed
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The new refcount
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2012-04-25 21:24:21 +02:00
|
|
|
static ULONG WINAPI ddraw_class_factory_Release(IClassFactory *iface)
|
2004-09-28 21:19:27 +02:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
struct ddraw_class_factory *factory = impl_from_IClassFactory(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&factory->ref);
|
2010-08-19 18:57:50 +02:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", factory, ref);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
if (!ref)
|
|
|
|
HeapFree(GetProcessHeap(), 0, factory);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
return ref;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectDrawClassFactory::CreateInstance
|
|
|
|
*
|
|
|
|
* What is this? Seems to create DirectDraw objects...
|
|
|
|
*
|
|
|
|
* Params
|
2008-04-02 21:26:42 +02:00
|
|
|
* The usual things???
|
2006-06-09 19:36:12 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* ???
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2012-04-25 21:24:21 +02:00
|
|
|
static HRESULT WINAPI ddraw_class_factory_CreateInstance(IClassFactory *iface,
|
|
|
|
IUnknown *outer_unknown, REFIID riid, void **out)
|
2004-09-28 21:19:27 +02:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
struct ddraw_class_factory *factory = impl_from_IClassFactory(iface);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
TRACE("iface %p, outer_unknown %p, riid %s, out %p.\n",
|
|
|
|
iface, outer_unknown, debugstr_guid(riid), out);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2012-04-25 21:24:21 +02:00
|
|
|
return factory->pfnCreateInstance(outer_unknown, riid, out);
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* IDirectDrawClassFactory::LockServer
|
|
|
|
*
|
|
|
|
* What is this?
|
|
|
|
*
|
|
|
|
* Params
|
|
|
|
* ???
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* S_OK, because it's a stub
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
2012-04-25 21:24:21 +02:00
|
|
|
static HRESULT WINAPI ddraw_class_factory_LockServer(IClassFactory *iface, BOOL dolock)
|
2004-09-28 21:19:27 +02:00
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
FIXME("iface %p, dolock %#x stub!\n", iface, dolock);
|
|
|
|
|
2000-04-09 16:30:50 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* The class factory VTable
|
|
|
|
*******************************************************************************/
|
|
|
|
static const IClassFactoryVtbl IClassFactory_Vtbl =
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
ddraw_class_factory_QueryInterface,
|
|
|
|
ddraw_class_factory_AddRef,
|
|
|
|
ddraw_class_factory_Release,
|
|
|
|
ddraw_class_factory_CreateInstance,
|
|
|
|
ddraw_class_factory_LockServer
|
2000-04-09 16:30:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* DllGetClassObject [DDRAW.@]
|
2000-04-09 16:30:50 +02:00
|
|
|
* Retrieves class object from a DLL object
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Docs say returns STDAPI
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* rclsid [I] CLSID for the class object
|
|
|
|
* riid [I] Reference to identifier of interface for class object
|
|
|
|
* ppv [O] Address of variable to receive interface pointer for riid
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
|
|
|
|
* E_UNEXPECTED
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2012-04-25 21:24:21 +02:00
|
|
|
struct ddraw_class_factory *factory;
|
2001-08-11 00:49:35 +02:00
|
|
|
unsigned int i;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("rclsid %s, riid %s, object %p.\n",
|
|
|
|
debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2010-09-08 11:24:49 +02:00
|
|
|
if (!IsEqualGUID(&IID_IClassFactory, riid)
|
|
|
|
&& !IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
return E_NOINTERFACE;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
|
|
|
|
{
|
2010-09-08 11:24:49 +02:00
|
|
|
if (IsEqualGUID(object_creation[i].clsid, rclsid))
|
|
|
|
break;
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i == sizeof(object_creation)/sizeof(object_creation[0]))
|
|
|
|
{
|
2010-09-08 11:24:49 +02:00
|
|
|
FIXME("%s: no class found.\n", debugstr_guid(rclsid));
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
|
2001-01-04 23:44:55 +01:00
|
|
|
if (factory == NULL) return E_OUTOFMEMORY;
|
|
|
|
|
2011-01-23 21:00:00 +01:00
|
|
|
factory->IClassFactory_iface.lpVtbl = &IClassFactory_Vtbl;
|
2001-01-04 23:44:55 +01:00
|
|
|
factory->ref = 1;
|
|
|
|
|
|
|
|
factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
|
|
|
|
|
2009-01-21 09:56:13 +01:00
|
|
|
*ppv = factory;
|
2001-01-04 23:44:55 +01:00
|
|
|
return S_OK;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2001-06-11 22:14:43 +02:00
|
|
|
* DllCanUnloadNow [DDRAW.@] Determines whether the DLL is in use.
|
2000-04-09 16:30:50 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: S_FALSE
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
2010-08-19 18:57:50 +02:00
|
|
|
TRACE("\n");
|
|
|
|
|
2010-01-12 00:25:24 +01:00
|
|
|
return S_FALSE;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2010-12-07 12:42:08 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllRegisterServer (DDRAW.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllRegisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_register_resources( instance );
|
2010-12-07 12:42:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* DllUnregisterServer (DDRAW.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI DllUnregisterServer(void)
|
|
|
|
{
|
2011-08-02 15:51:55 +02:00
|
|
|
return __wine_unregister_resources( instance );
|
2010-12-07 12:42:08 +01:00
|
|
|
}
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* DestroyCallback
|
|
|
|
*
|
|
|
|
* Callback function for the EnumSurfaces call in DllMain.
|
|
|
|
* Dumps some surface info and releases the surface
|
|
|
|
*
|
|
|
|
* Params:
|
|
|
|
* surf: The enumerated surface
|
|
|
|
* desc: it's description
|
|
|
|
* context: Pointer to the ddraw impl
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* DDENUMRET_OK;
|
|
|
|
*******************************************************************************/
|
2006-06-15 17:14:37 +02:00
|
|
|
static HRESULT WINAPI
|
2006-06-09 19:36:12 +02:00
|
|
|
DestroyCallback(IDirectDrawSurface7 *surf,
|
|
|
|
DDSURFACEDESC2 *desc,
|
|
|
|
void *context)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2012-03-11 22:03:12 +01:00
|
|
|
struct ddraw_surface *Impl = impl_from_IDirectDrawSurface7(surf);
|
2011-08-08 00:26:19 +02:00
|
|
|
ULONG ref7, ref4, ref3, ref2, ref1, gamma_count, iface_count;
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2011-06-20 23:15:55 +02:00
|
|
|
ref7 = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */
|
2011-12-06 22:57:46 +01:00
|
|
|
ref4 = Impl->ref4;
|
|
|
|
ref3 = Impl->ref3;
|
|
|
|
ref2 = Impl->ref2;
|
|
|
|
ref1 = Impl->ref1;
|
|
|
|
gamma_count = Impl->gamma_count;
|
|
|
|
|
2011-08-08 00:26:19 +02:00
|
|
|
WARN("Surface %p has an reference counts of 7: %u 4: %u 3: %u 2: %u 1: %u gamma: %u\n",
|
|
|
|
Impl, ref7, ref4, ref3, ref2, ref1, gamma_count);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
/* Skip surfaces which are attached somewhere or which are
|
|
|
|
* part of a complex compound. They will get released when destroying
|
|
|
|
* the root
|
|
|
|
*/
|
2007-04-27 15:31:12 +02:00
|
|
|
if( (!Impl->is_complex_root) || (Impl->first_attached != Impl) )
|
2006-06-09 19:36:12 +02:00
|
|
|
return DDENUMRET_OK;
|
|
|
|
|
|
|
|
/* Destroy the surface */
|
2011-06-28 00:06:16 +02:00
|
|
|
iface_count = ddraw_surface_release_iface(Impl);
|
|
|
|
while (iface_count) iface_count = ddraw_surface_release_iface(Impl);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
|
|
return DDENUMRET_OK;
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/***********************************************************************
|
2006-06-09 19:36:12 +02:00
|
|
|
* get_config_key
|
|
|
|
*
|
|
|
|
* Reads a config key from the registry. Taken from WineD3D
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2007-03-19 20:45:14 +01:00
|
|
|
static inline DWORD get_config_key(HKEY defkey, HKEY appkey, const char* name, char* buffer, DWORD size)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
if (0 != appkey && !RegQueryValueExA( appkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
|
|
|
if (0 != defkey && !RegQueryValueExA( defkey, name, 0, NULL, (LPBYTE) buffer, &size )) return 0;
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* DllMain (DDRAW.0)
|
|
|
|
*
|
|
|
|
* Could be used to register DirectDraw drivers, if we have more than
|
|
|
|
* one. Also used to destroy any objects left at unload if the
|
|
|
|
* app didn't release them properly(Gothic 2, Diablo 2, Moto racer, ...)
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
2013-05-14 11:29:47 +02:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD reason, LPVOID reserved)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2013-05-14 11:29:47 +02:00
|
|
|
TRACE("(%p,%x,%p)\n", hInstDLL, reason, reserved);
|
|
|
|
switch (reason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
2002-09-25 02:29:56 +02:00
|
|
|
{
|
2012-06-28 13:11:14 +02:00
|
|
|
static HMODULE ddraw_self;
|
2006-06-09 19:36:12 +02:00
|
|
|
HKEY hkey = 0;
|
2010-06-18 13:09:50 +02:00
|
|
|
WNDCLASSA wc;
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2010-06-18 13:09:50 +02:00
|
|
|
/* Register the window class. This is used to create a hidden window
|
|
|
|
* for D3D rendering, if the application didn't pass one. It can also
|
|
|
|
* be used for creating a device window from SetCooperativeLevel(). */
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wc.lpfnWndProc = DefWindowProcA;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hInstDLL;
|
|
|
|
wc.hIcon = 0;
|
|
|
|
wc.hCursor = 0;
|
|
|
|
wc.hbrBackground = GetStockObject(BLACK_BRUSH);
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = DDRAW_WINDOW_CLASS_NAME;
|
|
|
|
if (!RegisterClassA(&wc))
|
|
|
|
{
|
|
|
|
ERR("Failed to register ddraw window class, last error %#x.\n", GetLastError());
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-10 17:44:38 +01:00
|
|
|
/* On Windows one can force the refresh rate that DirectDraw uses by
|
|
|
|
* setting an override value in dxdiag. This is documented in KB315614
|
|
|
|
* (main article), KB230002, and KB217348. By comparing registry dumps
|
|
|
|
* before and after setting the override, we see that the override value
|
|
|
|
* is stored in HKLM\Software\Microsoft\DirectDraw\ForceRefreshRate as a
|
|
|
|
* DWORD that represents the refresh rate to force. We use this
|
|
|
|
* registry entry to modify the behavior of SetDisplayMode so that Wine
|
|
|
|
* users can override the refresh rate in a Windows-compatible way.
|
|
|
|
*
|
|
|
|
* dxdiag will not accept a refresh rate lower than 40 or higher than
|
|
|
|
* 120 so this value should be within that range. It is, of course,
|
|
|
|
* possible for a user to set the registry entry value directly so that
|
|
|
|
* assumption might not hold.
|
|
|
|
*
|
|
|
|
* There is no current mechanism for setting this value through the Wine
|
|
|
|
* GUI. It would be most appropriate to set this value through a dxdiag
|
|
|
|
* clone, but it may be sufficient to use winecfg.
|
|
|
|
*
|
|
|
|
* TODO: Create a mechanism for setting this value through the Wine GUI.
|
|
|
|
*/
|
|
|
|
if ( !RegOpenKeyA( HKEY_LOCAL_MACHINE, "Software\\Microsoft\\DirectDraw", &hkey ) )
|
|
|
|
{
|
2013-05-30 10:05:33 +02:00
|
|
|
DWORD type, data, size;
|
|
|
|
|
2008-03-10 17:44:38 +01:00
|
|
|
size = sizeof(data);
|
|
|
|
if (!RegQueryValueExA( hkey, "ForceRefreshRate", NULL, &type, (LPBYTE)&data, &size ) && type == REG_DWORD)
|
|
|
|
{
|
|
|
|
TRACE("ForceRefreshRate set; overriding refresh rate to %d Hz\n", data);
|
|
|
|
force_refresh_rate = data;
|
|
|
|
}
|
|
|
|
RegCloseKey( hkey );
|
|
|
|
}
|
|
|
|
|
2012-06-28 13:11:14 +02:00
|
|
|
/* Prevent the ddraw module from being unloaded. When switching to
|
|
|
|
* exclusive mode, we replace the window proc of the ddraw window. If
|
|
|
|
* an application would unload ddraw from the WM_DESTROY handler for
|
|
|
|
* that window, it would return to unmapped memory and die. Apparently
|
|
|
|
* this is supposed to work on Windows. We should probably use
|
|
|
|
* GET_MODULE_HANDLE_EX_FLAG_PIN for this, but that's not currently
|
|
|
|
* implemented. */
|
|
|
|
if (!GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)&ddraw_self, &ddraw_self))
|
|
|
|
ERR("Failed to get own module handle.\n");
|
|
|
|
|
2010-12-07 12:42:08 +01:00
|
|
|
instance = hInstDLL;
|
2003-06-30 22:53:48 +02:00
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
2013-05-14 11:29:47 +02:00
|
|
|
break;
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2013-05-14 11:29:47 +02:00
|
|
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
2006-10-09 15:29:05 +02:00
|
|
|
if(!list_empty(&global_ddraw_list))
|
2002-09-25 02:29:56 +02:00
|
|
|
{
|
2006-10-09 15:29:05 +02:00
|
|
|
struct list *entry, *entry2;
|
|
|
|
WARN("There are still existing DirectDraw interfaces. Wine bug or buggy application?\n");
|
|
|
|
|
2008-04-02 21:26:42 +02:00
|
|
|
/* We remove elements from this loop */
|
2006-10-09 15:29:05 +02:00
|
|
|
LIST_FOR_EACH_SAFE(entry, entry2, &global_ddraw_list)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2012-03-08 20:27:16 +01:00
|
|
|
struct ddraw *ddraw = LIST_ENTRY(entry, struct ddraw, ddraw_list_entry);
|
2006-10-09 15:29:05 +02:00
|
|
|
HRESULT hr;
|
|
|
|
DDSURFACEDESC2 desc;
|
|
|
|
int i;
|
|
|
|
|
2006-12-15 17:15:28 +01:00
|
|
|
WARN("DDraw %p has a refcount of %d\n", ddraw, ddraw->ref7 + ddraw->ref4 + ddraw->ref3 + ddraw->ref2 + ddraw->ref1);
|
2006-10-09 15:29:05 +02:00
|
|
|
|
2008-04-04 21:23:01 +02:00
|
|
|
/* Add references to each interface to avoid freeing them unexpectedly */
|
2011-01-19 01:33:42 +01:00
|
|
|
IDirectDraw_AddRef(&ddraw->IDirectDraw_iface);
|
2011-01-19 01:36:36 +01:00
|
|
|
IDirectDraw2_AddRef(&ddraw->IDirectDraw2_iface);
|
2011-01-19 01:40:53 +01:00
|
|
|
IDirectDraw4_AddRef(&ddraw->IDirectDraw4_iface);
|
2011-01-19 01:42:43 +01:00
|
|
|
IDirectDraw7_AddRef(&ddraw->IDirectDraw7_iface);
|
2006-10-09 15:29:05 +02:00
|
|
|
|
|
|
|
/* Does a D3D device exist? Destroy it
|
|
|
|
* TODO: Destroy all Vertex buffers, Lights, Materials
|
2008-04-02 21:26:42 +02:00
|
|
|
* and execute buffers too
|
2006-10-09 15:29:05 +02:00
|
|
|
*/
|
|
|
|
if(ddraw->d3ddevice)
|
|
|
|
{
|
|
|
|
WARN("DDraw %p has d3ddevice %p attached\n", ddraw, ddraw->d3ddevice);
|
2011-10-17 15:58:51 +02:00
|
|
|
while(IDirect3DDevice7_Release(&ddraw->d3ddevice->IDirect3DDevice7_iface));
|
2006-10-09 15:29:05 +02:00
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
2011-12-11 21:43:28 +01:00
|
|
|
/* Destroy the swapchain after any 3D device. The 3D device
|
|
|
|
* cleanup code needs a swapchain. Specifically, it tries to
|
|
|
|
* set the current render target to the front buffer. */
|
|
|
|
if (ddraw->wined3d_swapchain)
|
|
|
|
ddraw_destroy_swapchain(ddraw);
|
|
|
|
|
2006-10-09 15:29:05 +02:00
|
|
|
/* Try to release the objects
|
|
|
|
* Do an EnumSurfaces to find any hanging surfaces
|
|
|
|
*/
|
|
|
|
memset(&desc, 0, sizeof(desc));
|
|
|
|
desc.dwSize = sizeof(desc);
|
|
|
|
for(i = 0; i <= 1; i++)
|
2006-06-09 19:36:12 +02:00
|
|
|
{
|
2011-01-19 01:42:43 +01:00
|
|
|
hr = IDirectDraw7_EnumSurfaces(&ddraw->IDirectDraw7_iface, DDENUMSURFACES_ALL,
|
|
|
|
&desc, ddraw, DestroyCallback);
|
2006-10-09 15:29:05 +02:00
|
|
|
if(hr != D3D_OK)
|
|
|
|
ERR("(%p) EnumSurfaces failed, prepare for trouble\n", ddraw);
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2006-10-09 15:29:05 +02:00
|
|
|
|
2011-09-14 20:17:28 +02:00
|
|
|
if (!list_empty(&ddraw->surface_list))
|
|
|
|
ERR("DDraw %p still has surfaces attached.\n", ddraw);
|
2006-10-09 15:29:05 +02:00
|
|
|
|
|
|
|
/* Release all hanging references to destroy the objects. This
|
|
|
|
* restores the screen mode too
|
|
|
|
*/
|
2011-01-19 01:33:42 +01:00
|
|
|
while(IDirectDraw_Release(&ddraw->IDirectDraw_iface));
|
2011-01-19 01:36:36 +01:00
|
|
|
while(IDirectDraw2_Release(&ddraw->IDirectDraw2_iface));
|
2011-01-19 01:40:53 +01:00
|
|
|
while(IDirectDraw4_Release(&ddraw->IDirectDraw4_iface));
|
2011-01-19 01:42:43 +01:00
|
|
|
while(IDirectDraw7_Release(&ddraw->IDirectDraw7_iface));
|
2006-06-09 19:36:12 +02:00
|
|
|
}
|
2002-09-25 02:29:56 +02:00
|
|
|
}
|
2010-06-18 13:09:50 +02:00
|
|
|
|
2013-05-14 11:29:47 +02:00
|
|
|
if (reserved) break;
|
2010-06-18 13:09:50 +02:00
|
|
|
UnregisterClassA(DDRAW_WINDOW_CLASS_NAME, hInstDLL);
|
2006-03-21 15:06:36 +01:00
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|