From 49b1a496b1481b77354b20edef94e98231b4f23a Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Thu, 6 Jan 2022 19:18:47 -0600 Subject: [PATCH] GS: Fix OSD scaling on hidpi displays --- pcsx2/Frontend/ImGuiManager.cpp | 12 +++++------- pcsx2/gui/AppHost.cpp | 8 ++++++-- pcsx2/gui/AppHost.h | 2 +- pcsx2/gui/FrameForGS.cpp | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pcsx2/Frontend/ImGuiManager.cpp b/pcsx2/Frontend/ImGuiManager.cpp index 18fd1d0762..df975af085 100644 --- a/pcsx2/Frontend/ImGuiManager.cpp +++ b/pcsx2/Frontend/ImGuiManager.cpp @@ -66,7 +66,7 @@ bool ImGuiManager::Initialize() s_global_scale = std::max(1.0f, display->GetWindowScale() * static_cast(EmuConfig.GS.OsdScale / 100.0)); - ImGui::GetIO().DisplayFramebufferScale = ImVec2(display->GetWindowScale(), display->GetWindowScale()); + ImGui::GetIO().DisplayFramebufferScale = ImVec2(1, 1); // We already scale things ourselves, this would double-apply scaling ImGui::GetIO().DisplaySize.x = static_cast(display->GetWindowWidth()); ImGui::GetIO().DisplaySize.y = static_cast(display->GetWindowHeight()); ImGui::GetStyle() = ImGuiStyle(); @@ -111,18 +111,18 @@ void ImGuiManager::WindowResized() const u32 new_width = display ? display->GetWindowWidth() : 0; const u32 new_height = display ? display->GetWindowHeight() : 0; - const float new_scale = (display ? display->GetWindowScale() : 1.0f); ImGui::GetIO().DisplaySize = ImVec2(static_cast(new_width), static_cast(new_height)); - ImGui::GetIO().DisplayFramebufferScale = ImVec2(new_scale, new_scale); UpdateScale(); } void ImGuiManager::UpdateScale() { - const float scale = - std::max(ImGui::GetIO().DisplayFramebufferScale.x * static_cast(EmuConfig.GS.OsdScale / 100.0), 1.0f); + HostDisplay* display = Host::GetHostDisplay(); + const float window_scale = display ? display->GetWindowScale() : 1.0f; + const float scale = std::max(window_scale * static_cast(EmuConfig.GS.OsdScale / 100.0), 1.0f); + if (scale == s_global_scale) return; @@ -131,8 +131,6 @@ void ImGuiManager::UpdateScale() s_global_scale = scale; - HostDisplay* display = Host::GetHostDisplay(); - ImGui::GetStyle() = ImGuiStyle(); ImGui::GetStyle().WindowMinSize = ImVec2(1.0f, 1.0f); SetImGuiStyle(); diff --git a/pcsx2/gui/AppHost.cpp b/pcsx2/gui/AppHost.cpp index 2011df874d..0adc1b299c 100644 --- a/pcsx2/gui/AppHost.cpp +++ b/pcsx2/gui/AppHost.cpp @@ -178,12 +178,14 @@ static std::atomic_bool s_gs_window_resized{false}; static std::mutex s_gs_window_resized_lock; static int s_new_gs_window_width = 0; static int s_new_gs_window_height = 0; +static float s_new_gs_window_scale = 1; -void Host::GSWindowResized(int width, int height) +void Host::GSWindowResized(int width, int height, float scale) { std::unique_lock lock(s_gs_window_resized_lock); s_new_gs_window_width = width; s_new_gs_window_height = height; + s_new_gs_window_scale = scale; s_gs_window_resized.store(true); } @@ -193,17 +195,19 @@ void Host::CheckForGSWindowResize() return; int width, height; + float scale; { std::unique_lock lock(s_gs_window_resized_lock); width = s_new_gs_window_width; height = s_new_gs_window_height; + scale = s_new_gs_window_scale; s_gs_window_resized.store(false); } if (!s_host_display) return; - s_host_display->ResizeRenderWindow(width, height, s_host_display ? s_host_display->GetWindowScale() : 1.0f); + s_host_display->ResizeRenderWindow(width, height, scale); ImGuiManager::WindowResized(); } diff --git a/pcsx2/gui/AppHost.h b/pcsx2/gui/AppHost.h index 283e3a416f..91bf5a6f9a 100644 --- a/pcsx2/gui/AppHost.h +++ b/pcsx2/gui/AppHost.h @@ -4,7 +4,7 @@ namespace Host { // UI thread - void GSWindowResized(int width, int height); + void GSWindowResized(int width, int height, float scale); // MTGS thread void CheckForGSWindowResize(); diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 65894380fc..23e130548c 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -384,7 +384,7 @@ void GSPanel::OnResize(wxEvent& event) g_gs_window_info.surface_height = height; g_gs_window_info.surface_scale = scale; - Host::GSWindowResized(width, height); + Host::GSWindowResized(width, height, scale); } void GSPanel::OnMouseEvent( wxMouseEvent& evt )