Video: fix auto resolution scale calculations

This commit is contained in:
Filoppi 2023-09-07 02:37:34 +03:00
parent fdd1934f12
commit ff03189a60
1 changed files with 17 additions and 28 deletions

View File

@ -400,35 +400,24 @@ void* Presenter::GetNewSurfaceHandle()
u32 Presenter::AutoIntegralScale() const
{
const float efb_aspect_ratio = static_cast<float>(EFB_WIDTH) / EFB_HEIGHT;
const float target_aspect_ratio =
static_cast<float>(m_target_rectangle.GetWidth()) / m_target_rectangle.GetHeight();
u32 target_width;
u32 target_height;
// Instead of using the entire window (back buffer) resolution,
// find the portion of it that will actually contain the EFB output,
// and ignore the portion that will likely have black bars.
if (target_aspect_ratio >= efb_aspect_ratio)
{
target_height = m_target_rectangle.GetHeight();
target_width = static_cast<u32>(
std::round((static_cast<float>(m_target_rectangle.GetWidth()) / target_aspect_ratio) *
efb_aspect_ratio));
}
// Take the source resolution (XFB) and stretch it on the target aspect ratio.
// If the target resolution is larger (on either x or y), we scale the source
// by a integer multiplier until it won't have to be scaled up anymore.
u32 source_width = m_last_xfb_width;
u32 source_height = m_last_xfb_height;
const u32 target_width = m_target_rectangle.GetWidth();
const u32 target_height = m_target_rectangle.GetHeight();
const float source_aspect_ratio = (float)source_width / source_height;
const float target_aspect_ratio = (float)target_width / target_height;
if (source_aspect_ratio >= target_aspect_ratio)
source_width = std::round(source_height * target_aspect_ratio);
else
{
target_width = m_target_rectangle.GetWidth();
target_height = static_cast<u32>(
std::round((static_cast<float>(m_target_rectangle.GetHeight()) * target_aspect_ratio) /
efb_aspect_ratio));
}
// Calculate a scale based on the adjusted window size
u32 width = EFB_WIDTH * target_width / m_last_xfb_width;
u32 height = EFB_HEIGHT * target_height / m_last_xfb_height;
return std::max((width - 1) / EFB_WIDTH + 1, (height - 1) / EFB_HEIGHT + 1);
source_height = std::round(source_width / target_aspect_ratio);
const u32 width_scale =
source_width > 0 ? ((target_width + (source_width - 1)) / source_width) : 1;
const u32 height_scale =
source_height > 0 ? ((target_height + (source_height - 1)) / source_height) : 1;
return std::max(width_scale, height_scale);
}
void Presenter::SetSuggestedWindowSize(int width, int height)