2 * IDirect3D9 implementation
4 * Copyright 2002 Jason Edmeades
5 * Copyright 2005 Oliver Stieber
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "d3d9_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
27 /* IDirect3D9 IUnknown parts follow: */
28 HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface, REFIID riid, LPVOID* ppobj)
30 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
32 if (IsEqualGUID(riid, &IID_IUnknown)
33 || IsEqualGUID(riid, &IID_IDirect3D9)) {
34 IDirect3D9Impl_AddRef(iface);
39 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
43 ULONG WINAPI IDirect3D9Impl_AddRef(LPDIRECT3D9 iface) {
44 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
45 ULONG ref = InterlockedIncrement(&This->ref);
47 TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
52 ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9 iface) {
53 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
54 ULONG ref = InterlockedDecrement(&This->ref);
56 TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
59 IWineD3D_Release(This->WineD3D);
60 HeapFree(GetProcessHeap(), 0, This);
66 /* IDirect3D9 Interface follow: */
67 HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface, void* pInitializeFunction) {
68 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
69 return IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
72 UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) {
73 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
74 return IWineD3D_GetAdapterCount(This->WineD3D);
77 HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER9* pIdentifier) {
78 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
79 WINED3DADAPTER_IDENTIFIER adapter_id;
81 /* dx8 and dx9 have different structures to be filled in, with incompatible
82 layouts so pass in pointers to the places to be filled via an internal
84 adapter_id.Driver = pIdentifier->Driver;
85 adapter_id.Description = pIdentifier->Description;
86 adapter_id.DeviceName = pIdentifier->DeviceName;
87 adapter_id.DriverVersion = &pIdentifier->DriverVersion;
88 adapter_id.VendorId = &pIdentifier->VendorId;
89 adapter_id.DeviceId = &pIdentifier->DeviceId;
90 adapter_id.SubSysId = &pIdentifier->SubSysId;
91 adapter_id.Revision = &pIdentifier->Revision;
92 adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
93 adapter_id.WHQLLevel = &pIdentifier->WHQLLevel;
95 return IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
98 UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format) {
99 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
100 return IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, Format);
103 HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface, UINT Adapter, D3DFORMAT Format, UINT Mode, D3DDISPLAYMODE* pMode) {
104 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
105 return IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, Format, Mode, pMode);
108 HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
109 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
110 return IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, pMode);
113 HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface,
114 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
115 D3DFORMAT BackBufferFormat, BOOL Windowed) {
116 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
117 return IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, DisplayFormat,
118 BackBufferFormat, Windowed);
121 HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface,
122 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
123 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
124 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
125 return IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, AdapterFormat,
126 Usage, RType, CheckFormat);
129 HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9 iface,
130 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
131 BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
132 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
133 return IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType, SurfaceFormat,
134 Windowed, MultiSampleType, pQualityLevels);
137 HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9 iface,
138 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
139 D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
140 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
141 return IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType, AdapterFormat,
142 RenderTargetFormat, DepthStencilFormat);
145 HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SourceFormat, D3DFORMAT TargetFormat) {
146 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
147 return IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType, SourceFormat,
151 HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS9* pCaps) {
152 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
153 HRESULT hrc = D3D_OK;
154 WINED3DCAPS *pWineCaps;
156 TRACE("(%p) Relay %d %u %p \n", This, Adapter, DeviceType, pCaps);
159 return D3DERR_INVALIDCALL;
161 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
162 if(pWineCaps == NULL){
163 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
165 D3D9CAPSTOWINECAPS(pCaps, pWineCaps)
166 hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
167 HeapFree(GetProcessHeap(), 0, pWineCaps);
168 TRACE("(%p) returning %p\n", This, pCaps);
172 HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface, UINT Adapter) {
173 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
174 return IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
177 /* Internal function called back during the CreateDevice to create a render target */
178 HRESULT WINAPI D3D9CB_CreateRenderTarget(IUnknown *device, UINT Width, UINT Height,
179 WINED3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
180 DWORD MultisampleQuality, BOOL Lockable,
181 IWineD3DSurface** ppSurface, HANDLE* pSharedHandle) {
182 HRESULT res = D3D_OK;
183 IDirect3DSurface9Impl *d3dSurface = NULL;
184 IDirect3DDevice9Impl* pDeviceImpl = (IDirect3DDevice9Impl*) device;
186 res = IDirect3DDevice9_CreateRenderTarget((IDirect3DDevice9 *)device, Width, Height,
187 (D3DFORMAT) Format, MultiSample, MultisampleQuality, Lockable,
188 (IDirect3DSurface9 **)&d3dSurface, pSharedHandle);
190 if (SUCCEEDED(res)) {
191 *ppSurface = d3dSurface->wineD3DSurface;
192 if (NULL == pDeviceImpl->backBuffer) {
193 pDeviceImpl->backBuffer = d3dSurface;
194 pDeviceImpl->renderTarget = d3dSurface;
195 IDirect3DSurface9Impl_AddRef((LPDIRECT3DSURFACE9) pDeviceImpl->renderTarget);
203 HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow,
204 DWORD BehaviourFlags, D3DPRESENT_PARAMETERS* pPresentationParameters,
205 IDirect3DDevice9** ppReturnedDeviceInterface) {
207 IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
208 IDirect3DDevice9Impl *object = NULL;
209 WINED3DPRESENT_PARAMETERS localParameters;
211 /* Check the validity range of the adapter parameter */
212 if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
213 *ppReturnedDeviceInterface = NULL;
214 return D3DERR_INVALIDCALL;
217 /* Allocate the storage for the device object */
218 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
219 if (NULL == object) {
220 FIXME("Allocation of memory failed\n");
221 *ppReturnedDeviceInterface = NULL;
222 return D3DERR_OUTOFVIDEOMEMORY;
225 object->lpVtbl = &Direct3DDevice9_Vtbl;
227 object->direct3d = This;
228 IDirect3D9_AddRef((LPDIRECT3D9) object->direct3d);
229 *ppReturnedDeviceInterface = (IDirect3DDevice9 *)object;
231 /* Allocate an associated WineD3DDevice object */
232 localParameters.BackBufferWidth = &pPresentationParameters->BackBufferWidth;
233 localParameters.BackBufferHeight = &pPresentationParameters->BackBufferHeight;
234 localParameters.BackBufferFormat = &pPresentationParameters->BackBufferFormat;
235 localParameters.BackBufferCount = &pPresentationParameters->BackBufferCount;
236 localParameters.MultiSampleType = &pPresentationParameters->MultiSampleType;
237 localParameters.MultiSampleQuality = &pPresentationParameters->MultiSampleQuality;
238 localParameters.SwapEffect = &pPresentationParameters->SwapEffect;
239 localParameters.hDeviceWindow = &pPresentationParameters->hDeviceWindow;
240 localParameters.Windowed = &pPresentationParameters->Windowed;
241 localParameters.EnableAutoDepthStencil = &pPresentationParameters->EnableAutoDepthStencil;
242 localParameters.AutoDepthStencilFormat = &pPresentationParameters->AutoDepthStencilFormat;
243 localParameters.Flags = &pPresentationParameters->Flags;
244 localParameters.FullScreen_RefreshRateInHz = &pPresentationParameters->FullScreen_RefreshRateInHz;
245 localParameters.PresentationInterval = &pPresentationParameters->PresentationInterval;
246 return IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags, &localParameters, &object->WineD3DDevice, (IUnknown *)object, D3D9CB_CreateRenderTarget);
249 const IDirect3D9Vtbl Direct3D9_Vtbl =
251 IDirect3D9Impl_QueryInterface,
252 IDirect3D9Impl_AddRef,
253 IDirect3D9Impl_Release,
254 IDirect3D9Impl_RegisterSoftwareDevice,
255 IDirect3D9Impl_GetAdapterCount,
256 IDirect3D9Impl_GetAdapterIdentifier,
257 IDirect3D9Impl_GetAdapterModeCount,
258 IDirect3D9Impl_EnumAdapterModes,
259 IDirect3D9Impl_GetAdapterDisplayMode,
260 IDirect3D9Impl_CheckDeviceType,
261 IDirect3D9Impl_CheckDeviceFormat,
262 IDirect3D9Impl_CheckDeviceMultiSampleType,
263 IDirect3D9Impl_CheckDepthStencilMatch,
264 IDirect3D9Impl_CheckDeviceFormatConversion,
265 IDirect3D9Impl_GetDeviceCaps,
266 IDirect3D9Impl_GetAdapterMonitor,
267 IDirect3D9Impl_CreateDevice