[ros-diffs] [gbrunmar] 35594: D3D9: * Implemented IDirect3DSwapChain9::GetDevice() and GetPresentParameters() * Added helper function to D3D9BaseObject to convert IUnknown* to IDirect3D9Device* * Fixed behavior in IDirect3DDevice9::GetSwapChain() when an invalid index was specified

gbrunmar at svn.reactos.org gbrunmar at svn.reactos.org
Sun Aug 24 13:18:31 CEST 2008


Author: gbrunmar
Date: Sun Aug 24 06:18:30 2008
New Revision: 35594

URL: http://svn.reactos.org/svn/reactos?rev=35594&view=rev
Log:
D3D9:
* Implemented IDirect3DSwapChain9::GetDevice() and GetPresentParameters()
* Added helper function to D3D9BaseObject to convert IUnknown* to IDirect3D9Device*
* Fixed behavior in IDirect3DDevice9::GetSwapChain() when an invalid index was specified

Modified:
    trunk/reactos/dll/directx/d3d9/d3d9_baseobject.c
    trunk/reactos/dll/directx/d3d9/d3d9_baseobject.h
    trunk/reactos/dll/directx/d3d9/d3d9_device.c
    trunk/reactos/dll/directx/d3d9/d3d9_swapchain.c
    trunk/reactos/dll/directx/d3d9/d3d9_swapchain.h

Modified: trunk/reactos/dll/directx/d3d9/d3d9_baseobject.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_baseobject.c?rev=35594&r1=35593&r2=35594&view=diff
==============================================================================
--- trunk/reactos/dll/directx/d3d9/d3d9_baseobject.c [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_baseobject.c [iso-8859-1] Sun Aug 24 06:18:30 2008
@@ -61,3 +61,13 @@
 
     return Ref;
 }
+
+HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject* pBaseObject, IDirect3DDevice9** ppDevice)
+{
+    if (pBaseObject->pUnknown)
+    {
+        return pBaseObject->pUnknown->lpVtbl->QueryInterface((IUnknown*) &pBaseObject->pUnknown->lpVtbl, &IID_IDirect3DDevice9, (void**)ppDevice);
+    }
+
+    return E_NOINTERFACE;
+}

