From 89a49eb4b768f2d5cd48d9c31334e1d49d0cb0a2 Mon Sep 17 00:00:00 2001 From: Gregor Brunmar Date: Thu, 7 Feb 2008 17:32:49 +0000 Subject: [PATCH] * Fixed d3d9 critical section not being unlocked in GetAdapterIdentifier * Implemeted IDirect3D9::GetAdapterMonitor svn path=/trunk/; revision=32190 --- reactos/dll/directx/d3d9/adapter.c | 39 +++++++++++++++++++++++ reactos/dll/directx/d3d9/adapter.h | 2 ++ reactos/dll/directx/d3d9/d3d9_helpers.c | 3 ++ reactos/dll/directx/d3d9/d3d9_impl.c | 41 ++++++++++++++++++++++--- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/reactos/dll/directx/d3d9/adapter.c b/reactos/dll/directx/d3d9/adapter.c index 74bcc990f1f..01764e7ca72 100644 --- a/reactos/dll/directx/d3d9/adapter.c +++ b/reactos/dll/directx/d3d9/adapter.c @@ -10,11 +10,20 @@ #include #include #include +#include "adapter.h" typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL); typedef BOOL (WINAPI *LPFN_DISABLEWOW64FSREDIRECTION) (PVOID*); typedef BOOL (WINAPI *LPFN_REVERTWOW64FSREDIRECTION) (PVOID); + +typedef struct _ADAPTERMONITOR +{ + LPCSTR lpszDeviceName; + HMONITOR hMonitor; +} ADAPTERMONITOR, *LPADAPTERMONITOR; + + static BOOL GetDriverName(LPDISPLAY_DEVICEA pDisplayDevice, D3DADAPTER_IDENTIFIER9* pIdentifier) { HKEY hKey; @@ -156,3 +165,33 @@ BOOL GetAdapterInfo(LPCSTR lpszDeviceName, D3DADAPTER_IDENTIFIER9* pIdentifier) return TRUE; } + +static BOOL CALLBACK AdapterMonitorEnumProc(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) +{ + MONITORINFOEXA MonitorInfoEx; + LPADAPTERMONITOR lpAdapterMonitor = (LPADAPTERMONITOR)dwData; + + memset(&MonitorInfoEx, 0, sizeof(MONITORINFOEXA)); + MonitorInfoEx.cbSize = sizeof(MONITORINFOEXA); + + GetMonitorInfoA(hMonitor, (LPMONITORINFO)&MonitorInfoEx); + + if (_stricmp(lpAdapterMonitor->lpszDeviceName, MonitorInfoEx.szDevice) == 0) + { + lpAdapterMonitor->hMonitor = hMonitor; + return FALSE; + } + + return TRUE; +} + +HMONITOR GetAdapterMonitor(LPCSTR lpszDeviceName) +{ + ADAPTERMONITOR AdapterMonitor; + AdapterMonitor.lpszDeviceName = lpszDeviceName; + AdapterMonitor.hMonitor = NULL; + + EnumDisplayMonitors(NULL, NULL, AdapterMonitorEnumProc, (LPARAM)&AdapterMonitor); + + return AdapterMonitor.hMonitor; +} diff --git a/reactos/dll/directx/d3d9/adapter.h b/reactos/dll/directx/d3d9/adapter.h index b359691c2d9..e3c80fb70a0 100644 --- a/reactos/dll/directx/d3d9/adapter.h +++ b/reactos/dll/directx/d3d9/adapter.h @@ -11,4 +11,6 @@ BOOL GetAdapterInfo(LPCSTR lpszDeviceName, D3DADAPTER_IDENTIFIER9* pIdentifier); +HMONITOR GetAdapterMonitor(LPCSTR lpszDeviceName); + #endif diff --git a/reactos/dll/directx/d3d9/d3d9_helpers.c b/reactos/dll/directx/d3d9/d3d9_helpers.c index fe5e0a7bc58..fdc69793f47 100644 --- a/reactos/dll/directx/d3d9/d3d9_helpers.c +++ b/reactos/dll/directx/d3d9/d3d9_helpers.c @@ -18,6 +18,9 @@ static LPCSTR D3D9_DebugRegPath = "Software\\Microsoft\\Direct3D"; LPDIRECT3D9_INT impl_from_IDirect3D9(LPDIRECT3D9 iface) { + if (IsBadWritePtr(iface, sizeof(LPDIRECT3D9_INT))) + return NULL; + return (LPDIRECT3D9_INT)((ULONG_PTR)iface - FIELD_OFFSET(DIRECT3D9_INT, lpVtbl)); } diff --git a/reactos/dll/directx/d3d9/d3d9_impl.c b/reactos/dll/directx/d3d9/d3d9_impl.c index e77f9cb311d..49c62bccc5d 100644 --- a/reactos/dll/directx/d3d9/d3d9_impl.c +++ b/reactos/dll/directx/d3d9/d3d9_impl.c @@ -69,7 +69,7 @@ static HRESULT WINAPI IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9 iface, v * @param LPDIRECT3D iface * Pointer to the IDirect3D object returned from Direct3DCreate9() * -* @return +* @return UINT * The number of display adapters on the system when Direct3DCreate9() was called. * */ @@ -107,7 +107,7 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9 iface) * Pointer to a D3DADAPTER_IDENTIFIER9 structure to be filled with the available information * about the display adapter. * -* @return +* @return HRESULT * If the method successfully fills the pIdentified structure, the return value is D3D_OK. * If Adapter is out of range, Flags is invalid or pIdentifier is a bad pointer, the return value * will be D3DERR_INVALIDCALL. @@ -148,6 +148,7 @@ HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9 iface, UINT Adapt return D3DERR_INVALIDCALL; } + UNLOCK_D3D9(); return D3D_OK; } @@ -223,11 +224,43 @@ static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9 iface, UINT Adapt return D3D_OK; } +/*++ +* @name IDirect3D9::GetAdapterMonitor +* @implemented +* +* The function IDirect3D9Impl_GetAdapterMonitor returns the monitor associated +* with the specified display adapter. +* +* @param LPDIRECT3D iface +* Pointer to the IDirect3D object returned from Direct3DCreate9() +* +* @param UINT Adapter +* Adapter index to get information about. D3DADAPTER_DEFAULT is the primary display. +* The maximum value for this is the value returned by IDirect3D::GetAdapterCount(). +* +* @return HMONITOR +* If the method successfully it returns the HMONITOR belonging to the specified adapter. +* If the method fails, the return value is NULL. +* +*/ static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9 iface, UINT Adapter) { - UNIMPLEMENTED + HMONITOR hAdapterMonitor = NULL; - return NULL; + LPDIRECT3D9_INT This = impl_from_IDirect3D9(iface); + LOCK_D3D9(); + + if (Adapter < This->NumDisplayAdapters) + { + hAdapterMonitor = GetAdapterMonitor(This->DisplayAdapters[Adapter].szDeviceName); + } + else + { + DPRINT1("Invalid Adapter number specified"); + } + + UNLOCK_D3D9(); + return hAdapterMonitor; } static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,