diff options
| author | 2016-05-03 00:07:17 -0600 | |
|---|---|---|
| committer | 2016-11-05 02:55:41 -0600 | |
| commit | 2b1654ad9bbd8af53f22434d350704a1a1d0a285 (patch) | |
| tree | 0da3cc7a1c622c1a659f4b2a8c5c08984dabd5c3 /src/common/framebuffer_layout.cpp | |
| parent | Update CONTRIBUTING.md (diff) | |
| download | yuzu-2b1654ad9bbd8af53f22434d350704a1a1d0a285.tar.gz yuzu-2b1654ad9bbd8af53f22434d350704a1a1d0a285.tar.xz yuzu-2b1654ad9bbd8af53f22434d350704a1a1d0a285.zip | |
Support additional screen layouts.
Allows users to choose a single screen layout or a large screen layout.
Adds a configuration option to change the prominent screen.
Diffstat (limited to 'src/common/framebuffer_layout.cpp')
| -rw-r--r-- | src/common/framebuffer_layout.cpp | 312 |
1 files changed, 312 insertions, 0 deletions
diff --git a/src/common/framebuffer_layout.cpp b/src/common/framebuffer_layout.cpp new file mode 100644 index 000000000..a0e75090d --- /dev/null +++ b/src/common/framebuffer_layout.cpp | |||
| @@ -0,0 +1,312 @@ | |||
| 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 "common/framebuffer_layout.h" | ||
| 9 | #include "video_core/video_core.h" | ||
| 10 | |||
| 11 | namespace Layout { | ||
| 12 | static FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) { | ||
| 13 | |||
| 14 | ASSERT(width > 0); | ||
| 15 | ASSERT(height > 0); | ||
| 16 | |||
| 17 | FramebufferLayout res {width, height, true, true, {}, {}}; | ||
| 18 | |||
| 19 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 20 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight * 2) / | ||
| 21 | VideoCore::kScreenTopWidth; | ||
| 22 | |||
| 23 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 24 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 25 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 26 | |||
| 27 | res.top_screen.left = 0; | ||
| 28 | res.top_screen.right = res.top_screen.left + width; | ||
| 29 | res.top_screen.top = (height - viewport_height) / 2; | ||
| 30 | res.top_screen.bottom = res.top_screen.top + viewport_height / 2; | ||
| 31 | |||
| 32 | int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / | ||
| 33 | VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); | ||
| 34 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 35 | |||
| 36 | res.bottom_screen.left = bottom_border; | ||
| 37 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 38 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 39 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2; | ||
| 40 | } else { | ||
| 41 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 42 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 43 | |||
| 44 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 45 | res.top_screen.right = res.top_screen.left + viewport_width; | ||
| 46 | res.top_screen.top = 0; | ||
| 47 | res.top_screen.bottom = res.top_screen.top + height / 2; | ||
| 48 | |||
| 49 | int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / | ||
| 50 | VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); | ||
| 51 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 52 | |||
| 53 | res.bottom_screen.left = res.top_screen.left + bottom_border; | ||
| 54 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 55 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 56 | res.bottom_screen.bottom = res.bottom_screen.top + height / 2; | ||
| 57 | } | ||
| 58 | |||
| 59 | return res; | ||
| 60 | } | ||
| 61 | |||
| 62 | static FramebufferLayout DefaultFrameLayout_Swapped(unsigned width, unsigned height) { | ||
| 63 | |||
| 64 | ASSERT(width > 0); | ||
| 65 | ASSERT(height > 0); | ||
| 66 | |||
| 67 | FramebufferLayout res {width, height, true, true, {}, {}}; | ||
| 68 | |||
| 69 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 70 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight * 2) / | ||
| 71 | VideoCore::kScreenTopWidth; | ||
| 72 | |||
| 73 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 74 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 75 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 76 | |||
| 77 | res.top_screen.left = 0; | ||
| 78 | res.top_screen.right = res.top_screen.left + width; | ||
| 79 | |||
| 80 | int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / | ||
| 81 | VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); | ||
| 82 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 83 | |||
| 84 | res.bottom_screen.left = bottom_border; | ||
| 85 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 86 | res.bottom_screen.top = (height - viewport_height) / 2; | ||
| 87 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2; | ||
| 88 | |||
| 89 | res.top_screen.top = res.bottom_screen.bottom; | ||
| 90 | res.top_screen.bottom = res.top_screen.top + viewport_height / 2; | ||
| 91 | } else { | ||
| 92 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 93 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 94 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 95 | res.top_screen.right = res.top_screen.left + viewport_width; | ||
| 96 | |||
| 97 | int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) / | ||
| 98 | VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left)); | ||
| 99 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 100 | |||
| 101 | res.bottom_screen.left = res.top_screen.left + bottom_border; | ||
| 102 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 103 | res.bottom_screen.top = 0; | ||
| 104 | res.bottom_screen.bottom = res.bottom_screen.top + height / 2; | ||
| 105 | |||
| 106 | res.top_screen.top = res.bottom_screen.bottom; | ||
| 107 | res.top_screen.bottom = res.top_screen.top + height / 2; | ||
| 108 | } | ||
| 109 | |||
| 110 | return res; | ||
| 111 | } | ||
| 112 | |||
| 113 | static FramebufferLayout SingleFrameLayout(unsigned width, unsigned height) { | ||
| 114 | |||
| 115 | ASSERT(width > 0); | ||
| 116 | ASSERT(height > 0); | ||
| 117 | |||
| 118 | FramebufferLayout res {width, height, true, false, {}, {}}; | ||
| 119 | |||
| 120 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 121 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight) / | ||
| 122 | VideoCore::kScreenTopWidth; | ||
| 123 | |||
| 124 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 125 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 126 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 127 | |||
| 128 | res.top_screen.left = 0; | ||
| 129 | res.top_screen.right = res.top_screen.left + width; | ||
| 130 | res.top_screen.top = (height - viewport_height) / 2; | ||
| 131 | res.top_screen.bottom = res.top_screen.top + viewport_height; | ||
| 132 | |||
| 133 | res.bottom_screen.left = 0; | ||
| 134 | res.bottom_screen.right = VideoCore::kScreenBottomWidth; | ||
| 135 | res.bottom_screen.top = 0; | ||
| 136 | res.bottom_screen.bottom = VideoCore::kScreenBottomHeight; | ||
| 137 | } else { | ||
| 138 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 139 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 140 | |||
| 141 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 142 | res.top_screen.right = res.top_screen.left + viewport_width; | ||
| 143 | res.top_screen.top = 0; | ||
| 144 | res.top_screen.bottom = res.top_screen.top + height; | ||
| 145 | |||
| 146 | // The Rasterizer still depends on these fields to maintain the right aspect ratio | ||
| 147 | res.bottom_screen.left = 0; | ||
| 148 | res.bottom_screen.right = VideoCore::kScreenBottomWidth; | ||
| 149 | res.bottom_screen.top = 0; | ||
| 150 | res.bottom_screen.bottom = VideoCore::kScreenBottomHeight; | ||
| 151 | } | ||
| 152 | |||
| 153 | return res; | ||
| 154 | } | ||
| 155 | |||
| 156 | static FramebufferLayout SingleFrameLayout_Swapped(unsigned width, unsigned height) { | ||
| 157 | |||
| 158 | ASSERT(width > 0); | ||
| 159 | ASSERT(height > 0); | ||
| 160 | |||
| 161 | FramebufferLayout res {width, height, false, true, {}, {}}; | ||
| 162 | |||
| 163 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 164 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenBottomHeight) / | ||
| 165 | VideoCore::kScreenBottomWidth; | ||
| 166 | |||
| 167 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 168 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 169 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 170 | |||
| 171 | res.bottom_screen.left = 0; | ||
| 172 | res.bottom_screen.right = res.bottom_screen.left + width; | ||
| 173 | res.bottom_screen.top = (height - viewport_height) / 2; | ||
| 174 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height; | ||
| 175 | |||
| 176 | // The Rasterizer still depends on these fields to maintain the right aspect ratio | ||
| 177 | res.top_screen.left = 0; | ||
| 178 | res.top_screen.right = VideoCore::kScreenTopWidth; | ||
| 179 | res.top_screen.top = 0; | ||
| 180 | res.top_screen.bottom = VideoCore::kScreenTopHeight; | ||
| 181 | } else { | ||
| 182 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 183 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 184 | |||
| 185 | res.bottom_screen.left = (width - viewport_width) / 2; | ||
| 186 | res.bottom_screen.right = res.bottom_screen.left + viewport_width; | ||
| 187 | res.bottom_screen.top = 0; | ||
| 188 | res.bottom_screen.bottom = res.bottom_screen.top + height; | ||
| 189 | |||
| 190 | res.top_screen.left = 0; | ||
| 191 | res.top_screen.right = VideoCore::kScreenTopWidth; | ||
| 192 | res.top_screen.top = 0; | ||
| 193 | res.top_screen.bottom = VideoCore::kScreenTopHeight; | ||
| 194 | } | ||
| 195 | |||
| 196 | return res; | ||
| 197 | } | ||
| 198 | |||
| 199 | static FramebufferLayout LargeFrameLayout(unsigned width, unsigned height) { | ||
| 200 | |||
| 201 | ASSERT(width > 0); | ||
| 202 | ASSERT(height > 0); | ||
| 203 | |||
| 204 | FramebufferLayout res {width, height, true, true, {}, {}}; | ||
| 205 | |||
| 206 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 207 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight * 4) / | ||
| 208 | (VideoCore::kScreenTopWidth * 4 + VideoCore::kScreenBottomWidth); | ||
| 209 | |||
| 210 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 211 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 212 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 213 | |||
| 214 | res.top_screen.left = 0; | ||
| 215 | // Top screen occupies 4 / 5ths of the total width | ||
| 216 | res.top_screen.right = static_cast<int>(std::round(width / 5)) * 4; | ||
| 217 | res.top_screen.top = (height - viewport_height) / 2; | ||
| 218 | res.top_screen.bottom = res.top_screen.top + viewport_height; | ||
| 219 | |||
| 220 | int bottom_height = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomHeight) / | ||
| 221 | VideoCore::kScreenBottomWidth) * (width - res.top_screen.right)); | ||
| 222 | |||
| 223 | res.bottom_screen.left = res.top_screen.right; | ||
| 224 | res.bottom_screen.right = width; | ||
| 225 | res.bottom_screen.bottom = res.top_screen.bottom; | ||
| 226 | res.bottom_screen.top = res.bottom_screen.bottom - bottom_height; | ||
| 227 | } else { | ||
| 228 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 229 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 230 | // Break the viewport into fifths and give top 4 of them | ||
| 231 | int fifth_width = static_cast<int>(std::round(viewport_width / 5)); | ||
| 232 | |||
| 233 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 234 | res.top_screen.right = res.top_screen.left + fifth_width * 4; | ||
| 235 | res.top_screen.top = 0; | ||
| 236 | res.top_screen.bottom = height; | ||
| 237 | |||
| 238 | int bottom_height = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomHeight) / | ||
| 239 | VideoCore::kScreenBottomWidth) * (fifth_width)); | ||
| 240 | |||
| 241 | res.bottom_screen.left = res.top_screen.right; | ||
| 242 | res.bottom_screen.right = width - (width - viewport_width) / 2; | ||
| 243 | res.bottom_screen.bottom = res.top_screen.bottom; | ||
| 244 | res.bottom_screen.top = res.bottom_screen.bottom - bottom_height; | ||
| 245 | } | ||
| 246 | |||
| 247 | return res; | ||
| 248 | } | ||
| 249 | |||
| 250 | static FramebufferLayout LargeFrameLayout_Swapped(unsigned width, unsigned height) { | ||
| 251 | |||
| 252 | ASSERT(width > 0); | ||
| 253 | ASSERT(height > 0); | ||
| 254 | |||
| 255 | FramebufferLayout res {width, height, true, true, {}, {}}; | ||
| 256 | |||
| 257 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 258 | float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenBottomHeight * 4) / | ||
| 259 | (VideoCore::kScreenBottomWidth * 4 + VideoCore::kScreenTopWidth); | ||
| 260 | |||
| 261 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 262 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 263 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 264 | |||
| 265 | res.bottom_screen.left = 0; | ||
| 266 | // Top screen occupies 4 / 5ths of the total width | ||
| 267 | res.bottom_screen.right = static_cast<int>(std::round(width / 5)) * 4; | ||
| 268 | res.bottom_screen.top = (height - viewport_height) / 2; | ||
| 269 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height; | ||
| 270 | |||
| 271 | int top_height = static_cast<int>((static_cast<float>(VideoCore::kScreenTopHeight) / | ||
| 272 | VideoCore::kScreenTopWidth) * (width - res.bottom_screen.right)); | ||
| 273 | |||
| 274 | res.top_screen.left = res.bottom_screen.right; | ||
| 275 | res.top_screen.right = width; | ||
| 276 | res.top_screen.bottom = res.bottom_screen.bottom; | ||
| 277 | res.top_screen.top = res.top_screen.bottom - top_height; | ||
| 278 | } else { | ||
| 279 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 280 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 281 | // Break the viewport into fifths and give top 4 of them | ||
| 282 | int fifth_width = static_cast<int>(std::round(viewport_width / 5)); | ||
| 283 | |||
| 284 | res.bottom_screen.left = (width - viewport_width) / 2; | ||
| 285 | res.bottom_screen.right = res.bottom_screen.left + fifth_width * 4; | ||
| 286 | res.bottom_screen.top = 0; | ||
| 287 | res.bottom_screen.bottom = height; | ||
| 288 | |||
| 289 | int top_height = static_cast<int>((static_cast<float>(VideoCore::kScreenTopHeight) / | ||
| 290 | VideoCore::kScreenTopWidth) * (fifth_width)); | ||
| 291 | |||
| 292 | res.top_screen.left = res.bottom_screen.right; | ||
| 293 | res.top_screen.right = width - (width - viewport_width) / 2; | ||
| 294 | res.top_screen.bottom = res.bottom_screen.bottom; | ||
| 295 | res.top_screen.top = res.top_screen.bottom - top_height; | ||
| 296 | } | ||
| 297 | |||
| 298 | return res; | ||
| 299 | } | ||
| 300 | |||
| 301 | FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool is_swapped) { | ||
| 302 | return is_swapped ? DefaultFrameLayout_Swapped(width, height) : DefaultFrameLayout(width, height); | ||
| 303 | } | ||
| 304 | |||
| 305 | FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swapped) { | ||
| 306 | return is_swapped ? SingleFrameLayout_Swapped(width, height) : SingleFrameLayout(width, height); | ||
| 307 | } | ||
| 308 | |||
| 309 | FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped) { | ||
| 310 | return is_swapped ? LargeFrameLayout_Swapped(width, height) : LargeFrameLayout(width, height); | ||
| 311 | } | ||
| 312 | } \ No newline at end of file | ||