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.
|
2006-06-09 19:36:12 +02:00
|
|
|
|
* Copyright 2006 Stefan D<EFBFBD>singer
|
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"
|
2006-06-09 19:36:12 +02:00
|
|
|
|
#include "wine/debug.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"
|
2006-06-09 19:36:12 +02:00
|
|
|
|
#include "winreg.h"
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
|
|
#include "ddraw.h"
|
|
|
|
|
#include "d3d.h"
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
|
|
|
|
#include "ddraw_private.h"
|
2002-09-25 02:29:56 +02:00
|
|
|
|
|
2006-08-03 07:30:00 +02:00
|
|
|
|
typedef IWineD3D* (WINAPI *fnWineDirect3DCreate)(UINT, UINT, IUnknown *);
|
|
|
|
|
|
|
|
|
|
static HMODULE hWineD3D = (HMODULE) -1;
|
|
|
|
|
static fnWineDirect3DCreate pWineDirect3DCreate;
|
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* The configured default surface */
|
|
|
|
|
WINED3DSURFTYPE DefaultSurfaceType = SURFACE_UNKNOWN;
|
2003-06-04 22:13:21 +02:00
|
|
|
|
|
2006-10-09 15:18:11 +02:00
|
|
|
|
/* DDraw list and critical section */
|
2006-10-09 14:40:30 +02:00
|
|
|
|
static struct list global_ddraw_list = LIST_INIT(global_ddraw_list);
|
|
|
|
|
|
2006-10-09 15:18:11 +02:00
|
|
|
|
static CRITICAL_SECTION ddraw_list_cs;
|
|
|
|
|
static CRITICAL_SECTION_DEBUG ddraw_list_cs_debug =
|
|
|
|
|
{
|
|
|
|
|
0, 0, &ddraw_list_cs,
|
|
|
|
|
{ &ddraw_list_cs_debug.ProcessLocksList,
|
|
|
|
|
&ddraw_list_cs_debug.ProcessLocksList },
|
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": ddraw_list_cs") }
|
|
|
|
|
};
|
|
|
|
|
static CRITICAL_SECTION ddraw_list_cs = { &ddraw_list_cs_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
|
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
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
IDirectDrawImpl *This = NULL;
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
IWineD3D *wineD3D = NULL;
|
|
|
|
|
IWineD3DDevice *wineD3DDevice = NULL;
|
|
|
|
|
HDC hDC;
|
|
|
|
|
WINED3DDEVTYPE devicetype;
|
2003-08-18 21:55:11 +02:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE("(%s,%p,%p)\n", debugstr_guid(guid), DD, UnkOuter);
|
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
|
|
|
|
|
*/
|
|
|
|
|
devicetype = WINED3DDEVTYPE_REF;
|
2003-06-04 22:13:21 +02:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
else if(guid == (GUID *) DDCREATE_HARDWAREONLY)
|
|
|
|
|
{
|
|
|
|
|
devicetype = WINED3DDEVTYPE_HAL;
|
2004-07-30 20:54:32 +02:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
devicetype = 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 */
|
|
|
|
|
This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectDrawImpl));
|
|
|
|
|
if(!This)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* The interfaces:
|
|
|
|
|
* IDirectDraw and IDirect3D are the same object,
|
|
|
|
|
* QueryInterface is used to get other interfaces.
|
|
|
|
|
*/
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDraw, IDirectDraw1_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDraw2, IDirectDraw2_Vtbl);
|
2006-12-15 17:15:45 +01:00
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDraw3, IDirectDraw3_Vtbl);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDraw4, IDirectDraw4_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirectDraw7, IDirectDraw7_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirect3D, IDirect3D1_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirect3D2, IDirect3D2_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirect3D3, IDirect3D3_Vtbl);
|
|
|
|
|
ICOM_INIT_INTERFACE(This, IDirect3D7, IDirect3D7_Vtbl);
|
|
|
|
|
|
|
|
|
|
/* See comments in IDirectDrawImpl_CreateNewSurface for a description
|
|
|
|
|
* of this member.
|
|
|
|
|
* Read from a registry key, should add a winecfg option later
|
|
|
|
|
*/
|
|
|
|
|
This->ImplType = DefaultSurfaceType;
|
|
|
|
|
|
|
|
|
|
/* Get the current screen settings */
|
2007-01-02 17:16:36 +01:00
|
|
|
|
hDC = GetDC(0);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
This->orig_bpp = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES);
|
2007-01-02 17:16:36 +01:00
|
|
|
|
ReleaseDC(0, hDC);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
This->orig_width = GetSystemMetrics(SM_CXSCREEN);
|
|
|
|
|
This->orig_height = GetSystemMetrics(SM_CYSCREEN);
|
|
|
|
|
|
2006-08-03 07:30:00 +02:00
|
|
|
|
if (hWineD3D == (HMODULE) -1)
|
|
|
|
|
{
|
|
|
|
|
hWineD3D = LoadLibraryA("wined3d");
|
|
|
|
|
if (hWineD3D)
|
|
|
|
|
pWineDirect3DCreate = (fnWineDirect3DCreate) GetProcAddress(hWineD3D, "WineDirect3DCreate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hWineD3D)
|
|
|
|
|
{
|
|
|
|
|
ERR("Couldn't load WineD3D - OpenGL libs not present?\n");
|
2006-08-30 05:56:32 +02:00
|
|
|
|
hr = DDERR_NODIRECTDRAWSUPPORT;
|
2006-08-03 07:30:00 +02:00
|
|
|
|
goto err_out;
|
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* Initialize WineD3D
|
|
|
|
|
*
|
|
|
|
|
* All Rendering (2D and 3D) is relayed to WineD3D,
|
|
|
|
|
* but DirectDraw specific management, like DDSURFACEDESC and DDPIXELFORMAT
|
|
|
|
|
* structure handling is handled in this lib.
|
|
|
|
|
*/
|
2006-08-03 07:30:00 +02:00
|
|
|
|
wineD3D = pWineDirect3DCreate(0 /* SDKVersion */, 7 /* DXVersion */, (IUnknown *) This /* Parent */);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
if(!wineD3D)
|
2001-01-04 23:44:55 +01:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ERR("Failed to initialise WineD3D\n");
|
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
|
goto err_out;
|
2000-04-09 16:30:50 +02:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
This->wineD3D = wineD3D;
|
|
|
|
|
TRACE("WineD3D created at %p\n", wineD3D);
|
|
|
|
|
|
|
|
|
|
/* Initialized member...
|
|
|
|
|
*
|
|
|
|
|
* It is set to false at creation time, and set to true in
|
2006-06-23 18:18:02 +02:00
|
|
|
|
* IDirectDraw7::Initialize. Its sole purpose is to return DD_OK on
|
2006-06-09 19:36:12 +02:00
|
|
|
|
* initialize only once
|
|
|
|
|
*/
|
|
|
|
|
This->initialized = FALSE;
|
|
|
|
|
|
|
|
|
|
/* Initialize WineD3DDevice
|
|
|
|
|
*
|
|
|
|
|
* It is used for screen setup, surface and palette creation
|
2006-06-23 18:18:02 +02:00
|
|
|
|
* When a Direct3DDevice7 is created, the D3D capabilities of WineD3D are
|
2006-06-09 19:36:12 +02:00
|
|
|
|
* initialized
|
|
|
|
|
*/
|
|
|
|
|
hr = IWineD3D_CreateDevice(wineD3D,
|
|
|
|
|
0 /*D3D_ADAPTER_DEFAULT*/,
|
|
|
|
|
devicetype,
|
|
|
|
|
NULL, /* FocusWindow, don't know yet */
|
|
|
|
|
0, /* BehaviorFlags */
|
|
|
|
|
&wineD3DDevice,
|
|
|
|
|
(IUnknown *) ICOM_INTERFACE(This, IDirectDraw7));
|
|
|
|
|
if(FAILED(hr))
|
|
|
|
|
{
|
2006-10-10 19:23:27 +02:00
|
|
|
|
ERR("Failed to create a wineD3DDevice, result = %x\n", hr);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
goto err_out;
|
2000-05-13 03:28:49 +02:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
This->wineD3DDevice = wineD3DDevice;
|
|
|
|
|
TRACE("wineD3DDevice created at %p\n", This->wineD3DDevice);
|
|
|
|
|
|
|
|
|
|
/* Register the window class
|
|
|
|
|
*
|
|
|
|
|
* It 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
|
|
|
|
|
*
|
|
|
|
|
* The name: DDRAW_<address>. The classname is
|
|
|
|
|
* 32 bit long, so a 64 bit address will fit nicely
|
|
|
|
|
* (Will this be compiled for 64 bit anyway?)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
sprintf(This->classname, "DDRAW_%p", This);
|
|
|
|
|
|
|
|
|
|
memset(&This->wnd_class, 0, sizeof(This->wnd_class));
|
|
|
|
|
This->wnd_class.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
|
This->wnd_class.lpfnWndProc = DefWindowProcA;
|
|
|
|
|
This->wnd_class.cbClsExtra = 0;
|
|
|
|
|
This->wnd_class.cbWndExtra = 0;
|
|
|
|
|
This->wnd_class.hInstance = GetModuleHandleA(0);
|
|
|
|
|
This->wnd_class.hIcon = 0;
|
|
|
|
|
This->wnd_class.hCursor = 0;
|
|
|
|
|
This->wnd_class.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
|
|
|
|
|
This->wnd_class.lpszMenuName = NULL;
|
|
|
|
|
This->wnd_class.lpszClassName = This->classname;
|
|
|
|
|
if(!RegisterClassA(&This->wnd_class))
|
|
|
|
|
{
|
|
|
|
|
ERR("RegisterClassA failed!\n");
|
|
|
|
|
goto err_out;
|
2000-05-13 03:28:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* Get the amount of video memory */
|
|
|
|
|
This->total_vidmem = IWineD3DDevice_GetAvailableTextureMem(This->wineD3DDevice);
|
|
|
|
|
|
|
|
|
|
/* Initialize the caps */
|
|
|
|
|
This->caps.dwSize = sizeof(This->caps);
|
2006-08-15 13:43:42 +02:00
|
|
|
|
/* do not report DDCAPS_OVERLAY and friends since we don't support overlays */
|
2006-06-09 19:36:12 +02:00
|
|
|
|
#define BLIT_CAPS (DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTDEPTHFILL \
|
|
|
|
|
| DDCAPS_BLTSTRETCH | DDCAPS_CANBLTSYSMEM | DDCAPS_CANCLIP \
|
|
|
|
|
| DDCAPS_CANCLIPSTRETCHED | DDCAPS_COLORKEY \
|
2006-08-15 13:43:42 +02:00
|
|
|
|
| DDCAPS_COLORKEYHWASSIST | DDCAPS_ALIGNBOUNDARYSRC )
|
2006-06-09 19:36:12 +02:00
|
|
|
|
#define CKEY_CAPS (DDCKEYCAPS_DESTBLT | DDCKEYCAPS_SRCBLT)
|
|
|
|
|
#define FX_CAPS (DDFXCAPS_BLTALPHA | DDFXCAPS_BLTMIRRORLEFTRIGHT \
|
|
|
|
|
| DDFXCAPS_BLTMIRRORUPDOWN | DDFXCAPS_BLTROTATION90 \
|
|
|
|
|
| DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKXN \
|
|
|
|
|
| DDFXCAPS_BLTSHRINKY | DDFXCAPS_BLTSHRINKXN \
|
|
|
|
|
| DDFXCAPS_BLTSTRETCHX | DDFXCAPS_BLTSTRETCHXN \
|
|
|
|
|
| DDFXCAPS_BLTSTRETCHY | DDFXCAPS_BLTSTRETCHYN)
|
|
|
|
|
This->caps.dwCaps |= DDCAPS_GDI | DDCAPS_PALETTE | BLIT_CAPS;
|
|
|
|
|
|
|
|
|
|
This->caps.dwCaps2 |= DDCAPS2_CERTIFIED | DDCAPS2_NOPAGELOCKREQUIRED |
|
|
|
|
|
DDCAPS2_PRIMARYGAMMA | DDCAPS2_WIDESURFACES |
|
|
|
|
|
DDCAPS2_CANRENDERWINDOWED;
|
|
|
|
|
This->caps.dwCKeyCaps |= CKEY_CAPS;
|
|
|
|
|
This->caps.dwFXCaps |= FX_CAPS;
|
|
|
|
|
This->caps.dwPalCaps |= DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE;
|
|
|
|
|
This->caps.dwVidMemTotal = This->total_vidmem;
|
|
|
|
|
This->caps.dwVidMemFree = This->total_vidmem;
|
|
|
|
|
This->caps.dwSVBCaps |= BLIT_CAPS;
|
|
|
|
|
This->caps.dwSVBCKeyCaps |= CKEY_CAPS;
|
|
|
|
|
This->caps.dwSVBFXCaps |= FX_CAPS;
|
|
|
|
|
This->caps.dwVSBCaps |= BLIT_CAPS;
|
|
|
|
|
This->caps.dwVSBCKeyCaps |= CKEY_CAPS;
|
|
|
|
|
This->caps.dwVSBFXCaps |= FX_CAPS;
|
|
|
|
|
This->caps.dwSSBCaps |= BLIT_CAPS;
|
|
|
|
|
This->caps.dwSSBCKeyCaps |= CKEY_CAPS;
|
|
|
|
|
This->caps.dwSSBFXCaps |= FX_CAPS;
|
|
|
|
|
This->caps.ddsCaps.dwCaps |= DDSCAPS_ALPHA | DDSCAPS_BACKBUFFER |
|
|
|
|
|
DDSCAPS_FLIP | DDSCAPS_FRONTBUFFER |
|
|
|
|
|
DDSCAPS_OFFSCREENPLAIN | DDSCAPS_PALETTE |
|
|
|
|
|
DDSCAPS_PRIMARYSURFACE | DDSCAPS_SYSTEMMEMORY |
|
|
|
|
|
DDSCAPS_VIDEOMEMORY | DDSCAPS_VISIBLE;
|
|
|
|
|
/* Hacks for D3D code */
|
|
|
|
|
/* TODO: Check if WineD3D has 3D enabled
|
|
|
|
|
Need opengl surfaces or auto for 3D
|
|
|
|
|
*/
|
|
|
|
|
if(This->ImplType == 0 || This->ImplType == SURFACE_OPENGL)
|
|
|
|
|
{
|
|
|
|
|
This->caps.dwCaps |= DDCAPS_3D;
|
|
|
|
|
This->caps.ddsCaps.dwCaps |= DDSCAPS_3DDEVICE | DDSCAPS_MIPMAP | DDSCAPS_TEXTURE | DDSCAPS_ZBUFFER;
|
|
|
|
|
}
|
|
|
|
|
This->caps.ddsOldCaps.dwCaps = This->caps.ddsCaps.dwCaps;
|
|
|
|
|
|
|
|
|
|
#undef BLIT_CAPS
|
|
|
|
|
#undef CKEY_CAPS
|
|
|
|
|
#undef FX_CAPS
|
|
|
|
|
|
2006-10-14 21:57:09 +02:00
|
|
|
|
list_init(&This->surface_list);
|
|
|
|
|
|
2006-10-09 15:18:11 +02:00
|
|
|
|
EnterCriticalSection(&ddraw_list_cs);
|
2006-10-09 14:40:30 +02:00
|
|
|
|
list_add_head(&global_ddraw_list, &This->ddraw_list_entry);
|
2006-10-09 15:18:11 +02:00
|
|
|
|
LeaveCriticalSection(&ddraw_list_cs);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
2006-07-10 16:06:33 +02:00
|
|
|
|
/* Call QueryInterface to get the pointer to the requested interface. This also initializes
|
|
|
|
|
* The required refcount
|
|
|
|
|
*/
|
2006-06-09 19:36:12 +02:00
|
|
|
|
hr = IDirectDraw7_QueryInterface( ICOM_INTERFACE(This, IDirectDraw7), iid, DD);
|
|
|
|
|
if(SUCCEEDED(hr)) return DD_OK;
|
|
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
|
/* Let's hope we never need this ;) */
|
|
|
|
|
if(wineD3DDevice) IWineD3DDevice_Release(wineD3DDevice);
|
|
|
|
|
if(wineD3D) IWineD3D_Release(wineD3D);
|
2006-08-09 22:34:56 +02:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
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
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
|
DirectDrawCreate(GUID *GUID,
|
|
|
|
|
IDirectDraw **DD,
|
|
|
|
|
IUnknown *UnkOuter)
|
2000-04-09 16:30:50 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE("(%s,%p,%p)\n", debugstr_guid(GUID), DD, UnkOuter);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
return DDRAW_Create(GUID, (void **) DD, UnkOuter, &IID_IDirectDraw);
|
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
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
|
DirectDrawCreateEx(GUID *GUID,
|
|
|
|
|
void **DD,
|
|
|
|
|
REFIID iid,
|
|
|
|
|
IUnknown *UnkOuter)
|
2000-04-09 16:30:50 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE("(%s,%p,%s,%p)\n", 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
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
return DDRAW_Create(GUID, DD, UnkOuter, iid);
|
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
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
|
DirectDrawEnumerateA(LPDDENUMCALLBACKA Callback,
|
|
|
|
|
void *Context)
|
2000-04-09 16:30:50 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
BOOL stop = FALSE;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE(" Enumerating default DirectDraw HAL interface\n");
|
|
|
|
|
/* We only have one driver */
|
|
|
|
|
__TRY
|
2001-01-04 23:44:55 +01:00
|
|
|
|
{
|
2006-08-18 20:06:07 +02:00
|
|
|
|
static CHAR driver_desc[] = "DirectDraw HAL",
|
|
|
|
|
driver_name[] = "display";
|
|
|
|
|
|
|
|
|
|
stop = !Callback(NULL, driver_desc, driver_name, Context);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
__EXCEPT_PAGE_FAULT
|
2001-01-04 23:44:55 +01:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
return E_INVALIDARG;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
__ENDTRY
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE(" End of enumeration\n");
|
|
|
|
|
return DD_OK;
|
|
|
|
|
}
|
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.
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
HRESULT WINAPI
|
|
|
|
|
DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA Callback,
|
|
|
|
|
void *Context,
|
|
|
|
|
DWORD Flags)
|
|
|
|
|
{
|
|
|
|
|
BOOL stop = FALSE;
|
|
|
|
|
TRACE("Enumerating default DirectDraw HAL interface\n");
|
2003-01-13 19:30:47 +01:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* We only have one driver by now */
|
|
|
|
|
__TRY
|
2001-01-04 23:44:55 +01:00
|
|
|
|
{
|
2006-08-18 20:06:07 +02:00
|
|
|
|
static CHAR driver_desc[] = "DirectDraw HAL",
|
|
|
|
|
driver_name[] = "display";
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
/* QuickTime expects the description "DirectDraw HAL" */
|
2006-08-18 20:06:07 +02:00
|
|
|
|
stop = !Callback(NULL, driver_desc, driver_name, Context, 0);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
__EXCEPT_PAGE_FAULT
|
|
|
|
|
{
|
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
}
|
|
|
|
|
__ENDTRY;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
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
|
|
|
|
*
|
2006-06-09 19:36:12 +02:00
|
|
|
|
* Enumerates legacy drivers, unicode version. See
|
|
|
|
|
* the comments above DirectDrawEnumerateA for more details.
|
|
|
|
|
*
|
|
|
|
|
* The Flag member is not supported right now.
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
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
|
|
|
|
*
|
2006-06-09 19:36:12 +02:00
|
|
|
|
* Enumerates DirectDraw7 drivers, unicode version. See
|
|
|
|
|
* the comments above DirectDrawEnumerateA for more details.
|
|
|
|
|
*
|
|
|
|
|
* The Flag member is not supported right now.
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
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;
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE("(%p,%s,%p)\n", UnkOuter, debugstr_guid(iid), obj);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
hr = DDRAW_Create(NULL, obj, UnkOuter, iid);
|
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;
|
|
|
|
|
|
|
|
|
|
hr = DirectDrawCreateClipper(0, &Clip, UnkOuter);
|
|
|
|
|
if (hr != DD_OK) 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);
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************/
|
2002-06-01 01:06:46 +02:00
|
|
|
|
static HRESULT WINAPI
|
2006-06-09 19:36:12 +02:00
|
|
|
|
IDirectDrawClassFactoryImpl_QueryInterface(IClassFactory *iface,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
void **obj)
|
2001-01-04 23:44:55 +01:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_THIS_FROM(IClassFactoryImpl, IClassFactory, iface);
|
|
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obj);
|
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);
|
|
|
|
|
*obj = This;
|
|
|
|
|
return S_OK;
|
2001-01-04 23:44:55 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),obj);
|
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
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
IDirectDrawClassFactoryImpl_AddRef(IClassFactory *iface)
|
2004-09-28 21:19:27 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_THIS_FROM(IClassFactoryImpl, IClassFactory, iface);
|
2005-01-09 18:29:21 +01:00
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2003-01-13 19:30:47 +01:00
|
|
|
|
|
2006-10-10 19:23:27 +02:00
|
|
|
|
TRACE("(%p)->() incrementing from %d.\n", This, ref - 1);
|
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
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
static ULONG WINAPI
|
|
|
|
|
IDirectDrawClassFactoryImpl_Release(IClassFactory *iface)
|
2004-09-28 21:19:27 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_THIS_FROM(IClassFactoryImpl, IClassFactory, iface);
|
2004-09-28 21:19:27 +02:00
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2006-10-10 19:23:27 +02:00
|
|
|
|
TRACE("(%p)->() decrementing from %d.\n", This, ref+1);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
2004-09-28 21:19:27 +02:00
|
|
|
|
if (ref == 0)
|
2006-06-09 19:36:12 +02:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
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
|
|
|
|
|
* The ususal things???
|
|
|
|
|
*
|
|
|
|
|
* RETURNS
|
|
|
|
|
* ???
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirectDrawClassFactoryImpl_CreateInstance(IClassFactory *iface,
|
|
|
|
|
IUnknown *UnkOuter,
|
|
|
|
|
REFIID riid,
|
|
|
|
|
void **obj)
|
2004-09-28 21:19:27 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_THIS_FROM(IClassFactoryImpl, IClassFactory, iface);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
TRACE("(%p)->(%p,%s,%p)\n",This,UnkOuter,debugstr_guid(riid),obj);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
return This->pfnCreateInstance(UnkOuter, riid, obj);
|
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
|
|
|
|
|
*
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
static HRESULT WINAPI
|
|
|
|
|
IDirectDrawClassFactoryImpl_LockServer(IClassFactory *iface,BOOL dolock)
|
2004-09-28 21:19:27 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_THIS_FROM(IClassFactoryImpl, IClassFactory, iface);
|
2000-04-09 16:30:50 +02:00
|
|
|
|
FIXME("(%p)->(%d),stub!\n",This,dolock);
|
|
|
|
|
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
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
IDirectDrawClassFactoryImpl_QueryInterface,
|
|
|
|
|
IDirectDrawClassFactoryImpl_AddRef,
|
|
|
|
|
IDirectDrawClassFactoryImpl_Release,
|
|
|
|
|
IDirectDrawClassFactoryImpl_CreateInstance,
|
|
|
|
|
IDirectDrawClassFactoryImpl_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
|
|
|
|
{
|
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
|
|
|
|
|
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;
|
|
|
|
|
|
2006-06-09 19:36:12 +02:00
|
|
|
|
ICOM_INIT_INTERFACE(factory, IClassFactory, IClassFactory_Vtbl);
|
2001-01-04 23:44:55 +01:00
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
IDirectDrawSurfaceImpl *Impl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, surf);
|
|
|
|
|
IDirectDrawImpl *ddraw = (IDirectDrawImpl *) context;
|
|
|
|
|
ULONG ref;
|
|
|
|
|
|
|
|
|
|
ref = IDirectDrawSurface7_Release(surf); /* For the EnumSurfaces */
|
2006-10-10 19:23:27 +02:00
|
|
|
|
WARN("Surface %p has an reference count of %d\n", Impl, ref);
|
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
|
|
|
|
|
*/
|
|
|
|
|
if( (Impl->first_complex != Impl) || (Impl->first_attached != Impl) )
|
|
|
|
|
return DDENUMRET_OK;
|
|
|
|
|
/* Skip our depth stencil surface, it will be released with the render target */
|
|
|
|
|
if( Impl == ddraw->DepthStencilBuffer)
|
|
|
|
|
return DDENUMRET_OK;
|
|
|
|
|
|
|
|
|
|
/* Destroy the surface */
|
|
|
|
|
while(ref) ref = IDirectDrawSurface7_Release(surf);
|
|
|
|
|
|
|
|
|
|
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, ...)
|
|
|
|
|
*
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
BOOL WINAPI
|
|
|
|
|
DllMain(HINSTANCE hInstDLL,
|
|
|
|
|
DWORD Reason,
|
|
|
|
|
void *lpv)
|
|
|
|
|
{
|
2006-10-10 19:23:27 +02:00
|
|
|
|
TRACE("(%p,%x,%p)\n", hInstDLL, Reason, lpv);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
if (Reason == DLL_PROCESS_ATTACH)
|
2002-09-25 02:29:56 +02:00
|
|
|
|
{
|
2006-06-09 19:36:12 +02:00
|
|
|
|
char buffer[MAX_PATH+10];
|
|
|
|
|
DWORD size = sizeof(buffer);
|
|
|
|
|
HKEY hkey = 0;
|
|
|
|
|
HKEY appkey = 0;
|
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\Direct3D */
|
|
|
|
|
if ( RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\Direct3D", &hkey ) ) hkey = 0;
|
|
|
|
|
|
|
|
|
|
len = GetModuleFileNameA( 0, buffer, MAX_PATH );
|
|
|
|
|
if (len && len < MAX_PATH)
|
|
|
|
|
{
|
|
|
|
|
HKEY tmpkey;
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\Direct3D */
|
|
|
|
|
if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
|
|
|
|
{
|
|
|
|
|
char *p, *appname = buffer;
|
|
|
|
|
if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
|
|
|
|
if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
|
|
|
|
strcat( appname, "\\Direct3D" );
|
|
|
|
|
TRACE("appname = [%s]\n", appname);
|
|
|
|
|
if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
|
|
|
|
RegCloseKey( tmpkey );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( 0 != hkey || 0 != appkey )
|
|
|
|
|
{
|
|
|
|
|
if ( !get_config_key( hkey, appkey, "DirectDrawRenderer", buffer, size) )
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(buffer,"gdi"))
|
|
|
|
|
{
|
|
|
|
|
TRACE("Defaulting to GDI surfaces\n");
|
|
|
|
|
DefaultSurfaceType = SURFACE_GDI;
|
|
|
|
|
}
|
|
|
|
|
else if (!strcmp(buffer,"opengl"))
|
|
|
|
|
{
|
|
|
|
|
TRACE("Defaulting to opengl surfaces\n");
|
|
|
|
|
DefaultSurfaceType = SURFACE_OPENGL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2006-10-05 11:11:03 +02:00
|
|
|
|
ERR("Unknown default surface type. Supported are:\n gdi, opengl\n");
|
2006-06-09 19:36:12 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-06-30 22:53:48 +02:00
|
|
|
|
|
|
|
|
|
DisableThreadLibraryCalls(hInstDLL);
|
2006-06-09 19:36:12 +02:00
|
|
|
|
}
|
|
|
|
|
else if (Reason == 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");
|
|
|
|
|
|
|
|
|
|
/* We remove elemets from this loop */
|
|
|
|
|
LIST_FOR_EACH_SAFE(entry, entry2, &global_ddraw_list)
|
2006-06-09 19:36:12 +02:00
|
|
|
|
{
|
2006-10-09 15:29:05 +02:00
|
|
|
|
HRESULT hr;
|
|
|
|
|
DDSURFACEDESC2 desc;
|
|
|
|
|
int i;
|
|
|
|
|
IDirectDrawImpl *ddraw = LIST_ENTRY(entry, IDirectDrawImpl, ddraw_list_entry);
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/* Add references to each interface to avoid freeing them unexpectadely */
|
|
|
|
|
IDirectDraw_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw));
|
|
|
|
|
IDirectDraw2_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw2));
|
2006-12-15 17:15:28 +01:00
|
|
|
|
IDirectDraw3_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw3));
|
2006-10-09 15:29:05 +02:00
|
|
|
|
IDirectDraw4_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw4));
|
|
|
|
|
IDirectDraw7_AddRef(ICOM_INTERFACE(ddraw, IDirectDraw7));
|
|
|
|
|
|
|
|
|
|
/* Does a D3D device exist? Destroy it
|
|
|
|
|
* TODO: Destroy all Vertex buffers, Lights, Materials
|
|
|
|
|
* and execture buffers too
|
|
|
|
|
*/
|
|
|
|
|
if(ddraw->d3ddevice)
|
|
|
|
|
{
|
|
|
|
|
WARN("DDraw %p has d3ddevice %p attached\n", ddraw, ddraw->d3ddevice);
|
|
|
|
|
while(IDirect3DDevice7_Release(ICOM_INTERFACE(ddraw->d3ddevice, IDirect3DDevice7)));
|
|
|
|
|
}
|
2006-06-09 19:36:12 +02:00
|
|
|
|
|
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
|
|
|
|
{
|
2006-10-09 15:29:05 +02:00
|
|
|
|
hr = IDirectDraw7_EnumSurfaces(ICOM_INTERFACE(ddraw, IDirectDraw7),
|
|
|
|
|
DDENUMSURFACES_ALL,
|
|
|
|
|
&desc,
|
|
|
|
|
(void *) ddraw,
|
|
|
|
|
DestroyCallback);
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
/* Check the surface count */
|
|
|
|
|
if(ddraw->surfaces > 0)
|
2006-10-10 19:23:27 +02:00
|
|
|
|
ERR("DDraw %p still has %d surfaces attached\n", ddraw, ddraw->surfaces);
|
2006-10-09 15:29:05 +02:00
|
|
|
|
|
|
|
|
|
/* Release all hanging references to destroy the objects. This
|
|
|
|
|
* restores the screen mode too
|
|
|
|
|
*/
|
|
|
|
|
while(IDirectDraw_Release(ICOM_INTERFACE(ddraw, IDirectDraw)));
|
|
|
|
|
while(IDirectDraw2_Release(ICOM_INTERFACE(ddraw, IDirectDraw2)));
|
2006-12-15 17:15:28 +01:00
|
|
|
|
while(IDirectDraw3_Release(ICOM_INTERFACE(ddraw, IDirectDraw3)));
|
2006-10-09 15:29:05 +02:00
|
|
|
|
while(IDirectDraw4_Release(ICOM_INTERFACE(ddraw, IDirectDraw4)));
|
|
|
|
|
while(IDirectDraw7_Release(ICOM_INTERFACE(ddraw, IDirectDraw7)));
|
2006-06-09 19:36:12 +02:00
|
|
|
|
}
|
2002-09-25 02:29:56 +02:00
|
|
|
|
}
|
2006-03-21 15:06:36 +01:00
|
|
|
|
}
|
2001-01-04 23:44:55 +01:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2006-10-09 14:40:30 +02:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
remove_ddraw_object(IDirectDrawImpl *ddraw)
|
|
|
|
|
{
|
2006-10-09 15:18:11 +02:00
|
|
|
|
EnterCriticalSection(&ddraw_list_cs);
|
2006-10-09 14:40:30 +02:00
|
|
|
|
list_remove(&ddraw->ddraw_list_entry);
|
2006-10-09 15:18:11 +02:00
|
|
|
|
LeaveCriticalSection(&ddraw_list_cs);
|
2006-10-09 14:40:30 +02:00
|
|
|
|
}
|