diff options
| author | 2017-05-27 16:10:25 -0700 | |
|---|---|---|
| committer | 2017-05-27 16:10:25 -0700 | |
| commit | d1bf7919daf830befd8c2166f3844fcdb56d68fa (patch) | |
| tree | 60ab4434e7a0503d7ca5f5d195d4709fe634f3c1 /src/core/frontend/framebuffer_layout.cpp | |
| parent | Merge pull request #2732 from yuriks/add-fmt (diff) | |
| download | yuzu-d1bf7919daf830befd8c2166f3844fcdb56d68fa.tar.gz yuzu-d1bf7919daf830befd8c2166f3844fcdb56d68fa.tar.xz yuzu-d1bf7919daf830befd8c2166f3844fcdb56d68fa.zip | |
Move framebuffer_layout from Common to Core
This removes a dependency inversion between core and common. It's also
the proper place for the file since it makes screen layout decisions
specific to the 3DS.
Diffstat (limited to 'src/core/frontend/framebuffer_layout.cpp')
| -rw-r--r-- | src/core/frontend/framebuffer_layout.cpp | 157 |
1 files changed, 157 insertions, 0 deletions
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp new file mode 100644 index 000000000..f3815170d --- /dev/null +++ b/src/core/frontend/framebuffer_layout.cpp | |||
| @@ -0,0 +1,157 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "core/frontend/framebuffer_layout.h" | ||
| 9 | #include "core/settings.h" | ||
| 10 | #include "video_core/video_core.h" | ||
| 11 | |||
| 12 | namespace Layout { | ||
| 13 | |||
| 14 | static const float TOP_SCREEN_ASPECT_RATIO = | ||
| 15 | static_cast<float>(VideoCore::kScreenTopHeight) / VideoCore::kScreenTopWidth; | ||
| 16 | static const float BOT_SCREEN_ASPECT_RATIO = | ||
| 17 | static_cast<float>(VideoCore::kScreenBottomHeight) / VideoCore::kScreenBottomWidth; | ||
| 18 | |||
| 19 | // Finds the largest size subrectangle contained in window area that is confined to the aspect ratio | ||
| 20 | template <class T> | ||
| 21 | static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area, | ||
| 22 | float screen_aspect_ratio) { | ||
| 23 | float scale = std::min(static_cast<float>(window_area.GetWidth()), | ||
| 24 | window_area.GetHeight() / screen_aspect_ratio); | ||
| 25 | return MathUtil::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)), | ||
| 26 | static_cast<T>(std::round(scale * screen_aspect_ratio))}; | ||
| 27 | } | ||
| 28 | |||
| 29 | FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 30 | ASSERT(width > 0); | ||
| 31 | ASSERT(height > 0); | ||
| 32 | |||
| 33 | FramebufferLayout res{width, height, true, true, {}, {}}; | ||
| 34 | // Default layout gives equal screen sizes to the top and bottom screen | ||
| 35 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height / 2}; | ||
| 36 | MathUtil::Rectangle<unsigned> top_screen = | ||
| 37 | maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO); | ||
| 38 | MathUtil::Rectangle<unsigned> bot_screen = | ||
| 39 | maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 40 | |||
| 41 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 42 | // both screens height are taken into account by multiplying by 2 | ||
| 43 | float emulation_aspect_ratio = TOP_SCREEN_ASPECT_RATIO * 2; | ||
| 44 | |||
| 45 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 46 | // Apply borders to the left and right sides of the window. | ||
| 47 | top_screen = | ||
| 48 | top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2); | ||
| 49 | bot_screen = | ||
| 50 | bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 51 | } else { | ||
| 52 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 53 | // Recalculate the bottom screen to account for the width difference between top and bottom | ||
| 54 | screen_window_area = {0, 0, width, top_screen.GetHeight()}; | ||
| 55 | bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 56 | bot_screen = bot_screen.TranslateX((top_screen.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 57 | if (swapped) { | ||
| 58 | bot_screen = bot_screen.TranslateY(height / 2 - bot_screen.GetHeight()); | ||
| 59 | } else { | ||
| 60 | top_screen = top_screen.TranslateY(height / 2 - top_screen.GetHeight()); | ||
| 61 | } | ||
| 62 | } | ||
| 63 | // Move the top screen to the bottom if we are swapped. | ||
| 64 | res.top_screen = swapped ? top_screen.TranslateY(height / 2) : top_screen; | ||
| 65 | res.bottom_screen = swapped ? bot_screen : bot_screen.TranslateY(height / 2); | ||
| 66 | return res; | ||
| 67 | } | ||
| 68 | |||
| 69 | FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 70 | ASSERT(width > 0); | ||
| 71 | ASSERT(height > 0); | ||
| 72 | // The drawing code needs at least somewhat valid values for both screens | ||
| 73 | // so just calculate them both even if the other isn't showing. | ||
| 74 | FramebufferLayout res{width, height, !swapped, swapped, {}, {}}; | ||
| 75 | |||
| 76 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height}; | ||
| 77 | MathUtil::Rectangle<unsigned> top_screen = | ||
| 78 | maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO); | ||
| 79 | MathUtil::Rectangle<unsigned> bot_screen = | ||
| 80 | maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 81 | |||
| 82 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 83 | float emulation_aspect_ratio = (swapped) ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; | ||
| 84 | |||
| 85 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 86 | top_screen = | ||
| 87 | top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2); | ||
| 88 | bot_screen = | ||
| 89 | bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 90 | } else { | ||
| 91 | top_screen = top_screen.TranslateY((height - top_screen.GetHeight()) / 2); | ||
| 92 | bot_screen = bot_screen.TranslateY((height - bot_screen.GetHeight()) / 2); | ||
| 93 | } | ||
| 94 | res.top_screen = top_screen; | ||
| 95 | res.bottom_screen = bot_screen; | ||
| 96 | return res; | ||
| 97 | } | ||
| 98 | |||
| 99 | FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 100 | ASSERT(width > 0); | ||
| 101 | ASSERT(height > 0); | ||
| 102 | |||
| 103 | FramebufferLayout res{width, height, true, true, {}, {}}; | ||
| 104 | // Split the window into two parts. Give 4x width to the main screen and 1x width to the small | ||
| 105 | // To do that, find the total emulation box and maximize that based on window size | ||
| 106 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 107 | float emulation_aspect_ratio = | ||
| 108 | swapped | ||
| 109 | ? VideoCore::kScreenBottomHeight * 4 / | ||
| 110 | (VideoCore::kScreenBottomWidth * 4.0f + VideoCore::kScreenTopWidth) | ||
| 111 | : VideoCore::kScreenTopHeight * 4 / | ||
| 112 | (VideoCore::kScreenTopWidth * 4.0f + VideoCore::kScreenBottomWidth); | ||
| 113 | float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; | ||
| 114 | float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO; | ||
| 115 | |||
| 116 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height}; | ||
| 117 | MathUtil::Rectangle<unsigned> total_rect = | ||
| 118 | maxRectangle(screen_window_area, emulation_aspect_ratio); | ||
| 119 | MathUtil::Rectangle<unsigned> large_screen = | ||
| 120 | maxRectangle(total_rect, large_screen_aspect_ratio); | ||
| 121 | MathUtil::Rectangle<unsigned> fourth_size_rect = total_rect.Scale(.25f); | ||
| 122 | MathUtil::Rectangle<unsigned> small_screen = | ||
| 123 | maxRectangle(fourth_size_rect, small_screen_aspect_ratio); | ||
| 124 | |||
| 125 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 126 | large_screen = | ||
| 127 | large_screen.TranslateX((screen_window_area.GetWidth() - total_rect.GetWidth()) / 2); | ||
| 128 | } else { | ||
| 129 | large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2); | ||
| 130 | } | ||
| 131 | // Shift the small screen to the bottom right corner | ||
| 132 | small_screen = | ||
| 133 | small_screen.TranslateX(large_screen.right) | ||
| 134 | .TranslateY(large_screen.GetHeight() + large_screen.top - small_screen.GetHeight()); | ||
| 135 | res.top_screen = swapped ? small_screen : large_screen; | ||
| 136 | res.bottom_screen = swapped ? large_screen : small_screen; | ||
| 137 | return res; | ||
| 138 | } | ||
| 139 | |||
| 140 | FramebufferLayout CustomFrameLayout(unsigned width, unsigned height) { | ||
| 141 | ASSERT(width > 0); | ||
| 142 | ASSERT(height > 0); | ||
| 143 | |||
| 144 | FramebufferLayout res{width, height, true, true, {}, {}}; | ||
| 145 | |||
| 146 | MathUtil::Rectangle<unsigned> top_screen{ | ||
| 147 | Settings::values.custom_top_left, Settings::values.custom_top_top, | ||
| 148 | Settings::values.custom_top_right, Settings::values.custom_top_bottom}; | ||
| 149 | MathUtil::Rectangle<unsigned> bot_screen{ | ||
| 150 | Settings::values.custom_bottom_left, Settings::values.custom_bottom_top, | ||
| 151 | Settings::values.custom_bottom_right, Settings::values.custom_bottom_bottom}; | ||
| 152 | |||
| 153 | res.top_screen = top_screen; | ||
| 154 | res.bottom_screen = bot_screen; | ||
| 155 | return res; | ||
| 156 | } | ||
| 157 | } | ||