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 | |
| 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')
| -rw-r--r-- | src/core/frontend/emu_window.cpp | 8 | ||||
| -rw-r--r-- | src/core/frontend/emu_window.h | 2 | ||||
| -rw-r--r-- | src/core/frontend/framebuffer_layout.cpp | 161 | ||||
| -rw-r--r-- | src/core/frontend/framebuffer_layout.h | 64 |
4 files changed, 229 insertions, 6 deletions
diff --git a/src/core/frontend/emu_window.cpp b/src/core/frontend/emu_window.cpp index 5fdb3a7e8..4f7d54a33 100644 --- a/src/core/frontend/emu_window.cpp +++ b/src/core/frontend/emu_window.cpp | |||
| @@ -5,10 +5,10 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <cmath> | 6 | #include <cmath> |
| 7 | #include "common/assert.h" | 7 | #include "common/assert.h" |
| 8 | #include "core/3ds.h" | ||
| 8 | #include "core/core.h" | 9 | #include "core/core.h" |
| 9 | #include "core/frontend/emu_window.h" | 10 | #include "core/frontend/emu_window.h" |
| 10 | #include "core/settings.h" | 11 | #include "core/settings.h" |
| 11 | #include "video_core/video_core.h" | ||
| 12 | 12 | ||
| 13 | /** | 13 | /** |
| 14 | * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout | 14 | * Check if the given x/y coordinates are within the touchpad specified by the framebuffer layout |
| @@ -38,11 +38,9 @@ void EmuWindow::TouchPressed(unsigned framebuffer_x, unsigned framebuffer_y) { | |||
| 38 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) | 38 | if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) |
| 39 | return; | 39 | return; |
| 40 | 40 | ||
| 41 | touch_x = VideoCore::kScreenBottomWidth * | 41 | touch_x = Core::kScreenBottomWidth * (framebuffer_x - framebuffer_layout.bottom_screen.left) / |
| 42 | (framebuffer_x - framebuffer_layout.bottom_screen.left) / | ||
| 43 | (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); | 42 | (framebuffer_layout.bottom_screen.right - framebuffer_layout.bottom_screen.left); |
| 44 | touch_y = VideoCore::kScreenBottomHeight * | 43 | touch_y = Core::kScreenBottomHeight * (framebuffer_y - framebuffer_layout.bottom_screen.top) / |
| 45 | (framebuffer_y - framebuffer_layout.bottom_screen.top) / | ||
| 46 | (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); | 44 | (framebuffer_layout.bottom_screen.bottom - framebuffer_layout.bottom_screen.top); |
| 47 | 45 | ||
| 48 | touch_pressed = true; | 46 | touch_pressed = true; |
diff --git a/src/core/frontend/emu_window.h b/src/core/frontend/emu_window.h index 36f2667fa..9414123a4 100644 --- a/src/core/frontend/emu_window.h +++ b/src/core/frontend/emu_window.h | |||
| @@ -8,8 +8,8 @@ | |||
| 8 | #include <tuple> | 8 | #include <tuple> |
| 9 | #include <utility> | 9 | #include <utility> |
| 10 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/framebuffer_layout.h" | ||
| 12 | #include "common/math_util.h" | 11 | #include "common/math_util.h" |
| 12 | #include "core/frontend/framebuffer_layout.h" | ||
| 13 | 13 | ||
| 14 | /** | 14 | /** |
| 15 | * Abstraction class used to provide an interface between emulation code and the frontend | 15 | * Abstraction class used to provide an interface between emulation code and the frontend |
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 | } | ||
diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h new file mode 100644 index 000000000..9a7738969 --- /dev/null +++ b/src/core/frontend/framebuffer_layout.h | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/math_util.h" | ||
| 8 | |||
| 9 | namespace Layout { | ||
| 10 | |||
| 11 | /// Describes the layout of the window framebuffer (size and top/bottom screen positions) | ||
| 12 | struct FramebufferLayout { | ||
| 13 | unsigned width; | ||
| 14 | unsigned height; | ||
| 15 | bool top_screen_enabled; | ||
| 16 | bool bottom_screen_enabled; | ||
| 17 | MathUtil::Rectangle<unsigned> top_screen; | ||
| 18 | MathUtil::Rectangle<unsigned> bottom_screen; | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Returns the ration of pixel size of the top screen, compared to the native size of the 3DS | ||
| 22 | * screen. | ||
| 23 | */ | ||
| 24 | float GetScalingRatio() const; | ||
| 25 | }; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * Factory method for constructing a default FramebufferLayout | ||
| 29 | * @param width Window framebuffer width in pixels | ||
| 30 | * @param height Window framebuffer height in pixels | ||
| 31 | * @param is_swapped if true, the bottom screen will be displayed above the top screen | ||
| 32 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 33 | */ | ||
| 34 | FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Factory method for constructing a FramebufferLayout with only the top or bottom screen | ||
| 38 | * @param width Window framebuffer width in pixels | ||
| 39 | * @param height Window framebuffer height in pixels | ||
| 40 | * @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed) | ||
| 41 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 42 | */ | ||
| 43 | FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Factory method for constructing a Frame with the a 4x size Top screen with a 1x size bottom | ||
| 47 | * screen on the right | ||
| 48 | * This is useful in particular because it matches well with a 1920x1080 resolution monitor | ||
| 49 | * @param width Window framebuffer width in pixels | ||
| 50 | * @param height Window framebuffer height in pixels | ||
| 51 | * @param is_swapped if true, the bottom screen will be the large display | ||
| 52 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 53 | */ | ||
| 54 | FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Factory method for constructing a custom FramebufferLayout | ||
| 58 | * @param width Window framebuffer width in pixels | ||
| 59 | * @param height Window framebuffer height in pixels | ||
| 60 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 61 | */ | ||
| 62 | FramebufferLayout CustomFrameLayout(unsigned width, unsigned height); | ||
| 63 | |||
| 64 | } // namespace Layout | ||