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
|
|
|
*/
|
|
|
|
|
2003-06-04 22:13:21 +02:00
|
|
|
#define GLPRIVATE_NO_REDEFINE
|
|
|
|
|
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
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-04-09 16:30:50 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2002-01-01 01:24:30 +01:00
|
|
|
#include "winnls.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "wingdi.h"
|
2005-12-05 20:40:42 +01:00
|
|
|
#include "wine/exception.h"
|
|
|
|
#include "excpt.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"
|
2003-06-04 22:13:21 +02:00
|
|
|
#include "wine/library.h"
|
|
|
|
|
|
|
|
#include "gl_private.h"
|
|
|
|
|
|
|
|
#undef GLPRIVATE_NO_REDEFINE
|
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;
|
|
|
|
|
2003-06-04 22:13:21 +02:00
|
|
|
BOOL opengl_initialized = 0;
|
|
|
|
|
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
|
2005-06-06 17:51:50 +02:00
|
|
|
#include "opengl_private.h"
|
2003-07-28 21:05:49 +02:00
|
|
|
|
2003-06-04 22:13:21 +02:00
|
|
|
static void *gl_handle = NULL;
|
|
|
|
|
|
|
|
#define GL_API_FUNCTION(f) typeof(f) * p##f;
|
|
|
|
#include "gl_api.h"
|
|
|
|
#undef GL_API_FUNCTION
|
|
|
|
|
|
|
|
#ifndef SONAME_LIBGL
|
|
|
|
#define SONAME_LIBGL "libGL.so"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static BOOL DDRAW_bind_to_opengl( void )
|
|
|
|
{
|
2003-10-06 23:03:32 +02:00
|
|
|
const char *glname = SONAME_LIBGL;
|
2003-08-18 21:55:11 +02:00
|
|
|
|
2003-06-04 22:13:21 +02:00
|
|
|
gl_handle = wine_dlopen(glname, RTLD_NOW, NULL, 0);
|
|
|
|
if (!gl_handle) {
|
|
|
|
WARN("Wine cannot find the OpenGL graphics library (%s).\n",glname);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GL_API_FUNCTION(f) \
|
|
|
|
if((p##f = wine_dlsym(gl_handle, #f, NULL, 0)) == NULL) \
|
|
|
|
{ \
|
|
|
|
WARN("Can't find symbol %s\n", #f); \
|
|
|
|
goto sym_not_found; \
|
|
|
|
}
|
|
|
|
#include "gl_api.h"
|
|
|
|
#undef GL_API_FUNCTION
|
|
|
|
|
2003-07-28 21:05:49 +02:00
|
|
|
/* And now calls the function to initialize the various fields for the rendering devices */
|
2004-07-30 20:54:32 +02:00
|
|
|
return d3ddevice_init_at_startup(gl_handle);
|
2003-07-28 21:05:49 +02:00
|
|
|
|
2003-06-04 22:13:21 +02:00
|
|
|
sym_not_found:
|
|
|
|
WARN("Wine cannot find certain functions that it needs inside the OpenGL\n"
|
|
|
|
"graphics library. To enable Wine to use OpenGL please upgrade\n"
|
|
|
|
"your OpenGL libraries\n");
|
|
|
|
wine_dlclose(gl_handle, NULL, 0);
|
|
|
|
gl_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_OPENGL */
|
|
|
|
|
2004-07-30 20:54:32 +02:00
|
|
|
BOOL s3tc_initialized = 0;
|
|
|
|
|
|
|
|
static void *s3tc_handle = NULL;
|
|
|
|
|
|
|
|
FUNC_FETCH_2D_TEXEL_RGBA_DXT1 fetch_2d_texel_rgba_dxt1;
|
|
|
|
FUNC_FETCH_2D_TEXEL_RGBA_DXT3 fetch_2d_texel_rgba_dxt3;
|
|
|
|
FUNC_FETCH_2D_TEXEL_RGBA_DXT5 fetch_2d_texel_rgba_dxt5;
|
|
|
|
|
|
|
|
#ifndef SONAME_LIBTXC_DXTN
|
|
|
|
#define SONAME_LIBTXC_DXTN "libtxc_dxtn.so"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static BOOL DDRAW_bind_to_s3tc( void )
|
|
|
|
{
|
|
|
|
const char * const s3tcname = SONAME_LIBTXC_DXTN;
|
|
|
|
|
|
|
|
s3tc_handle = wine_dlopen(s3tcname, RTLD_NOW, NULL, 0);
|
|
|
|
if (!s3tc_handle) {
|
|
|
|
TRACE("No S3TC software decompression library seems to be present (%s).\n",s3tcname);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
TRACE("Found S3TC software decompression library (%s).\n",s3tcname);
|
|
|
|
|
|
|
|
#define API_FUNCTION(f) \
|
|
|
|
if((f = wine_dlsym(s3tc_handle, #f, NULL, 0)) == NULL) \
|
|
|
|
{ \
|
|
|
|
WARN("Can't find symbol %s\n", #f); \
|
|
|
|
goto sym_not_found; \
|
|
|
|
}
|
|
|
|
API_FUNCTION(fetch_2d_texel_rgba_dxt1);
|
|
|
|
API_FUNCTION(fetch_2d_texel_rgba_dxt3);
|
|
|
|
API_FUNCTION(fetch_2d_texel_rgba_dxt5);
|
|
|
|
#undef API_FUNCTION
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
sym_not_found:
|
|
|
|
WARN("Wine cannot find functions that are necessary for S3TC software decompression\n");
|
|
|
|
wine_dlclose(s3tc_handle, NULL, 0);
|
|
|
|
s3tc_handle = NULL;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2004-08-30 20:37:17 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* DirectDrawEnumerateExA (DDRAW.@)
|
|
|
|
*
|
|
|
|
* Enumerates all DirectDraw devices installed on the system.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpCallback [I] DDEnumCallbackEx function to be called with a description of
|
|
|
|
* each enumerated HAL.
|
|
|
|
* lpContext [I] application-defined value to be passed to the callback.
|
|
|
|
* dwFlags [I] Specifies the enumeration scope. see msdn.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: DD_OK.
|
|
|
|
* Failure: DDERR_INVALIDPARAMS
|
2000-04-09 16:30:50 +02:00
|
|
|
*/
|
|
|
|
HRESULT WINAPI DirectDrawEnumerateExA(
|
|
|
|
LPDDENUMCALLBACKEXA lpCallback, LPVOID lpContext, DWORD dwFlags)
|
|
|
|
{
|
|
|
|
int i;
|
2005-12-05 20:40:42 +01:00
|
|
|
BOOL stop = FALSE;
|
2000-04-09 16:30:50 +02:00
|
|
|
TRACE("(%p,%p, %08lx)\n", lpCallback, lpContext, dwFlags);
|
|
|
|
|
|
|
|
if (TRACE_ON(ddraw)) {
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE(" Flags : ");
|
2000-04-09 16:30:50 +02:00
|
|
|
if (dwFlags & DDENUM_ATTACHEDSECONDARYDEVICES)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("DDENUM_ATTACHEDSECONDARYDEVICES ");
|
2000-04-09 16:30:50 +02:00
|
|
|
if (dwFlags & DDENUM_DETACHEDSECONDARYDEVICES)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("DDENUM_DETACHEDSECONDARYDEVICES ");
|
2000-04-09 16:30:50 +02:00
|
|
|
if (dwFlags & DDENUM_NONDISPLAYDEVICES)
|
2003-03-15 01:12:42 +01:00
|
|
|
TRACE("DDENUM_NONDISPLAYDEVICES ");
|
|
|
|
TRACE("\n");
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
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. */
|
2005-12-05 20:40:42 +01:00
|
|
|
__TRY
|
|
|
|
{
|
|
|
|
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))
|
|
|
|
stop = TRUE;
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2005-12-05 20:40:42 +01:00
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
__ENDTRY
|
|
|
|
if (stop) return DD_OK;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2004-08-30 20:37:17 +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;
|
|
|
|
|
2003-01-13 19:30:47 +01:00
|
|
|
TRACE("(%s,%p,%p,%d)\n", debugstr_guid(lpGUID), lplpDD, pUnkOuter, ex);
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
) {
|
2003-01-13 19:30:47 +01:00
|
|
|
TRACE("(%s,%p,%p)\n", debugstr_guid(lpGUID), lplpDD, pUnkOuter);
|
|
|
|
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
|
|
|
|
) {
|
2003-01-13 19:30:47 +01:00
|
|
|
TRACE("(%s,%p,%s,%p)\n", debugstr_guid(lpGUID), lplpDD, debugstr_guid(iid), pUnkOuter);
|
|
|
|
|
2001-01-04 23:44:55 +01:00
|
|
|
if (!IsEqualGUID(iid, &IID_IDirectDraw7))
|
|
|
|
return DDERR_INVALIDPARAMS;
|
|
|
|
|
2003-01-13 19:30:47 +01:00
|
|
|
return DDRAW_Create(lpGUID, lplpDD, pUnkOuter, iid, TRUE);
|
2001-01-04 23:44:55 +01:00
|
|
|
}
|
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;
|
2003-01-13 19:30:47 +01:00
|
|
|
BOOL ex;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2003-01-13 19:30:47 +01:00
|
|
|
TRACE("(%p,%s,%p)\n", pUnkOuter, debugstr_guid(iid), ppObj);
|
|
|
|
|
|
|
|
/* This is a mighty hack :-) */
|
|
|
|
if (IsEqualGUID(iid, &IID_IDirectDraw7))
|
|
|
|
ex = TRUE;
|
|
|
|
else
|
|
|
|
ex = FALSE;
|
|
|
|
|
|
|
|
hr = Uninit_DirectDraw_Create(NULL, &pDD, pUnkOuter, ex);
|
2001-01-04 23:44:55 +01:00
|
|
|
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);
|
|
|
|
|
2005-07-11 15:21:17 +02:00
|
|
|
LONG ref;
|
2001-01-04 23:44:55 +01:00
|
|
|
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)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2000-04-09 16:30:50 +02:00
|
|
|
|
2003-01-13 19:30:47 +01:00
|
|
|
TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppobj);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
static ULONG WINAPI DDCF_AddRef(LPCLASSFACTORY iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2005-01-09 18:29:21 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2003-01-13 19:30:47 +01:00
|
|
|
|
2005-01-09 18:29:21 +01:00
|
|
|
TRACE("(%p)->() incrementing from %ld.\n", This, ref - 1);
|
2003-01-13 19:30:47 +01:00
|
|
|
|
2005-01-09 18:29:21 +01:00
|
|
|
return ref;
|
2000-04-09 16:30:50 +02:00
|
|
|
}
|
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
static ULONG WINAPI DDCF_Release(LPCLASSFACTORY iface)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2004-09-28 21:19:27 +02:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
TRACE("(%p)->() decrementing from %ld.\n", This, ref+1);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
if (ref == 0)
|
2001-01-04 23:44:55 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
|
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
|
|
|
|
2000-04-09 16:30:50 +02:00
|
|
|
static HRESULT WINAPI DDCF_CreateInstance(
|
|
|
|
LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj
|
2004-09-28 21:19:27 +02:00
|
|
|
)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
static HRESULT WINAPI DDCF_LockServer(LPCLASSFACTORY iface,BOOL dolock)
|
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
|
2000-04-09 16:30:50 +02:00
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
static const IClassFactoryVtbl DDCF_Vtbl =
|
2000-04-09 16:30:50 +02:00
|
|
|
{
|
|
|
|
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
|
|
|
|
*/
|
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
|
|
|
{
|
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
|
|
|
|
*/
|
2005-08-08 19:35:28 +02:00
|
|
|
HRESULT WINAPI DllCanUnloadNow(void)
|
|
|
|
{
|
2000-04-09 16:30:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2004-02-20 21:19:23 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* DllMain (DDRAW.0)
|
|
|
|
*/
|
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)
|
|
|
|
{
|
2003-06-30 22:53:48 +02:00
|
|
|
HMODULE mod;
|
|
|
|
|
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
|
|
|
|
2005-05-06 21:38:50 +02:00
|
|
|
mod = GetModuleHandleA( "winex11.drv" );
|
2002-09-25 02:29:56 +02:00
|
|
|
if (mod)
|
|
|
|
{
|
|
|
|
wine_tsx11_lock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_lock" );
|
|
|
|
wine_tsx11_unlock_ptr = (void *)GetProcAddress( mod, "wine_tsx11_unlock" );
|
|
|
|
}
|
2003-06-04 22:13:21 +02:00
|
|
|
#ifdef HAVE_OPENGL
|
|
|
|
opengl_initialized = DDRAW_bind_to_opengl();
|
|
|
|
#endif /* HAVE_OPENGL */
|
2004-07-30 20:54:32 +02:00
|
|
|
s3tc_initialized = DDRAW_bind_to_s3tc();
|
2002-09-25 02:29:56 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|