GS: Fix OSD scaling on hidpi displays

This commit is contained in:
TellowKrinkle 2022-01-06 19:18:47 -06:00 committed by tellowkrinkle
parent 50afd83bc6
commit 49b1a496b1
4 changed files with 13 additions and 11 deletions

View File

@ -66,7 +66,7 @@ bool ImGuiManager::Initialize()
s_global_scale = std::max(1.0f, display->GetWindowScale() * static_cast<float>(EmuConfig.GS.OsdScale / 100.0)); s_global_scale = std::max(1.0f, display->GetWindowScale() * static_cast<float>(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<float>(display->GetWindowWidth()); ImGui::GetIO().DisplaySize.x = static_cast<float>(display->GetWindowWidth());
ImGui::GetIO().DisplaySize.y = static_cast<float>(display->GetWindowHeight()); ImGui::GetIO().DisplaySize.y = static_cast<float>(display->GetWindowHeight());
ImGui::GetStyle() = ImGuiStyle(); ImGui::GetStyle() = ImGuiStyle();
@ -111,18 +111,18 @@ void ImGuiManager::WindowResized()
const u32 new_width = display ? display->GetWindowWidth() : 0; const u32 new_width = display ? display->GetWindowWidth() : 0;
const u32 new_height = display ? display->GetWindowHeight() : 0; const u32 new_height = display ? display->GetWindowHeight() : 0;
const float new_scale = (display ? display->GetWindowScale() : 1.0f);
ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height)); ImGui::GetIO().DisplaySize = ImVec2(static_cast<float>(new_width), static_cast<float>(new_height));
ImGui::GetIO().DisplayFramebufferScale = ImVec2(new_scale, new_scale);
UpdateScale(); UpdateScale();
} }
void ImGuiManager::UpdateScale() void ImGuiManager::UpdateScale()
{ {
const float scale = HostDisplay* display = Host::GetHostDisplay();
std::max(ImGui::GetIO().DisplayFramebufferScale.x * static_cast<float>(EmuConfig.GS.OsdScale / 100.0), 1.0f); const float window_scale = display ? display->GetWindowScale() : 1.0f;
const float scale = std::max(window_scale * static_cast<float>(EmuConfig.GS.OsdScale / 100.0), 1.0f);
if (scale == s_global_scale) if (scale == s_global_scale)
return; return;
@ -131,8 +131,6 @@ void ImGuiManager::UpdateScale()
s_global_scale = scale; s_global_scale = scale;
HostDisplay* display = Host::GetHostDisplay();
ImGui::GetStyle() = ImGuiStyle(); ImGui::GetStyle() = ImGuiStyle();
ImGui::GetStyle().WindowMinSize = ImVec2(1.0f, 1.0f); ImGui::GetStyle().WindowMinSize = ImVec2(1.0f, 1.0f);
SetImGuiStyle(); SetImGuiStyle();

View File

@ -178,12 +178,14 @@ static std::atomic_bool s_gs_window_resized{false};
static std::mutex s_gs_window_resized_lock; static std::mutex s_gs_window_resized_lock;
static int s_new_gs_window_width = 0; static int s_new_gs_window_width = 0;
static int s_new_gs_window_height = 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); std::unique_lock lock(s_gs_window_resized_lock);
s_new_gs_window_width = width; s_new_gs_window_width = width;
s_new_gs_window_height = height; s_new_gs_window_height = height;
s_new_gs_window_scale = scale;
s_gs_window_resized.store(true); s_gs_window_resized.store(true);
} }
@ -193,17 +195,19 @@ void Host::CheckForGSWindowResize()
return; return;
int width, height; int width, height;
float scale;
{ {
std::unique_lock lock(s_gs_window_resized_lock); std::unique_lock lock(s_gs_window_resized_lock);
width = s_new_gs_window_width; width = s_new_gs_window_width;
height = s_new_gs_window_height; height = s_new_gs_window_height;
scale = s_new_gs_window_scale;
s_gs_window_resized.store(false); s_gs_window_resized.store(false);
} }
if (!s_host_display) if (!s_host_display)
return; 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(); ImGuiManager::WindowResized();
} }

View File

@ -4,7 +4,7 @@
namespace Host namespace Host
{ {
// UI thread // UI thread
void GSWindowResized(int width, int height); void GSWindowResized(int width, int height, float scale);
// MTGS thread // MTGS thread
void CheckForGSWindowResize(); void CheckForGSWindowResize();

View File

@ -384,7 +384,7 @@ void GSPanel::OnResize(wxEvent& event)
g_gs_window_info.surface_height = height; g_gs_window_info.surface_height = height;
g_gs_window_info.surface_scale = scale; g_gs_window_info.surface_scale = scale;
Host::GSWindowResized(width, height); Host::GSWindowResized(width, height, scale);
} }
void GSPanel::OnMouseEvent( wxMouseEvent& evt ) void GSPanel::OnMouseEvent( wxMouseEvent& evt )