From 96506544b74c121653d30c534d3c125dc1b4e915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 10 Aug 2023 10:28:25 +0200 Subject: [PATCH] Just some random driveby code cleanup --- Windows/GPU/D3D11Context.cpp | 17 ++--------------- Windows/GPU/D3D11Context.h | 15 ++++++--------- Windows/GPU/D3D9Context.cpp | 13 +++---------- Windows/MainWindow.cpp | 7 ++----- Windows/W32Util/Misc.cpp | 7 +++++++ Windows/W32Util/Misc.h | 2 ++ android/jni/AndroidVulkanContext.cpp | 3 --- android/jni/AndroidVulkanContext.h | 2 +- 8 files changed, 23 insertions(+), 43 deletions(-) diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index 750755618b..fe485925bb 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -33,12 +33,6 @@ #error This file should not be compiled for UWP. #endif -D3D11Context::D3D11Context() : draw_(nullptr), adapterId(-1), hDC(nullptr), hWnd_(nullptr), hD3D11(nullptr) { -} - -D3D11Context::~D3D11Context() { -} - void D3D11Context::SwapBuffers() { swapChain_->Present(swapInterval_, 0); draw_->HandleEvent(Draw::Event::PRESENTED, 0, 0, nullptr, nullptr); @@ -81,13 +75,6 @@ HRESULT D3D11Context::CreateTheDevice(IDXGIAdapter *adapter) { return hr; } -static void GetRes(HWND hWnd, int &xres, int &yres) { - RECT rc; - GetClientRect(hWnd, &rc); - xres = rc.right - rc.left; - yres = rc.bottom - rc.top; -} - bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { hWnd_ = wnd; LoadD3D11Error result = LoadD3D11(); @@ -178,7 +165,7 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { int width; int height; - GetRes(hWnd_, width, height); + W32Util::GetWindowRes(hWnd_, &width, &height); // Obtain DXGI factory from device (since we used nullptr for pAdapter above) IDXGIFactory1 *dxgiFactory = nullptr; @@ -249,7 +236,7 @@ void D3D11Context::Resize() { LostBackbuffer(); int width; int height; - GetRes(hWnd_, width, height); + W32Util::GetWindowRes(hWnd_, &width, &height); swapChain_->ResizeBuffers(0, width, height, DXGI_FORMAT_UNKNOWN, 0); GotBackbuffer(); } diff --git a/Windows/GPU/D3D11Context.h b/Windows/GPU/D3D11Context.h index 07d551b7de..f2f03b2756 100644 --- a/Windows/GPU/D3D11Context.h +++ b/Windows/GPU/D3D11Context.h @@ -28,8 +28,6 @@ class DrawContext; class D3D11Context : public WindowsGraphicsContext { public: - D3D11Context(); - ~D3D11Context(); bool Init(HINSTANCE hInst, HWND window, std::string *error_message) override; void Shutdown() override; void SwapInterval(int interval) override; @@ -59,13 +57,12 @@ private: ID3D11Debug *d3dDebug_ = nullptr; ID3D11InfoQueue *d3dInfoQueue_ = nullptr; #endif - D3D_FEATURE_LEVEL featureLevel_ = D3D_FEATURE_LEVEL_11_0; - int adapterId; - HDC hDC; // Private GDI Device Context - HWND hWnd_; // Holds Our Window Handle - HMODULE hD3D11; - int width; - int height; + int adapterId = -1; + HDC hDC = nullptr; // Private GDI Device Context + HWND hWnd_ = nullptr; // Holds Our Window Handle + HMODULE hD3D11 = nullptr; + int width = 0; + int height = 0; int swapInterval_ = 0; }; diff --git a/Windows/GPU/D3D9Context.cpp b/Windows/GPU/D3D9Context.cpp index 7ffe7f79f0..faf5568561 100644 --- a/Windows/GPU/D3D9Context.cpp +++ b/Windows/GPU/D3D9Context.cpp @@ -35,13 +35,6 @@ void D3D9Context::SwapBuffers() { typedef HRESULT (__stdcall *DIRECT3DCREATE9EX)(UINT, IDirect3D9Ex**); -static void GetRes(HWND hWnd, int &xres, int &yres) { - RECT rc; - GetClientRect(hWnd, &rc); - xres = rc.right - rc.left; - yres = rc.bottom - rc.top; -} - void D3D9Context::SwapInterval(int interval) { swapInterval_ = interval; } @@ -126,7 +119,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { dwBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; int xres, yres; - GetRes(hWnd_, xres, yres); + W32Util::GetWindowRes(hWnd_, &xres, &yres); presentParams_ = {}; presentParams_.BackBufferWidth = xres; @@ -183,8 +176,8 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { void D3D9Context::Resize() { // This should only be called from the emu thread. int xres, yres; - GetRes(hWnd_, xres, yres); - uint32_t newInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;; + W32Util::GetWindowRes(hWnd_, &xres, &yres); + uint32_t newInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; bool w_changed = presentParams_.BackBufferWidth != xres; bool h_changed = presentParams_.BackBufferHeight != yres; bool i_changed = presentParams_.PresentationInterval != newInterval; diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 78a7cc07e0..d0dbbf1ce2 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -285,11 +285,8 @@ namespace MainWindow System_PostUIMessage("window minimized", "false"); } - int width = 0, height = 0; - RECT rc; - GetClientRect(hwndMain, &rc); - width = rc.right - rc.left; - height = rc.bottom - rc.top; + int width, height; + W32Util::GetWindowRes(hwndMain, &width, &height); // Moves the internal display window to match the inner size of the main window. MoveWindow(hwndDisplay, 0, 0, width, height, TRUE); diff --git a/Windows/W32Util/Misc.cpp b/Windows/W32Util/Misc.cpp index 97f4e475e5..f7f015c122 100644 --- a/Windows/W32Util/Misc.cpp +++ b/Windows/W32Util/Misc.cpp @@ -87,6 +87,13 @@ namespace W32Util SetWindowPos(hwnd, style, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE); } + void GetWindowRes(HWND hWnd, int *xres, int *yres) { + RECT rc; + GetClientRect(hWnd, &rc); + *xres = rc.right - rc.left; + *yres = rc.bottom - rc.top; + } + static const wchar_t *RemoveExecutableFromCommandLine(const wchar_t *cmdline) { if (!cmdline) { return L""; diff --git a/Windows/W32Util/Misc.h b/Windows/W32Util/Misc.h index ddfaa0a893..8fd41b0989 100644 --- a/Windows/W32Util/Misc.h +++ b/Windows/W32Util/Misc.h @@ -15,6 +15,8 @@ namespace W32Util void SpawnNewInstance(bool overrideArgs = false, const std::string &args = ""); void GetSelfExecuteParams(std::wstring &workingDirectory, std::wstring &moduleFilename); + void GetWindowRes(HWND hWnd, int *xres, int *yres); + struct ClipboardData { ClipboardData(const char *format, size_t sz); ClipboardData(UINT format, size_t sz); diff --git a/android/jni/AndroidVulkanContext.cpp b/android/jni/AndroidVulkanContext.cpp index 6a501c68f9..467880aab6 100644 --- a/android/jni/AndroidVulkanContext.cpp +++ b/android/jni/AndroidVulkanContext.cpp @@ -161,9 +161,6 @@ void AndroidVulkanContext::Shutdown() { INFO_LOG(G3D, "AndroidVulkanContext::Shutdown completed"); } -void AndroidVulkanContext::SwapBuffers() { -} - void AndroidVulkanContext::Resize() { INFO_LOG(G3D, "AndroidVulkanContext::Resize begin (oldsize: %dx%d)", g_Vulkan->GetBackbufferWidth(), g_Vulkan->GetBackbufferHeight()); diff --git a/android/jni/AndroidVulkanContext.h b/android/jni/AndroidVulkanContext.h index 31d88c1a20..f938643353 100644 --- a/android/jni/AndroidVulkanContext.h +++ b/android/jni/AndroidVulkanContext.h @@ -16,7 +16,7 @@ public: void Shutdown() override; void SwapInterval(int interval) override; - void SwapBuffers() override; + void SwapBuffers() override {} void Resize() override; void *GetAPIContext() override { return g_Vulkan; }