* Fixed d3d9 critical section not being unlocked in GetAdapterIdentifier
authorGregor Brunmar <gbrunmar.ros@gmail.com>
Thu, 7 Feb 2008 17:32:49 +0000 (17:32 +0000)
committerGregor Brunmar <gbrunmar.ros@gmail.com>
Thu, 7 Feb 2008 17:32:49 +0000 (17:32 +0000)
* Implemeted IDirect3D9::GetAdapterMonitor

svn path=/trunk/; revision=32190

reactos/dll/directx/d3d9/adapter.c
reactos/dll/directx/d3d9/adapter.h
reactos/dll/directx/d3d9/d3d9_helpers.c
reactos/dll/directx/d3d9/d3d9_impl.c

index 74bcc99..01764e7 100644 (file)
 #include <d3d9.h>
 #include <ddraw.h>
 #include <strsafe.h>
+#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;
+}
index b359691..e3c80fb 100644 (file)
@@ -11,4 +11,6 @@
 
 BOOL GetAdapterInfo(LPCSTR lpszDeviceName, D3DADAPTER_IDENTIFIER9* pIdentifier);
 
+HMONITOR GetAdapterMonitor(LPCSTR lpszDeviceName);
+
 #endif
index fe5e0a7..fdc6979 100644 (file)
@@ -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));
 }
 
index e77f9cb..49c62bc 100644 (file)
@@ -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;
+
+    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");
+    }
 
-    return NULL;
+    UNLOCK_D3D9();
+    return hAdapterMonitor;
 }
 
 static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9 iface, UINT Adapter, D3DDEVTYPE DeviceType,