Move the Check* type functions into wined3d and copy from d3d9, and
[wine] / dlls / d3d9 / directx.c
1 /*
2  * IDirect3D9 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "wingdi.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "d3d9_private.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
37
38 /* IDirect3D9 IUnknown parts follow: */
39 HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppobj)
40 {
41     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
42
43     if (IsEqualGUID(riid, &IID_IUnknown)
44         || IsEqualGUID(riid, &IID_IDirect3D9)) {
45         IDirect3D9Impl_AddRef(iface);
46         *ppobj = This;
47         return D3D_OK;
48     }
49
50     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
51     return E_NOINTERFACE;
52 }
53
54 ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9 iface) {
55     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
56     TRACE("(%p) : AddRef from %ld\n", This, This->ref);
57     return ++(This->ref);
58 }
59
60 ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9 iface) {
61     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
62     ULONG ref = --This->ref;
63     TRACE("(%p) : ReleaseRef to %ld\n", This, This->ref);
64     if (ref == 0) {
65         IWineD3D_Release(This->WineD3D);
66         HeapFree(GetProcessHeap(), 0, This);
67     }
68
69     return ref;
70 }
71
72 /* IDirect3D9 Interface follow: */
73 HRESULT  WINAPI  IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface, void* pInitializeFunction) {
74     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
75     return IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
76 }
77
78 UINT     WINAPI  IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) {
79     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
80     return IWineD3D_GetAdapterCount(This->WineD3D);
81 }
82
83 HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
84     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
85     WINED3DADAPTER_IDENTIFIER adapter_id;
86
87     /* dx8 and dx9 have different structures to be filled in, with incompatible 
88        layouts so pass in pointers to the places to be filled via an internal 
89        structure                                                                */
90     adapter_id.Driver           = pIdentifier->Driver;          
91     adapter_id.Description      = pIdentifier->Description;     
92     adapter_id.DeviceName       = pIdentifier->DeviceName;      
93     adapter_id.DriverVersion    = &pIdentifier->DriverVersion;   
94     adapter_id.VendorId         = &pIdentifier->VendorId;        
95     adapter_id.DeviceId         = &pIdentifier->DeviceId;        
96     adapter_id.SubSysId         = &pIdentifier->SubSysId;        
97     adapter_id.Revision         = &pIdentifier->Revision;        
98     adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
99     adapter_id.WHQLLevel        = &pIdentifier->WHQLLevel;       
100
101     return IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
102 }
103
104 UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format) {
105     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
106     return IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, Format);
107 }
108
109 HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
110     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
111     return IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, Format, Mode, pMode);
112 }
113
114 HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
115     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
116     return IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, pMode);
117 }
118
119 HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface,
120                                               UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
121                                               D3DFORMAT BackBufferFormat, BOOL Windowed) {
122     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
123     return IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, DisplayFormat,
124                                     BackBufferFormat, Windowed);
125 }
126
127 HRESULT  WINAPI  IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface,
128                                                   UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
129                                                   DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
130     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
131     return IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, AdapterFormat,
132                                     Usage, RType, CheckFormat);
133 }
134
135 HRESULT  WINAPI  IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9 iface,
136                                                            UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
137                                                            BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
138     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
139     return IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType, SurfaceFormat,
140                                                Windowed, MultiSampleType, pQualityLevels);
141 }
142
143 HRESULT  WINAPI  IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9 iface, 
144                                                        UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
145                                                        D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
146     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
147     return IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType, AdapterFormat,
148                                            RenderTargetFormat, DepthStencilFormat);
149 }
150
151 HRESULT  WINAPI  IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
152     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
153     return IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType, SourceFormat,
154                                                 TargetFormat);
155 }
156
157 HRESULT  WINAPI  IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
158     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
159     FIXME("(%p): stub\n", This);
160     return D3D_OK;
161 }
162
163 HMONITOR WINAPI  IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface, UINT Adapter) {
164     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
165     return IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
166 }
167
168 HRESULT  WINAPI  IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
169                                              DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, 
170                                              IDirect3DDevice9** ppReturnedDeviceInterface) {
171
172     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
173     FIXME("(%p) : stub\n", This);
174     return D3D_OK;
175 }
176
177 IDirect3D9Vtbl Direct3D9_Vtbl =
178 {
179     IDirect3D9Impl_QueryInterface,
180     IDirect3D9Impl_AddRef,
181     IDirect3D9Impl_Release,
182     IDirect3D9Impl_RegisterSoftwareDevice,
183     IDirect3D9Impl_GetAdapterCount,
184     IDirect3D9Impl_GetAdapterIdentifier,
185     IDirect3D9Impl_GetAdapterModeCount,
186     IDirect3D9Impl_EnumAdapterModes,
187     IDirect3D9Impl_GetAdapterDisplayMode,
188     IDirect3D9Impl_CheckDeviceType,
189     IDirect3D9Impl_CheckDeviceFormat,
190     IDirect3D9Impl_CheckDeviceMultiSampleType,
191     IDirect3D9Impl_CheckDepthStencilMatch,
192     IDirect3D9Impl_CheckDeviceFormatConversion,
193     IDirect3D9Impl_GetDeviceCaps,
194     IDirect3D9Impl_GetAdapterMonitor,
195     IDirect3D9Impl_CreateDevice
196 };