2000-04-09 14:30:50 +00:00
|
|
|
/* DirectDraw Base Functions
|
|
|
|
*
|
|
|
|
* Copyright 1997-1999 Marcus Meissner
|
|
|
|
* Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
|
2001-04-17 17:48:19 +00:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
2001-01-04 22:44:55 +00:00
|
|
|
*
|
|
|
|
* This file contains the (internal) driver registration functions,
|
|
|
|
* driver enumeration APIs and DirectDraw creation functions.
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-01-01 00:24:30 +00:00
|
|
|
#include "winnls.h"
|
2000-04-09 14:30:50 +00:00
|
|
|
#include "winerror.h"
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2000-04-09 14:30:50 +00:00
|
|
|
|
|
|
|
/* This for all the enumeration and creation of D3D-related objects */
|
|
|
|
#include "ddraw_private.h"
|
2002-01-01 00:24:30 +00:00
|
|
|
#include "debugtools.h"
|
2000-04-09 14:30:50 +00:00
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
#define MAX_DDRAW_DRIVERS 3
|
|
|
|
static const ddraw_driver* DDRAW_drivers[MAX_DDRAW_DRIVERS];
|
|
|
|
static int DDRAW_num_drivers; /* = 0 */
|
|
|
|
static int DDRAW_default_driver;
|
2000-04-09 14:30:50 +00:00
|
|
|
|
|
|
|
DEFAULT_DEBUG_CHANNEL(ddraw);
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LPVOID lpCallback;
|
|
|
|
LPVOID lpContext;
|
|
|
|
} DirectDrawEnumerateProcData;
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* DirectDrawEnumerateExA (DDRAW.@)
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateExA(
|
|
|
|
LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TRACE("(%p,%p, %08lx)\n", lpCallback, lpContext, dwFlags);
|
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
|
|
|
DPRINTF(" Flags : ");
|
|
|
|
if (dwFlags & DDENUM_ATTACHEDSECONDARYDEVICES)
|
|
|
|
DPRINTF("DDENUM_ATTACHEDSECONDARYDEVICES ");
|
|
|
|
if (dwFlags & DDENUM_DETACHEDSECONDARYDEVICES)
|
|
|
|
DPRINTF("DDENUM_DETACHEDSECONDARYDEVICES ");
|
|
|
|
if (dwFlags & DDENUM_NONDISPLAYDEVICES)
|
|
|
|
DPRINTF("DDENUM_NONDISPLAYDEVICES ");
|
|
|
|
DPRINTF("\n");
|
|
|
|
}
|
2000-10-15 00:23:09 +00:00
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
for (i=0; i<DDRAW_num_drivers; i++)
|
|
|
|
{
|
|
|
|
TRACE("Enumerating %s/%s interface\n",
|
|
|
|
DDRAW_drivers[i]->info->szDriver,
|
|
|
|
DDRAW_drivers[i]->info->szDescription);
|
|
|
|
|
|
|
|
/* We have to pass NULL from the primary display device.
|
|
|
|
* RoadRage chapter 6's enumeration routine expects it. */
|
|
|
|
if (!lpCallback((DDRAW_default_driver == i) ? NULL
|
|
|
|
:(LPGUID)&DDRAW_drivers[i]->info->guidDeviceIdentifier,
|
|
|
|
(LPSTR)DDRAW_drivers[i]->info->szDescription,
|
|
|
|
(LPSTR)DDRAW_drivers[i]->info->szDriver,
|
|
|
|
lpContext, 0))
|
2000-04-09 14:30:50 +00:00
|
|
|
return DD_OK;
|
|
|
|
}
|
2000-05-13 01:28:49 +00:00
|
|
|
|
|
|
|
/* Unsupported flags */
|
|
|
|
if (dwFlags & DDENUM_NONDISPLAYDEVICES) {
|
|
|
|
FIXME("no non-display devices supported.\n");
|
|
|
|
}
|
|
|
|
if (dwFlags & DDENUM_DETACHEDSECONDARYDEVICES) {
|
|
|
|
FIXME("no detached secondary devices supported.\n");
|
|
|
|
}
|
|
|
|
|
2000-04-09 14:30:50 +00:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* DirectDrawEnumerateExW (DDRAW.@)
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL CALLBACK DirectDrawEnumerateExProcW(
|
|
|
|
GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName,
|
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
2002-01-01 00:24:30 +00:00
|
|
|
INT len;
|
|
|
|
BOOL bResult;
|
|
|
|
LPWSTR lpDriverDescriptionW, lpDriverNameW;
|
2000-04-09 14:30:50 +00:00
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
|
|
|
|
2002-01-01 00:24:30 +00:00
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpDriverDescription, -1, NULL, 0 );
|
|
|
|
lpDriverDescriptionW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpDriverDescription, -1, lpDriverDescriptionW, len );
|
|
|
|
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
|
|
|
|
lpDriverNameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, lpDriverNameW, len );
|
|
|
|
|
|
|
|
bResult = (*(LPDDENUMCALLBACKEXW *) pEPD->lpCallback)(lpGUID, lpDriverDescriptionW,
|
|
|
|
lpDriverNameW, pEPD->lpContext, hm);
|
2000-04-09 14:30:50 +00:00
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpDriverDescriptionW);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpDriverNameW);
|
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateExW(
|
|
|
|
LPDDENUMCALLBACKEXW lpCallback, LPVOID lpContext, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData epd;
|
|
|
|
epd.lpCallback = (LPVOID) lpCallback;
|
|
|
|
epd.lpContext = lpContext;
|
|
|
|
|
|
|
|
return DirectDrawEnumerateExA(DirectDrawEnumerateExProcW, (LPVOID) &epd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* DirectDrawEnumerateA (DDRAW.@)
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL CALLBACK DirectDrawEnumerateProcA(
|
|
|
|
GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName,
|
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
|
|
|
|
|
|
|
return ((LPDDENUMCALLBACKA) pEPD->lpCallback)(
|
|
|
|
lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateA(
|
|
|
|
LPDDENUMCALLBACKA lpCallback, LPVOID lpContext)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData epd;
|
|
|
|
epd.lpCallback = (LPVOID) lpCallback;
|
|
|
|
epd.lpContext = lpContext;
|
|
|
|
|
|
|
|
return DirectDrawEnumerateExA(DirectDrawEnumerateProcA, (LPVOID) &epd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-20 23:03:14 +00:00
|
|
|
* DirectDrawEnumerateW (DDRAW.@)
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL WINAPI DirectDrawEnumerateProcW(
|
|
|
|
GUID *lpGUID, LPWSTR lpDriverDescription, LPWSTR lpDriverName,
|
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
|
|
|
|
|
|
|
return ((LPDDENUMCALLBACKW) pEPD->lpCallback)(
|
|
|
|
lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateW(
|
|
|
|
LPDDENUMCALLBACKW lpCallback, LPVOID lpContext)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData epd;
|
|
|
|
epd.lpCallback = (LPVOID) lpCallback;
|
|
|
|
epd.lpContext = lpContext;
|
|
|
|
|
|
|
|
return DirectDrawEnumerateExW(DirectDrawEnumerateProcW, (LPVOID) &epd, 0);
|
|
|
|
}
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* DirectDrawCreate (DDRAW.@)
|
2000-04-09 14:30:50 +00:00
|
|
|
*/
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
const ddraw_driver* DDRAW_FindDriver(const GUID* pGUID)
|
2000-04-09 14:30:50 +00:00
|
|
|
{
|
2001-01-04 22:44:55 +00:00
|
|
|
static const GUID zeroGUID; /* gets zero-inited */
|
|
|
|
|
|
|
|
TRACE("(%s)\n", pGUID ? debugstr_guid(pGUID) : "(null)");
|
|
|
|
|
|
|
|
if (DDRAW_num_drivers == 0) return NULL;
|
|
|
|
|
|
|
|
if (pGUID == (LPGUID)DDCREATE_EMULATIONONLY
|
|
|
|
|| pGUID == (LPGUID)DDCREATE_HARDWAREONLY)
|
|
|
|
pGUID = NULL;
|
|
|
|
|
|
|
|
if (pGUID == NULL || memcmp(pGUID, &zeroGUID, sizeof(GUID)) == 0)
|
|
|
|
{
|
|
|
|
/* Use the default driver. */
|
|
|
|
return DDRAW_drivers[DDRAW_default_driver];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Look for a matching GUID. */
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i=0; i < DDRAW_num_drivers; i++)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(pGUID,
|
|
|
|
&DDRAW_drivers[i]->info->guidDeviceIdentifier))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i < DDRAW_num_drivers)
|
|
|
|
{
|
|
|
|
return DDRAW_drivers[i];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("(%s): did not recognize requested GUID.\n",debugstr_guid(pGUID));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT DDRAW_Create(
|
|
|
|
LPGUID lpGUID, LPVOID *lplpDD, LPUNKNOWN pUnkOuter, REFIID iid, BOOL ex
|
|
|
|
) {
|
|
|
|
const ddraw_driver* driver;
|
|
|
|
LPDIRECTDRAW7 pDD;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (DDRAW_num_drivers == 0)
|
|
|
|
{
|
|
|
|
WARN("no DirectDraw drivers registered\n");
|
|
|
|
return DDERR_INVALIDDIRECTDRAWGUID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpGUID == (LPGUID)DDCREATE_EMULATIONONLY
|
|
|
|
|| lpGUID == (LPGUID)DDCREATE_HARDWAREONLY)
|
|
|
|
lpGUID = NULL;
|
|
|
|
|
|
|
|
TRACE("(%s,%p,%p)\n",debugstr_guid(lpGUID),lplpDD,pUnkOuter);
|
|
|
|
|
|
|
|
if (pUnkOuter != NULL)
|
|
|
|
return DDERR_INVALIDPARAMS; /* CLASS_E_NOAGGREGATION? */
|
|
|
|
|
|
|
|
driver = DDRAW_FindDriver(lpGUID);
|
|
|
|
if (driver == NULL) return DDERR_INVALIDDIRECTDRAWGUID;
|
|
|
|
|
|
|
|
hr = driver->create(lpGUID, &pDD, pUnkOuter, ex);
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(pDD, iid, lplpDD);
|
|
|
|
IDirectDraw7_Release(pDD);
|
|
|
|
return hr;
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
2000-04-15 20:44:21 +00:00
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* DirectDrawCreate (DDRAW.@)
|
2001-01-04 22:44:55 +00:00
|
|
|
*
|
|
|
|
* Only creates legacy IDirectDraw interfaces.
|
|
|
|
* Cannot create IDirectDraw7 interfaces.
|
|
|
|
* In theory.
|
2000-04-15 20:44:21 +00:00
|
|
|
*/
|
2000-04-09 14:30:50 +00:00
|
|
|
HRESULT WINAPI DirectDrawCreate(
|
2001-01-04 22:44:55 +00:00
|
|
|
LPGUID lpGUID, LPDIRECTDRAW* lplpDD, LPUNKNOWN pUnkOuter
|
2000-04-09 14:30:50 +00:00
|
|
|
) {
|
2001-01-04 22:44:55 +00:00
|
|
|
return DDRAW_Create(lpGUID,(LPVOID*)lplpDD,pUnkOuter,&IID_IDirectDraw,FALSE);
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 23:38:32 +00:00
|
|
|
/***********************************************************************
|
2001-06-19 18:20:47 +00:00
|
|
|
* DirectDrawCreateEx (DDRAW.@)
|
2001-01-04 22:44:55 +00:00
|
|
|
*
|
|
|
|
* Only creates new IDirectDraw7 interfaces.
|
|
|
|
* Supposed to fail if legacy interfaces are requested.
|
|
|
|
* In theory.
|
2000-05-23 23:38:32 +00:00
|
|
|
*/
|
2000-05-13 01:28:49 +00:00
|
|
|
HRESULT WINAPI DirectDrawCreateEx(
|
|
|
|
LPGUID lpGUID, LPVOID* lplpDD, REFIID iid, LPUNKNOWN pUnkOuter
|
|
|
|
) {
|
2001-01-04 22:44:55 +00:00
|
|
|
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
|
|
|
return DDRAW_Create(lpGUID, lplpDD, pUnkOuter, iid, TRUE);
|
|
|
|
}
|
2000-10-22 23:47:09 +00:00
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
extern HRESULT Uninit_DirectDraw_Create(const GUID*, LPDIRECTDRAW7*,
|
|
|
|
LPUNKNOWN, BOOL);
|
2000-10-22 23:47:09 +00:00
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
/* This is for the class factory. */
|
|
|
|
static HRESULT DDRAW_CreateDirectDraw(IUnknown* pUnkOuter, REFIID iid,
|
|
|
|
LPVOID* ppObj)
|
|
|
|
{
|
|
|
|
LPDIRECTDRAW7 pDD;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = Uninit_DirectDraw_Create(NULL, &pDD, pUnkOuter, TRUE); /* ex? */
|
|
|
|
if (FAILED(hr)) return hr;
|
|
|
|
|
|
|
|
hr = IDirectDraw7_QueryInterface(pDD, iid, ppObj);
|
|
|
|
IDirectDraw_Release(pDD);
|
|
|
|
return hr;
|
2000-05-13 01:28:49 +00:00
|
|
|
}
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
/******************************************************************************
|
2000-04-09 14:30:50 +00:00
|
|
|
* DirectDraw ClassFactory
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2001-01-04 22:44:55 +00:00
|
|
|
ICOM_VFIELD_MULTI(IClassFactory);
|
|
|
|
|
|
|
|
DWORD ref;
|
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid,
|
|
|
|
LPVOID *ppObj);
|
2000-04-09 14:30:50 +00:00
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
struct object_creation_info
|
|
|
|
{
|
|
|
|
const CLSID *clsid;
|
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID riid,
|
|
|
|
LPVOID *ppObj);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* There should be more, but these are the only ones listed in the header
|
|
|
|
* file. */
|
|
|
|
extern HRESULT DDRAW_CreateDirectDrawClipper(IUnknown *pUnkOuter, REFIID riid,
|
|
|
|
LPVOID *ppObj);
|
|
|
|
|
|
|
|
static const struct object_creation_info object_creation[] =
|
|
|
|
{
|
|
|
|
{ &CLSID_DirectDraw, DDRAW_CreateDirectDraw },
|
|
|
|
{ &CLSID_DirectDraw7, DDRAW_CreateDirectDraw },
|
|
|
|
{ &CLSID_DirectDrawClipper, DDRAW_CreateDirectDrawClipper }
|
|
|
|
};
|
|
|
|
|
2000-04-09 14:30:50 +00:00
|
|
|
static HRESULT WINAPI
|
2001-01-04 22:44:55 +00:00
|
|
|
DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
2000-04-09 14:30:50 +00:00
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IClassFactory))
|
|
|
|
{
|
|
|
|
IClassFactory_AddRef(iface);
|
|
|
|
*ppobj = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
|
2000-04-09 14:30:50 +00:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface) {
|
2000-04-09 14:30:50 +00:00
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
return ++(This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface) {
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
ULONG ref = --This->ref;
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
|
|
|
return ref;
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
2001-01-04 22:44:55 +00:00
|
|
|
|
2000-04-09 14:30:50 +00:00
|
|
|
static HRESULT WINAPI DDCF_CreateInstance(
|
|
|
|
LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
|
|
|
|
) {
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
return This->pfnCreateInstance(pOuter, riid, ppobj);
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ICOM_VTABLE(IClassFactory) DDCF_Vtbl =
|
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
DDCF_QueryInterface,
|
|
|
|
DDCF_AddRef,
|
|
|
|
DDCF_Release,
|
|
|
|
DDCF_CreateInstance,
|
|
|
|
DDCF_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2001-06-11 20:14:43 +00:00
|
|
|
* DllGetClassObject [DDRAW.@]
|
2000-04-09 14:30:50 +00: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
|
|
|
|
*/
|
|
|
|
DWORD WINAPI DDRAW_DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
|
|
|
|
{
|
2001-08-10 22:49:35 +00:00
|
|
|
unsigned int i;
|
2001-01-04 22:44:55 +00:00
|
|
|
IClassFactoryImpl *factory;
|
|
|
|
|
2001-04-09 18:32:38 +00:00
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
if ( !IsEqualGUID( &IID_IClassFactory, riid )
|
|
|
|
&& ! IsEqualGUID( &IID_IUnknown, riid) )
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
|
|
|
|
{
|
2001-01-07 21:49:00 +00:00
|
|
|
if (IsEqualGUID(object_creation[i].clsid, rclsid))
|
2001-01-04 22:44:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == sizeof(object_creation)/sizeof(object_creation[0]))
|
|
|
|
{
|
|
|
|
FIXME("%s: no class found.\n", debugstr_guid(rclsid));
|
|
|
|
return CLASS_E_CLASSNOTAVAILABLE;
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
|
|
|
|
if (factory == NULL) return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
ICOM_INIT_INTERFACE(factory, IClassFactory, DDCF_Vtbl);
|
|
|
|
factory->ref = 1;
|
|
|
|
|
|
|
|
factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
|
|
|
|
|
|
|
|
*ppv = ICOM_INTERFACE(factory, IClassFactory);
|
|
|
|
return S_OK;
|
2000-04-09 14:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
2001-06-11 20:14:43 +00:00
|
|
|
* DllCanUnloadNow [DDRAW.@] Determines whether the DLL is in use.
|
2000-04-09 14:30:50 +00:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK
|
|
|
|
* Failure: S_FALSE
|
|
|
|
*/
|
|
|
|
DWORD WINAPI DDRAW_DllCanUnloadNow(void) {
|
|
|
|
FIXME("(void): stub\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2001-01-04 22:44:55 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Initialisation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Choose which driver is considered the primary display driver. It will
|
|
|
|
* be created when we get a NULL guid for the DirectDrawCreate(Ex). */
|
|
|
|
static int DDRAW_ChooseDefaultDriver(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int best = 0;
|
|
|
|
int best_score = 0;
|
|
|
|
|
|
|
|
assert(DDRAW_num_drivers > 0);
|
|
|
|
|
|
|
|
/* This algorithm is really stupid. */
|
|
|
|
for (i=0; i < DDRAW_num_drivers; i++)
|
|
|
|
{
|
|
|
|
if (DDRAW_drivers[i]->preference > best_score)
|
|
|
|
{
|
|
|
|
best_score = DDRAW_drivers[i]->preference;
|
|
|
|
best = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(best_score > 0);
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL WINAPI DDRAW_DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
|
|
|
{
|
|
|
|
/* If we were sufficiently cool, DDraw drivers would just be COM
|
|
|
|
* objects, registered with a particular component category. */
|
|
|
|
|
2001-04-17 17:48:19 +00:00
|
|
|
DDRAW_HAL_Init(hInstDLL, fdwReason, lpv);
|
2001-01-04 22:44:55 +00:00
|
|
|
DDRAW_User_Init(hInstDLL, fdwReason, lpv);
|
|
|
|
|
|
|
|
if (DDRAW_num_drivers > 0)
|
|
|
|
DDRAW_default_driver = DDRAW_ChooseDefaultDriver();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register a direct draw driver. This should be called from your init
|
|
|
|
* function. (That's why there is no locking: your init func is called from
|
|
|
|
* our DllInit, which is serialised.) */
|
|
|
|
void DDRAW_register_driver(const ddraw_driver *driver)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < DDRAW_num_drivers; i++)
|
|
|
|
{
|
|
|
|
if (DDRAW_drivers[i] == driver)
|
|
|
|
{
|
|
|
|
ERR("Driver reregistering %p\n", driver);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DDRAW_num_drivers == sizeof(DDRAW_drivers)/sizeof(DDRAW_drivers[0]))
|
|
|
|
{
|
|
|
|
ERR("too many DDRAW drivers\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDRAW_drivers[DDRAW_num_drivers++] = driver;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This totally doesn't belong here. */
|
|
|
|
LONG DDRAW_width_bpp_to_pitch(DWORD width, DWORD bpp)
|
|
|
|
{
|
|
|
|
LONG pitch;
|
|
|
|
|
|
|
|
assert(bpp != 0); /* keeps happening... */
|
|
|
|
|
|
|
|
if (bpp == 15) bpp = 16;
|
|
|
|
pitch = width * (bpp / 8);
|
|
|
|
return pitch + (8 - (pitch % 8)) % 8;
|
|
|
|
}
|