Skip to content

Commit

Permalink
Change how QueryInterface() works with Direct3D9
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Aug 24, 2024
1 parent ec472d5 commit 1f22bb9
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 137 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 7111
#define BUILD_NUMBER 7112
13 changes: 8 additions & 5 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ HRESULT m_IDirect3D9Ex::QueryInterface(REFIID riid, void** ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IUnknown || riid == WrapperID) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);

if (SUCCEEDED(hr) && ppvObj)
if (SUCCEEDED(hr))
{
if (riid == IID_IDirect3D9 || riid == IID_IDirect3D9Ex)
{
Expand Down
17 changes: 8 additions & 9 deletions d3d9/IDirect3DCubeTexture9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DCubeTexture9::QueryInterface(THIS_ REFIID riid, void** ppvObj
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DCubeTexture9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9 || riid == IID_IDirect3DBaseTexture9) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID || riid == IID_IDirect3DBaseTexture9 || riid == IID_IDirect3DResource9)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -62,11 +65,7 @@ HRESULT m_IDirect3DCubeTexture9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DCubeTexture9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DCubeTexture9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class m_IDirect3DCubeTexture9 : public IDirect3DCubeTexture9, public AddressLook
private:
LPDIRECT3DCUBETEXTURE9 ProxyInterface;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DCubeTexture9;

public:
m_IDirect3DCubeTexture9(LPDIRECT3DCUBETEXTURE9 pTexture9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pTexture9), m_pDeviceEx(pDevice)
Expand Down
19 changes: 9 additions & 10 deletions d3d9/IDirect3DDevice9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,21 @@ HRESULT m_IDirect3DDevice9Ex::QueryInterface(REFIID riid, void** ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IUnknown || riid == WrapperID) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);

if (SUCCEEDED(hr) && ppvObj)
if (SUCCEEDED(hr))
{
if (riid == IID_IDirect3DDevice9 || riid == IID_IDirect3DDevice9Ex)
{
Expand Down Expand Up @@ -697,11 +700,7 @@ HRESULT m_IDirect3DDevice9Ex::GetDirect3D(IDirect3D9 **ppD3D9)
return D3DERR_INVALIDCALL;
}

m_pD3DEx->AddRef();

*ppD3D9 = m_pD3DEx;

return D3D_OK;
return m_pD3DEx->QueryInterface(WrapperID == IID_IDirect3DDevice9Ex ? IID_IDirect3D9Ex : IID_IDirect3D9, (LPVOID*)ppD3D9);
}

HRESULT m_IDirect3DDevice9Ex::GetRasterStatus(THIS_ UINT iSwapChain, D3DRASTER_STATUS* pRasterStatus)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DDevice9Ex.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,5 @@ class m_IDirect3DDevice9Ex : public IDirect3DDevice9Ex, public AddressLookupTabl
// Helper functions
inline LPDIRECT3DDEVICE9 GetProxyInterface() { return ProxyInterface; }
inline D3DMULTISAMPLE_TYPE GetMultiSampleType() { return DeviceDetailsMap[DDKey].DeviceMultiSampleType; }
REFIID GetIID() { return WrapperID; }
};
17 changes: 8 additions & 9 deletions d3d9/IDirect3DIndexBuffer9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DIndexBuffer9::QueryInterface(THIS_ REFIID riid, void** ppvObj
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DIndexBuffer9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID || riid == IID_IDirect3DResource9)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -62,11 +65,7 @@ HRESULT m_IDirect3DIndexBuffer9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DIndexBuffer9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DIndexBuffer9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class m_IDirect3DIndexBuffer9 : public IDirect3DIndexBuffer9, public AddressLook
private:
LPDIRECT3DINDEXBUFFER9 ProxyInterface;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DIndexBuffer9;

public:
m_IDirect3DIndexBuffer9(LPDIRECT3DINDEXBUFFER9 pBuffer9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pBuffer9), m_pDeviceEx(pDevice)
Expand Down
17 changes: 8 additions & 9 deletions d3d9/IDirect3DPixelShader9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DPixelShader9::QueryInterface(THIS_ REFIID riid, void** ppvObj
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DPixelShader9 || riid == IID_IUnknown) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -62,11 +65,7 @@ HRESULT m_IDirect3DPixelShader9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DPixelShader9::GetFunction(THIS_ void* pData, UINT* pSizeOfData)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DPixelShader9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class m_IDirect3DPixelShader9 : public IDirect3DPixelShader9, public AddressLook
private:
LPDIRECT3DPIXELSHADER9 ProxyInterface;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DPixelShader9;

public:
m_IDirect3DPixelShader9(LPDIRECT3DPIXELSHADER9 pShader9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pShader9), m_pDeviceEx(pDevice)
Expand Down
17 changes: 8 additions & 9 deletions d3d9/IDirect3DQuery9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DQuery9::QueryInterface(THIS_ REFIID riid, void** ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DQuery9 || riid == IID_IUnknown) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -62,11 +65,7 @@ HRESULT m_IDirect3DQuery9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

D3DQUERYTYPE m_IDirect3DQuery9::GetType(THIS)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DQuery9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class m_IDirect3DQuery9 : public IDirect3DQuery9, public AddressLookupTableD3d9O
private:
LPDIRECT3DQUERY9 ProxyInterface;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DQuery9;

