D3DCommon: Migrate few remaining raw pointers to WRL::ComPtr

This commit is contained in:
Silent 2019-11-10 15:51:43 +01:00
parent 7fa5a95800
commit 8445644e05
No known key found for this signature in database
GPG Key ID: AE53149BB0C45AF1
2 changed files with 11 additions and 10 deletions

View File

@ -72,20 +72,20 @@ void UnloadLibraries()
s_libraries_loaded = false; s_libraries_loaded = false;
} }
IDXGIFactory* CreateDXGIFactory(bool debug_device) Microsoft::WRL::ComPtr<IDXGIFactory> CreateDXGIFactory(bool debug_device)
{ {
IDXGIFactory* factory; Microsoft::WRL::ComPtr<IDXGIFactory> factory;
// Use Win8.1 version if available. // Use Win8.1 version if available.
if (create_dxgi_factory2 && if (create_dxgi_factory2 &&
SUCCEEDED(create_dxgi_factory2(debug_device ? DXGI_CREATE_FACTORY_DEBUG : 0, SUCCEEDED(create_dxgi_factory2(debug_device ? DXGI_CREATE_FACTORY_DEBUG : 0,
IID_PPV_ARGS(&factory)))) IID_PPV_ARGS(factory.GetAddressOf()))))
{ {
return factory; return factory;
} }
// Fallback to original version, without debug support. // Fallback to original version, without debug support.
HRESULT hr = create_dxgi_factory(IID_PPV_ARGS(&factory)); HRESULT hr = create_dxgi_factory(IID_PPV_ARGS(factory.ReleaseAndGetAddressOf()));
if (FAILED(hr)) if (FAILED(hr))
{ {
PanicAlert("CreateDXGIFactory() failed with HRESULT %08X", hr); PanicAlert("CreateDXGIFactory() failed with HRESULT %08X", hr);
@ -98,14 +98,14 @@ IDXGIFactory* CreateDXGIFactory(bool debug_device)
std::vector<std::string> GetAdapterNames() std::vector<std::string> GetAdapterNames()
{ {
Microsoft::WRL::ComPtr<IDXGIFactory> factory; Microsoft::WRL::ComPtr<IDXGIFactory> factory;
HRESULT hr = create_dxgi_factory(IID_PPV_ARGS(&factory)); HRESULT hr = create_dxgi_factory(IID_PPV_ARGS(factory.GetAddressOf()));
if (!SUCCEEDED(hr)) if (FAILED(hr))
return {}; return {};
std::vector<std::string> adapters; std::vector<std::string> adapters;
IDXGIAdapter* adapter; Microsoft::WRL::ComPtr<IDXGIAdapter> adapter;
while (factory->EnumAdapters(static_cast<UINT>(adapters.size()), &adapter) != while (factory->EnumAdapters(static_cast<UINT>(adapters.size()),
DXGI_ERROR_NOT_FOUND) adapter.ReleaseAndGetAddressOf()) != DXGI_ERROR_NOT_FOUND)
{ {
std::string name; std::string name;
DXGI_ADAPTER_DESC desc; DXGI_ADAPTER_DESC desc;

View File

@ -8,6 +8,7 @@
#include <dxgiformat.h> #include <dxgiformat.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <wrl/client.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -25,7 +26,7 @@ void UnloadLibraries();
std::vector<std::string> GetAdapterNames(); std::vector<std::string> GetAdapterNames();
// Helper function which creates a DXGI factory. // Helper function which creates a DXGI factory.
IDXGIFactory* CreateDXGIFactory(bool debug_device); Microsoft::WRL::ComPtr<IDXGIFactory> CreateDXGIFactory(bool debug_device);
// Globally-accessible D3DCompiler function. // Globally-accessible D3DCompiler function.
extern pD3DCompile d3d_compile; extern pD3DCompile d3d_compile;