summaryrefslogtreecommitdiff
path: root/src/core/frontend/framebuffer_layout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/frontend/framebuffer_layout.cpp')
-rw-r--r--src/core/frontend/framebuffer_layout.cpp170
1 files changed, 9 insertions, 161 deletions
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp
index e9f778fcb..8551858d1 100644
--- a/src/core/frontend/framebuffer_layout.cpp
+++ b/src/core/frontend/framebuffer_layout.cpp
@@ -1,25 +1,12 @@
1// Copyright 2016 Citra Emulator Project 1// Copyright 2018 Yuzu Emulator Team
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cmath>
6
7#include "common/assert.h" 5#include "common/assert.h"
8#include "core/3ds.h"
9#include "core/frontend/framebuffer_layout.h" 6#include "core/frontend/framebuffer_layout.h"
10#include "core/settings.h"
11 7
12namespace Layout { 8namespace Layout {
13 9
14static const float TOP_SCREEN_ASPECT_RATIO =
15 static_cast<float>(Core::kScreenTopHeight) / Core::kScreenTopWidth;
16static const float BOT_SCREEN_ASPECT_RATIO =
17 static_cast<float>(Core::kScreenBottomHeight) / Core::kScreenBottomWidth;
18
19float 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 10// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
24template <class T> 11template <class T>
25static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area, 12static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area,
@@ -30,166 +17,27 @@ static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area,
30 static_cast<T>(std::round(scale * screen_aspect_ratio))}; 17 static_cast<T>(std::round(scale * screen_aspect_ratio))};
31} 18}
32 19
33FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) { 20FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
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
73FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool swapped) {
74 ASSERT(width > 0); 21 ASSERT(width > 0);
75 ASSERT(height > 0); 22 ASSERT(height > 0);
76 // The drawing code needs at least somewhat valid values for both screens 23 // 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. 24 // so just calculate them both even if the other isn't showing.
78 FramebufferLayout res{width, height, !swapped, swapped, {}, {}}; 25 FramebufferLayout res{width, height};
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
103FramebufferLayout 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 26
27 const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
28 ScreenUndocked::Width};
120 MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height}; 29 MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
121 MathUtil::Rectangle<unsigned> total_rect = 30 MathUtil::Rectangle<unsigned> screen = maxRectangle(screen_window_area, emulation_aspect_ratio);
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
144FramebufferLayout SideFrameLayout(unsigned width, unsigned height, bool swapped) {
145 ASSERT(width > 0);
146 ASSERT(height > 0);
147 31
148 FramebufferLayout res{width, height, true, true, {}, {}};
149 // Aspect ratio of both screens side by side
150 const float emulation_aspect_ratio = static_cast<float>(Core::kScreenTopHeight) /
151 (Core::kScreenTopWidth + Core::kScreenBottomWidth);
152 float window_aspect_ratio = static_cast<float>(height) / width; 32 float window_aspect_ratio = static_cast<float>(height) / width;
153 MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
154 // Find largest Rectangle that can fit in the window size with the given aspect ratio
155 MathUtil::Rectangle<unsigned> screen_rect =
156 maxRectangle(screen_window_area, emulation_aspect_ratio);
157 // Find sizes of top and bottom screen
158 MathUtil::Rectangle<unsigned> top_screen = maxRectangle(screen_rect, TOP_SCREEN_ASPECT_RATIO);
159 MathUtil::Rectangle<unsigned> bot_screen = maxRectangle(screen_rect, BOT_SCREEN_ASPECT_RATIO);
160 33
161 if (window_aspect_ratio < emulation_aspect_ratio) { 34 if (window_aspect_ratio < emulation_aspect_ratio) {
162 // Apply borders to the left and right sides of the window. 35 screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
163 u32 shift_horizontal = (screen_window_area.GetWidth() - screen_rect.GetWidth()) / 2;
164 top_screen = top_screen.TranslateX(shift_horizontal);
165 bot_screen = bot_screen.TranslateX(shift_horizontal);
166 } else { 36 } else {
167 // Window is narrower than the emulation content => apply borders to the top and bottom 37 screen = screen.TranslateY((height - screen.GetHeight()) / 2);
168 u32 shift_vertical = (screen_window_area.GetHeight() - screen_rect.GetHeight()) / 2;
169 top_screen = top_screen.TranslateY(shift_vertical);
170 bot_screen = bot_screen.TranslateY(shift_vertical);
171 } 38 }
172 // Move the top screen to the right if we are swapped. 39 res.screen = screen;
173 res.top_screen = swapped ? top_screen.TranslateX(bot_screen.GetWidth()) : top_screen;
174 res.bottom_screen = swapped ? bot_screen : bot_screen.TranslateX(top_screen.GetWidth());
175 return res; 40 return res;
176} 41}
177 42
178FramebufferLayout CustomFrameLayout(unsigned width, unsigned height) {
179 ASSERT(width > 0);
180 ASSERT(height > 0);
181
182 FramebufferLayout res{width, height, true, true, {}, {}};
183
184 MathUtil::Rectangle<unsigned> top_screen{
185 Settings::values.custom_top_left, Settings::values.custom_top_top,
186 Settings::values.custom_top_right, Settings::values.custom_top_bottom};
187 MathUtil::Rectangle<unsigned> bot_screen{
188 Settings::values.custom_bottom_left, Settings::values.custom_bottom_top,
189 Settings::values.custom_bottom_right, Settings::values.custom_bottom_bottom};
190
191 res.top_screen = top_screen;
192 res.bottom_screen = bot_screen;
193 return res;
194}
195} // namespace Layout 43} // namespace Layout