Modified: trunk/reactos/dll/directx/d3d9/d3d9_baseobject.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_baseobject.h?rev=35594&r1=35593&r2=35594&view=diff
==============================================================================
--- trunk/reactos/dll/directx/d3d9/d3d9_baseobject.h [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_baseobject.h [iso-8859-1] Sun Aug 24 06:18:30 2008
@@ -9,6 +9,9 @@
 #define _D3D9_BASEOBJECT_H_
 
 #include "d3d9_common.h"
+#include <d3d9.h>
+
+struct _D3D9BaseObject;
 
 enum REF_TYPE
 {
@@ -38,5 +41,6 @@
 
 ULONG D3D9BaseObject_AddRef(D3D9BaseObject* pBaseObject);
 ULONG D3D9BaseObject_Release(D3D9BaseObject* pBaseObject);
+HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject* pBaseObject, IDirect3DDevice9** ppDevice);
 
 #endif // _D3D9_BASEOBJECT_H_

Modified: trunk/reactos/dll/directx/d3d9/d3d9_device.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_device.c?rev=35594&r1=35593&r2=35594&view=diff
==============================================================================
--- trunk/reactos/dll/directx/d3d9/d3d9_device.c [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_device.c [iso-8859-1] Sun Aug 24 06:18:30 2008
@@ -341,16 +341,18 @@
     LPDIRECT3DDEVICE9_INT This = impl_from_IDirect3DDevice9(iface);
     LOCK_D3DDEVICE9();
 
+    if (IsBadWritePtr(ppSwapChain, sizeof(IDirect3DSwapChain9*)))
+    {
+        DPRINT1("Invalid ppSwapChain parameter specified");
+        UNLOCK_D3DDEVICE9();
+        return D3DERR_INVALIDCALL;
+    }
+
+    *ppSwapChain = NULL;
+
     if (iSwapChain >= IDirect3DDevice9_GetNumberOfSwapChains(iface))
     {
         DPRINT1("Invalid iSwapChain parameter specified");
-        UNLOCK_D3DDEVICE9();
-        return D3DERR_INVALIDCALL;
-    }
-
-    if (IsBadWritePtr(ppSwapChain, sizeof(IDirect3DSwapChain9*)))
-    {
-        DPRINT1("Invalid ppSwapChain parameter specified");
         UNLOCK_D3DDEVICE9();
         return D3DERR_INVALIDCALL;
     }

Modified: trunk/reactos/dll/directx/d3d9/d3d9_swapchain.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_swapchain.c?rev=35594&r1=35593&r2=35594&view=diff
==============================================================================
--- trunk/reactos/dll/directx/d3d9/d3d9_swapchain.c [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_swapchain.c [iso-8859-1] Sun Aug 24 06:18:30 2008
@@ -13,6 +13,11 @@
 #include "d3d9_helpers.h"
 #include "d3d9_device.h"
 
+#define LOCK_D3DDEVICE9()   if (This->BaseObject.pUnknown && ((LPDIRECT3DDEVICE9_INT)This->BaseObject.pUnknown)->bLockDevice) \
+                                EnterCriticalSection(&((LPDIRECT3DDEVICE9_INT)This->BaseObject.pUnknown)->CriticalSection);
+#define UNLOCK_D3DDEVICE9() if (This->BaseObject.pUnknown && ((LPDIRECT3DDEVICE9_INT)This->BaseObject.pUnknown)->bLockDevice) \
+                                LeaveCriticalSection(&((LPDIRECT3DDEVICE9_INT)This->BaseObject.pUnknown)->CriticalSection);
+
 /* Convert a IDirect3DSwapChain9 pointer safely to the internal implementation struct */
 static LPDIRECT3DSWAPCHAIN9_INT IDirect3DSwapChain9ToImpl(LPDIRECT3DSWAPCHAIN9 iface)
 {
@@ -81,15 +86,81 @@
     return D3D_OK;
 }
 
+/*++
+* @name IDirect3DSwapChain9::GetDevice
+* @implemented
+*
+* The function Direct3DSwapChain9_GetDevice sets the ppDevice argument
+* to the device connected to create the swap chain.
+*
+* @param LPDIRECT3DSWAPCHAIN9 iface
+* Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
+*
+* @param IDirect3DDevice9** ppDevice
+* Pointer to a IDirect3DDevice9* structure to be set to the device object.
+*
+* @return HRESULT
+* If the method successfully sets the ppDevice value, the return value is D3D_OK.
+* If ppDevice is a bad pointer the return value will be D3DERR_INVALIDCALL.
+* If the swap chain didn't contain any device, the return value will be D3DERR_INVALIDDEVICE.
+*
+*/
 static HRESULT WINAPI Direct3DSwapChain9_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice)
 {
-    UNIMPLEMENTED
-    return D3D_OK;
-}
-
+    LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
+    LOCK_D3DDEVICE9();
+
+    if (IsBadWritePtr(ppDevice, sizeof(IDirect3DDevice9**)))
+    {
+        DPRINT1("Invalid ppDevice parameter specified");
+        UNLOCK_D3DDEVICE9();
+        return D3DERR_INVALIDCALL;
+    }
+
+    if (FAILED(D3D9BaseObject_GetDevice(&This->BaseObject, ppDevice)))
+    {
+        DPRINT1("Invalid This parameter speficied");
+        UNLOCK_D3DDEVICE9();
+        return D3DERR_INVALIDDEVICE;
+    }
+
+    UNLOCK_D3DDEVICE9();
+    return D3D_OK;
+}
+
+/*++
+* @name IDirect3DSwapChain9::GetPresentParameters
+* @implemented
+*
+* The function Direct3DSwapChain9_GetPresentParameters fills the pPresentationParameters
+* argument with the D3DPRESENT_PARAMETERS parameters that was used to create the swap chain.
+*
+* @param LPDIRECT3DSWAPCHAIN9 iface
+* Pointer to a IDirect3DSwapChain9 object returned from IDirect3D9Device::GetSwapChain()
+*
+* @param D3DPRESENT_PARAMETERS* pPresentationParameters
+* Pointer to a D3DPRESENT_PARAMETERS structure to be filled with the creation parameters.
+*
+* @return HRESULT
+* If the method successfully fills the pPresentationParameters structure, the return value is D3D_OK.
+* If pPresentationParameters is a bad pointer the return value will be D3DERR_INVALIDCALL.
+*
+*/
 static HRESULT WINAPI Direct3DSwapChain9_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters)
 {
-    UNIMPLEMENTED
+    LPDIRECT3DSWAPCHAIN9_INT This = IDirect3DSwapChain9ToImpl(iface);
+    LOCK_D3DDEVICE9();
+
+    if (IsBadWritePtr(pPresentationParameters, sizeof(D3DPRESENT_PARAMETERS)))
+    {
+        DPRINT1("Invalid pPresentationParameters parameter specified");
+        UNLOCK_D3DDEVICE9();
+        return D3DERR_INVALIDCALL;
+    }
+
+    *pPresentationParameters = This->PresentParameters;
+
+    UNLOCK_D3DDEVICE9();
     return D3D_OK;
 }
 

Modified: trunk/reactos/dll/directx/d3d9/d3d9_swapchain.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/directx/d3d9/d3d9_swapchain.h?rev=35594&r1=35593&r2=35594&view=diff
==============================================================================
--- trunk/reactos/dll/directx/d3d9/d3d9_swapchain.h [iso-8859-1] (original)
+++ trunk/reactos/dll/directx/d3d9/d3d9_swapchain.h [iso-8859-1] Sun Aug 24 06:18:30 2008
@@ -12,6 +12,8 @@
 #include <d3d9.h>
 #include <ddraw.h>
 #include "d3d9_baseobject.h"
+
+struct _Direct3DDevice9_INT;
 
 typedef struct _Direct3DSwapChain9_INT
 {



More information about the Ros-diffs mailing list