Refactor to use Microsoft::WRL::ComPtr (#1599)

This commit is contained in:
oltolm 2025-06-16 23:25:06 +02:00 committed by GitHub
parent da98aa4176
commit 2f02fda9ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 56 additions and 119 deletions

View file

@ -1,7 +1,7 @@
#pragma once
#include <dxgi1_4.h>
//#include <atlbase.h>
#include <wrl/client.h>
class DXGIWrapper
{
@ -23,34 +23,28 @@ public:
throw std::runtime_error("can't find CreateDXGIFactory1 in dxgi module");
}
IDXGIFactory1* dxgiFactory = nullptr;
Microsoft::WRL::ComPtr<IDXGIFactory1> dxgiFactory;
pCreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory));
IDXGIAdapter1* tmpDxgiAdapter = nullptr;
Microsoft::WRL::ComPtr<IDXGIAdapter1> dxgiAdapter;
UINT adapterIndex = 0;
while (dxgiFactory->EnumAdapters1(adapterIndex, &tmpDxgiAdapter) != DXGI_ERROR_NOT_FOUND)
while (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) != DXGI_ERROR_NOT_FOUND)
{
DXGI_ADAPTER_DESC1 desc;
tmpDxgiAdapter->GetDesc1(&desc);
dxgiAdapter->GetDesc1(&desc);
if (deviceLUID == nullptr || memcmp(&desc.AdapterLuid, deviceLUID, sizeof(LUID)) == 0)
{
tmpDxgiAdapter->QueryInterface(IID_PPV_ARGS(&m_dxgiAdapter));
tmpDxgiAdapter->Release();
if (FAILED(dxgiAdapter.As(&m_dxgiAdapter)))
{
Cleanup();
throw std::runtime_error("can't create dxgi adapter");
}
break;
}
tmpDxgiAdapter->Release();
++adapterIndex;
}
dxgiFactory->Release();
if (!m_dxgiAdapter)
{
Cleanup();
throw std::runtime_error("can't create dxgi adapter");
}
}
~DXGIWrapper()
@ -65,15 +59,11 @@ public:
private:
HMODULE m_moduleHandle = nullptr;
IDXGIAdapter3* m_dxgiAdapter = nullptr;
Microsoft::WRL::ComPtr<IDXGIAdapter3> m_dxgiAdapter;
void Cleanup()
{
if (m_dxgiAdapter)
{
m_dxgiAdapter->Release();
m_dxgiAdapter = nullptr;
}
m_dxgiAdapter.Reset();
if (m_moduleHandle)
{
@ -81,4 +71,4 @@ private:
m_moduleHandle = nullptr;
}
}
};
};