Skip to content

Commit

Permalink
Settings: Fix race toggling OSD messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Feb 28, 2025
1 parent cdb1cf1 commit 46439ed
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/core/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void Settings::Load(const SettingsInterface& si, const SettingsInterface& contro
display_active_end_offset = static_cast<s16>(si.GetIntValue("Display", "ActiveEndOffset", 0));
display_line_start_offset = static_cast<s8>(si.GetIntValue("Display", "LineStartOffset", 0));
display_line_end_offset = static_cast<s8>(si.GetIntValue("Display", "LineEndOffset", 0));
ImGuiManager::SetShowOSDMessages(si.GetBoolValue("Display", "ShowOSDMessages", true));
display_show_messages = si.GetBoolValue("Display", "ShowOSDMessages", true);
display_show_fps = si.GetBoolValue("Display", "ShowFPS", false);
display_show_speed = si.GetBoolValue("Display", "ShowSpeed", false);
display_show_gpu_stats = si.GetBoolValue("Display", "ShowGPUStatistics", false);
Expand Down Expand Up @@ -629,7 +629,7 @@ void Settings::Save(SettingsInterface& si, bool ignore_base) const
si.GetIntValue("Display", "CustomAspectRatioDenominator", display_aspect_ratio_custom_denominator);
if (!ignore_base)
{
si.SetBoolValue("Display", "ShowOSDMessages", ImGuiManager::IsShowingOSDMessages());
si.SetBoolValue("Display", "ShowOSDMessages", display_show_messages);
si.SetBoolValue("Display", "ShowFPS", display_show_fps);
si.SetBoolValue("Display", "ShowSpeed", display_show_speed);
si.SetBoolValue("Display", "ShowResolution", display_show_resolution);
Expand Down
1 change: 1 addition & 0 deletions src/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ struct GPUSettings
bool display_disable_mailbox_presentation : 1 = true;
bool display_force_4_3_for_24bit : 1 = false;
bool display_24bit_chroma_smoothing : 1 = false;
bool display_show_messages : 1 = false;
bool display_show_fps : 1 = false;
bool display_show_speed : 1 = false;
bool display_show_gpu_stats : 1 = false;
Expand Down
6 changes: 4 additions & 2 deletions src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,7 @@ void System::SetDefaultSettings(SettingsInterface& si)
Settings temp;

// we don't want to reset some things (e.g. OSD)
temp.display_show_messages = g_settings.display_show_messages;
temp.display_show_fps = g_settings.display_show_fps;
temp.display_show_speed = g_settings.display_show_speed;
temp.display_show_gpu_stats = g_settings.display_show_gpu_stats;
Expand Down Expand Up @@ -4524,7 +4525,8 @@ void System::CheckForSettingsChanges(const Settings& old_settings)
}
}
else if (const bool device_settings_changed = g_settings.AreGPUDeviceSettingsChanged(old_settings);
device_settings_changed || g_settings.display_show_fps != old_settings.display_show_fps ||
device_settings_changed || g_settings.display_show_messages != old_settings.display_show_messages ||
g_settings.display_show_fps != old_settings.display_show_fps ||
g_settings.display_show_speed != old_settings.display_show_speed ||
g_settings.display_show_gpu_stats != old_settings.display_show_gpu_stats ||
g_settings.display_show_resolution != old_settings.display_show_resolution ||
Expand Down Expand Up @@ -4906,7 +4908,7 @@ void System::WarnAboutUnsafeSettings()

// Force the message, but use a reduced duration if they have OSD messages disabled.
Host::AddKeyedOSDWarning("performance_settings_warning", std::string(messages.view()),
ImGuiManager::IsShowingOSDMessages() ? Host::OSD_INFO_DURATION : Host::OSD_QUICK_DURATION);
g_settings.display_show_messages ? Host::OSD_INFO_DURATION : Host::OSD_QUICK_DURATION);
}
else
{
Expand Down
26 changes: 3 additions & 23 deletions src/util/imgui_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// TODO: Remove me when GPUDevice config is also cleaned up.
#include "core/gpu_thread.h"
#include "core/host.h"
#include "core/settings.h"

#include "common/assert.h"
#include "common/bitutils.h"
Expand Down Expand Up @@ -110,7 +111,6 @@ struct ALIGN_TO_CACHE_LINE State

std::deque<OSDMessage> osd_posted_messages;
std::mutex osd_messages_lock;
bool show_osd_messages = true;

// Owned by GPU thread
ALIGN_TO_CACHE_LINE Timer::Value last_render_time = 0;
Expand Down Expand Up @@ -219,21 +219,6 @@ void ImGuiManager::SetGlobalScale(float global_scale)
s_state.scale_changed = true;
}

bool ImGuiManager::IsShowingOSDMessages()
{
return s_state.show_osd_messages;
}

void ImGuiManager::SetShowOSDMessages(bool enable)
{
if (s_state.show_osd_messages == enable)
return;

s_state.show_osd_messages = enable;
if (!enable)
Host::ClearOSDMessages(false);
}

bool ImGuiManager::Initialize(float global_scale, float screen_margin, Error* error)
{
if (!LoadFontData(error))
Expand Down Expand Up @@ -864,9 +849,6 @@ void ImGuiManager::AddOSDMessage(std::string key, std::string message, float dur
else
INFO_LOG("OSD: {}", message);

if (!s_state.show_osd_messages && !is_warning)
return;

const Timer::Value current_time = Timer::GetCurrentValue();

OSDMessage msg;
Expand All @@ -885,9 +867,6 @@ void ImGuiManager::AddOSDMessage(std::string key, std::string message, float dur

void ImGuiManager::RemoveKeyedOSDMessage(std::string key, bool is_warning)
{
if (!s_state.show_osd_messages && !is_warning)
return;

ImGuiManager::OSDMessage msg = {};
msg.key = std::move(key);
msg.duration = 0.0f;
Expand Down Expand Up @@ -983,6 +962,7 @@ void ImGuiManager::DrawOSDMessages(Timer::Value current_time)
const float padding = std::ceil(9.0f * scale);
const float rounding = std::ceil(6.0f * scale);
const float max_width = s_state.window_width - (margin + padding) * 2.0f;
const bool show_messages = g_gpu_settings.display_show_messages;
float position_x = margin;
float position_y = margin;

Expand Down Expand Up @@ -1044,7 +1024,7 @@ void ImGuiManager::DrawOSDMessages(Timer::Value current_time)
}
}

if (actual_y >= ImGui::GetIO().DisplaySize.y)
if (actual_y >= ImGui::GetIO().DisplaySize.y || (!show_messages && !msg.is_warning))
break;

const ImVec2 pos(position_x, actual_y);
Expand Down
4 changes: 0 additions & 4 deletions src/util/imgui_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ std::vector<WCharType> CompactFontRange(std::span<const WCharType> range);
/// Changes the global scale.
void SetGlobalScale(float global_scale);

/// Changes whether OSD messages are silently dropped.
bool IsShowingOSDMessages();
void SetShowOSDMessages(bool enable);

/// Initializes ImGui, creates fonts, etc.
bool Initialize(float global_scale, float screen_margin, Error* error);

Expand Down

0 comments on commit 46439ed

Please sign in to comment.