Merge pull request #20358 from oltolm/comptr

ComPtr
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2025-05-18 00:40:39 +02:00
commit 33fbeec7dd
4 files changed
+16 -20

No files matched your search

+3 -3
View File
@@ -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<std::string> deviceList, int maxInflightFrames);
D3D11DrawContext(ComPtr<ID3D11Device> device, ComPtr<ID3D11DeviceContext> deviceContext, ComPtr<ID3D11Device1> device1, ComPtr<ID3D11DeviceContext1> deviceContext1, ComPtr<IDXGISwapChain> swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector<std::string> deviceList, int maxInflightFrames);
~D3D11DrawContext();
const DeviceCaps &GetDeviceCaps() const override {
@@ -274,7 +274,7 @@ private:
std::vector<std::string> deviceList_;
};
D3D11DrawContext::D3D11DrawContext(ID3D11Device *device, ID3D11DeviceContext *deviceContext, ID3D11Device1 *device1, ID3D11DeviceContext1 *deviceContext1, IDXGISwapChain *swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector<std::string> deviceList, int maxInflightFrames)
D3D11DrawContext::D3D11DrawContext(ComPtr<ID3D11Device> device, ComPtr<ID3D11DeviceContext> deviceContext, ComPtr<ID3D11Device1> device1, ComPtr<ID3D11DeviceContext1> deviceContext1, ComPtr<IDXGISwapChain> swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, std::vector<std::string> 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<std::string> &adapterNames, int maxInflightFrames) {
DrawContext *T3DCreateD3D11Context(ComPtr<ID3D11Device> device, ComPtr<ID3D11DeviceContext> context, ComPtr<ID3D11Device1> device1, ComPtr<ID3D11DeviceContext1> context1, ComPtr<IDXGISwapChain> swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector<std::string> &adapterNames, int maxInflightFrames) {
return new D3D11DrawContext(device, context, device1, context1, swapChain, featureLevel, hWnd, adapterNames, maxInflightFrames);
}
+2 -1
View File
@@ -9,6 +9,7 @@
#ifdef _WIN32
#include "Common/CommonWindows.h"
#include <D3Dcommon.h>
#include <wrl/client.h>
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<std::string> &adapterNames, int maxInflightFrames);
DrawContext *T3DCreateD3D11Context(Microsoft::WRL::ComPtr<ID3D11Device> device, Microsoft::WRL::ComPtr<ID3D11DeviceContext> context, Microsoft::WRL::ComPtr<ID3D11Device1> device1, Microsoft::WRL::ComPtr<ID3D11DeviceContext1> context1, Microsoft::WRL::ComPtr<IDXGISwapChain> swapChain, D3D_FEATURE_LEVEL featureLevel, HWND hWnd, const std::vector<std::string> &adapterNames, int maxInflightFrames);
#endif
DrawContext *T3DCreateVulkanContext(VulkanContext *context, bool useRenderThread);
+1 -1
View File
@@ -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");
+10 -15
View File
@@ -18,9 +18,10 @@
#include <wrl/client.h>
namespace W32Util {
using Microsoft::WRL::ComPtr;
bool MoveToTrash(const Path &path) {
IFileOperation *pFileOp = nullptr;
ComPtr<IFileOperation> 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<IShellItem> 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<IFileDialog> 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<IShellItem> 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<IShellItem> 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<IShellLink> psl;
ComPtr<IShellLink> 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<IPersistFile> ppf;
ComPtr<IPersistFile> ppf;
// Set the path to the shortcut target and add the description.
psl->SetPath(lpszPathObj);