From 2c7791c7bd71915da836d03b6796281ee96f0ecc Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 26 Oct 2016 13:20:07 +0200 Subject: [PATCH] Don't wrap each DXGI interface individually, wrap most derived * This lets naughty applications downcast e.g. from an IDXGIAdapter to a IDXGIAdapter1 without QueryInterfacing (I'm looking at you, ROTTR). --- renderdoc/driver/d3d11/d3d11_device.cpp | 6 +- renderdoc/driver/d3d12/d3d12_device.cpp | 6 +- renderdoc/driver/dxgi/dxgi_wrapped.cpp | 799 +++++++------ renderdoc/driver/dxgi/dxgi_wrapped.h | 1369 +++-------------------- 4 files changed, 604 insertions(+), 1576 deletions(-) diff --git a/renderdoc/driver/d3d11/d3d11_device.cpp b/renderdoc/driver/d3d11/d3d11_device.cpp index 594c51e5d..c22bdfaa9 100644 --- a/renderdoc/driver/d3d11/d3d11_device.cpp +++ b/renderdoc/driver/d3d11/d3d11_device.cpp @@ -621,7 +621,7 @@ HRESULT WrappedID3D11Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice *real = (IDXGIDevice *)(*ppvObject); - *ppvObject = (IDXGIDevice *)(new WrappedIDXGIDevice(real, this)); + *ppvObject = (IDXGIDevice *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else @@ -637,7 +637,7 @@ HRESULT WrappedID3D11Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice1 *real = (IDXGIDevice1 *)(*ppvObject); - *ppvObject = (IDXGIDevice1 *)(new WrappedIDXGIDevice1(real, this)); + *ppvObject = (IDXGIDevice1 *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else @@ -653,7 +653,7 @@ HRESULT WrappedID3D11Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice2 *real = (IDXGIDevice2 *)(*ppvObject); - *ppvObject = (IDXGIDevice2 *)(new WrappedIDXGIDevice2(real, this)); + *ppvObject = (IDXGIDevice2 *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else diff --git a/renderdoc/driver/d3d12/d3d12_device.cpp b/renderdoc/driver/d3d12/d3d12_device.cpp index 42d12a702..b7e700555 100644 --- a/renderdoc/driver/d3d12/d3d12_device.cpp +++ b/renderdoc/driver/d3d12/d3d12_device.cpp @@ -392,7 +392,7 @@ HRESULT WrappedID3D12Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice *real = (IDXGIDevice *)(*ppvObject); - *ppvObject = (IDXGIDevice *)(new WrappedIDXGIDevice(real, this)); + *ppvObject = (IDXGIDevice *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else @@ -408,7 +408,7 @@ HRESULT WrappedID3D12Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice1 *real = (IDXGIDevice1 *)(*ppvObject); - *ppvObject = (IDXGIDevice1 *)(new WrappedIDXGIDevice1(real, this)); + *ppvObject = (IDXGIDevice1 *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else @@ -424,7 +424,7 @@ HRESULT WrappedID3D12Device::QueryInterface(REFIID riid, void **ppvObject) if(SUCCEEDED(hr)) { IDXGIDevice2 *real = (IDXGIDevice2 *)(*ppvObject); - *ppvObject = (IDXGIDevice2 *)(new WrappedIDXGIDevice2(real, this)); + *ppvObject = (IDXGIDevice2 *)(new WrappedIDXGIDevice3(real, this)); return S_OK; } else diff --git a/renderdoc/driver/dxgi/dxgi_wrapped.cpp b/renderdoc/driver/dxgi/dxgi_wrapped.cpp index bef557cb8..0f7fc764d 100644 --- a/renderdoc/driver/dxgi/dxgi_wrapped.cpp +++ b/renderdoc/driver/dxgi/dxgi_wrapped.cpp @@ -40,9 +40,6 @@ string ToStrHelper::Get(const IID &el) return tostrBuf; } -WRAPPED_POOL_INST(WrappedIDXGIDevice); -WRAPPED_POOL_INST(WrappedIDXGIDevice1); -WRAPPED_POOL_INST(WrappedIDXGIDevice2); WRAPPED_POOL_INST(WrappedIDXGIDevice3); std::vector WrappedIDXGISwapChain3::m_D3DCallbacks; @@ -51,18 +48,8 @@ ID3DDevice *GetD3DDevice(IUnknown *pDevice) { ID3DDevice *wrapDevice = NULL; - if(WrappedIDXGIDevice::IsAlloc(pDevice) || WrappedIDXGIDevice1::IsAlloc(pDevice) || - WrappedIDXGIDevice2::IsAlloc(pDevice) || WrappedIDXGIDevice3::IsAlloc(pDevice)) - { - if(WrappedIDXGIDevice::IsAlloc(pDevice)) - wrapDevice = ((WrappedIDXGIDevice *)(IDXGIDevice *)pDevice)->GetD3DDevice(); - if(WrappedIDXGIDevice1::IsAlloc(pDevice)) - wrapDevice = ((WrappedIDXGIDevice1 *)(IDXGIDevice1 *)pDevice)->GetD3DDevice(); - if(WrappedIDXGIDevice2::IsAlloc(pDevice)) - wrapDevice = ((WrappedIDXGIDevice2 *)(IDXGIDevice2 *)pDevice)->GetD3DDevice(); - if(WrappedIDXGIDevice3::IsAlloc(pDevice)) - wrapDevice = ((WrappedIDXGIDevice3 *)(IDXGIDevice3 *)pDevice)->GetD3DDevice(); - } + if(WrappedIDXGIDevice3::IsAlloc(pDevice)) + wrapDevice = ((WrappedIDXGIDevice3 *)(IDXGIDevice3 *)pDevice)->GetD3DDevice(); if(wrapDevice == NULL) wrapDevice = WrappedIDXGISwapChain3::GetD3DDevice(pDevice); @@ -70,137 +57,115 @@ ID3DDevice *GetD3DDevice(IUnknown *pDevice) return wrapDevice; } -HRESULT WrappedIDXGIFactory::staticCreateSwapChain(IDXGIFactory *factory, IUnknown *pDevice, - DXGI_SWAP_CHAIN_DESC *pDesc, - IDXGISwapChain **ppSwapChain) +bool RefCountDXGIObject::HandleWrap(REFIID riid, void **ppvObject) { - ID3DDevice *wrapDevice = GetD3DDevice(pDevice); - - if(wrapDevice) + if(ppvObject == NULL || *ppvObject == NULL) { - if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pDesc) - { - pDesc->Windowed = TRUE; - } - - HRESULT ret = factory->CreateSwapChain(wrapDevice->GetRealIUnknown(), pDesc, ppSwapChain); - - if(SUCCEEDED(ret)) - { - *ppSwapChain = - new WrappedIDXGISwapChain3(*ppSwapChain, pDesc ? pDesc->OutputWindow : NULL, wrapDevice); - } - - return ret; + RDCWARN("HandleWrap called with NULL ppvObject"); + return false; } - RDCERR("Creating swap chain with non-hooked device!"); - - return factory->CreateSwapChain(pDevice, pDesc, ppSwapChain); -} - -HRESULT WrappedIDXGIFactory2::staticCreateSwapChainForHwnd( - IDXGIFactory2 *factory, IUnknown *pDevice, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1 *pDesc, - const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain) -{ - ID3DDevice *wrapDevice = GetD3DDevice(pDevice); - - if(wrapDevice) + if(riid == __uuidof(IDXGIDevice)) { - if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pFullscreenDesc) - { - pFullscreenDesc = NULL; - } + // should have been handled elsewhere, so we can properly create this device + RDCERR("Unexpected uuid in RefCountDXGIObject::HandleWrap"); + return false; + } + else if(riid == __uuidof(IDXGIAdapter)) + { + IDXGIAdapter *real = (IDXGIAdapter *)(*ppvObject); + *ppvObject = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(real)); + return true; + } + else if(riid == __uuidof(IDXGIFactory)) + { + // yes I know PRECISELY how fucked up this is. Speak to microsoft - after KB2670838 the internal + // D3D11 device creation function will pass in __uuidof(IDXGIFactory) then attempt to call + // EnumDevices1 (which is in the IDXGIFactory1 vtable). Doing this *should* be safe as using a + // IDXGIFactory1 like a IDXGIFactory should all just work by definition, but there's no way to + // know now if someone trying to create a IDXGIFactory really means it or not. + IDXGIFactory *real = (IDXGIFactory *)(*ppvObject); + *ppvObject = (IDXGIFactory *)(new WrappedIDXGIFactory4(real)); + return true; + } - HRESULT ret = factory->CreateSwapChainForHwnd(wrapDevice->GetRealIUnknown(), hWnd, pDesc, - pFullscreenDesc, pRestrictToOutput, ppSwapChain); - - if(SUCCEEDED(ret)) - { - *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, hWnd, wrapDevice); - } - - return ret; + else if(riid == __uuidof(IDXGIDevice1)) + { + // should have been handled elsewhere, so we can properly create this device + RDCERR("Unexpected uuid in RefCountDXGIObject::HandleWrap"); + return false; + } + else if(riid == __uuidof(IDXGIAdapter1)) + { + IDXGIAdapter1 *real = (IDXGIAdapter1 *)(*ppvObject); + *ppvObject = (IDXGIAdapter1 *)(new WrappedIDXGIAdapter3(real)); + return true; + } + else if(riid == __uuidof(IDXGIFactory1)) + { + IDXGIFactory1 *real = (IDXGIFactory1 *)(*ppvObject); + *ppvObject = (IDXGIFactory1 *)(new WrappedIDXGIFactory4(real)); + return true; + } + else if(riid == __uuidof(IDXGIAdapter2)) + { + IDXGIAdapter2 *real = (IDXGIAdapter2 *)(*ppvObject); + *ppvObject = (IDXGIAdapter2 *)(new WrappedIDXGIAdapter3(real)); + return true; + } + else if(riid == __uuidof(IDXGIAdapter3)) + { + IDXGIAdapter3 *real = (IDXGIAdapter3 *)(*ppvObject); + *ppvObject = (IDXGIAdapter3 *)(new WrappedIDXGIAdapter3(real)); + return true; + } + else if(riid == __uuidof(IDXGIFactory2)) + { + IDXGIFactory2 *real = (IDXGIFactory2 *)(*ppvObject); + *ppvObject = (IDXGIFactory2 *)(new WrappedIDXGIFactory4(real)); + return true; + } + else if(riid == __uuidof(IDXGIFactory3)) + { + IDXGIFactory3 *real = (IDXGIFactory3 *)(*ppvObject); + *ppvObject = (IDXGIFactory3 *)(new WrappedIDXGIFactory4(real)); + return true; + } + else if(riid == __uuidof(IDXGIFactory4)) + { + IDXGIFactory4 *real = (IDXGIFactory4 *)(*ppvObject); + *ppvObject = (IDXGIFactory4 *)(new WrappedIDXGIFactory4(real)); + return true; } else { - RDCERR("Creating swap chain with non-hooked device!"); + string guid = ToStr::Get(riid); + RDCWARN("Querying IDXGIObject for interface: %s", guid.c_str()); } - return factory->CreateSwapChainForHwnd(pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, - ppSwapChain); + return false; } -HRESULT WrappedIDXGIFactory2::staticCreateSwapChainForCoreWindow(IDXGIFactory2 *factory, - IUnknown *pDevice, IUnknown *pWindow, - const DXGI_SWAP_CHAIN_DESC1 *pDesc, - IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain) +HRESULT STDMETHODCALLTYPE RefCountDXGIObject::GetParent( + /* [in] */ REFIID riid, + /* [retval][out] */ void **ppParent) { - ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + HRESULT ret = m_pReal->GetParent(riid, ppParent); - if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen) - { - RDCWARN("Impossible to disallow fullscreen on call to CreateSwapChainForCoreWindow"); - } + if(SUCCEEDED(ret)) + HandleWrap(riid, ppParent); - if(wrapDevice) - { - HRESULT ret = factory->CreateSwapChainForCoreWindow(wrapDevice->GetRealIUnknown(), pWindow, - pDesc, pRestrictToOutput, ppSwapChain); - - if(SUCCEEDED(ret)) - { - HWND wnd = NULL; - (*ppSwapChain)->GetHwnd(&wnd); - *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, wnd, wrapDevice); - } - - return ret; - } - else - { - RDCERR("Creating swap chain with non-hooked device!"); - } - - return factory->CreateSwapChainForCoreWindow(pDevice, pWindow, pDesc, pRestrictToOutput, - ppSwapChain); + return ret; } -HRESULT WrappedIDXGIFactory2::staticCreateSwapChainForComposition(IDXGIFactory2 *factory, - IUnknown *pDevice, - const DXGI_SWAP_CHAIN_DESC1 *pDesc, - IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain) +HRESULT RefCountDXGIObject::WrapQueryInterface(IUnknown *real, REFIID riid, void **ppvObject) { - ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + HRESULT ret = real->QueryInterface(riid, ppvObject); - if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen) - { - RDCWARN("Impossible to disallow fullscreen on call to CreateSwapChainForComposition"); - } + if(SUCCEEDED(ret)) + HandleWrap(riid, ppvObject); - if(wrapDevice) - { - HRESULT ret = factory->CreateSwapChainForComposition(wrapDevice->GetRealIUnknown(), pDesc, - pRestrictToOutput, ppSwapChain); - - if(SUCCEEDED(ret)) - { - HWND wnd = NULL; - (*ppSwapChain)->GetHwnd(&wnd); - *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, wnd, wrapDevice); - } - - return ret; - } - else - { - RDCERR("Creating swap chain with non-hooked device!"); - } - - return factory->CreateSwapChainForComposition(pDevice, pDesc, pRestrictToOutput, ppSwapChain); + return ret; } WrappedIDXGISwapChain3::WrappedIDXGISwapChain3(IDXGISwapChain *real, HWND wnd, ID3DDevice *device) @@ -237,6 +202,62 @@ WrappedIDXGISwapChain3::~WrappedIDXGISwapChain3() SAFE_RELEASE(m_pReal); } +HRESULT STDMETHODCALLTYPE WrappedIDXGISwapChain3::QueryInterface(REFIID riid, void **ppvObject) +{ + if(riid == __uuidof(IDXGISwapChain)) + { + AddRef(); + *ppvObject = (IDXGISwapChain *)this; + return S_OK; + } + else if(riid == __uuidof(IDXGISwapChain1)) + { + if(m_pReal1) + { + AddRef(); + *ppvObject = (IDXGISwapChain1 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(IDXGISwapChain2)) + { + if(m_pReal2) + { + AddRef(); + *ppvObject = (IDXGISwapChain2 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(IDXGISwapChain3)) + { + if(m_pReal3) + { + AddRef(); + *ppvObject = (IDXGISwapChain3 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else + { + string guid = ToStr::Get(riid); + RDCWARN("Querying IDXGISwapChain for interface: %s", guid.c_str()); + } + + return RefCountDXGIObject::QueryInterface(riid, ppvObject); +} + void WrappedIDXGISwapChain3::ReleaseBuffersForResize() { m_pDevice->ReleaseSwapchainResources(this); @@ -432,131 +453,39 @@ HRESULT WrappedIDXGISwapChain3::Present1(UINT SyncInterval, UINT Flags, return m_pReal1->Present1(SyncInterval, Flags, pPresentParameters); } -bool RefCountDXGIObject::HandleWrap(REFIID riid, void **ppvObject) +WrappedIDXGIAdapter3::WrappedIDXGIAdapter3(IDXGIAdapter *real) + : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) { - if(ppvObject == NULL || *ppvObject == NULL) - { - RDCWARN("HandleWrap called with NULL ppvObject"); - return false; - } - - if(riid == __uuidof(IDXGIDevice)) - { - // should have been handled elsewhere, so we can properly create this device - RDCERR("Unexpected uuid in RefCountDXGIObject::HandleWrap"); - return false; - } - else if(riid == __uuidof(IDXGIAdapter)) - { - IDXGIAdapter *real = (IDXGIAdapter *)(*ppvObject); - *ppvObject = (IDXGIAdapter *)(new WrappedIDXGIAdapter(real)); - return true; - } - else if(riid == __uuidof(IDXGIFactory)) - { - // yes I know PRECISELY how fucked up this is. Speak to microsoft - after KB2670838 the internal - // D3D11 device creation function will pass in __uuidof(IDXGIFactory) then attempt to call - // EnumDevices1 (which is in the IDXGIFactory1 vtable). Doing this *should* be safe as using a - // IDXGIFactory1 like a IDXGIFactory should all just work by definition, but there's no way to - // know now if someone trying to create a IDXGIFactory really means it or not. - IDXGIFactory1 *real = (IDXGIFactory1 *)(*ppvObject); - *ppvObject = (IDXGIFactory *)(new WrappedIDXGIFactory1(real)); - return true; - } - - else if(riid == __uuidof(IDXGIDevice1)) - { - // should have been handled elsewhere, so we can properly create this device - RDCERR("Unexpected uuid in RefCountDXGIObject::HandleWrap"); - return false; - } - else if(riid == __uuidof(IDXGIAdapter1)) - { - IDXGIAdapter1 *real = (IDXGIAdapter1 *)(*ppvObject); - *ppvObject = (IDXGIAdapter1 *)(new WrappedIDXGIAdapter1(real)); - return true; - } - else if(riid == __uuidof(IDXGIFactory1)) - { - IDXGIFactory1 *real = (IDXGIFactory1 *)(*ppvObject); - *ppvObject = (IDXGIFactory1 *)(new WrappedIDXGIFactory1(real)); - return true; - } - else if(riid == __uuidof(IDXGIAdapter2)) - { - IDXGIAdapter2 *real = (IDXGIAdapter2 *)(*ppvObject); - *ppvObject = (IDXGIAdapter2 *)(new WrappedIDXGIAdapter2(real)); - return true; - } - else if(riid == __uuidof(IDXGIAdapter3)) - { - IDXGIAdapter3 *real = (IDXGIAdapter3 *)(*ppvObject); - *ppvObject = (IDXGIAdapter3 *)(new WrappedIDXGIAdapter3(real)); - return true; - } - else if(riid == __uuidof(IDXGIFactory2)) - { - IDXGIFactory2 *real = (IDXGIFactory2 *)(*ppvObject); - *ppvObject = (IDXGIFactory2 *)(new WrappedIDXGIFactory2(real)); - return true; - } - else if(riid == __uuidof(IDXGIFactory3)) - { - IDXGIFactory3 *real = (IDXGIFactory3 *)(*ppvObject); - *ppvObject = (IDXGIFactory3 *)(new WrappedIDXGIFactory3(real)); - return true; - } - else if(riid == __uuidof(IDXGIFactory4)) - { - IDXGIFactory4 *real = (IDXGIFactory4 *)(*ppvObject); - *ppvObject = (IDXGIFactory4 *)(new WrappedIDXGIFactory4(real)); - return true; - } - else - { - string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGIObject for interface: %s", guid.c_str()); - } - - return false; + m_pReal1 = NULL; + real->QueryInterface(__uuidof(IDXGIAdapter1), (void **)&m_pReal1); + m_pReal2 = NULL; + real->QueryInterface(__uuidof(IDXGIAdapter2), (void **)&m_pReal2); + m_pReal3 = NULL; + real->QueryInterface(__uuidof(IDXGIAdapter3), (void **)&m_pReal3); } -HRESULT STDMETHODCALLTYPE RefCountDXGIObject::GetParent( - /* [in] */ REFIID riid, - /* [retval][out] */ void **ppParent) +WrappedIDXGIAdapter3::~WrappedIDXGIAdapter3() { - HRESULT ret = m_pReal->GetParent(riid, ppParent); - - if(SUCCEEDED(ret)) - HandleWrap(riid, ppParent); - - return ret; + SAFE_RELEASE(m_pReal1); + SAFE_RELEASE(m_pReal2); + SAFE_RELEASE(m_pReal3); + SAFE_RELEASE(m_pReal); } -HRESULT RefCountDXGIObject::WrapQueryInterface(IUnknown *real, REFIID riid, void **ppvObject) +HRESULT STDMETHODCALLTYPE WrappedIDXGIAdapter3::QueryInterface(REFIID riid, void **ppvObject) { - HRESULT ret = real->QueryInterface(riid, ppvObject); - - if(SUCCEEDED(ret)) - HandleWrap(riid, ppvObject); - - return ret; -} - -HRESULT STDMETHODCALLTYPE WrappedIDXGISwapChain3::QueryInterface(REFIID riid, void **ppvObject) -{ - if(riid == __uuidof(IDXGISwapChain)) + if(riid == __uuidof(IDXGIAdapter)) { AddRef(); - *ppvObject = (IDXGISwapChain *)this; + *ppvObject = (IDXGIAdapter *)this; return S_OK; } - else if(riid == __uuidof(IDXGISwapChain1)) + else if(riid == __uuidof(IDXGIAdapter1)) { if(m_pReal1) { AddRef(); - *ppvObject = (IDXGISwapChain1 *)this; + *ppvObject = (IDXGIAdapter1 *)this; return S_OK; } else @@ -564,12 +493,12 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGISwapChain3::QueryInterface(REFIID riid, vo return E_NOINTERFACE; } } - else if(riid == __uuidof(IDXGISwapChain2)) + else if(riid == __uuidof(IDXGIAdapter2)) { if(m_pReal2) { AddRef(); - *ppvObject = (IDXGISwapChain2 *)this; + *ppvObject = (IDXGIAdapter2 *)this; return S_OK; } else @@ -577,12 +506,12 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGISwapChain3::QueryInterface(REFIID riid, vo return E_NOINTERFACE; } } - else if(riid == __uuidof(IDXGISwapChain3)) + else if(riid == __uuidof(IDXGIAdapter3)) { if(m_pReal3) { AddRef(); - *ppvObject = (IDXGISwapChain3 *)this; + *ppvObject = (IDXGIAdapter3 *)this; return S_OK; } else @@ -593,126 +522,32 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGISwapChain3::QueryInterface(REFIID riid, vo else { string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGISwapChain for interface: %s", guid.c_str()); + RDCWARN("Querying IDXGIAdapter for interface: %s", guid.c_str()); } return RefCountDXGIObject::QueryInterface(riid, ppvObject); } -HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice::QueryInterface(REFIID riid, void **ppvObject) +WrappedIDXGIDevice3::WrappedIDXGIDevice3(IDXGIDevice *real, ID3DDevice *d3d) + : RefCountDXGIObject(real), m_pReal(real), m_pD3DDevice(d3d) { - if(m_pD3DDevice->IsDeviceUUID(riid)) - { - m_pD3DDevice->AddRef(); - *ppvObject = m_pD3DDevice->GetDeviceInterface(riid); - return S_OK; - } - else - { - string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGIDevice for interface: %s", guid.c_str()); - } + m_pD3DDevice->AddRef(); - return RefCountDXGIObject::QueryInterface(riid, ppvObject); + m_pReal1 = NULL; + real->QueryInterface(__uuidof(IDXGIDevice1), (void **)&m_pReal1); + m_pReal2 = NULL; + real->QueryInterface(__uuidof(IDXGIDevice2), (void **)&m_pReal2); + m_pReal3 = NULL; + real->QueryInterface(__uuidof(IDXGIDevice3), (void **)&m_pReal3); } -HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice1::QueryInterface(REFIID riid, void **ppvObject) +WrappedIDXGIDevice3::~WrappedIDXGIDevice3() { - HRESULT hr = S_OK; - - if(m_pD3DDevice->IsDeviceUUID(riid)) - { - m_pD3DDevice->AddRef(); - *ppvObject = m_pD3DDevice->GetDeviceInterface(riid); - return S_OK; - } - else if(riid == __uuidof(IDXGIDevice1)) - { - AddRef(); - *ppvObject = (IDXGIDevice1 *)this; - return S_OK; - } - else if(riid == __uuidof(IDXGIDevice2)) - { - hr = m_pReal->QueryInterface(riid, ppvObject); - - if(SUCCEEDED(hr)) - { - IDXGIDevice2 *real = (IDXGIDevice2 *)(*ppvObject); - *ppvObject = (IDXGIDevice2 *)(new WrappedIDXGIDevice2(real, m_pD3DDevice)); - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else if(riid == __uuidof(IDXGIDevice3)) - { - hr = m_pReal->QueryInterface(riid, ppvObject); - - if(SUCCEEDED(hr)) - { - IDXGIDevice3 *real = (IDXGIDevice3 *)(*ppvObject); - *ppvObject = (IDXGIDevice3 *)(new WrappedIDXGIDevice3(real, m_pD3DDevice)); - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else - { - string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGIDevice1 for interface: %s", guid.c_str()); - } - - return RefCountDXGIObject::QueryInterface(riid, ppvObject); -} - -HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice2::QueryInterface(REFIID riid, void **ppvObject) -{ - if(m_pD3DDevice->IsDeviceUUID(riid)) - { - m_pD3DDevice->AddRef(); - *ppvObject = m_pD3DDevice->GetDeviceInterface(riid); - return S_OK; - } - else if(riid == __uuidof(IDXGIDevice1)) - { - AddRef(); - *ppvObject = (IDXGIDevice1 *)this; - return S_OK; - } - else if(riid == __uuidof(IDXGIDevice2)) - { - AddRef(); - *ppvObject = (IDXGIDevice2 *)this; - return S_OK; - } - else if(riid == __uuidof(IDXGIDevice3)) - { - HRESULT hr = m_pReal->QueryInterface(riid, ppvObject); - - if(SUCCEEDED(hr)) - { - IDXGIDevice3 *real = (IDXGIDevice3 *)(*ppvObject); - *ppvObject = (IDXGIDevice3 *)(new WrappedIDXGIDevice3(real, m_pD3DDevice)); - return S_OK; - } - else - { - return E_NOINTERFACE; - } - } - else - { - string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGIDevice2 for interface: %s", guid.c_str()); - } - - return RefCountDXGIObject::QueryInterface(riid, ppvObject); + SAFE_RELEASE(m_pReal1); + SAFE_RELEASE(m_pReal2); + SAFE_RELEASE(m_pReal3); + SAFE_RELEASE(m_pReal); + SAFE_RELEASE(m_pD3DDevice); } HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice3::QueryInterface(REFIID riid, void **ppvObject) @@ -723,29 +558,277 @@ HRESULT STDMETHODCALLTYPE WrappedIDXGIDevice3::QueryInterface(REFIID riid, void *ppvObject = m_pD3DDevice->GetDeviceInterface(riid); return S_OK; } - else if(riid == __uuidof(IDXGIDevice1)) + else if(riid == __uuidof(IDXGIDevice)) { AddRef(); - *ppvObject = (IDXGIDevice1 *)this; + *ppvObject = (IDXGIDevice *)this; return S_OK; } + else if(riid == __uuidof(IDXGIDevice1)) + { + if(m_pReal1) + { + AddRef(); + *ppvObject = (IDXGIDevice1 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } else if(riid == __uuidof(IDXGIDevice2)) { - AddRef(); - *ppvObject = (IDXGIDevice2 *)this; - return S_OK; + if(m_pReal2) + { + AddRef(); + *ppvObject = (IDXGIDevice2 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } } else if(riid == __uuidof(IDXGIDevice3)) { - AddRef(); - *ppvObject = (IDXGIDevice3 *)this; - return S_OK; + if(m_pReal3) + { + AddRef(); + *ppvObject = (IDXGIDevice3 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } } else { string guid = ToStr::Get(riid); - RDCWARN("Querying IDXGIDevice3 for interface: %s", guid.c_str()); + RDCWARN("Querying IDXGIDevice for interface: %s", guid.c_str()); } return RefCountDXGIObject::QueryInterface(riid, ppvObject); } + +WrappedIDXGIFactory4::WrappedIDXGIFactory4(IDXGIFactory *real) + : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) +{ + m_pReal1 = NULL; + real->QueryInterface(__uuidof(IDXGIFactory1), (void **)&m_pReal1); + m_pReal2 = NULL; + real->QueryInterface(__uuidof(IDXGIFactory2), (void **)&m_pReal2); + m_pReal3 = NULL; + real->QueryInterface(__uuidof(IDXGIFactory3), (void **)&m_pReal3); + m_pReal4 = NULL; + real->QueryInterface(__uuidof(IDXGIFactory4), (void **)&m_pReal4); +} + +WrappedIDXGIFactory4::~WrappedIDXGIFactory4() +{ + SAFE_RELEASE(m_pReal1); + SAFE_RELEASE(m_pReal2); + SAFE_RELEASE(m_pReal3); + SAFE_RELEASE(m_pReal4); + SAFE_RELEASE(m_pReal); +} + +HRESULT STDMETHODCALLTYPE WrappedIDXGIFactory4::QueryInterface(REFIID riid, void **ppvObject) +{ + if(riid == __uuidof(IDXGIFactory)) + { + AddRef(); + *ppvObject = (IDXGIFactory *)this; + return S_OK; + } + else if(riid == __uuidof(IDXGIFactory1)) + { + if(m_pReal1) + { + AddRef(); + *ppvObject = (IDXGIFactory1 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(IDXGIFactory2)) + { + if(m_pReal2) + { + AddRef(); + *ppvObject = (IDXGIFactory2 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(IDXGIFactory3)) + { + if(m_pReal3) + { + AddRef(); + *ppvObject = (IDXGIFactory3 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else if(riid == __uuidof(IDXGIFactory4)) + { + if(m_pReal4) + { + AddRef(); + *ppvObject = (IDXGIFactory4 *)this; + return S_OK; + } + else + { + return E_NOINTERFACE; + } + } + else + { + string guid = ToStr::Get(riid); + RDCWARN("Querying IDXGIFactory for interface: %s", guid.c_str()); + } + + return RefCountDXGIObject::QueryInterface(riid, ppvObject); +} + +HRESULT WrappedIDXGIFactory4::CreateSwapChain(IUnknown *pDevice, DXGI_SWAP_CHAIN_DESC *pDesc, + IDXGISwapChain **ppSwapChain) +{ + ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + + if(wrapDevice) + { + if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pDesc) + { + pDesc->Windowed = TRUE; + } + + HRESULT ret = m_pReal->CreateSwapChain(wrapDevice->GetRealIUnknown(), pDesc, ppSwapChain); + + if(SUCCEEDED(ret)) + { + *ppSwapChain = + new WrappedIDXGISwapChain3(*ppSwapChain, pDesc ? pDesc->OutputWindow : NULL, wrapDevice); + } + + return ret; + } + + RDCERR("Creating swap chain with non-hooked device!"); + + return m_pReal->CreateSwapChain(pDevice, pDesc, ppSwapChain); +} + +HRESULT WrappedIDXGIFactory4::CreateSwapChainForHwnd( + IUnknown *pDevice, HWND hWnd, const DXGI_SWAP_CHAIN_DESC1 *pDesc, + const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, IDXGIOutput *pRestrictToOutput, + IDXGISwapChain1 **ppSwapChain) +{ + ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + + if(wrapDevice) + { + if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen && pFullscreenDesc) + { + pFullscreenDesc = NULL; + } + + HRESULT ret = m_pReal2->CreateSwapChainForHwnd(wrapDevice->GetRealIUnknown(), hWnd, pDesc, + pFullscreenDesc, pRestrictToOutput, ppSwapChain); + + if(SUCCEEDED(ret)) + { + *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, hWnd, wrapDevice); + } + + return ret; + } + else + { + RDCERR("Creating swap chain with non-hooked device!"); + } + + return m_pReal2->CreateSwapChainForHwnd(pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, + ppSwapChain); +} + +HRESULT WrappedIDXGIFactory4::CreateSwapChainForCoreWindow(IUnknown *pDevice, IUnknown *pWindow, + const DXGI_SWAP_CHAIN_DESC1 *pDesc, + IDXGIOutput *pRestrictToOutput, + IDXGISwapChain1 **ppSwapChain) +{ + ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + + if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen) + { + RDCWARN("Impossible to disallow fullscreen on call to CreateSwapChainForCoreWindow"); + } + + if(wrapDevice) + { + HRESULT ret = m_pReal2->CreateSwapChainForCoreWindow(wrapDevice->GetRealIUnknown(), pWindow, + pDesc, pRestrictToOutput, ppSwapChain); + + if(SUCCEEDED(ret)) + { + HWND wnd = NULL; + (*ppSwapChain)->GetHwnd(&wnd); + *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, wnd, wrapDevice); + } + + return ret; + } + else + { + RDCERR("Creating swap chain with non-hooked device!"); + } + + return m_pReal2->CreateSwapChainForCoreWindow(pDevice, pWindow, pDesc, pRestrictToOutput, + ppSwapChain); +} + +HRESULT WrappedIDXGIFactory4::CreateSwapChainForComposition(IUnknown *pDevice, + const DXGI_SWAP_CHAIN_DESC1 *pDesc, + IDXGIOutput *pRestrictToOutput, + IDXGISwapChain1 **ppSwapChain) +{ + ID3DDevice *wrapDevice = GetD3DDevice(pDevice); + + if(!RenderDoc::Inst().GetCaptureOptions().AllowFullscreen) + { + RDCWARN("Impossible to disallow fullscreen on call to CreateSwapChainForComposition"); + } + + if(wrapDevice) + { + HRESULT ret = m_pReal2->CreateSwapChainForComposition(wrapDevice->GetRealIUnknown(), pDesc, + pRestrictToOutput, ppSwapChain); + + if(SUCCEEDED(ret)) + { + HWND wnd = NULL; + (*ppSwapChain)->GetHwnd(&wnd); + *ppSwapChain = new WrappedIDXGISwapChain3(*ppSwapChain, wnd, wrapDevice); + } + + return ret; + } + else + { + RDCERR("Creating swap chain with non-hooked device!"); + } + + return m_pReal2->CreateSwapChainForComposition(pDevice, pDesc, pRestrictToOutput, ppSwapChain); +} diff --git a/renderdoc/driver/dxgi/dxgi_wrapped.h b/renderdoc/driver/dxgi/dxgi_wrapped.h index f811d1685..ab41ba2ca 100644 --- a/renderdoc/driver/dxgi/dxgi_wrapped.h +++ b/renderdoc/driver/dxgi/dxgi_wrapped.h @@ -813,203 +813,21 @@ public: _In_reads_(BufferCount) IUnknown *const *ppPresentQueue); }; -////////////////////////////////////////////////////////////////////////////// -// Crap classes we don't really care about, except capturing the swap chain - -class WrappedIDXGIAdapter : public IDXGIAdapter, public RefCountDXGIObject +class WrappedIDXGIAdapter3 : public IDXGIAdapter3, public RefCountDXGIObject { IDXGIAdapter *m_pReal; + IDXGIAdapter1 *m_pReal1; + IDXGIAdapter2 *m_pReal2; + IDXGIAdapter3 *m_pReal3; unsigned int m_iRefcount; public: - WrappedIDXGIAdapter(IDXGIAdapter *real) : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIAdapter() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIAdapter - - virtual HRESULT STDMETHODCALLTYPE EnumOutputs( - /* [in] */ UINT Output, - /* [annotation][out][in] */ - __out IDXGIOutput **ppOutput) - { - return m_pReal->EnumOutputs(Output, ppOutput); - } - - virtual HRESULT STDMETHODCALLTYPE GetDesc( - /* [annotation][out] */ - __out DXGI_ADAPTER_DESC *pDesc) - { - return m_pReal->GetDesc(pDesc); - } - - virtual HRESULT STDMETHODCALLTYPE CheckInterfaceSupport( - /* [annotation][in] */ - __in REFGUID InterfaceName, - /* [annotation][out] */ - __out LARGE_INTEGER *pUMDVersion) - { - return m_pReal->CheckInterfaceSupport(InterfaceName, pUMDVersion); - } -}; - -class WrappedIDXGIDevice : public IDXGIDevice, public RefCountDXGIObject -{ - IDXGIDevice *m_pReal; - ID3DDevice *m_pD3DDevice; - -public: - WrappedIDXGIDevice(IDXGIDevice *real, ID3DDevice *d3d) - : RefCountDXGIObject(real), m_pReal(real), m_pD3DDevice(d3d) - { - m_pD3DDevice->AddRef(); - } - - virtual ~WrappedIDXGIDevice() - { - SAFE_RELEASE(m_pReal); - SAFE_RELEASE(m_pD3DDevice); - } - - static const int AllocPoolCount = 4; - ALLOCATE_WITH_WRAPPED_POOL(WrappedIDXGIDevice, AllocPoolCount); + WrappedIDXGIAdapter3(IDXGIAdapter *real); + virtual ~WrappedIDXGIAdapter3(); IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - ID3DDevice *GetD3DDevice() { return m_pD3DDevice; } - ////////////////////////////// - // implement IDXGIDevice - - virtual HRESULT STDMETHODCALLTYPE GetAdapter( - /* [annotation][out] */ - __out IDXGIAdapter **pAdapter) - { - HRESULT ret = m_pReal->GetAdapter(pAdapter); - if(SUCCEEDED(ret)) - *pAdapter = new WrappedIDXGIAdapter(*pAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE CreateSurface( - /* [annotation][in] */ - __in const DXGI_SURFACE_DESC *pDesc, - /* [in] */ UINT NumSurfaces, - /* [in] */ DXGI_USAGE Usage, - /* [annotation][in] */ - __in_opt const DXGI_SHARED_RESOURCE *pSharedResource, - /* [annotation][out] */ - __out IDXGISurface **ppSurface) - { - return m_pReal->CreateSurface(pDesc, NumSurfaces, Usage, pSharedResource, ppSurface); - } - - virtual HRESULT STDMETHODCALLTYPE QueryResourceResidency( - /* [annotation][size_is][in] */ - __in_ecount(NumResources) IUnknown *const *ppResources, - /* [annotation][size_is][out] */ - __out_ecount(NumResources) DXGI_RESIDENCY *pResidencyStatus, - /* [in] */ UINT NumResources) - { - return m_pReal->QueryResourceResidency(ppResources, pResidencyStatus, NumResources); - } - - virtual HRESULT STDMETHODCALLTYPE SetGPUThreadPriority( - /* [in] */ INT Priority) - { - return m_pReal->SetGPUThreadPriority(Priority); - } - - virtual HRESULT STDMETHODCALLTYPE GetGPUThreadPriority( - /* [annotation][retval][out] */ - __out INT *pPriority) - { - return m_pReal->GetGPUThreadPriority(pPriority); - } -}; - -class WrappedIDXGIFactory : public IDXGIFactory, public RefCountDXGIObject -{ - IDXGIFactory *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIFactory(IDXGIFactory *real) : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIFactory() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIFactory - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(HWND WindowHandle, UINT Flags) - { - return m_pReal->MakeWindowAssociation(WindowHandle, Flags); - } - - virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation( - /* [annotation][out] */ - __out HWND *pWindowHandle) - { - return m_pReal->GetWindowAssociation(pWindowHandle); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChain( - /* [annotation][in] */ - __in IUnknown *pDevice, - /* [annotation][in] */ - __in DXGI_SWAP_CHAIN_DESC *pDesc, - /* [annotation][out] */ - __out IDXGISwapChain **ppSwapChain) - { - return WrappedIDXGIFactory::staticCreateSwapChain(m_pReal, pDevice, pDesc, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - /* [in] */ HMODULE Module, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - static HRESULT staticCreateSwapChain(IDXGIFactory *factory, IUnknown *pDevice, - DXGI_SWAP_CHAIN_DESC *pDesc, IDXGISwapChain **ppSwapChain); -}; - -// version 1 - -class WrappedIDXGIAdapter1 : public IDXGIAdapter1, public RefCountDXGIObject -{ - IDXGIAdapter1 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIAdapter1(IDXGIAdapter1 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIAdapter1() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - ////////////////////////////// // implement IDXGIAdapter @@ -1043,314 +861,88 @@ public: virtual HRESULT STDMETHODCALLTYPE GetDesc1( /* [out] */ DXGI_ADAPTER_DESC1 *pDesc) { - return m_pReal->GetDesc1(pDesc); + return m_pReal1->GetDesc1(pDesc); + } + + ////////////////////////////// + // implement IDXGIAdapter2 + + virtual HRESULT STDMETHODCALLTYPE GetDesc2( + /* [annotation][out] */ + _Out_ DXGI_ADAPTER_DESC2 *pDesc) + { + return m_pReal2->GetDesc2(pDesc); + } + + ////////////////////////////// + // implement IDXGIAdapter3 + + virtual HRESULT STDMETHODCALLTYPE RegisterHardwareContentProtectionTeardownStatusEvent( + /* [annotation][in] */ + _In_ HANDLE hEvent, + /* [annotation][out] */ + _Out_ DWORD *pdwCookie) + { + return m_pReal3->RegisterHardwareContentProtectionTeardownStatusEvent(hEvent, pdwCookie); + } + + virtual void STDMETHODCALLTYPE UnregisterHardwareContentProtectionTeardownStatus( + /* [annotation][in] */ + _In_ DWORD dwCookie) + { + return m_pReal3->UnregisterHardwareContentProtectionTeardownStatus(dwCookie); + } + + virtual HRESULT STDMETHODCALLTYPE QueryVideoMemoryInfo( + /* [annotation][in] */ + _In_ UINT NodeIndex, + /* [annotation][in] */ + _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, + /* [annotation][out] */ + _Out_ DXGI_QUERY_VIDEO_MEMORY_INFO *pVideoMemoryInfo) + { + return m_pReal3->QueryVideoMemoryInfo(NodeIndex, MemorySegmentGroup, pVideoMemoryInfo); + } + + virtual HRESULT STDMETHODCALLTYPE SetVideoMemoryReservation( + /* [annotation][in] */ + _In_ UINT NodeIndex, + /* [annotation][in] */ + _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, + /* [annotation][in] */ + _In_ UINT64 Reservation) + { + return m_pReal3->SetVideoMemoryReservation(NodeIndex, MemorySegmentGroup, Reservation); + } + + virtual HRESULT STDMETHODCALLTYPE RegisterVideoMemoryBudgetChangeNotificationEvent( + /* [annotation][in] */ + _In_ HANDLE hEvent, + /* [annotation][out] */ + _Out_ DWORD *pdwCookie) + { + return m_pReal3->RegisterVideoMemoryBudgetChangeNotificationEvent(hEvent, pdwCookie); + } + + virtual void STDMETHODCALLTYPE UnregisterVideoMemoryBudgetChangeNotification( + /* [annotation][in] */ + _In_ DWORD dwCookie) + { + return m_pReal3->UnregisterVideoMemoryBudgetChangeNotification(dwCookie); } }; -class WrappedIDXGIDevice1 : public IDXGIDevice1, public RefCountDXGIObject -{ - IDXGIDevice1 *m_pReal; - ID3DDevice *m_pD3DDevice; - -public: - WrappedIDXGIDevice1(IDXGIDevice1 *real, ID3DDevice *d3d) - : RefCountDXGIObject(real), m_pReal(real), m_pD3DDevice(d3d) - { - m_pD3DDevice->AddRef(); - } - virtual ~WrappedIDXGIDevice1() - { - SAFE_RELEASE(m_pReal); - SAFE_RELEASE(m_pD3DDevice); - } - - static const int AllocPoolCount = 4; - ALLOCATE_WITH_WRAPPED_POOL(WrappedIDXGIDevice1, AllocPoolCount); - - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - - ID3DDevice *GetD3DDevice() { return m_pD3DDevice; } - ////////////////////////////// - // implement IDXGIDevice - - virtual HRESULT STDMETHODCALLTYPE GetAdapter( - /* [annotation][out] */ - __out IDXGIAdapter **pAdapter) - { - HRESULT ret = m_pReal->GetAdapter(pAdapter); - if(SUCCEEDED(ret)) - *pAdapter = new WrappedIDXGIAdapter(*pAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE CreateSurface( - /* [annotation][in] */ - __in const DXGI_SURFACE_DESC *pDesc, - /* [in] */ UINT NumSurfaces, - /* [in] */ DXGI_USAGE Usage, - /* [annotation][in] */ - __in_opt const DXGI_SHARED_RESOURCE *pSharedResource, - /* [annotation][out] */ - __out IDXGISurface **ppSurface) - { - return m_pReal->CreateSurface(pDesc, NumSurfaces, Usage, pSharedResource, ppSurface); - } - - virtual HRESULT STDMETHODCALLTYPE QueryResourceResidency( - /* [annotation][size_is][in] */ - __in_ecount(NumResources) IUnknown *const *ppResources, - /* [annotation][size_is][out] */ - __out_ecount(NumResources) DXGI_RESIDENCY *pResidencyStatus, - /* [in] */ UINT NumResources) - { - return m_pReal->QueryResourceResidency(ppResources, pResidencyStatus, NumResources); - } - - virtual HRESULT STDMETHODCALLTYPE SetGPUThreadPriority( - /* [in] */ INT Priority) - { - return m_pReal->SetGPUThreadPriority(Priority); - } - - virtual HRESULT STDMETHODCALLTYPE GetGPUThreadPriority( - /* [annotation][retval][out] */ - __out INT *pPriority) - { - return m_pReal->GetGPUThreadPriority(pPriority); - } - - ////////////////////////////// - // implement IDXGIDevice1 - - virtual HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency( - /* [in] */ UINT MaxLatency) - { - return m_pReal->SetMaximumFrameLatency(MaxLatency); - } - - virtual HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency( - /* [annotation][out] */ - __out UINT *pMaxLatency) - { - return m_pReal->GetMaximumFrameLatency(pMaxLatency); - } -}; - -class WrappedIDXGIFactory1 : public IDXGIFactory1, public RefCountDXGIObject -{ - IDXGIFactory1 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIFactory1(IDXGIFactory1 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIFactory1() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIFactory - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(HWND WindowHandle, UINT Flags) - { - return m_pReal->MakeWindowAssociation(WindowHandle, Flags); - } - - virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation( - /* [annotation][out] */ - __out HWND *pWindowHandle) - { - return m_pReal->GetWindowAssociation(pWindowHandle); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChain( - /* [annotation][in] */ - __in IUnknown *pDevice, - /* [annotation][in] */ - __in DXGI_SWAP_CHAIN_DESC *pDesc, - /* [annotation][out] */ - __out IDXGISwapChain **ppSwapChain) - { - return WrappedIDXGIFactory::staticCreateSwapChain(m_pReal, pDevice, pDesc, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - /* [in] */ HMODULE Module, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory1 - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters1( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter1 **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters1(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter1(*ppAdapter); - return ret; - } - - virtual BOOL STDMETHODCALLTYPE IsCurrent(void) { return m_pReal->IsCurrent(); } -}; - -class WrappedIDXGIDevice2 : public IDXGIDevice2, public RefCountDXGIObject -{ - IDXGIDevice2 *m_pReal; - ID3DDevice *m_pD3DDevice; - -public: - WrappedIDXGIDevice2(IDXGIDevice2 *real, ID3DDevice *d3d) - : RefCountDXGIObject(real), m_pReal(real), m_pD3DDevice(d3d) - { - m_pD3DDevice->AddRef(); - } - virtual ~WrappedIDXGIDevice2() - { - SAFE_RELEASE(m_pReal); - SAFE_RELEASE(m_pD3DDevice); - } - - static const int AllocPoolCount = 4; - ALLOCATE_WITH_WRAPPED_POOL(WrappedIDXGIDevice2, AllocPoolCount); - - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; - HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); - - ID3DDevice *GetD3DDevice() { return m_pD3DDevice; } - ////////////////////////////// - // implement IDXGIDevice - - virtual HRESULT STDMETHODCALLTYPE GetAdapter( - /* [annotation][out] */ - __out IDXGIAdapter **pAdapter) - { - HRESULT ret = m_pReal->GetAdapter(pAdapter); - if(SUCCEEDED(ret)) - *pAdapter = new WrappedIDXGIAdapter(*pAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE CreateSurface( - /* [annotation][in] */ - __in const DXGI_SURFACE_DESC *pDesc, - /* [in] */ UINT NumSurfaces, - /* [in] */ DXGI_USAGE Usage, - /* [annotation][in] */ - __in_opt const DXGI_SHARED_RESOURCE *pSharedResource, - /* [annotation][out] */ - __out IDXGISurface **ppSurface) - { - return m_pReal->CreateSurface(pDesc, NumSurfaces, Usage, pSharedResource, ppSurface); - } - - virtual HRESULT STDMETHODCALLTYPE QueryResourceResidency( - /* [annotation][size_is][in] */ - __in_ecount(NumResources) IUnknown *const *ppResources, - /* [annotation][size_is][out] */ - __out_ecount(NumResources) DXGI_RESIDENCY *pResidencyStatus, - /* [in] */ UINT NumResources) - { - return m_pReal->QueryResourceResidency(ppResources, pResidencyStatus, NumResources); - } - - virtual HRESULT STDMETHODCALLTYPE SetGPUThreadPriority( - /* [in] */ INT Priority) - { - return m_pReal->SetGPUThreadPriority(Priority); - } - - virtual HRESULT STDMETHODCALLTYPE GetGPUThreadPriority( - /* [annotation][retval][out] */ - __out INT *pPriority) - { - return m_pReal->GetGPUThreadPriority(pPriority); - } - - ////////////////////////////// - // implement IDXGIDevice1 - - virtual HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency( - /* [in] */ UINT MaxLatency) - { - return m_pReal->SetMaximumFrameLatency(MaxLatency); - } - - virtual HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency( - /* [annotation][out] */ - __out UINT *pMaxLatency) - { - return m_pReal->GetMaximumFrameLatency(pMaxLatency); - } - - ////////////////////////////// - // implement IDXGIDevice2 - virtual HRESULT STDMETHODCALLTYPE OfferResources( - /* [annotation][in] */ - _In_ UINT NumResources, - /* [annotation][size_is][in] */ - _In_reads_(NumResources) IDXGIResource *const *ppResources, - /* [annotation][in] */ - _In_ DXGI_OFFER_RESOURCE_PRIORITY Priority) - { - return m_pReal->OfferResources(NumResources, ppResources, Priority); - } - - virtual HRESULT STDMETHODCALLTYPE ReclaimResources( - /* [annotation][in] */ - _In_ UINT NumResources, - /* [annotation][size_is][in] */ - _In_reads_(NumResources) IDXGIResource *const *ppResources, - /* [annotation][size_is][out] */ - _Out_writes_all_opt_(NumResources) BOOL *pDiscarded) - { - return m_pReal->ReclaimResources(NumResources, ppResources, pDiscarded); - } - - virtual HRESULT STDMETHODCALLTYPE EnqueueSetEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent) - { - return m_pReal->EnqueueSetEvent(hEvent); - } -}; class WrappedIDXGIDevice3 : public IDXGIDevice3, public RefCountDXGIObject { - IDXGIDevice3 *m_pReal; + IDXGIDevice *m_pReal; + IDXGIDevice1 *m_pReal1; + IDXGIDevice2 *m_pReal2; + IDXGIDevice3 *m_pReal3; ID3DDevice *m_pD3DDevice; public: - WrappedIDXGIDevice3(IDXGIDevice3 *real, ID3DDevice *d3d) - : RefCountDXGIObject(real), m_pReal(real), m_pD3DDevice(d3d) - { - m_pD3DDevice->AddRef(); - } - virtual ~WrappedIDXGIDevice3() - { - SAFE_RELEASE(m_pReal); - SAFE_RELEASE(m_pD3DDevice); - } + WrappedIDXGIDevice3(IDXGIDevice *real, ID3DDevice *d3d); + virtual ~WrappedIDXGIDevice3(); static const int AllocPoolCount = 4; ALLOCATE_WITH_WRAPPED_POOL(WrappedIDXGIDevice3, AllocPoolCount); @@ -1368,7 +960,7 @@ public: { HRESULT ret = m_pReal->GetAdapter(pAdapter); if(SUCCEEDED(ret)) - *pAdapter = new WrappedIDXGIAdapter(*pAdapter); + *pAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(*pAdapter)); return ret; } @@ -1414,14 +1006,14 @@ public: virtual HRESULT STDMETHODCALLTYPE SetMaximumFrameLatency( /* [in] */ UINT MaxLatency) { - return m_pReal->SetMaximumFrameLatency(MaxLatency); + return m_pReal1->SetMaximumFrameLatency(MaxLatency); } virtual HRESULT STDMETHODCALLTYPE GetMaximumFrameLatency( /* [annotation][out] */ __out UINT *pMaxLatency) { - return m_pReal->GetMaximumFrameLatency(pMaxLatency); + return m_pReal1->GetMaximumFrameLatency(pMaxLatency); } ////////////////////////////// @@ -1435,7 +1027,7 @@ public: /* [annotation][in] */ _In_ DXGI_OFFER_RESOURCE_PRIORITY Priority) { - return m_pReal->OfferResources(NumResources, ppResources, Priority); + return m_pReal2->OfferResources(NumResources, ppResources, Priority); } virtual HRESULT STDMETHODCALLTYPE ReclaimResources( @@ -1446,666 +1038,37 @@ public: /* [annotation][size_is][out] */ _Out_writes_all_opt_(NumResources) BOOL *pDiscarded) { - return m_pReal->ReclaimResources(NumResources, ppResources, pDiscarded); + return m_pReal2->ReclaimResources(NumResources, ppResources, pDiscarded); } virtual HRESULT STDMETHODCALLTYPE EnqueueSetEvent( /* [annotation][in] */ _In_ HANDLE hEvent) { - return m_pReal->EnqueueSetEvent(hEvent); + return m_pReal2->EnqueueSetEvent(hEvent); } ////////////////////////////// // implement IDXGIDevice3 - virtual void STDMETHODCALLTYPE Trim() { m_pReal->Trim(); } -}; - -class WrappedIDXGIAdapter2 : public IDXGIAdapter2, public RefCountDXGIObject -{ - IDXGIAdapter2 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIAdapter2(IDXGIAdapter2 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIAdapter2() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIAdapter - - virtual HRESULT STDMETHODCALLTYPE EnumOutputs( - /* [in] */ UINT Output, - /* [annotation][out][in] */ - __out IDXGIOutput **ppOutput) - { - return m_pReal->EnumOutputs(Output, ppOutput); - } - - virtual HRESULT STDMETHODCALLTYPE GetDesc( - /* [annotation][out] */ - __out DXGI_ADAPTER_DESC *pDesc) - { - return m_pReal->GetDesc(pDesc); - } - - virtual HRESULT STDMETHODCALLTYPE CheckInterfaceSupport( - /* [annotation][in] */ - __in REFGUID InterfaceName, - /* [annotation][out] */ - __out LARGE_INTEGER *pUMDVersion) - { - return m_pReal->CheckInterfaceSupport(InterfaceName, pUMDVersion); - } - - ////////////////////////////// - // implement IDXGIAdapter1 - - virtual HRESULT STDMETHODCALLTYPE GetDesc1( - /* [out] */ DXGI_ADAPTER_DESC1 *pDesc) - { - return m_pReal->GetDesc1(pDesc); - } - - ////////////////////////////// - // implement IDXGIAdapter2 - - virtual HRESULT STDMETHODCALLTYPE GetDesc2( - /* [annotation][out] */ - _Out_ DXGI_ADAPTER_DESC2 *pDesc) - { - return m_pReal->GetDesc2(pDesc); - } -}; - -class WrappedIDXGIFactory2 : public IDXGIFactory2, public RefCountDXGIObject -{ - IDXGIFactory2 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIFactory2(IDXGIFactory2 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIFactory2() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIFactory - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(HWND WindowHandle, UINT Flags) - { - return m_pReal->MakeWindowAssociation(WindowHandle, Flags); - } - - virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation( - /* [annotation][out] */ - __out HWND *pWindowHandle) - { - return m_pReal->GetWindowAssociation(pWindowHandle); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChain( - /* [annotation][in] */ - __in IUnknown *pDevice, - /* [annotation][in] */ - __in DXGI_SWAP_CHAIN_DESC *pDesc, - /* [annotation][out] */ - __out IDXGISwapChain **ppSwapChain) - { - return WrappedIDXGIFactory::staticCreateSwapChain(m_pReal, pDevice, pDesc, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - /* [in] */ HMODULE Module, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory1 - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters1( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter1 **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters1(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter1(*ppAdapter); - return ret; - } - - virtual BOOL STDMETHODCALLTYPE IsCurrent(void) { return m_pReal->IsCurrent(); } - ////////////////////////////// - // implement IDXGIFactory2 - - virtual BOOL STDMETHODCALLTYPE IsWindowedStereoEnabled(void) - { - return m_pReal->IsWindowedStereoEnabled(); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ HWND hWnd, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForHwnd( - m_pReal, pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForCoreWindow( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ IUnknown *pWindow, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForCoreWindow( - m_pReal, pDevice, pWindow, pDesc, pRestrictToOutput, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid( - /* [annotation] */ - _In_ HANDLE hResource, - /* [annotation] */ - _Out_ LUID *pLuid) - { - return m_pReal->GetSharedResourceAdapterLuid(hResource, pLuid); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterStereoStatusEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterStereoStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterStereoStatus(dwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterOcclusionStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterOcclusionStatus(dwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForComposition( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Outptr_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForComposition( - m_pReal, pDevice, pDesc, pRestrictToOutput, ppSwapChain); - } - - // static functions to share implementation between this and WrappedIDXGIFactory3 - - static HRESULT staticCreateSwapChainForHwnd(IDXGIFactory2 *factory, IUnknown *pDevice, HWND hWnd, - const DXGI_SWAP_CHAIN_DESC1 *pDesc, - const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, - IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForCoreWindow(IDXGIFactory2 *factory, IUnknown *pDevice, - IUnknown *pWindow, - const DXGI_SWAP_CHAIN_DESC1 *pDesc, - IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForComposition(IDXGIFactory2 *factory, IUnknown *pDevice, - const DXGI_SWAP_CHAIN_DESC1 *pDesc, - IDXGIOutput *pRestrictToOutput, - IDXGISwapChain1 **ppSwapChain); -}; - -class WrappedIDXGIFactory3 : public IDXGIFactory3, public RefCountDXGIObject -{ - IDXGIFactory3 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIFactory3(IDXGIFactory3 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIFactory3() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIFactory - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - virtual HRESULT STDMETHODCALLTYPE MakeWindowAssociation(HWND WindowHandle, UINT Flags) - { - return m_pReal->MakeWindowAssociation(WindowHandle, Flags); - } - - virtual HRESULT STDMETHODCALLTYPE GetWindowAssociation( - /* [annotation][out] */ - __out HWND *pWindowHandle) - { - return m_pReal->GetWindowAssociation(pWindowHandle); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChain( - /* [annotation][in] */ - __in IUnknown *pDevice, - /* [annotation][in] */ - __in DXGI_SWAP_CHAIN_DESC *pDesc, - /* [annotation][out] */ - __out IDXGISwapChain **ppSwapChain) - { - return WrappedIDXGIFactory::staticCreateSwapChain(m_pReal, pDevice, pDesc, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( - /* [in] */ HMODULE Module, - /* [annotation][out] */ - __out IDXGIAdapter **ppAdapter) - { - HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); - return ret; - } - - ////////////////////////////// - // implement IDXGIFactory1 - - virtual HRESULT STDMETHODCALLTYPE EnumAdapters1( - /* [in] */ UINT Adapter, - /* [annotation][out] */ - __out IDXGIAdapter1 **ppAdapter) - { - HRESULT ret = m_pReal->EnumAdapters1(Adapter, ppAdapter); - if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter1(*ppAdapter); - return ret; - } - - virtual BOOL STDMETHODCALLTYPE IsCurrent(void) { return m_pReal->IsCurrent(); } - ////////////////////////////// - // implement IDXGIFactory2 - - virtual BOOL STDMETHODCALLTYPE IsWindowedStereoEnabled(void) - { - return m_pReal->IsWindowedStereoEnabled(); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ HWND hWnd, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForHwnd( - m_pReal, pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForCoreWindow( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ IUnknown *pWindow, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForCoreWindow( - m_pReal, pDevice, pWindow, pDesc, pRestrictToOutput, ppSwapChain); - } - - virtual HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid( - /* [annotation] */ - _In_ HANDLE hResource, - /* [annotation] */ - _Out_ LUID *pLuid) - { - return m_pReal->GetSharedResourceAdapterLuid(hResource, pLuid); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterStereoStatusEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterStereoStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterStereoStatus(dwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusWindow( - /* [annotation][in] */ - _In_ HWND WindowHandle, - /* [annotation][in] */ - _In_ UINT wMsg, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterOcclusionStatusEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterOcclusionStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterOcclusionStatus(dwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForComposition( - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Outptr_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForComposition( - m_pReal, pDevice, pDesc, pRestrictToOutput, ppSwapChain); - } - - // static functions to share implementation between this and WrappedIDXGIFactory3 - - static HRESULT staticCreateSwapChainForHwnd( - IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ HWND hWnd, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForCoreWindow(IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ IUnknown *pWindow, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForComposition(IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Outptr_ IDXGISwapChain1 **ppSwapChain); - - ////////////////////////////// - // implement IDXGIFactory3 - - virtual UINT STDMETHODCALLTYPE GetCreationFlags(void) { return m_pReal->GetCreationFlags(); } -}; - -class WrappedIDXGIAdapter3 : public IDXGIAdapter3, public RefCountDXGIObject -{ - IDXGIAdapter3 *m_pReal; - unsigned int m_iRefcount; - -public: - WrappedIDXGIAdapter3(IDXGIAdapter3 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIAdapter3() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; - - ////////////////////////////// - // implement IDXGIAdapter - - virtual HRESULT STDMETHODCALLTYPE EnumOutputs( - /* [in] */ UINT Output, - /* [annotation][out][in] */ - __out IDXGIOutput **ppOutput) - { - return m_pReal->EnumOutputs(Output, ppOutput); - } - - virtual HRESULT STDMETHODCALLTYPE GetDesc( - /* [annotation][out] */ - __out DXGI_ADAPTER_DESC *pDesc) - { - return m_pReal->GetDesc(pDesc); - } - - virtual HRESULT STDMETHODCALLTYPE CheckInterfaceSupport( - /* [annotation][in] */ - __in REFGUID InterfaceName, - /* [annotation][out] */ - __out LARGE_INTEGER *pUMDVersion) - { - return m_pReal->CheckInterfaceSupport(InterfaceName, pUMDVersion); - } - - ////////////////////////////// - // implement IDXGIAdapter1 - - virtual HRESULT STDMETHODCALLTYPE GetDesc1( - /* [out] */ DXGI_ADAPTER_DESC1 *pDesc) - { - return m_pReal->GetDesc1(pDesc); - } - - ////////////////////////////// - // implement IDXGIAdapter2 - - virtual HRESULT STDMETHODCALLTYPE GetDesc2( - /* [annotation][out] */ - _Out_ DXGI_ADAPTER_DESC2 *pDesc) - { - return m_pReal->GetDesc2(pDesc); - } - - ////////////////////////////// - // implement IDXGIAdapter3 - - virtual HRESULT STDMETHODCALLTYPE RegisterHardwareContentProtectionTeardownStatusEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterHardwareContentProtectionTeardownStatusEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterHardwareContentProtectionTeardownStatus( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterHardwareContentProtectionTeardownStatus(dwCookie); - } - - virtual HRESULT STDMETHODCALLTYPE QueryVideoMemoryInfo( - /* [annotation][in] */ - _In_ UINT NodeIndex, - /* [annotation][in] */ - _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, - /* [annotation][out] */ - _Out_ DXGI_QUERY_VIDEO_MEMORY_INFO *pVideoMemoryInfo) - { - return m_pReal->QueryVideoMemoryInfo(NodeIndex, MemorySegmentGroup, pVideoMemoryInfo); - } - - virtual HRESULT STDMETHODCALLTYPE SetVideoMemoryReservation( - /* [annotation][in] */ - _In_ UINT NodeIndex, - /* [annotation][in] */ - _In_ DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup, - /* [annotation][in] */ - _In_ UINT64 Reservation) - { - return m_pReal->SetVideoMemoryReservation(NodeIndex, MemorySegmentGroup, Reservation); - } - - virtual HRESULT STDMETHODCALLTYPE RegisterVideoMemoryBudgetChangeNotificationEvent( - /* [annotation][in] */ - _In_ HANDLE hEvent, - /* [annotation][out] */ - _Out_ DWORD *pdwCookie) - { - return m_pReal->RegisterVideoMemoryBudgetChangeNotificationEvent(hEvent, pdwCookie); - } - - virtual void STDMETHODCALLTYPE UnregisterVideoMemoryBudgetChangeNotification( - /* [annotation][in] */ - _In_ DWORD dwCookie) - { - return m_pReal->UnregisterVideoMemoryBudgetChangeNotification(dwCookie); - } + virtual void STDMETHODCALLTYPE Trim() { m_pReal3->Trim(); } }; class WrappedIDXGIFactory4 : public IDXGIFactory4, public RefCountDXGIObject { - IDXGIFactory4 *m_pReal; + IDXGIFactory *m_pReal; + IDXGIFactory1 *m_pReal1; + IDXGIFactory2 *m_pReal2; + IDXGIFactory3 *m_pReal3; + IDXGIFactory4 *m_pReal4; unsigned int m_iRefcount; public: - WrappedIDXGIFactory4(IDXGIFactory4 *real) - : RefCountDXGIObject(real), m_pReal(real), m_iRefcount(1) - { - } - virtual ~WrappedIDXGIFactory4() { SAFE_RELEASE(m_pReal); } - IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT; + WrappedIDXGIFactory4(IDXGIFactory *real); + virtual ~WrappedIDXGIFactory4(); + + IMPLEMENT_IDXGIOBJECT_WITH_REFCOUNTDXGIOBJECT_CUSTOMQUERY; + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject); ////////////////////////////// // implement IDXGIFactory @@ -2117,7 +1080,7 @@ public: { HRESULT ret = m_pReal->EnumAdapters(Adapter, ppAdapter); if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); + *ppAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(*ppAdapter)); return ret; } @@ -2139,10 +1102,7 @@ public: /* [annotation][in] */ __in DXGI_SWAP_CHAIN_DESC *pDesc, /* [annotation][out] */ - __out IDXGISwapChain **ppSwapChain) - { - return WrappedIDXGIFactory::staticCreateSwapChain(m_pReal, pDevice, pDesc, ppSwapChain); - } + __out IDXGISwapChain **ppSwapChain); virtual HRESULT STDMETHODCALLTYPE CreateSoftwareAdapter( /* [in] */ HMODULE Module, @@ -2151,7 +1111,7 @@ public: { HRESULT ret = m_pReal->CreateSoftwareAdapter(Module, ppAdapter); if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter(*ppAdapter); + *ppAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(*ppAdapter)); return ret; } @@ -2163,19 +1123,19 @@ public: /* [annotation][out] */ __out IDXGIAdapter1 **ppAdapter) { - HRESULT ret = m_pReal->EnumAdapters1(Adapter, ppAdapter); + HRESULT ret = m_pReal1->EnumAdapters1(Adapter, ppAdapter); if(SUCCEEDED(ret)) - *ppAdapter = new WrappedIDXGIAdapter1(*ppAdapter); + *ppAdapter = (IDXGIAdapter1 *)(new WrappedIDXGIAdapter3(*ppAdapter)); return ret; } - virtual BOOL STDMETHODCALLTYPE IsCurrent(void) { return m_pReal->IsCurrent(); } + virtual BOOL STDMETHODCALLTYPE IsCurrent(void) { return m_pReal1->IsCurrent(); } ////////////////////////////// // implement IDXGIFactory2 virtual BOOL STDMETHODCALLTYPE IsWindowedStereoEnabled(void) { - return m_pReal->IsWindowedStereoEnabled(); + return m_pReal2->IsWindowedStereoEnabled(); } virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForHwnd( @@ -2190,11 +1150,7 @@ public: /* [annotation][in] */ _In_opt_ IDXGIOutput *pRestrictToOutput, /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForHwnd( - m_pReal, pDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput, ppSwapChain); - } + _Out_ IDXGISwapChain1 **ppSwapChain); virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForCoreWindow( /* [annotation][in] */ @@ -2206,11 +1162,7 @@ public: /* [annotation][in] */ _In_opt_ IDXGIOutput *pRestrictToOutput, /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForCoreWindow( - m_pReal, pDevice, pWindow, pDesc, pRestrictToOutput, ppSwapChain); - } + _Out_ IDXGISwapChain1 **ppSwapChain); virtual HRESULT STDMETHODCALLTYPE GetSharedResourceAdapterLuid( /* [annotation] */ @@ -2218,7 +1170,7 @@ public: /* [annotation] */ _Out_ LUID *pLuid) { - return m_pReal->GetSharedResourceAdapterLuid(hResource, pLuid); + return m_pReal2->GetSharedResourceAdapterLuid(hResource, pLuid); } virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusWindow( @@ -2229,7 +1181,7 @@ public: /* [annotation][out] */ _Out_ DWORD *pdwCookie) { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); + return m_pReal2->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); } virtual HRESULT STDMETHODCALLTYPE RegisterStereoStatusEvent( @@ -2238,14 +1190,14 @@ public: /* [annotation][out] */ _Out_ DWORD *pdwCookie) { - return m_pReal->RegisterStereoStatusEvent(hEvent, pdwCookie); + return m_pReal2->RegisterStereoStatusEvent(hEvent, pdwCookie); } virtual void STDMETHODCALLTYPE UnregisterStereoStatus( /* [annotation][in] */ _In_ DWORD dwCookie) { - return m_pReal->UnregisterStereoStatus(dwCookie); + return m_pReal2->UnregisterStereoStatus(dwCookie); } virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusWindow( @@ -2256,7 +1208,7 @@ public: /* [annotation][out] */ _Out_ DWORD *pdwCookie) { - return m_pReal->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); + return m_pReal2->RegisterOcclusionStatusWindow(WindowHandle, wMsg, pdwCookie); } virtual HRESULT STDMETHODCALLTYPE RegisterOcclusionStatusEvent( @@ -2265,14 +1217,14 @@ public: /* [annotation][out] */ _Out_ DWORD *pdwCookie) { - return m_pReal->RegisterOcclusionStatusEvent(hEvent, pdwCookie); + return m_pReal2->RegisterOcclusionStatusEvent(hEvent, pdwCookie); } virtual void STDMETHODCALLTYPE UnregisterOcclusionStatus( /* [annotation][in] */ _In_ DWORD dwCookie) { - return m_pReal->UnregisterOcclusionStatus(dwCookie); + return m_pReal2->UnregisterOcclusionStatus(dwCookie); } virtual HRESULT STDMETHODCALLTYPE CreateSwapChainForComposition( @@ -2283,55 +1235,12 @@ public: /* [annotation][in] */ _In_opt_ IDXGIOutput *pRestrictToOutput, /* [annotation][out] */ - _Outptr_ IDXGISwapChain1 **ppSwapChain) - { - return WrappedIDXGIFactory2::staticCreateSwapChainForComposition( - m_pReal, pDevice, pDesc, pRestrictToOutput, ppSwapChain); - } - - // static functions to share implementation between this and WrappedIDXGIFactory3 - - static HRESULT staticCreateSwapChainForHwnd( - IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ HWND hWnd, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ const DXGI_SWAP_CHAIN_FULLSCREEN_DESC *pFullscreenDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForCoreWindow(IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ IUnknown *pWindow, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Out_ IDXGISwapChain1 **ppSwapChain); - - static HRESULT staticCreateSwapChainForComposition(IDXGIFactory2 *factory, - /* [annotation][in] */ - _In_ IUnknown *pDevice, - /* [annotation][in] */ - _In_ const DXGI_SWAP_CHAIN_DESC1 *pDesc, - /* [annotation][in] */ - _In_opt_ IDXGIOutput *pRestrictToOutput, - /* [annotation][out] */ - _Outptr_ IDXGISwapChain1 **ppSwapChain); + _Outptr_ IDXGISwapChain1 **ppSwapChain); ////////////////////////////// // implement IDXGIFactory3 - virtual UINT STDMETHODCALLTYPE GetCreationFlags(void) { return m_pReal->GetCreationFlags(); } + virtual UINT STDMETHODCALLTYPE GetCreationFlags(void) { return m_pReal3->GetCreationFlags(); } ////////////////////////////// // implement IDXGIFactory4 @@ -2343,11 +1252,29 @@ public: /* [annotation] */ _COM_Outptr_ void **ppvAdapter) { - HRESULT ret = m_pReal->EnumAdapterByLuid(AdapterLuid, riid, ppvAdapter); + HRESULT ret = m_pReal4->EnumAdapterByLuid(AdapterLuid, riid, ppvAdapter); if(SUCCEEDED(ret) && ppvAdapter && *ppvAdapter) { - IDXGIAdapter *adapter = (IDXGIAdapter *)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter(adapter)); + if(riid == __uuidof(IDXGIAdapter3)) + { + IDXGIAdapter3 *adapter = (IDXGIAdapter3 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter3 *)(new WrappedIDXGIAdapter3(adapter)); + } + else if(riid == __uuidof(IDXGIAdapter2)) + { + IDXGIAdapter2 *adapter = (IDXGIAdapter2 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter2 *)(new WrappedIDXGIAdapter3(adapter)); + } + else if(riid == __uuidof(IDXGIAdapter1)) + { + IDXGIAdapter1 *adapter = (IDXGIAdapter1 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter1 *)(new WrappedIDXGIAdapter3(adapter)); + } + else + { + IDXGIAdapter *adapter = (IDXGIAdapter *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(adapter)); + } } return ret; } @@ -2358,11 +1285,29 @@ public: /* [annotation] */ _COM_Outptr_ void **ppvAdapter) { - HRESULT ret = m_pReal->EnumWarpAdapter(riid, ppvAdapter); + HRESULT ret = m_pReal4->EnumWarpAdapter(riid, ppvAdapter); if(SUCCEEDED(ret) && ppvAdapter && *ppvAdapter) { - IDXGIAdapter *adapter = (IDXGIAdapter *)*ppvAdapter; - *ppvAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter(adapter)); + if(riid == __uuidof(IDXGIAdapter3)) + { + IDXGIAdapter3 *adapter = (IDXGIAdapter3 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter3 *)(new WrappedIDXGIAdapter3(adapter)); + } + else if(riid == __uuidof(IDXGIAdapter2)) + { + IDXGIAdapter2 *adapter = (IDXGIAdapter2 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter2 *)(new WrappedIDXGIAdapter3(adapter)); + } + else if(riid == __uuidof(IDXGIAdapter1)) + { + IDXGIAdapter1 *adapter = (IDXGIAdapter1 *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter1 *)(new WrappedIDXGIAdapter3(adapter)); + } + else + { + IDXGIAdapter *adapter = (IDXGIAdapter *)*ppvAdapter; + *ppvAdapter = (IDXGIAdapter *)(new WrappedIDXGIAdapter3(adapter)); + } } return ret; }