diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 0456d46530..b41b892f99 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -476,6 +476,21 @@ float Renderer::CalculateDrawAspectRatio(int target_width, int target_height) } } +std::tuple Renderer::ScaleToDisplayAspectRatio(const int width, const int height) +{ + // Scale either the width or height depending the content aspect ratio. + // This way we preserve as much resolution as possible when scaling. + float ratio = CalculateDrawAspectRatio(width, height); + if (ratio >= 1.0f) + { + // Preserve horizontal resolution, scale vertically. + return std::make_tuple(static_cast(width), static_cast(height) * ratio); + } + + // Preserve vertical resolution, scale horizontally. + return std::make_tuple(static_cast(width) / ratio, static_cast(height)); +} + TargetRectangle Renderer::CalculateFrameDumpDrawRectangle() { // No point including any borders in the frame dump image, since they'd have to be cropped anyway. @@ -498,22 +513,8 @@ TargetRectangle Renderer::CalculateFrameDumpDrawRectangle() unsigned int efb_width, efb_height; g_framebuffer_manager->GetTargetSize(&efb_width, &efb_height); - // Scale either the width or height depending the content aspect ratio. - // This way we preserve as much resolution as possible when scaling. - float ratio = CalculateDrawAspectRatio(efb_width, efb_height); float draw_width, draw_height; - if (ratio >= 1.0f) - { - // Preserve horizontal resolution, scale vertically. - draw_width = static_cast(efb_width); - draw_height = static_cast(efb_height) * ratio; - } - else - { - // Preserve vertical resolution, scale horizontally. - draw_width = static_cast(efb_width) / ratio; - draw_height = static_cast(efb_height); - } + std::tie(draw_width, draw_height) = ScaleToDisplayAspectRatio(efb_width, efb_height); rc.right = static_cast(std::ceil(draw_width)); rc.bottom = static_cast(std::ceil(draw_height)); diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 22d6093420..be997f7fb3 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "Common/CommonTypes.h" @@ -94,6 +95,7 @@ public: static const TargetRectangle& GetTargetRectangle() { return target_rc; } static float CalculateDrawAspectRatio(int target_width, int target_height); + static std::tuple ScaleToDisplayAspectRatio(int width, int height); static TargetRectangle CalculateFrameDumpDrawRectangle(); static void UpdateDrawRectangle();