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(d3d9
);
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 IUnknown_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 TRACE("(%p) call back\n", device
);
185 res
= IDirect3DDevice9_CreateRenderTarget((IDirect3DDevice9
*)device
, Width
, Height
,
186 (D3DFORMAT
)Format
, MultiSample
, MultisampleQuality
, Lockable
,
187 (IDirect3DSurface9
**)&d3dSurface
, pSharedHandle
);
189 if (SUCCEEDED(res
)) {
190 *ppSurface
= d3dSurface
->wineD3DSurface
;
197 HRESULT WINAPI
D3D9CB_CreateAdditionalSwapChain(IUnknown
*device
,
198 WINED3DPRESENT_PARAMETERS
* pPresentationParameters
,
199 IWineD3DSwapChain
** ppSwapChain
) {
200 HRESULT res
= D3D_OK
;
201 IDirect3DSwapChain9Impl
*d3dSwapChain
= NULL
;
202 D3DPRESENT_PARAMETERS localParameters
;
203 TRACE("(%p) call back\n", device
);
205 localParameters
.BackBufferWidth
= *(pPresentationParameters
->BackBufferWidth
);
206 localParameters
.BackBufferHeight
= *(pPresentationParameters
->BackBufferHeight
);
207 localParameters
.BackBufferFormat
= *(pPresentationParameters
->BackBufferFormat
);
208 localParameters
.BackBufferCount
= *(pPresentationParameters
->BackBufferCount
);
209 localParameters
.MultiSampleType
= *(pPresentationParameters
->MultiSampleType
);
210 localParameters
.MultiSampleQuality
= *(pPresentationParameters
->MultiSampleQuality
);
211 localParameters
.SwapEffect
= *(pPresentationParameters
->SwapEffect
);
212 localParameters
.hDeviceWindow
= *(pPresentationParameters
->hDeviceWindow
);
213 localParameters
.Windowed
= *(pPresentationParameters
->Windowed
);
214 localParameters
.EnableAutoDepthStencil
= *(pPresentationParameters
->EnableAutoDepthStencil
);
215 localParameters
.AutoDepthStencilFormat
= *(pPresentationParameters
->AutoDepthStencilFormat
);
216 localParameters
.Flags
= *(pPresentationParameters
->Flags
);
217 localParameters
.FullScreen_RefreshRateInHz
= *(pPresentationParameters
->FullScreen_RefreshRateInHz
);
218 localParameters
.PresentationInterval
= *(pPresentationParameters
->PresentationInterval
);
220 /*copy the presentation parameters*/
221 res
= IDirect3DDevice9_CreateAdditionalSwapChain((IDirect3DDevice9
*)device
, &localParameters
, (IDirect3DSwapChain9
**)&d3dSwapChain
);
223 if (res
== D3D_OK
&& d3dSwapChain
!= NULL
) {
224 *ppSwapChain
= d3dSwapChain
->wineD3DSwapChain
;
228 /*Copy back the presentation parameters*/
229 *pPresentationParameters
->BackBufferWidth
= localParameters
.BackBufferWidth
;
230 *pPresentationParameters
->BackBufferHeight
= localParameters
.BackBufferHeight
;
231 *pPresentationParameters
->BackBufferFormat
= localParameters
.BackBufferFormat
;
232 *pPresentationParameters
->BackBufferCount
= localParameters
.BackBufferCount
;
233 *pPresentationParameters
->MultiSampleType
= localParameters
.MultiSampleType
;
234 *pPresentationParameters
->MultiSampleQuality
= localParameters
.MultiSampleQuality
;
235 *pPresentationParameters
->SwapEffect
= localParameters
.SwapEffect
;
236 *pPresentationParameters
->hDeviceWindow
= localParameters
.hDeviceWindow
;
237 *pPresentationParameters
->Windowed
= localParameters
.Windowed
;
238 *pPresentationParameters
->EnableAutoDepthStencil
= localParameters
.EnableAutoDepthStencil
;
239 *pPresentationParameters
->AutoDepthStencilFormat
= localParameters
.AutoDepthStencilFormat
;
240 *pPresentationParameters
->Flags
= localParameters
.Flags
;
241 *pPresentationParameters
->FullScreen_RefreshRateInHz
= localParameters
.FullScreen_RefreshRateInHz
;
242 *pPresentationParameters
->PresentationInterval
= localParameters
.PresentationInterval
;
247 /* Internal function called back during the CreateDevice to create a render target */
248 HRESULT WINAPI
D3D9CB_CreateDepthStencilSurface(IUnknown
*device
, UINT Width
, UINT Height
,
249 WINED3DFORMAT Format
, D3DMULTISAMPLE_TYPE MultiSample
,
250 DWORD MultisampleQuality
, BOOL Discard
,
251 IWineD3DSurface
** ppSurface
, HANDLE
* pSharedHandle
) {
252 HRESULT res
= D3D_OK
;
253 IDirect3DSurface9Impl
*d3dSurface
= NULL
;
254 TRACE("(%p) call back\n", device
);
256 res
= IDirect3DDevice9_CreateDepthStencilSurface((IDirect3DDevice9
*)device
, Width
, Height
,
257 (D3DFORMAT
)Format
, MultiSample
, MultisampleQuality
, Discard
,
258 (IDirect3DSurface9
**)&d3dSurface
, pSharedHandle
);
260 *ppSurface
= d3dSurface
->wineD3DSurface
;
266 HRESULT WINAPI
IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
, HWND hFocusWindow
,
267 DWORD BehaviourFlags
, D3DPRESENT_PARAMETERS
* pPresentationParameters
,
268 IDirect3DDevice9
** ppReturnedDeviceInterface
) {
270 IDirect3D9Impl
*This
= (IDirect3D9Impl
*)iface
;
271 IDirect3DDevice9Impl
*object
= NULL
;
272 WINED3DPRESENT_PARAMETERS localParameters
;
274 TRACE("(%p) Relay \n", This
);
276 /* Check the validity range of the adapter parameter */
277 if (Adapter
>= IDirect3D9Impl_GetAdapterCount(iface
)) {
278 *ppReturnedDeviceInterface
= NULL
;
279 return D3DERR_INVALIDCALL
;
282 /* Allocate the storage for the device object */
283 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DDevice9Impl
));
284 if (NULL
== object
) {
285 FIXME("Allocation of memory failed\n");
286 *ppReturnedDeviceInterface
= NULL
;
287 return D3DERR_OUTOFVIDEOMEMORY
;
290 object
->lpVtbl
= &Direct3DDevice9_Vtbl
;
292 *ppReturnedDeviceInterface
= (IDirect3DDevice9
*)object
;
294 /* Allocate an associated WineD3DDevice object */
295 localParameters
.BackBufferWidth
= &pPresentationParameters
->BackBufferWidth
;
296 localParameters
.BackBufferHeight
= &pPresentationParameters
->BackBufferHeight
;
297 localParameters
.BackBufferFormat
= (WINED3DFORMAT
*)&pPresentationParameters
->BackBufferFormat
;
298 localParameters
.BackBufferCount
= &pPresentationParameters
->BackBufferCount
;
299 localParameters
.MultiSampleType
= &pPresentationParameters
->MultiSampleType
;
300 localParameters
.MultiSampleQuality
= &pPresentationParameters
->MultiSampleQuality
;
301 localParameters
.SwapEffect
= &pPresentationParameters
->SwapEffect
;
302 localParameters
.hDeviceWindow
= &pPresentationParameters
->hDeviceWindow
;
303 localParameters
.Windowed
= &pPresentationParameters
->Windowed
;
304 localParameters
.EnableAutoDepthStencil
= &pPresentationParameters
->EnableAutoDepthStencil
;
305 localParameters
.AutoDepthStencilFormat
= (WINED3DFORMAT
*)&pPresentationParameters
->AutoDepthStencilFormat
;
306 localParameters
.Flags
= &pPresentationParameters
->Flags
;
307 localParameters
.FullScreen_RefreshRateInHz
= &pPresentationParameters
->FullScreen_RefreshRateInHz
;
308 localParameters
.PresentationInterval
= &pPresentationParameters
->PresentationInterval
;
310 hr
=IWineD3D_CreateDevice(This
->WineD3D
, Adapter
, DeviceType
, hFocusWindow
, BehaviourFlags
, &localParameters
, &object
->WineD3DDevice
, (IUnknown
*)object
, D3D9CB_CreateAdditionalSwapChain
);
314 TRACE("(%p) : Created Device %p\n", This
, object
);
316 HeapFree(GetProcessHeap(), 0, object
);
317 *ppReturnedDeviceInterface
= NULL
;
324 const IDirect3D9Vtbl Direct3D9_Vtbl
=
327 IDirect3D9Impl_QueryInterface
,
328 IDirect3D9Impl_AddRef
,
329 IDirect3D9Impl_Release
,
331 IDirect3D9Impl_RegisterSoftwareDevice
,
332 IDirect3D9Impl_GetAdapterCount
,
333 IDirect3D9Impl_GetAdapterIdentifier
,
334 IDirect3D9Impl_GetAdapterModeCount
,
335 IDirect3D9Impl_EnumAdapterModes
,
336 IDirect3D9Impl_GetAdapterDisplayMode
,
337 IDirect3D9Impl_CheckDeviceType
,
338 IDirect3D9Impl_CheckDeviceFormat
,
339 IDirect3D9Impl_CheckDeviceMultiSampleType
,
340 IDirect3D9Impl_CheckDepthStencilMatch
,
341 IDirect3D9Impl_CheckDeviceFormatConversion
,
342 IDirect3D9Impl_GetDeviceCaps
,
343 IDirect3D9Impl_GetAdapterMonitor
,
344 IDirect3D9Impl_CreateDevice