public:
m_IDirect3DQuery9(LPDIRECT3DQUERY9 pQuery9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pQuery9), m_pDeviceEx(pDevice)
Expand Down
17 changes: 8 additions & 9 deletions d3d9/IDirect3DStateBlock9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DStateBlock9::QueryInterface(THIS_ REFIID riid, void** ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DStateBlock9 || riid == IID_IUnknown) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -62,11 +65,7 @@ HRESULT m_IDirect3DStateBlock9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DStateBlock9::Capture(THIS)
Expand Down
1 change: 1 addition & 0 deletions d3d9/IDirect3DStateBlock9.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class m_IDirect3DStateBlock9 : public IDirect3DStateBlock9, public AddressLookup
private:
LPDIRECT3DSTATEBLOCK9 ProxyInterface;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DStateBlock9;

public:
m_IDirect3DStateBlock9(LPDIRECT3DSTATEBLOCK9 pBlock9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pBlock9), m_pDeviceEx(pDevice)
Expand Down
21 changes: 10 additions & 11 deletions d3d9/IDirect3DSurface9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DSurface9::QueryInterface(THIS_ REFIID riid, void** ppvObj)
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == IID_IDirect3DSurface9 || riid == IID_IUnknown || riid == IID_IDirect3DResource9) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID || riid == IID_IDirect3DResource9)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -71,11 +74,7 @@ HRESULT m_IDirect3DSurface9::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DSurface9::SetPrivateData(THIS_ REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags)
Expand Down Expand Up @@ -152,8 +151,8 @@ m_IDirect3DSurface9* m_IDirect3DSurface9::m_GetNonMultiSampledSurface(const RECT
{
if (!Emu.pSurface)
{
if (SUCCEEDED((Desc.Usage & D3DUSAGE_RENDERTARGET) ? pDeviceEx->CreateRenderTarget(Desc.Width, Desc.Height, Desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, (LPDIRECT3DSURFACE9*)&Emu.pSurface, nullptr) :
pDeviceEx->CreateOffscreenPlainSurface(Desc.Width, Desc.Height, Desc.Format, D3DPOOL_SYSTEMMEM, (LPDIRECT3DSURFACE9*)&Emu.pSurface, nullptr)))
if (SUCCEEDED((Desc.Usage & D3DUSAGE_RENDERTARGET) ? m_pDeviceEx->GetProxyInterface()->CreateRenderTarget(Desc.Width, Desc.Height, Desc.Format, D3DMULTISAMPLE_NONE, 0, TRUE, (LPDIRECT3DSURFACE9*)&Emu.pSurface, nullptr) :
m_pDeviceEx->GetProxyInterface()->CreateOffscreenPlainSurface(Desc.Width, Desc.Height, Desc.Format, D3DPOOL_SYSTEMMEM, (LPDIRECT3DSURFACE9*)&Emu.pSurface, nullptr)))
{
Emu.pSurface = new m_IDirect3DSurface9(Emu.pSurface, m_pDeviceEx);
}
Expand Down
4 changes: 2 additions & 2 deletions d3d9/IDirect3DSurface9.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ class m_IDirect3DSurface9 : public IDirect3DSurface9, public AddressLookupTableD
{
private:
LPDIRECT3DSURFACE9 ProxyInterface;
LPDIRECT3DDEVICE9 pDeviceEx;
m_IDirect3DDevice9Ex* m_pDeviceEx;
REFIID WrapperID = IID_IDirect3DSurface9;

// For fake emulated locking
D3DSURFACE_DESC Desc = {};
Expand All @@ -19,7 +19,7 @@ class m_IDirect3DSurface9 : public IDirect3DSurface9, public AddressLookupTableD
m_IDirect3DSurface9* m_GetNonMultiSampledSurface(const RECT* pSurfaceRect, DWORD Flags);

public:
m_IDirect3DSurface9(LPDIRECT3DSURFACE9 pSurface9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pSurface9), m_pDeviceEx(pDevice), pDeviceEx(pDevice->GetProxyInterface())
m_IDirect3DSurface9(LPDIRECT3DSURFACE9 pSurface9, m_IDirect3DDevice9Ex* pDevice) : ProxyInterface(pSurface9), m_pDeviceEx(pDevice)
{
LOG_LIMIT(3, "Creating interface " << __FUNCTION__ << " (" << this << ")");

Expand Down
17 changes: 8 additions & 9 deletions d3d9/IDirect3DSwapChain9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ HRESULT m_IDirect3DSwapChain9Ex::QueryInterface(THIS_ REFIID riid, void** ppvObj
{
Logging::LogDebug() << __FUNCTION__ << " (" << this << ") " << riid;

if ((riid == WrapperID || riid == IID_IUnknown) && ppvObj)
if (riid == IID_IUnknown || riid == WrapperID)
{
AddRef();
HRESULT hr = ProxyInterface->QueryInterface(WrapperID, ppvObj);

*ppvObj = this;
if (SUCCEEDED(hr))
{
*ppvObj = this;
}

return D3D_OK;
return hr;
}

HRESULT hr = ProxyInterface->QueryInterface(riid, ppvObj);
Expand Down Expand Up @@ -109,11 +112,7 @@ HRESULT m_IDirect3DSwapChain9Ex::GetDevice(THIS_ IDirect3DDevice9** ppDevice)
return D3DERR_INVALIDCALL;
}

m_pDeviceEx->AddRef();

*ppDevice = m_pDeviceEx;

return D3D_OK;
return m_pDeviceEx->QueryInterface(WrapperID == IID_IDirect3DSwapChain9Ex ? IID_IDirect3DDevice9Ex : m_pDeviceEx->GetIID(), (LPVOID*)ppDevice);
}

HRESULT m_IDirect3DSwapChain9Ex::GetPresentParameters(THIS_ D3DPRESENT_PARAMETERS* pPresentationParameters)
Expand Down
Loading

0 comments on commit 1f22bb9

Please sign in to comment.