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