diff --git a/Common/GPU/D3D11/thin3d_d3d11.cpp b/Common/GPU/D3D11/thin3d_d3d11.cpp index ef4d87d9b0..12c4aeeef8 100644 --- a/Common/GPU/D3D11/thin3d_d3d11.cpp +++ b/Common/GPU/D3D11/thin3d_d3d11.cpp @@ -84,7 +84,7 @@ public: class D3D11DrawContext : public DrawContext { public: - D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Device1 *device1, ID3D11DeviceContext1 *deviceContext1, IDXGISwapChain *swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector deviceList, int maxInflightFrames); + D3D11DrawContext(ComPtr device, ComPtr deviceContext, ComPtr device1, ComPtr deviceContext1, ComPtr swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector deviceList, int maxInflightFrames); ~D3D11DrawContext(); const DeviceCaps &GetDeviceCaps() const override { @@ -274,7 +274,7 @@ private: std::vector deviceList_; }; -D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Device1 *device1, ID3D11DeviceContext1 *deviceContext1, IDXGISwapChain *swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector deviceList, int maxInflightFrames) +D3D11DrawContext::D3D11DrawContext(ComPtr device, ComPtr deviceContext, ComPtr device1, ComPtr deviceContext1, ComPtr swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector deviceList, int maxInflightFrames) : hWnd_(hWnd), device_(device), context_(deviceContext1), @@ -1952,7 +1952,7 @@ void D3D11DrawContext::GetFramebufferDimensions(Framebuffer *fbo, int *w, int *h } } -DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, ID3D11Device1 *device1, ID3D11DeviceContext1 *context1, IDXGISwapChain *swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector &adapterNames, int maxInflightFrames) { +DrawContext *T3DCreateD3D11Context(ComPtr device, ComPtr context, ComPtr device1, ComPtr context1, ComPtr swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector &adapterNames, int maxInflightFrames) { return new D3D11DrawContext(device, context, device1, context1, swapChain, featureLevel, hWnd, adapterNames, maxInflightFrames); } diff --git a/Common/GPU/thin3d_create.h b/Common/GPU/thin3d_create.h index 81aba58a1e..730788a4e9 100644 --- a/Common/GPU/thin3d_create.h +++ b/Common/GPU/thin3d_create.h @@ -9,6 +9,7 @@ #ifdef _WIN32 #include "Common/CommonWindows.h" #include +#include struct IDirect3DDevice9; struct IDirect3D9; struct IDirect3DDevice9Ex; @@ -28,7 +29,7 @@ DrawContext *T3DCreateGLContext(bool canChangeSwapInterval); #ifdef _WIN32 DrawContext *T3DCreateDX9Context(IDirect3D9 *d3d, IDirect3D9Ex *d3dEx, int adapterId, IDirect3DDevice9 *device, IDirect3DDevice9Ex *deviceEx); -DrawContext *T3DCreateD3D11Context(ID3D11Device *device, ID3D11DeviceContext *context, ID3D11Device1 *device1, ID3D11DeviceContext1 *context1, IDXGISwapChain *swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector &adapterNames, int maxInflightFrames); +DrawContext *T3DCreateD3D11Context(Microsoft::WRL::ComPtr device, Microsoft::WRL::ComPtr context, Microsoft::WRL::ComPtr device1, Microsoft::WRL::ComPtr context1, Microsoft::WRL::ComPtr swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector &adapterNames, int maxInflightFrames); #endif DrawContext *T3DCreateVulkanContext(VulkanContext *context, bool useRenderThread); diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index 95be2cab21..38ad73e563 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -196,7 +196,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { hr = dxgiFactory->CreateSwapChain(device_.Get(), &swapChainDesc_, &swapChain_); dxgiFactory->MakeWindowAssociation(hWnd_, DXGI_MWA_NO_ALT_ENTER); - draw_ = Draw::T3DCreateD3D11Context(device_.Get(), context_.Get(), device1_.Get(), context1_.Get(), swapChain_.Get(), featureLevel_, hWnd_, adapterNames, g_Config.iInflightFrames); + draw_ = Draw::T3DCreateD3D11Context(device_, context_, device1_, context1_, swapChain_, featureLevel_, hWnd_, adapterNames, g_Config.iInflightFrames); SetGPUBackend(GPUBackend::DIRECT3D11, chosenAdapterName); bool success = draw_->CreatePresets(); // If we can run D3D11, there's a compiler installed. I think. _assert_msg_(success, "Failed to compile preset shaders"); diff --git a/Windows/W32Util/ShellUtil.cpp b/Windows/W32Util/ShellUtil.cpp index d9b659ab95..125a63dec9 100644 --- a/Windows/W32Util/ShellUtil.cpp +++ b/Windows/W32Util/ShellUtil.cpp @@ -18,9 +18,10 @@ #include namespace W32Util { +using Microsoft::WRL::ComPtr; bool MoveToTrash(const Path &path) { - IFileOperation *pFileOp = nullptr; + ComPtr pFileOp; HRESULT hr = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pFileOp)); if (FAILED(hr)) { @@ -30,22 +31,19 @@ bool MoveToTrash(const Path &path) { // Set operation flags hr = pFileOp->SetOperationFlags(FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_SILENT); if (FAILED(hr)) { - pFileOp->Release(); return false; } // Create a shell item from the file path - IShellItem* pItem = nullptr; + ComPtr pItem; hr = SHCreateItemFromParsingName(path.ToWString().c_str(), nullptr, IID_PPV_ARGS(&pItem)); if (SUCCEEDED(hr)) { // Schedule the delete (move to recycle bin) - hr = pFileOp->DeleteItem(pItem, nullptr); + hr = pFileOp->DeleteItem(pItem.Get(), nullptr); if (SUCCEEDED(hr)) { hr = pFileOp->PerformOperations(); // Execute } - pItem->Release(); } - pFileOp->Release(); if (SUCCEEDED(hr)) { INFO_LOG(Log::IO, "Moved file to trash successfully: %s", path.c_str()); @@ -63,7 +61,7 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi std::wstring selectedFolder; // Create the FileOpenDialog object - IFileDialog* pFileDialog = nullptr; + ComPtr pFileDialog; HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog)); if (!SUCCEEDED(hr)) { return ""; @@ -79,11 +77,10 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi // Set the initial directory if (!initialDir.empty()) { - IShellItem* pShellItem = nullptr; + ComPtr pShellItem; hr = SHCreateItemFromParsingName(initialDir.c_str(), nullptr, IID_PPV_ARGS(&pShellItem)); if (SUCCEEDED(hr)) { - hr = pFileDialog->SetFolder(pShellItem); - pShellItem->Release(); + hr = pFileDialog->SetFolder(pShellItem.Get()); } } pFileDialog->SetTitle(wtitle.c_str()); @@ -92,7 +89,7 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi hr = pFileDialog->Show(parent); if (SUCCEEDED(hr)) { // Get the selected folder - IShellItem* pShellItem = nullptr; + ComPtr pShellItem; hr = pFileDialog->GetResult(&pShellItem); if (SUCCEEDED(hr)) { PWSTR pszFilePath = nullptr; @@ -101,11 +98,9 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi selectedFolder = pszFilePath; CoTaskMemFree(pszFilePath); } - pShellItem->Release(); } } - pFileDialog->Release(); return ConvertWStringToUTF8(selectedFolder); } @@ -229,7 +224,7 @@ std::string BrowseForFolder2(HWND parent, std::string_view title, std::string_vi // http://msdn.microsoft.com/en-us/library/aa969393.aspx static HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lpszPathLink, LPCWSTR lpszDesc, LPCWSTR lpszIcon, int iconIndex) { HRESULT hres; - Microsoft::WRL::ComPtr psl; + ComPtr psl; hres = CoInitializeEx(NULL, COINIT_MULTITHREADED); if (FAILED(hres)) return hres; @@ -238,7 +233,7 @@ static HRESULT CreateLink(LPCWSTR lpszPathObj, LPCWSTR lpszArguments, LPCWSTR lp // has already been called. hres = CoCreateInstance(__uuidof(ShellLink), NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&psl)); if (SUCCEEDED(hres) && psl) { - Microsoft::WRL::ComPtr ppf; + ComPtr ppf; // Set the path to the shortcut target and add the description. psl->SetPath(lpszPathObj);