diff --git a/src/common/framebuffer_layout.cpp b/src/common/framebuffer_layout.cpp index 46c008d9c..dfc6e7514 100644 --- a/src/common/framebuffer_layout.cpp +++ b/src/common/framebuffer_layout.cpp @@ -100,39 +100,31 @@ FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped ASSERT(height > 0); FramebufferLayout res{width, height, true, true, {}, {}}; - // Split the window into two parts. Give 4x width to the main screen and 1x width to the small - // To do that, find the total emulation box and maximize that based on window size - float window_aspect_ratio = static_cast(height) / width; - float emulation_aspect_ratio = - swapped - ? VideoCore::kScreenBottomHeight * 4 / - (VideoCore::kScreenBottomWidth * 4.0f + VideoCore::kScreenTopWidth) - : VideoCore::kScreenTopHeight * 4 / - (VideoCore::kScreenTopWidth * 4.0f + VideoCore::kScreenBottomWidth); - float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; - float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO; + int viewport_height = static_cast(std::round((width - VideoCore::kScreenBottomWidth) * + TOP_SCREEN_ASPECT_RATIO)); - MathUtil::Rectangle screen_window_area{0, 0, width, height}; - MathUtil::Rectangle total_rect = - maxRectangle(screen_window_area, emulation_aspect_ratio); - MathUtil::Rectangle large_screen = - maxRectangle(total_rect, large_screen_aspect_ratio); - MathUtil::Rectangle fourth_size_rect = total_rect.Scale(.25f); - MathUtil::Rectangle small_screen = - maxRectangle(fourth_size_rect, small_screen_aspect_ratio); - - if (window_aspect_ratio < emulation_aspect_ratio) { - large_screen = - large_screen.TranslateX((screen_window_area.GetWidth() - total_rect.GetWidth()) / 2); + if (height > viewport_height) { + // Apply borders to the top and bottom. + unsigned top_screen_bottom = viewport_height + (height - viewport_height) / 2; + res.top_screen = {0, (height - viewport_height) / 2, + width - VideoCore::kScreenBottomWidth, top_screen_bottom}; + res.bottom_screen = {width - VideoCore::kScreenBottomWidth, + top_screen_bottom - VideoCore::kScreenBottomHeight, + width, top_screen_bottom}; } else { - large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2); + // Apply borders to the left and right sides of the window. + int viewport_width = static_cast(std::round((height / TOP_SCREEN_ASPECT_RATIO) + + VideoCore::kScreenBottomWidth)); + unsigned top_screen_right = (height / TOP_SCREEN_ASPECT_RATIO) + (width - viewport_width) / 2; + res.top_screen = {(width - viewport_width) / 2, 0, top_screen_right, height}; + res.bottom_screen = {top_screen_right, height - VideoCore::kScreenBottomHeight, + top_screen_right + VideoCore::kScreenBottomWidth, height}; + } + if (swapped) { + MathUtil::Rectangle temp = res.top_screen; + res.top_screen = res.bottom_screen; + res.bottom_screen = temp; } - // Shift the small screen to the bottom right corner - small_screen = - small_screen.TranslateX(large_screen.right) - .TranslateY(large_screen.GetHeight() + large_screen.top - small_screen.GetHeight()); - res.top_screen = swapped ? small_screen : large_screen; - res.bottom_screen = swapped ? large_screen : small_screen; return res; } }