mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-07-07 07:21:25 +12:00
overlays/perf_overlay: Make pos, font, opacity, margin configurable
- Also some perf overlay refactoring
This commit is contained in:
parent
58f4b26134
commit
dd0684b58a
5 changed files with 178 additions and 38 deletions
|
@ -11,26 +11,67 @@ namespace rsx
|
||||||
{
|
{
|
||||||
namespace overlays
|
namespace overlays
|
||||||
{
|
{
|
||||||
|
void perf_metrics_overlay::reset_transform(label& elm) const
|
||||||
|
{
|
||||||
|
const u32 text_padding = m_font_size / 2;
|
||||||
|
|
||||||
|
// left, top, right, bottom
|
||||||
|
const areau padding { text_padding, text_padding - 4, text_padding, text_padding };
|
||||||
|
const positionu margin { m_margin, m_margin };
|
||||||
|
positionu pos;
|
||||||
|
|
||||||
|
const auto overlay_width = m_body.w + margin.x;
|
||||||
|
const auto overlay_height = m_body.h + margin.y;
|
||||||
|
|
||||||
|
switch (m_quadrant)
|
||||||
|
{
|
||||||
|
case screen_quadrant::top_left:
|
||||||
|
pos.x = margin.x;
|
||||||
|
pos.y = margin.y;
|
||||||
|
break;
|
||||||
|
case screen_quadrant::top_right:
|
||||||
|
pos.x = virtual_width - overlay_width;
|
||||||
|
pos.y = margin.y;
|
||||||
|
break;
|
||||||
|
case screen_quadrant::bottom_left:
|
||||||
|
pos.x = margin.x;
|
||||||
|
pos.y = virtual_height - overlay_height;
|
||||||
|
break;
|
||||||
|
case screen_quadrant::bottom_right:
|
||||||
|
pos.x = virtual_width - overlay_width;
|
||||||
|
pos.y = virtual_height - overlay_height;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
elm.set_pos(pos.x, pos.y);
|
||||||
|
elm.set_padding(padding.x1, padding.x2, padding.y1, padding.y2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void perf_metrics_overlay::reset_transforms()
|
||||||
|
{
|
||||||
|
reset_transform(m_body);
|
||||||
|
reset_transform(m_titles);
|
||||||
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::reset_body()
|
void perf_metrics_overlay::reset_body()
|
||||||
{
|
{
|
||||||
m_body.set_font("n023055ms.ttf", m_font_size);
|
const float text_opacity = get_text_opacity();
|
||||||
m_body.set_pos(50, 50);
|
const float bg_opacity = m_opacity;
|
||||||
m_body.fore_color = {0xFF / 255.f, 0xe1 / 255.f, 0x38 / 255.f, 1.0f};
|
|
||||||
m_body.back_color = {0x00 / 255.f, 0x23 / 255.f, 0x39 / 255.f, 0.7f};
|
m_body.set_font(m_font.c_str(), m_font_size);
|
||||||
m_body.padding_top = 0;
|
m_body.fore_color = {0xFF / 255.f, 0xE1 / 255.f, 0x38 / 255.f, text_opacity};
|
||||||
m_body.padding_bottom = -14;
|
m_body.back_color = {0x00 / 255.f, 0x23 / 255.f, 0x39 / 255.f, bg_opacity};
|
||||||
m_body.set_margin(5, 5, 0, 0);
|
reset_transform(m_body);
|
||||||
}
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::reset_titles()
|
void perf_metrics_overlay::reset_titles()
|
||||||
{
|
{
|
||||||
m_titles.set_font("n023055ms.ttf", m_font_size);
|
const float text_opacity = get_text_opacity();
|
||||||
m_titles.set_pos(50, 50);
|
|
||||||
m_titles.fore_color = {0xf2 / 256.0, 0x6C / 256.0, 0x24 / 256.0, 1.0f};
|
m_titles.set_font(m_font.c_str(), m_font_size);
|
||||||
|
m_titles.fore_color = {0xF2 / 256.0, 0x6C / 256.0, 0x24 / 256.0, text_opacity};
|
||||||
m_titles.back_color = {0.0f, 0.0f, 0.0f, 0.0f};
|
m_titles.back_color = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||||
m_titles.padding_top = 0;
|
reset_transform(m_titles);
|
||||||
m_titles.padding_bottom = -14;
|
|
||||||
m_titles.set_margin(5, 5, 0, 0);
|
|
||||||
|
|
||||||
switch (m_detail)
|
switch (m_detail)
|
||||||
{
|
{
|
||||||
|
@ -43,25 +84,40 @@ namespace rsx
|
||||||
m_titles.refresh();
|
m_titles.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void perf_metrics_overlay::reset_text()
|
||||||
|
{
|
||||||
|
reset_body();
|
||||||
|
reset_titles();
|
||||||
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::init()
|
void perf_metrics_overlay::init()
|
||||||
{
|
{
|
||||||
reset_titles();
|
reset_text();
|
||||||
reset_body();
|
|
||||||
|
|
||||||
force_next_update();
|
force_next_update();
|
||||||
update();
|
update();
|
||||||
m_update_timer.Start();
|
m_update_timer.Start();
|
||||||
|
|
||||||
|
m_is_initialised = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
perf_metrics_overlay::perf_metrics_overlay(bool initialize)
|
void perf_metrics_overlay::set_detail_level(detail_level level)
|
||||||
{
|
{
|
||||||
// Default values, will change based on config options
|
m_detail = level;
|
||||||
m_update_interval = 350;
|
|
||||||
m_detail = detail_level::high;
|
|
||||||
m_font_size = 10;
|
|
||||||
|
|
||||||
if (initialize)
|
if (m_is_initialised)
|
||||||
init();
|
{
|
||||||
|
reset_titles();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void perf_metrics_overlay::set_position(screen_quadrant quadrant)
|
||||||
|
{
|
||||||
|
m_quadrant = quadrant;
|
||||||
|
|
||||||
|
if (m_is_initialised)
|
||||||
|
{
|
||||||
|
reset_transforms();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In ms
|
// In ms
|
||||||
|
@ -70,17 +126,44 @@ namespace rsx
|
||||||
m_update_interval = update_interval;
|
m_update_interval = update_interval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::set_detail_level(detail_level level)
|
void perf_metrics_overlay::set_font(std::string font)
|
||||||
{
|
{
|
||||||
m_detail = level;
|
m_font = font;
|
||||||
reset_titles();
|
|
||||||
|
if (m_is_initialised)
|
||||||
|
{
|
||||||
|
reset_text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::set_font_size(u32 font_size)
|
void perf_metrics_overlay::set_font_size(u32 font_size)
|
||||||
{
|
{
|
||||||
m_font_size = font_size;
|
m_font_size = font_size;
|
||||||
reset_titles();
|
|
||||||
reset_body();
|
if (m_is_initialised)
|
||||||
|
{
|
||||||
|
reset_text();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void perf_metrics_overlay::set_margin(u32 margin)
|
||||||
|
{
|
||||||
|
m_margin = margin;
|
||||||
|
|
||||||
|
if (m_is_initialised)
|
||||||
|
{
|
||||||
|
reset_transforms();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void perf_metrics_overlay::set_opacity(f32 opacity)
|
||||||
|
{
|
||||||
|
m_opacity = opacity;
|
||||||
|
|
||||||
|
if (m_is_initialised)
|
||||||
|
{
|
||||||
|
reset_text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void perf_metrics_overlay::force_next_update()
|
void perf_metrics_overlay::force_next_update()
|
||||||
|
@ -214,7 +297,12 @@ namespace rsx
|
||||||
}
|
}
|
||||||
|
|
||||||
m_body.text = perf_text;
|
m_body.text = perf_text;
|
||||||
m_body.auto_resize();
|
|
||||||
|
if (m_body.auto_resize())
|
||||||
|
{
|
||||||
|
reset_transforms();
|
||||||
|
}
|
||||||
|
|
||||||
m_body.refresh();
|
m_body.refresh();
|
||||||
|
|
||||||
if (!m_force_update)
|
if (!m_force_update)
|
||||||
|
|
|
@ -418,6 +418,9 @@ namespace rsx
|
||||||
*/
|
*/
|
||||||
detail_level m_detail;
|
detail_level m_detail;
|
||||||
|
|
||||||
|
screen_quadrant m_quadrant;
|
||||||
|
positioni m_position;
|
||||||
|
|
||||||
label m_body;
|
label m_body;
|
||||||
label m_titles;
|
label m_titles;
|
||||||
|
|
||||||
|
@ -425,24 +428,39 @@ namespace rsx
|
||||||
Timer m_update_timer;
|
Timer m_update_timer;
|
||||||
u32 m_update_interval; // in ms
|
u32 m_update_interval; // in ms
|
||||||
u32 m_frames{ 0 };
|
u32 m_frames{ 0 };
|
||||||
|
std::string m_font;
|
||||||
u32 m_font_size;
|
u32 m_font_size;
|
||||||
|
u32 m_margin; // distance to screen borders in px
|
||||||
|
f32 m_opacity; // 0..1
|
||||||
|
|
||||||
bool m_force_update;
|
bool m_force_update;
|
||||||
|
bool m_is_initialised{ false };
|
||||||
|
|
||||||
const std::string title1_medium{"CPU Utilization:"};
|
const std::string title1_medium{"CPU Utilization:"};
|
||||||
const std::string title1_high{"Host Utilization (CPU):"};
|
const std::string title1_high{"Host Utilization (CPU):"};
|
||||||
const std::string title2{"Guest Utilization (PS3):"};
|
const std::string title2{"Guest Utilization (PS3):"};
|
||||||
|
|
||||||
|
void reset_transform(label& elm) const;
|
||||||
|
void reset_transforms();
|
||||||
void reset_body();
|
void reset_body();
|
||||||
void reset_titles();
|
void reset_titles();
|
||||||
|
void reset_text();
|
||||||
|
|
||||||
|
u32 get_text_opacity() const
|
||||||
|
{
|
||||||
|
return std::clamp(m_opacity + 0.3f, 0.3f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
perf_metrics_overlay(bool initialize = true);
|
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
void set_detail_level(detail_level level);
|
void set_detail_level(detail_level level);
|
||||||
|
void set_position(screen_quadrant pos);
|
||||||
void set_update_interval(u32 update_interval);
|
void set_update_interval(u32 update_interval);
|
||||||
|
void set_font(std::string font);
|
||||||
void set_font_size(u32 font_size);
|
void set_font_size(u32 font_size);
|
||||||
|
void set_margin(u32 margin);
|
||||||
|
void set_opacity(f32 opacity);
|
||||||
void force_next_update();
|
void force_next_update();
|
||||||
|
|
||||||
void update() override;
|
void update() override;
|
||||||
|
|
|
@ -358,11 +358,16 @@ namespace rsx
|
||||||
|
|
||||||
if (g_cfg.video.perf_overlay.perf_overlay_enabled)
|
if (g_cfg.video.perf_overlay.perf_overlay_enabled)
|
||||||
{
|
{
|
||||||
auto perf_overlay = m_overlay_manager->create<rsx::overlays::perf_metrics_overlay>(false);
|
auto perf_overlay = m_overlay_manager->create<rsx::overlays::perf_metrics_overlay>();
|
||||||
|
|
||||||
perf_overlay->set_detail_level(g_cfg.video.perf_overlay.level);
|
auto& perf_settings = g_cfg.video.perf_overlay;
|
||||||
perf_overlay->set_update_interval(g_cfg.video.perf_overlay.update_interval);
|
perf_overlay->set_detail_level(perf_settings.level);
|
||||||
perf_overlay->set_font_size(g_cfg.video.perf_overlay.font_size);
|
perf_overlay->set_position(perf_settings.position);
|
||||||
|
perf_overlay->set_update_interval(perf_settings.update_interval);
|
||||||
|
perf_overlay->set_font(perf_settings.font);
|
||||||
|
perf_overlay->set_font_size(perf_settings.font_size);
|
||||||
|
perf_overlay->set_margin(perf_settings.margin);
|
||||||
|
perf_overlay->set_opacity(perf_settings.opacity / 100.f);
|
||||||
perf_overlay->init();
|
perf_overlay->init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,6 +224,23 @@ inline void fmt_class_string<detail_level>::format(std::string& out, u64 arg)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline void fmt_class_string<screen_quadrant>::format(std::string& out, u64 arg)
|
||||||
|
{
|
||||||
|
format_enum(out, arg, [](screen_quadrant value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case screen_quadrant::top_left: return "Top Left";
|
||||||
|
case screen_quadrant::top_right: return "Top Right";
|
||||||
|
case screen_quadrant::bottom_left: return "Bottom Left";
|
||||||
|
case screen_quadrant::bottom_right: return "Bottom Right";
|
||||||
|
}
|
||||||
|
|
||||||
|
return unknown;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
void fmt_class_string<tsx_usage>::format(std::string& out, u64 arg)
|
void fmt_class_string<tsx_usage>::format(std::string& out, u64 arg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,6 +155,14 @@ enum class detail_level
|
||||||
high,
|
high,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum class screen_quadrant
|
||||||
|
{
|
||||||
|
top_left,
|
||||||
|
top_right,
|
||||||
|
bottom_left,
|
||||||
|
bottom_right
|
||||||
|
};
|
||||||
|
|
||||||
enum class tsx_usage
|
enum class tsx_usage
|
||||||
{
|
{
|
||||||
disabled,
|
disabled,
|
||||||
|
@ -421,6 +429,10 @@ struct cfg_root : cfg::node
|
||||||
cfg::_enum<detail_level> level{this, "Detail level", detail_level::high};
|
cfg::_enum<detail_level> level{this, "Detail level", detail_level::high};
|
||||||
cfg::_int<30, 5000> update_interval{ this, "Metrics update interval (ms)", 350 };
|
cfg::_int<30, 5000> update_interval{ this, "Metrics update interval (ms)", 350 };
|
||||||
cfg::_int<4, 36> font_size{ this, "Font size (px)", 10 };
|
cfg::_int<4, 36> font_size{ this, "Font size (px)", 10 };
|
||||||
|
cfg::_enum<screen_quadrant> position{this, "Position", screen_quadrant::top_left};
|
||||||
|
cfg::string font{this, "Font", "n023055ms.ttf"};
|
||||||
|
cfg::_int<0, 500> margin{this, "Margin (px)", 50};
|
||||||
|
cfg::_int<0, 100> opacity{this, "Opacity (%)", 70};
|
||||||
|
|
||||||
} perf_overlay{this};
|
} perf_overlay{this};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue