2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS ReactX
4 * FILE: dll/directx/d3d9/d3d9_impl.c
5 * PURPOSE: IDirect3D9 implementation
6 * PROGRAMERS: Gregor Brunmar <gregor (dot) brunmar (at) home (dot) se>
9 #include "d3d9_common.h"
12 #include "d3d9_helpers.h"
15 /* IDirect3D9: IUnknown implementation */
16 static HRESULT WINAPI
IDirect3D9Impl_QueryInterface(LPDIRECT3D9 iface
, REFIID riid
, LPVOID
* ppvObject
)
18 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
20 if (IsEqualGUID(riid
, &IID_IUnknown
) || IsEqualGUID(riid
, &IID_IDirect3D9
))
22 IUnknown_AddRef(iface
);
23 *ppvObject
= &This
->lpVtbl
;
31 static ULONG WINAPI
IDirect3D9Impl_AddRef(LPDIRECT3D9 iface
)
33 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
34 ULONG ref
= InterlockedIncrement(&This
->dwRefCnt
);
39 static ULONG WINAPI
IDirect3D9Impl_Release(LPDIRECT3D9 iface
)
41 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
42 ULONG ref
= InterlockedDecrement(&This
->dwRefCnt
);
46 EnterCriticalSection(&This
->d3d9_cs
);
47 /* TODO: Free resources here */
48 LeaveCriticalSection(&This
->d3d9_cs
);
55 /* IDirect3D9 interface */
56 static HRESULT WINAPI
IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface
, void* pInitializeFunction
)
64 * @name IDirect3D9::GetAdapterCount
67 * The function IDirect3D9Impl_GetAdapterCount returns the number of adapters
69 * @param LPDIRECT3D iface
70 * Pointer to the IDirect3D object returned from Direct3DCreate9()
73 * The number of display adapters on the system when Direct3DCreate9() was called.
76 static UINT WINAPI
IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface
)
78 UINT NumDisplayAdapters
;
80 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
83 NumDisplayAdapters
= This
->NumDisplayAdapters
;
86 return NumDisplayAdapters
;
90 * @name IDirect3D9::GetAdapterIdentifier
93 * The function IDirect3D9Impl_GetAdapterIdentifier gathers information about
94 * a specified display adapter and fills the pIdentifier argument with the available information.
96 * @param LPDIRECT3D iface
97 * Pointer to the IDirect3D object returned from Direct3DCreate9()
100 * Adapter index to get information about. D3DADAPTER_DEFAULT is the primary display.
101 * The maximum value for this is the value returned by IDirect3D::GetAdapterCount().
104 * Ignored at the moment, but the only valid flag is D3DENUM_WHQL_LEVEL
106 * @param D3DADAPTER_IDENTIFIER9* pIdentifier
107 * Pointer to a D3DADAPTER_IDENTIFIER9 structure to be filled with the available information
108 * about the display adapter.
111 * If the method successfully fills the pIdentified structure, the return value is D3D_OK.
112 * If Adapter is out of range, Flags is invalid or pIdentifier is a bad pointer, the return value
113 * will be D3DERR_INVALIDCALL.
116 HRESULT WINAPI
IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface
, UINT Adapter
, DWORD Flags
,
117 D3DADAPTER_IDENTIFIER9
* pIdentifier
)
119 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
122 if (Adapter
>= This
->NumDisplayAdapters
)
124 DPRINT1("Invalid Adapter number specified");
126 return D3DERR_INVALIDCALL
;
129 if (Flags
& ~D3DENUM_WHQL_LEVEL
)
131 DPRINT1("Invalid Flags specified");
133 return D3DERR_INVALIDCALL
;
136 if (IsBadWritePtr(pIdentifier
, sizeof(D3DADAPTER_IDENTIFIER9
)))
139 return D3DERR_INVALIDCALL
;
142 memset(pIdentifier
, 0, sizeof(D3DADAPTER_IDENTIFIER9
));
144 if (FALSE
== GetAdapterInfo(This
->DisplayAdapters
[Adapter
].szDeviceName
, pIdentifier
))
146 DPRINT1("Internal error: Couldn't get the adapter info for device (%d): %s", Adapter
, This
->DisplayAdapters
[Adapter
].szDeviceName
);
148 return D3DERR_INVALIDCALL
;
155 static UINT WINAPI
IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9 iface
, UINT Adapter
, D3DFORMAT Format
)
162 static HRESULT WINAPI
IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9 iface
, UINT Adapter
, D3DFORMAT Format
,
163 UINT Mode
, D3DDISPLAYMODE
* pMode
)
170 static HRESULT WINAPI
IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9 iface
, UINT Adapter
, D3DDISPLAYMODE
* pMode
)
177 static HRESULT WINAPI
IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE CheckType
,
178 D3DFORMAT DisplayFormat
, D3DFORMAT BackBufferFormat
, BOOL Windowed
)
185 static HRESULT WINAPI
IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
,
186 D3DFORMAT AdapterFormat
, DWORD Usage
, D3DRESOURCETYPE RType
,
187 D3DFORMAT CheckFormat
)
194 static HRESULT WINAPI
IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
,
195 D3DFORMAT SurfaceFormat
, BOOL Windowed
,
196 D3DMULTISAMPLE_TYPE MultiSampleType
, DWORD
* pQualityLevels
)
203 static HRESULT WINAPI
IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
,
204 D3DFORMAT AdapterFormat
, D3DFORMAT RenderTargetFormat
,
205 D3DFORMAT DepthStencilFormat
)
212 static HRESULT WINAPI
IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
,
213 D3DFORMAT SourceFormat
, D3DFORMAT TargetFormat
)
220 static HRESULT WINAPI
IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
, D3DCAPS9
* pCaps
)
228 * @name IDirect3D9::GetAdapterMonitor
231 * The function IDirect3D9Impl_GetAdapterMonitor returns the monitor associated
232 * with the specified display adapter.
234 * @param LPDIRECT3D iface
235 * Pointer to the IDirect3D object returned from Direct3DCreate9()
237 * @param UINT Adapter
238 * Adapter index to get information about. D3DADAPTER_DEFAULT is the primary display.
239 * The maximum value for this is the value returned by IDirect3D::GetAdapterCount().
242 * If the method successfully it returns the HMONITOR belonging to the specified adapter.
243 * If the method fails, the return value is NULL.
246 static HMONITOR WINAPI
IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface
, UINT Adapter
)
248 HMONITOR hAdapterMonitor
= NULL
;
250 LPDIRECT3D9_INT This
= impl_from_IDirect3D9(iface
);
253 if (Adapter
< This
->NumDisplayAdapters
)
255 hAdapterMonitor
= GetAdapterMonitor(This
->DisplayAdapters
[Adapter
].szDeviceName
);
259 DPRINT1("Invalid Adapter number specified");
263 return hAdapterMonitor
;
266 static HRESULT WINAPI
IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface
, UINT Adapter
, D3DDEVTYPE DeviceType
,
267 HWND hFocusWindow
, DWORD BehaviourFlags
,
268 D3DPRESENT_PARAMETERS
* pPresentationParameters
,
269 struct IDirect3DDevice9
** ppReturnedDeviceInterface
)
276 IDirect3D9Vtbl Direct3D9_Vtbl
=
279 IDirect3D9Impl_QueryInterface
,
280 IDirect3D9Impl_AddRef
,
281 IDirect3D9Impl_Release
,
284 IDirect3D9Impl_RegisterSoftwareDevice
,
285 IDirect3D9Impl_GetAdapterCount
,
286 IDirect3D9Impl_GetAdapterIdentifier
,
287 IDirect3D9Impl_GetAdapterModeCount
,
288 IDirect3D9Impl_EnumAdapterModes
,
289 IDirect3D9Impl_GetAdapterDisplayMode
,
290 IDirect3D9Impl_CheckDeviceType
,
291 IDirect3D9Impl_CheckDeviceFormat
,
292 IDirect3D9Impl_CheckDeviceMultiSampleType
,
293 IDirect3D9Impl_CheckDepthStencilMatch
,
294 IDirect3D9Impl_CheckDeviceFormatConversion
,
295 IDirect3D9Impl_GetDeviceCaps
,
296 IDirect3D9Impl_GetAdapterMonitor
,
297 IDirect3D9Impl_CreateDevice