diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 57efb35f975..0856d8f5763 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -196,9 +196,6 @@ struct IDirect3D9Impl IWineD3D *WineD3D; /* IDirect3D9 fields */ - /* - GL_Info gl_info; - */ }; /* IUnknown: */ @@ -242,7 +239,9 @@ struct IDirect3DDevice9Impl /* IDirect3DDevice9 fields */ IDirect3D9Impl *direct3d; + IWineD3DDevice *WineD3DDevice; + /* FIXME: To be sorted out during move */ IDirect3DSurface9Impl *frontBuffer; IDirect3DSurface9Impl *backBuffer; IDirect3DSurface9Impl *depthStencilBuffer; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index 2d2cddd6cd2..f93631b9ada 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -67,6 +67,7 @@ ULONG WINAPI IDirect3DDevice9Impl_Release(LPDIRECT3DDEVICE9 iface) { ULONG ref = --This->ref; TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref); if (ref == 0) { + IDirect3D9_Release((LPDIRECT3D9) This->direct3d); HeapFree(GetProcessHeap(), 0, This); } return ref; diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c index 4bcea3f34a6..516cdc16ebb 100644 --- a/dlls/d3d9/directx.c +++ b/dlls/d3d9/directx.c @@ -168,8 +168,35 @@ HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) { - IDirect3D9Impl *This = (IDirect3D9Impl *)iface; - FIXME("(%p) : stub\n", This); + IDirect3D9Impl *This = (IDirect3D9Impl *)iface; + IDirect3DDevice9Impl *object = NULL; + WINED3DPRESENT_PARAMETERS localParameters; + + TRACE("(%p)->(Adptr:%d, DevType: %x, FocusHwnd: %p, BehFlags: %lx, PresParms: %p, RetDevInt: %p)\n", This, Adapter, DeviceType, + hFocusWindow, BehaviourFlags, pPresentationParameters, ppReturnedDeviceInterface); + + /* Check the validity range of the adapter parameter */ + if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) { + return D3DERR_INVALIDCALL; + } + + /* Allocate the storage for the device object */ + object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl)); + if (NULL == object) { + return D3DERR_OUTOFVIDEOMEMORY; + } + object->lpVtbl = &Direct3DDevice9_Vtbl; + object->ref = 1; + object->direct3d = This; + IDirect3D9_AddRef((LPDIRECT3D9) object->direct3d); + *ppReturnedDeviceInterface = (IDirect3DDevice9 *)object; + + /* Allocate an associated WineD3DDevice object */ + memcpy(&localParameters, pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS)); + IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &localParameters, &object->WineD3DDevice); + memcpy(pPresentationParameters, &localParameters, sizeof(D3DPRESENT_PARAMETERS)); + + FIXME("(%p) : incomplete stub\n", This); return D3D_OK; } diff --git a/dlls/wined3d/Makefile.in b/dlls/wined3d/Makefile.in index 62d081700b6..352b2aa4a45 100644 --- a/dlls/wined3d/Makefile.in +++ b/dlls/wined3d/Makefile.in @@ -8,6 +8,7 @@ EXTRAINCL = @X_CFLAGS@ EXTRALIBS = -ldxguid -luuid @X_LIBS@ @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@ @OPENGL_LIBS@ C_SRCS = \ + device.c \ directx.c \ utils.c \ vertexshader.c \ diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c new file mode 100644 index 00000000000..7055f898a9b --- /dev/null +++ b/dlls/wined3d/device.c @@ -0,0 +1,75 @@ +/* + * IWineD3DDevice implementation + * + * Copyright 2002-2004 Jason Edmeades + * Copyright 2003-2004 Raphael Junqueira + * Copyright 2004 Christian Costa + * + * 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 + */ + +#include "config.h" +#include "wined3d_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(d3d); +WINE_DECLARE_DEBUG_CHANNEL(d3d_caps); + +/********************************************************** + * Utility functions follow + **********************************************************/ + + +/********************************************************** + * IWineD3DDevice implementation follows + **********************************************************/ + + +/********************************************************** + * IUnknown parts follows + **********************************************************/ + +HRESULT WINAPI IWineD3DDeviceImpl_QueryInterface(IWineD3DDevice *iface,REFIID riid,LPVOID *ppobj) +{ + return E_NOINTERFACE; +} + +ULONG WINAPI IWineD3DDeviceImpl_AddRef(IWineD3DDevice *iface) { + IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; + FIXME("(%p) : AddRef increasing from %ld\n", This, This->ref); + return InterlockedIncrement(&This->ref); +} + +ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) { + IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface; + ULONG ref; + TRACE("(%p) : Releasing from %ld\n", This, This->ref); + ref = InterlockedDecrement(&This->ref); + if (ref == 0) { + IWineD3D_Release(This->WineD3D); + HeapFree(GetProcessHeap(), 0, This); + } + return ref; +} + +/********************************************************** + * IWineD3DDevice VTbl follows + **********************************************************/ + +IWineD3DDeviceVtbl IWineD3DDevice_Vtbl = +{ + IWineD3DDeviceImpl_QueryInterface, + IWineD3DDeviceImpl_AddRef, + IWineD3DDeviceImpl_Release +}; diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 818b0727ff9..c7e72c146fd 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -1306,6 +1306,24 @@ HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, D3DDEVT return D3D_OK; } +/* Note due to structure differences between dx8 and dx9 D3DPRESENT_PARAMETERS, + and fields being inserted in the middle, a new structure is used in place */ +HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, + DWORD BehaviourFlags, WINED3DPRESENT_PARAMETERS* pPresentationParameters, + IWineD3DDevice** ppReturnedDeviceInterface) { + + /* Create a WineD3DDevice object */ + IWineD3DDeviceImpl* object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DDeviceImpl)); + object->lpVtbl = &IWineD3DDevice_Vtbl; + object->ref = 1; + object->WineD3D = iface; + IWineD3D_AddRef(object->WineD3D); + *ppReturnedDeviceInterface = (IWineD3DDevice *)object; + + TRACE("Created WineD3DDevice object @ %p \n", object); + return D3D_OK; +} + /********************************************************** * IUnknown parts follows **********************************************************/ @@ -1351,5 +1369,6 @@ IWineD3DVtbl IWineD3D_Vtbl = IWineD3DImpl_CheckDeviceType, IWineD3DImpl_CheckDeviceFormat, IWineD3DImpl_CheckDeviceFormatConversion, - IWineD3DImpl_GetDeviceCaps + IWineD3DImpl_GetDeviceCaps, + IWineD3DImpl_CreateDevice }; diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 6191541ec5f..6e5f384f5a8 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -94,6 +94,23 @@ typedef struct IWineD3DImpl extern IWineD3DVtbl IWineD3D_Vtbl; +/***************************************************************************** + * IWineD3DDevice implementation structure + */ +typedef struct IWineD3DDeviceImpl +{ + /* IUnknown fields */ + IWineD3DDeviceVtbl *lpVtbl; + DWORD ref; /* Note: Ref counting not required */ + + /* WineD3D Information */ + IWineD3D *WineD3D; + + /* GL Information */ +} IWineD3DDeviceImpl; + +extern IWineD3DDeviceVtbl IWineD3DDevice_Vtbl; + /* Utility function prototypes */ const char* debug_d3dformat(D3DFORMAT fmt); const char* debug_d3ddevicetype(D3DDEVTYPE devtype); diff --git a/include/wine/wined3d_interface.h b/include/wine/wined3d_interface.h index 420a2967dfc..633873fd5f4 100644 --- a/include/wine/wined3d_interface.h +++ b/include/wine/wined3d_interface.h @@ -53,12 +53,29 @@ typedef struct _WINED3DADAPTER_IDENTIFIER { DWORD *WHQLLevel; } WINED3DADAPTER_IDENTIFIER; +typedef struct _WINED3DPRESENT_PARAMETERS { + UINT BackBufferWidth; + UINT BackBufferHeight; + D3DFORMAT BackBufferFormat; + UINT BackBufferCount; + D3DMULTISAMPLE_TYPE MultiSampleType; + DWORD MultiSampleQuality; + D3DSWAPEFFECT SwapEffect; + HWND hDeviceWindow; + BOOL Windowed; + BOOL EnableAutoDepthStencil; + D3DFORMAT AutoDepthStencilFormat; + DWORD Flags; + UINT FullScreen_RefreshRateInHz; + UINT PresentationInterval; +} WINED3DPRESENT_PARAMETERS; +typedef struct IWineD3D IWineD3D; +typedef struct IWineD3DDevice IWineD3DDevice; /***************************************************************************** * WineD3D interface */ -typedef struct IWineD3D IWineD3D; #define INTERFACE IWineD3D DECLARE_INTERFACE_(IWineD3D,IUnknown) @@ -81,6 +98,7 @@ DECLARE_INTERFACE_(IWineD3D,IUnknown) STDMETHOD(CheckDeviceFormat)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) PURE; STDMETHOD(CheckDeviceFormatConversion)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) PURE; STDMETHOD(GetDeviceCaps)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType, void * pCaps) PURE; + STDMETHOD(CreateDevice)(THIS_ UINT Adapter, D3DDEVTYPE DeviceType,HWND hFocusWindow, DWORD BehaviorFlags, WINED3DPRESENT_PARAMETERS * pPresentationParameters, IWineD3DDevice ** ppReturnedDeviceInterface) PURE; }; #undef INTERFACE @@ -103,13 +121,33 @@ DECLARE_INTERFACE_(IWineD3D,IUnknown) #define IWineD3D_CheckDeviceFormat(p,a,b,c,d,e,f) (p)->lpVtbl->CheckDeviceFormat(p,a,b,c,d,e,f) #define IWineD3D_CheckDeviceFormatConversion(p,a,b,c,d) (p)->lpVtbl->CheckDeviceFormatConversion(p,a,b,c,d) #define IWineD3D_GetDeviceCaps(p,a,b,c) (p)->lpVtbl->GetDeviceCaps(p,a,b,c) +#define IWineD3D_CreateDevice(p,a,b,c,d,e,f) (p)->lpVtbl->CreateDevice(p,a,b,c,d,e,f) #endif /* Define the main WineD3D entrypoint */ IWineD3D* WINAPI WineDirect3DCreate(UINT SDKVersion, UINT dxVersion); +/***************************************************************************** + * WineD3DDevice interface + */ +#define INTERFACE IWineD3DDevice +DECLARE_INTERFACE_(IWineD3DDevice,IUnknown) +{ + /*** IUnknown methods ***/ + STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + /*** IWineD3D methods ***/ +}; +#undef INTERFACE - +#if !defined(__cplusplus) || defined(CINTERFACE) +/*** IUnknown methods ***/ +#define IWineD3D_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) +#define IWineD3D_AddRef(p) (p)->lpVtbl->AddRef(p) +#define IWineD3D_Release(p) (p)->lpVtbl->Release(p) +/*** IWineD3D methods ***/ +#endif #if 0 /* FIXME: During porting in from d3d8 - the following will be used */ /*****************************************************************