Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGuiManager: Defer scale updates #10831

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pcsx2/GS/GS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void GSUpdateConfig(const Pcsx2Config::GSOptions& new_config)

// Handle OSD scale changes by pushing a window resize through.
if (new_config.OsdScale != old_config.OsdScale)
ImGuiManager::WindowResized();
ImGuiManager::RequestScaleUpdate();

// Options which need a full teardown/recreate.
if (!GSConfig.RestartOptionsAreEqual(old_config))
Expand Down
24 changes: 15 additions & 9 deletions pcsx2/ImGui/ImGuiManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace ImGuiManager
std::pair<float, float> pos;
};

static void UpdateScale();
static void SetStyle();
static void SetKeyMap();
static bool LoadFontData();
Expand Down Expand Up @@ -96,6 +97,7 @@ static constexpr float OSD_FADE_OUT_TIME = 0.4f;

// need to keep track of this, so we can reinitialize on renderer switch
static bool s_fullscreen_ui_was_initialized = false;
static bool s_scale_changed = false;

static std::array<ImGuiManager::SoftwareCursor, InputManager::MAX_SOFTWARE_CURSORS> s_software_cursors = {};

Expand Down Expand Up @@ -134,6 +136,7 @@ bool ImGuiManager::Initialize()
}

s_global_scale = std::max(0.5f, g_gs_device->GetWindowScale() * (GSConfig.OsdScale / 100.0f));
s_scale_changed = false;

ImGui::CreateContext();

Expand Down Expand Up @@ -225,11 +228,13 @@ void ImGuiManager::WindowResized()
s_window_height = static_cast<float>(new_height);
ImGui::GetIO().DisplaySize = ImVec2(s_window_width, s_window_height);

UpdateScale();
// Scale might have changed as a result of window resize.
RequestScaleUpdate();
}

// restart imgui frame on the new window size to pick it up, otherwise we draw to the old size
ImGui::EndFrame();
NewFrame();
void ImGuiManager::RequestScaleUpdate()
{
s_scale_changed = true;
}

void ImGuiManager::UpdateScale()
Expand All @@ -240,9 +245,6 @@ void ImGuiManager::UpdateScale()
if ((!HasFullscreenFonts() || !ImGuiFullscreen::UpdateLayoutScale()) && scale == s_global_scale)
return;

// This is assumed to be called mid-frame.
ImGui::EndFrame();

s_global_scale = scale;
SetStyle();

Expand All @@ -251,15 +253,19 @@ void ImGuiManager::UpdateScale()

if (!g_gs_device->UpdateImGuiFontTexture())
pxFailRel("Failed to recreate font texture after scale+resize");

NewFrame();
}

void ImGuiManager::NewFrame()
{
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = s_last_render_time.GetTimeSecondsAndReset();

if (s_scale_changed)
{
s_scale_changed = false;
UpdateScale();
}

ImGui::NewFrame();

// Disable nav input on the implicit (Debug##Default) window. Otherwise we end up requesting keyboard
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/ImGui/ImGuiManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace ImGuiManager
void WindowResized();

/// Updates scaling of the on-screen elements.
void UpdateScale();
void RequestScaleUpdate();

/// Call at the beginning of the frame to set up ImGui state.
void NewFrame();
Expand Down
Loading