2000-04-09 16:30:50 +02:00
|
|
|
/* DirectDraw Base Functions
|
|
|
|
*
|
|
|
|
* Copyright 1997-1999 Marcus Meissner
|
|
|
|
* Copyright 1998 Lionel Ulmer (most of Direct3D stuff)
|
2001-04-17 19:48:19 +02:00
|
|
|
* Copyright 2000-2001 TransGaming Technologies Inc.
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2002-01-01 01:24:30 +01:00
|
|
|
#include "winnls.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
#include "winerror.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
#include "ddraw.h"
|
|
|
|
#include "d3d.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
|
|
/* This for all the enumeration and creation of D3D-related objects */
|
|
|
|
#include "ddraw_private.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2001-01-04 23:44:55 +01: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 16:30:50 +02:00
|
|
|
|
2002-09-25 02:29:56 +02:00
|
|
|
void (*wine_tsx11_lock_ptr)(void) = NULL;
|
|
|
|
void (*wine_tsx11_unlock_ptr)(void) = NULL;
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
LPVOID lpCallback;
|
2002-06-01 01:06:46 +02:00
|
|
|
LPVOID lpContext;
|
2000-04-09 16:30:50 +02:00
|
|
|
} DirectDrawEnumerateProcData;
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* DirectDrawEnumerateExA (DDRAW.@)
|
2000-04-09 16:30:50 +02: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 02:23:09 +02:00
|
|
|
|
2001-01-04 23:44:55 +01: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 16:30:50 +02:00
|
|
|
return DD_OK;
|
|
|
|
}
|
2000-05-13 03:28:49 +02: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 16:30:50 +02:00
|
|
|
return DD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* DirectDrawEnumerateExW (DDRAW.@)
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL CALLBACK DirectDrawEnumerateExProcW(
|
2002-06-01 01:06:46 +02:00
|
|
|
GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName,
|
2000-04-09 16:30:50 +02:00
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
2002-01-01 01:24:30 +01:00
|
|
|
INT len;
|
|
|
|
BOOL bResult;
|
|
|
|
LPWSTR lpDriverDescriptionW, lpDriverNameW;
|
2000-04-09 16:30:50 +02:00
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
|
|
|
|
2002-01-01 01:24:30 +01: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 16:30:50 +02: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-21 01:03:14 +02:00
|
|
|
* DirectDrawEnumerateA (DDRAW.@)
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL CALLBACK DirectDrawEnumerateProcA(
|
2002-06-01 01:06:46 +02:00
|
|
|
GUID *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName,
|
2000-04-09 16:30:50 +02:00
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
|
|
|
|
|
|
|
return ((LPDDENUMCALLBACKA) pEPD->lpCallback)(
|
|
|
|
lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateA(
|
2002-06-01 01:06:46 +02:00
|
|
|
LPDDENUMCALLBACKA lpCallback, LPVOID lpContext)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
DirectDrawEnumerateProcData epd;
|
2000-04-09 16:30:50 +02:00
|
|
|
epd.lpCallback = (LPVOID) lpCallback;
|
|
|
|
epd.lpContext = lpContext;
|
|
|
|
|
|
|
|
return DirectDrawEnumerateExA(DirectDrawEnumerateProcA, (LPVOID) &epd, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-21 01:03:14 +02:00
|
|
|
* DirectDrawEnumerateW (DDRAW.@)
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
static BOOL WINAPI DirectDrawEnumerateProcW(
|
2002-06-01 01:06:46 +02:00
|
|
|
GUID *lpGUID, LPWSTR lpDriverDescription, LPWSTR lpDriverName,
|
2000-04-09 16:30:50 +02:00
|
|
|
LPVOID lpContext, HMONITOR hm)
|
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-09 16:30:50 +02:00
|
|
|
return ((LPDDENUMCALLBACKW) pEPD->lpCallback)(
|
|
|
|
lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateW(
|
2002-06-01 01:06:46 +02:00
|
|
|
LPDDENUMCALLBACKW lpCallback, LPVOID lpContext)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
|
|
|
DirectDrawEnumerateProcData epd;
|
|
|
|
epd.lpCallback = (LPVOID) lpCallback;
|
|
|
|
epd.lpContext = lpContext;
|
|
|
|
|
|
|
|
return DirectDrawEnumerateExW(DirectDrawEnumerateProcW, (LPVOID) &epd, 0);
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* DirectDrawCreate (DDRAW.@)
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
const ddraw_driver* DDRAW_FindDriver(const GUID* pGUID)
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
2001-01-04 23:44:55 +01: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 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2000-04-15 22:44:21 +02:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* DirectDrawCreate (DDRAW.@)
|
2001-01-04 23:44:55 +01:00
|
|
|
*
|
|
|
|
* Only creates legacy IDirectDraw interfaces.
|
|
|
|
* Cannot create IDirectDraw7 interfaces.
|
|
|
|
* In theory.
|
2000-04-15 22:44:21 +02:00
|
|
|
*/
|
2000-04-09 16:30:50 +02:00
|
|
|
HRESULT WINAPI DirectDrawCreate(
|
2001-01-04 23:44:55 +01:00
|
|
|
LPGUID lpGUID, LPDIRECTDRAW* lplpDD, LPUNKNOWN pUnkOuter
|
2000-04-09 16:30:50 +02:00
|
|
|
) {
|
2001-01-04 23:44:55 +01:00
|
|
|
return DDRAW_Create(lpGUID,(LPVOID*)lplpDD,pUnkOuter,&IID_IDirectDraw,FALSE);
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2000-05-24 01:38:32 +02:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* DirectDrawCreateEx (DDRAW.@)
|
2001-01-04 23:44:55 +01:00
|
|
|
*
|
|
|
|
* Only creates new IDirectDraw7 interfaces.
|
|
|
|
* Supposed to fail if legacy interfaces are requested.
|
|
|
|
* In theory.
|
2000-05-24 01:38:32 +02:00
|
|
|
*/
|
2000-05-13 03:28:49 +02:00
|
|
|
HRESULT WINAPI DirectDrawCreateEx(
|
|
|
|
LPGUID lpGUID, LPVOID* lplpDD, REFIID iid, LPUNKNOWN pUnkOuter
|
|
|
|
) {
|
2001-01-04 23:44:55 +01:00
|
|
|
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
|
|
|
return DDRAW_Create(lpGUID, lplpDD, pUnkOuter, iid, TRUE);
|
|
|
|
}
|
2000-10-23 01:47:09 +02:00
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
extern HRESULT Uninit_DirectDraw_Create(const GUID*, LPDIRECTDRAW7*,
|
|
|
|
LPUNKNOWN, BOOL);
|
2000-10-23 01:47:09 +02:00
|
|
|
|
2001-01-04 23:44:55 +01: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 03:28:49 +02:00
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
/******************************************************************************
|
2000-04-09 16:30:50 +02:00
|
|
|
* DirectDraw ClassFactory
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2001-01-04 23:44:55 +01:00
|
|
|
ICOM_VFIELD_MULTI(IClassFactory);
|
|
|
|
|
|
|
|
DWORD ref;
|
|
|
|
HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, REFIID iid,
|
|
|
|
LPVOID *ppObj);
|
2000-04-09 16:30:50 +02:00
|
|
|
} IClassFactoryImpl;
|
|
|
|
|
2001-01-04 23:44:55 +01: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 }
|
|
|
|
};
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static HRESULT WINAPI
|
2001-01-04 23:44:55 +01:00
|
|
|
DDCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
|
|
|
|
{
|
2000-04-09 16:30:50 +02:00
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
|
2001-01-04 23:44:55 +01: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 16:30:50 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface) {
|
2000-04-09 16:30:50 +02:00
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
return ++(This->ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface) {
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
ULONG ref = --This->ref;
|
|
|
|
|
|
|
|
if (ref == 0)
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
|
|
|
return ref;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2000-04-09 16:30:50 +02: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 23:44:55 +01:00
|
|
|
|
|
|
|
return This->pfnCreateInstance(pOuter, riid, ppobj);
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock) {
|
|
|
|
ICOM_THIS(IClassFactoryImpl,iface);
|
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
static ICOM_VTABLE(IClassFactory) DDCF_Vtbl =
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
|
|
|
ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
|
|
|
|
DDCF_QueryInterface,
|
|
|
|
DDCF_AddRef,
|
|
|
|
DDCF_Release,
|
|
|
|
DDCF_CreateInstance,
|
|
|
|
DDCF_LockServer
|
|
|
|
};
|
|
|
|
|
|
|
|
/*******************************************************************************
|
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
|
|
|
|
*/
|
|
|
|
DWORD WINAPI DDRAW_DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID *ppv)
|
|
|
|
{
|
2001-08-11 00:49:35 +02:00
|
|
|
unsigned int i;
|
2001-01-04 23:44:55 +01:00
|
|
|
IClassFactoryImpl *factory;
|
|
|
|
|
2001-04-09 20:32:38 +02:00
|
|
|
TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
|
2001-01-04 23:44:55 +01: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 22:49:00 +01:00
|
|
|
if (IsEqualGUID(object_creation[i].clsid, rclsid))
|
2001-01-04 23:44:55 +01: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 16:30:50 +02:00
|
|
|
}
|
2001-01-04 23:44:55 +01: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 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
|
|
|
|
*/
|
|
|
|
DWORD WINAPI DDRAW_DllCanUnloadNow(void) {
|
|
|
|
FIXME("(void): stub\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
2001-01-04 23:44:55 +01: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;
|
|
|
|
}
|
|
|
|
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
|
2001-01-04 23:44:55 +01:00
|
|
|
{
|
|
|
|
/* If we were sufficiently cool, DDraw drivers would just be COM
|
|
|
|
* objects, registered with a particular component category. */
|
|
|
|
|
2001-04-17 19:48:19 +02:00
|
|
|
DDRAW_HAL_Init(hInstDLL, fdwReason, lpv);
|
2001-01-04 23:44:55 +01:00
|
|
|
DDRAW_User_Init(hInstDLL, fdwReason, lpv);
|
|
|
|
|
2002-09-25 02:29:56 +02:00
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
|
|
|
{
|
|
|
|
HMODULE mod = GetModuleHandleA( "x11drv.dll" );
|
|
|
|
if (mod)
|
|
|
|
{
|
|
|
|
wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
|
|
|
|
wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
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;
|
|
|
|
}
|