2003-07-01 03:09:17 +02:00
|
|
|
/*
|
|
|
|
* IDirect3D9 implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002 Jason Edmeades
|
2005-06-17 11:59:03 +02:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2003-07-01 03:09:17 +02: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
|
2003-07-01 03:09:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "d3d9_private.h"
|
|
|
|
|
2005-08-23 11:34:57 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
2003-07-01 03:09:17 +02:00
|
|
|
|
|
|
|
/* IDirect3D9 IUnknown parts follow: */
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppobj)
|
2003-07-01 03:09:17 +02:00
|
|
|
{
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2003-07-01 03:09:17 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDirect3D9)) {
|
2005-08-23 11:34:57 +02:00
|
|
|
IUnknown_AddRef(iface);
|
2003-07-01 03:09:17 +02:00
|
|
|
*ppobj = This;
|
2006-06-07 15:13:29 +02:00
|
|
|
return S_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
|
2006-06-07 15:13:29 +02:00
|
|
|
*ppobj = NULL;
|
2003-07-01 03:09:17 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9 iface) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2005-01-24 12:31:45 +01:00
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-10 19:23:22 +02:00
|
|
|
TRACE("(%p) : AddRef from %d\n", This, ref - 1);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
|
|
|
return ref;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9 iface) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2005-01-24 12:31:45 +01:00
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-10 19:23:22 +02:00
|
|
|
TRACE("(%p) : ReleaseRef to %d\n", This, ref);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2004-09-28 04:12:12 +02:00
|
|
|
if (ref == 0) {
|
2007-06-10 17:32:37 +02:00
|
|
|
EnterCriticalSection(&d3d9_cs);
|
2004-09-28 04:12:12 +02:00
|
|
|
IWineD3D_Release(This->WineD3D);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
2003-07-01 03:09:17 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2004-09-28 04:12:12 +02:00
|
|
|
}
|
|
|
|
|
2003-07-01 03:09:17 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDirect3D9 Interface follow: */
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface, void* pInitializeFunction) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%p)\n", This, pInitializeFunction);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_GetAdapterCount(This->WineD3D);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2004-09-29 23:26:47 +02:00
|
|
|
WINED3DADAPTER_IDENTIFIER adapter_id;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
2004-09-29 23:26:47 +02:00
|
|
|
|
|
|
|
/* dx8 and dx9 have different structures to be filled in, with incompatible
|
|
|
|
layouts so pass in pointers to the places to be filled via an internal
|
|
|
|
structure */
|
|
|
|
adapter_id.Driver = pIdentifier->Driver;
|
|
|
|
adapter_id.Description = pIdentifier->Description;
|
|
|
|
adapter_id.DeviceName = pIdentifier->DeviceName;
|
|
|
|
adapter_id.DriverVersion = &pIdentifier->DriverVersion;
|
|
|
|
adapter_id.VendorId = &pIdentifier->VendorId;
|
|
|
|
adapter_id.DeviceId = &pIdentifier->DeviceId;
|
|
|
|
adapter_id.SubSysId = &pIdentifier->SubSysId;
|
|
|
|
adapter_id.Revision = &pIdentifier->Revision;
|
|
|
|
adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
|
|
|
|
adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
|
|
|
|
|
2007-06-10 17:32:37 +02:00
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%d, %d\n", This, Adapter, Format);
|
2007-04-13 16:38:10 +02:00
|
|
|
|
|
|
|
/* Others than that not supported by d3d9, but reported by wined3d for ddraw. Filter them out */
|
2007-04-17 09:20:54 +02:00
|
|
|
if(Format != D3DFMT_X8R8G8B8 && Format != D3DFMT_R5G6B5) {
|
2007-04-13 16:38:10 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-06-10 17:32:37 +02:00
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, Format);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%d, %d, %d, %p)\n", This, Adapter, Format, Mode, pMode);
|
2007-04-13 16:38:10 +02:00
|
|
|
/* We can't pass this to WineD3D, otherwise it'll think it came from D3D8 or DDraw.
|
2006-12-20 13:44:08 +01:00
|
|
|
It's supposed to fail anyway, so no harm returning failure. */
|
2007-04-13 16:38:10 +02:00
|
|
|
if(Format != WINED3DFMT_X8R8G8B8 && Format != WINED3DFMT_R5G6B5)
|
2006-12-20 13:44:08 +01:00
|
|
|
return D3DERR_INVALIDCALL;
|
2007-06-10 17:32:37 +02:00
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, Format, Mode, (WINED3DDISPLAYMODE *) pMode);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2006-04-01 21:33:46 +02:00
|
|
|
return IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface,
|
2003-07-01 03:09:17 +02:00
|
|
|
UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
|
|
|
|
D3DFORMAT BackBufferFormat, BOOL Windowed) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("(%p)->(%d, %d, %d, %d, %s\n", This, Adapter, CheckType, DisplayFormat,
|
|
|
|
BackBufferFormat, Windowed ? "true" : "false");
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, DisplayFormat,
|
2004-10-05 04:14:06 +02:00
|
|
|
BackBufferFormat, Windowed);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface,
|
2003-07-01 03:09:17 +02:00
|
|
|
UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
|
|
|
|
DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, AdapterFormat,
|
2004-10-05 04:14:06 +02:00
|
|
|
Usage, RType, CheckFormat);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9 iface,
|
2003-07-01 03:09:17 +02:00
|
|
|
UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
|
|
|
|
BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType, SurfaceFormat,
|
2004-10-05 04:14:06 +02:00
|
|
|
Windowed, MultiSampleType, pQualityLevels);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9 iface,
|
2003-07-01 03:09:17 +02:00
|
|
|
UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
|
|
|
|
D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType, AdapterFormat,
|
2004-10-05 04:14:06 +02:00
|
|
|
RenderTargetFormat, DepthStencilFormat);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HRESULT hr;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType, SourceFormat,
|
2004-10-05 04:14:06 +02:00
|
|
|
TargetFormat);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2005-06-17 11:59:03 +02:00
|
|
|
HRESULT hrc = D3D_OK;
|
|
|
|
WINED3DCAPS *pWineCaps;
|
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("(%p) Relay %d %u %p\n", This, Adapter, DeviceType, pCaps);
|
2005-06-17 11:59:03 +02:00
|
|
|
|
|
|
|
if(NULL == pCaps){
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
|
|
|
|
if(pWineCaps == NULL){
|
|
|
|
return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
|
|
|
|
}
|
|
|
|
D3D9CAPSTOWINECAPS(pCaps, pWineCaps)
|
2007-06-10 17:32:37 +02:00
|
|
|
EnterCriticalSection(&d3d9_cs);
|
2005-06-17 11:59:03 +02:00
|
|
|
hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
2005-06-17 11:59:03 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, pWineCaps);
|
2007-01-12 00:08:29 +01:00
|
|
|
|
|
|
|
/* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
|
2007-01-12 23:13:58 +01:00
|
|
|
pCaps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
|
2005-06-17 11:59:03 +02:00
|
|
|
TRACE("(%p) returning %p\n", This, pCaps);
|
|
|
|
return hrc;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2006-06-10 11:51:05 +02:00
|
|
|
static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface, UINT Adapter) {
|
2004-09-08 03:50:37 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
2007-06-10 17:32:37 +02:00
|
|
|
HMONITOR ret;
|
|
|
|
TRACE("%p\n", This);
|
|
|
|
|
|
|
|
EnterCriticalSection(&d3d9_cs);
|
|
|
|
ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
|
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
|
|
|
return ret;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2005-01-09 18:37:02 +01:00
|
|
|
/* Internal function called back during the CreateDevice to create a render target */
|
2006-12-03 21:52:03 +01:00
|
|
|
HRESULT WINAPI D3D9CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
|
2006-03-24 17:34:26 +01:00
|
|
|
WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample,
|
2005-06-23 13:05:24 +02:00
|
|
|
DWORD MultisampleQuality, BOOL Lockable,
|
2005-01-09 18:37:02 +01:00
|
|
|
IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
|
|
|
|
HRESULT res = D3D_OK;
|
|
|
|
IDirect3DSurface9Impl *d3dSurface = NULL;
|
2005-06-23 13:05:24 +02:00
|
|
|
TRACE("(%p) call back\n", device);
|
2005-01-09 18:37:02 +01:00
|
|
|
res = IDirect3DDevice9_CreateRenderTarget((IDirect3DDevice9 *)device, Width, Height,
|
2005-06-23 13:05:24 +02:00
|
|
|
(D3DFORMAT)Format, MultiSample, MultisampleQuality, Lockable,
|
2005-01-09 18:37:02 +01:00
|
|
|
(IDirect3DSurface9 **)&d3dSurface, pSharedHandle);
|
2005-01-28 15:03:32 +01:00
|
|
|
|
|
|
|
if (SUCCEEDED(res)) {
|
2005-01-09 18:37:02 +01:00
|
|
|
*ppSurface = d3dSurface->wineD3DSurface;
|
2006-12-18 00:17:51 +01:00
|
|
|
d3dSurface->container = pSuperior;
|
2006-12-18 00:17:16 +01:00
|
|
|
d3dSurface->isImplicit = TRUE;
|
|
|
|
/* Implicit surfaces are created with an refcount of 0 */
|
|
|
|
IUnknown_Release((IUnknown *)d3dSurface);
|
2005-01-18 12:42:29 +01:00
|
|
|
} else {
|
|
|
|
*ppSurface = NULL;
|
2005-01-09 18:37:02 +01:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-12-18 00:17:16 +01:00
|
|
|
ULONG WINAPI D3D9CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
|
|
|
|
IDirect3DSurface9Impl* surfaceParent;
|
|
|
|
TRACE("(%p) call back\n", pSurface);
|
|
|
|
|
|
|
|
IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
|
|
|
|
surfaceParent->isImplicit = FALSE;
|
|
|
|
/* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
|
|
|
|
return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
|
|
|
|
}
|
|
|
|
|
2007-01-04 18:01:21 +01:00
|
|
|
static HRESULT WINAPI D3D9CB_CreateAdditionalSwapChain(IUnknown *device,
|
|
|
|
WINED3DPRESENT_PARAMETERS* pPresentationParameters,
|
|
|
|
IWineD3DSwapChain ** ppSwapChain) {
|
2005-06-23 13:05:24 +02:00
|
|
|
HRESULT res = D3D_OK;
|
|
|
|
IDirect3DSwapChain9Impl *d3dSwapChain = NULL;
|
|
|
|
D3DPRESENT_PARAMETERS localParameters;
|
|
|
|
TRACE("(%p) call back\n", device);
|
|
|
|
|
2007-02-15 22:36:50 +01:00
|
|
|
/* Copy the presentation parameters */
|
|
|
|
localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
|
|
|
|
localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
|
|
|
|
localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
|
|
|
|
localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
|
|
|
|
localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
|
|
|
|
localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
|
|
|
|
localParameters.SwapEffect = pPresentationParameters->SwapEffect;
|
|
|
|
localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
|
|
|
|
localParameters.Windowed = pPresentationParameters->Windowed;
|
|
|
|
localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
|
|
|
|
localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
|
|
|
|
localParameters.Flags = pPresentationParameters->Flags;
|
|
|
|
localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
|
|
|
|
localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
|
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
res = IDirect3DDevice9_CreateAdditionalSwapChain((IDirect3DDevice9 *)device, &localParameters, (IDirect3DSwapChain9 **)&d3dSwapChain);
|
|
|
|
|
2006-05-29 23:01:04 +02:00
|
|
|
if (SUCCEEDED(res)) {
|
2005-06-23 13:05:24 +02:00
|
|
|
*ppSwapChain = d3dSwapChain->wineD3DSwapChain;
|
2006-12-18 00:17:31 +01:00
|
|
|
d3dSwapChain->isImplicit = TRUE;
|
|
|
|
/* Implicit swap chains are created with an refcount of 0 */
|
|
|
|
IUnknown_Release((IUnknown *)d3dSwapChain);
|
2005-06-23 13:05:24 +02:00
|
|
|
} else {
|
|
|
|
*ppSwapChain = NULL;
|
|
|
|
}
|
2007-02-15 22:36:50 +01:00
|
|
|
|
|
|
|
/* Copy back the presentation parameters */
|
|
|
|
pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
|
|
|
|
pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
|
|
|
|
pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
|
|
|
|
pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
|
|
|
|
pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
|
|
|
|
pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
|
|
|
|
pPresentationParameters->SwapEffect = localParameters.SwapEffect;
|
|
|
|
pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
|
|
|
|
pPresentationParameters->Windowed = localParameters.Windowed;
|
|
|
|
pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
|
|
|
|
pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
|
|
|
|
pPresentationParameters->Flags = localParameters.Flags;
|
|
|
|
pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
|
|
|
|
pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
|
|
|
|
|
|
|
|
return res;
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
|
2006-12-18 00:17:24 +01:00
|
|
|
ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
|
2006-12-18 00:17:31 +01:00
|
|
|
IDirect3DSwapChain9Impl* swapChainParent;
|
2006-12-18 00:17:24 +01:00
|
|
|
TRACE("(%p) call back\n", pSwapChain);
|
|
|
|
|
2006-12-18 00:17:31 +01:00
|
|
|
IWineD3DSwapChain_GetParent(pSwapChain,(IUnknown **) &swapChainParent);
|
|
|
|
swapChainParent->isImplicit = FALSE;
|
|
|
|
/* Swap chain had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
|
|
|
|
return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
|
2006-12-18 00:17:24 +01:00
|
|
|
}
|
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
/* Internal function called back during the CreateDevice to create a render target */
|
2006-12-03 21:52:03 +01:00
|
|
|
HRESULT WINAPI D3D9CB_CreateDepthStencilSurface(IUnknown *device, IUnknown *pSuperior, UINT Width, UINT Height,
|
2006-03-24 17:34:26 +01:00
|
|
|
WINED3DFORMAT Format, WINED3DMULTISAMPLE_TYPE MultiSample,
|
2005-06-23 13:05:24 +02:00
|
|
|
DWORD MultisampleQuality, BOOL Discard,
|
|
|
|
IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
|
|
|
|
HRESULT res = D3D_OK;
|
|
|
|
IDirect3DSurface9Impl *d3dSurface = NULL;
|
|
|
|
TRACE("(%p) call back\n", device);
|
|
|
|
|
|
|
|
res = IDirect3DDevice9_CreateDepthStencilSurface((IDirect3DDevice9 *)device, Width, Height,
|
|
|
|
(D3DFORMAT)Format, MultiSample, MultisampleQuality, Discard,
|
|
|
|
(IDirect3DSurface9 **)&d3dSurface, pSharedHandle);
|
2006-05-29 23:01:04 +02:00
|
|
|
if (SUCCEEDED(res)) {
|
2005-06-23 13:05:24 +02:00
|
|
|
*ppSurface = d3dSurface->wineD3DSurface;
|
2006-12-18 00:17:51 +01:00
|
|
|
d3dSurface->container = device;
|
2006-12-18 00:17:16 +01:00
|
|
|
d3dSurface->isImplicit = TRUE;
|
|
|
|
/* Implicit surfaces are created with an refcount of 0 */
|
|
|
|
IUnknown_Release((IUnknown *)d3dSurface);
|
2005-06-23 13:05:24 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-12-05 00:29:31 +01:00
|
|
|
ULONG WINAPI D3D9CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
|
|
|
|
IDirect3DSurface9Impl* surfaceParent;
|
|
|
|
TRACE("(%p) call back\n", pSurface);
|
|
|
|
|
|
|
|
IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
|
2006-12-18 00:17:16 +01:00
|
|
|
surfaceParent->isImplicit = FALSE;
|
|
|
|
/* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
|
2006-12-05 00:29:31 +01:00
|
|
|
return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
|
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2007-01-04 18:01:21 +01:00
|
|
|
static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,
|
|
|
|
HWND hFocusWindow, DWORD BehaviourFlags,
|
|
|
|
D3DPRESENT_PARAMETERS* pPresentationParameters,
|
|
|
|
IDirect3DDevice9** ppReturnedDeviceInterface) {
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2004-10-07 06:22:21 +02:00
|
|
|
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
|
|
|
IDirect3DDevice9Impl *object = NULL;
|
|
|
|
WINED3DPRESENT_PARAMETERS localParameters;
|
2005-06-23 13:05:24 +02:00
|
|
|
HRESULT hr;
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("(%p) Relay\n", This);
|
2004-10-07 06:22:21 +02:00
|
|
|
|
|
|
|
/* Check the validity range of the adapter parameter */
|
|
|
|
if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
|
2005-01-18 12:42:29 +01:00
|
|
|
*ppReturnedDeviceInterface = NULL;
|
2004-10-07 06:22:21 +02:00
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate the storage for the device object */
|
|
|
|
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
|
|
|
|
if (NULL == object) {
|
2005-01-18 12:42:29 +01:00
|
|
|
FIXME("Allocation of memory failed\n");
|
|
|
|
*ppReturnedDeviceInterface = NULL;
|
2004-10-08 22:52:33 +02:00
|
|
|
return D3DERR_OUTOFVIDEOMEMORY;
|
2004-10-07 06:22:21 +02:00
|
|
|
}
|
2005-01-18 12:42:29 +01:00
|
|
|
|
2004-10-07 06:22:21 +02:00
|
|
|
object->lpVtbl = &Direct3DDevice9_Vtbl;
|
|
|
|
object->ref = 1;
|
|
|
|
*ppReturnedDeviceInterface = (IDirect3DDevice9 *)object;
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2004-10-07 06:22:21 +02:00
|
|
|
/* Allocate an associated WineD3DDevice object */
|
2007-06-10 17:32:37 +02:00
|
|
|
EnterCriticalSection(&d3d9_cs);
|
2006-04-18 22:38:30 +02:00
|
|
|
hr =IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &object->WineD3DDevice, (IUnknown *)object);
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2006-04-12 21:08:57 +02:00
|
|
|
if (hr != D3D_OK) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
*ppReturnedDeviceInterface = NULL;
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
2006-04-12 21:08:57 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2005-06-23 13:05:24 +02:00
|
|
|
|
2006-04-12 21:08:57 +02:00
|
|
|
TRACE("(%p) : Created Device %p\n", This, object);
|
|
|
|
|
2007-02-15 22:36:50 +01:00
|
|
|
localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
|
|
|
|
localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
|
|
|
|
localParameters.BackBufferFormat = pPresentationParameters->BackBufferFormat;
|
|
|
|
localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
|
|
|
|
localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
|
|
|
|
localParameters.MultiSampleQuality = pPresentationParameters->MultiSampleQuality;
|
|
|
|
localParameters.SwapEffect = pPresentationParameters->SwapEffect;
|
|
|
|
localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
|
|
|
|
localParameters.Windowed = pPresentationParameters->Windowed;
|
|
|
|
localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
|
|
|
|
localParameters.AutoDepthStencilFormat = pPresentationParameters->AutoDepthStencilFormat;
|
|
|
|
localParameters.Flags = pPresentationParameters->Flags;
|
|
|
|
localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
|
|
|
|
localParameters.PresentationInterval = pPresentationParameters->PresentationInterval;
|
|
|
|
|
2007-03-04 17:03:03 +01:00
|
|
|
if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
|
|
|
|
IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
|
|
|
|
}
|
|
|
|
|
2006-04-18 22:38:30 +02:00
|
|
|
hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters, D3D9CB_CreateAdditionalSwapChain);
|
2007-02-15 22:36:50 +01:00
|
|
|
|
|
|
|
pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth;
|
|
|
|
pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight;
|
|
|
|
pPresentationParameters->BackBufferFormat = localParameters.BackBufferFormat;
|
|
|
|
pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
|
|
|
|
pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
|
|
|
|
pPresentationParameters->MultiSampleQuality = localParameters.MultiSampleQuality;
|
|
|
|
pPresentationParameters->SwapEffect = localParameters.SwapEffect;
|
|
|
|
pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
|
|
|
|
pPresentationParameters->Windowed = localParameters.Windowed;
|
|
|
|
pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
|
|
|
|
pPresentationParameters->AutoDepthStencilFormat = localParameters.AutoDepthStencilFormat;
|
|
|
|
pPresentationParameters->Flags = localParameters.Flags;
|
|
|
|
pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
|
|
|
|
pPresentationParameters->PresentationInterval = localParameters.PresentationInterval;
|
|
|
|
|
2006-04-12 21:08:57 +02:00
|
|
|
if (hr != D3D_OK) {
|
|
|
|
FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
|
2005-06-23 13:05:24 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
*ppReturnedDeviceInterface = NULL;
|
|
|
|
}
|
2007-03-04 17:03:03 +01:00
|
|
|
|
2007-04-17 20:04:26 +02:00
|
|
|
/* Initialize the converted declaration array. This creates a valid pointer and when adding decls HeapReAlloc
|
|
|
|
* can be used without further checking
|
|
|
|
*/
|
|
|
|
object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
|
2007-06-10 17:32:37 +02:00
|
|
|
LeaveCriticalSection(&d3d9_cs);
|
2007-04-17 20:04:26 +02:00
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2005-06-23 13:05:24 +02:00
|
|
|
|
|
|
|
|
2005-05-27 22:17:35 +02:00
|
|
|
const IDirect3D9Vtbl Direct3D9_Vtbl =
|
2003-07-01 03:09:17 +02:00
|
|
|
{
|
2005-08-23 11:34:57 +02:00
|
|
|
/* IUnknown */
|
2003-07-01 03:09:17 +02:00
|
|
|
IDirect3D9Impl_QueryInterface,
|
|
|
|
IDirect3D9Impl_AddRef,
|
|
|
|
IDirect3D9Impl_Release,
|
2005-08-23 11:34:57 +02:00
|
|
|
/* IDirect3D9 */
|
2003-07-01 03:09:17 +02:00
|
|
|
IDirect3D9Impl_RegisterSoftwareDevice,
|
|
|
|
IDirect3D9Impl_GetAdapterCount,
|
|
|
|
IDirect3D9Impl_GetAdapterIdentifier,
|
|
|
|
IDirect3D9Impl_GetAdapterModeCount,
|
|
|
|
IDirect3D9Impl_EnumAdapterModes,
|
|
|
|
IDirect3D9Impl_GetAdapterDisplayMode,
|
|
|
|
IDirect3D9Impl_CheckDeviceType,
|
|
|
|
IDirect3D9Impl_CheckDeviceFormat,
|
|
|
|
IDirect3D9Impl_CheckDeviceMultiSampleType,
|
|
|
|
IDirect3D9Impl_CheckDepthStencilMatch,
|
|
|
|
IDirect3D9Impl_CheckDeviceFormatConversion,
|
|
|
|
IDirect3D9Impl_GetDeviceCaps,
|
|
|
|
IDirect3D9Impl_GetAdapterMonitor,
|
|
|
|
IDirect3D9Impl_CreateDevice
|
|
|
|
};
|