summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-07 18:18:40 -0500
committerGravatar bunnei2015-03-07 18:18:40 -0500
commit06bf4715810489548a9a3b5e9274dfc78bc3fc4d (patch)
treea2722e2b7e1356d9cb9725f18f0561fcaf815ec1 /src/common
parentMerge pull request #637 from Subv/etc (diff)
parentSet framebuffer layout from EmuWindow. (diff)
downloadyuzu-06bf4715810489548a9a3b5e9274dfc78bc3fc4d.tar.gz
yuzu-06bf4715810489548a9a3b5e9274dfc78bc3fc4d.tar.xz
yuzu-06bf4715810489548a9a3b5e9274dfc78bc3fc4d.zip
Merge pull request #636 from bunnei/refactor-screen-win
Set framebuffer layout from EmuWindow.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/emu_window.cpp50
-rw-r--r--src/common/emu_window.h32
2 files changed, 75 insertions, 7 deletions
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp
index 48bb35db5..1082ae26d 100644
--- a/src/common/emu_window.cpp
+++ b/src/common/emu_window.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "emu_window.h" 5#include "emu_window.h"
6#include "video_core/video_core.h"
6 7
7void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) { 8void EmuWindow::KeyPressed(KeyMap::HostDeviceKey key) {
8 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key); 9 Service::HID::PadState mapped_key = KeyMap::GetPadKey(key);
@@ -15,3 +16,52 @@ void EmuWindow::KeyReleased(KeyMap::HostDeviceKey key) {
15 16
16 Service::HID::PadButtonRelease(mapped_key); 17 Service::HID::PadButtonRelease(mapped_key);
17} 18}
19
20EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(int width, int height) {
21 ASSERT(width > 0);
22 ASSERT(height > 0);
23
24 EmuWindow::FramebufferLayout res = { width, height, {}, {} };
25
26 float window_aspect_ratio = static_cast<float>(height) / width;
27 float emulation_aspect_ratio = static_cast<float>(VideoCore::kScreenTopHeight * 2) /
28 VideoCore::kScreenTopWidth;
29
30 if (window_aspect_ratio > emulation_aspect_ratio) {
31 // Window is narrower than the emulation content => apply borders to the top and bottom
32 int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width));
33
34 res.top_screen.left = 0;
35 res.top_screen.right = res.top_screen.left + width;
36 res.top_screen.top = (height - viewport_height) / 2;
37 res.top_screen.bottom = res.top_screen.top + viewport_height / 2;
38
39 int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) /
40 VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left));
41 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
42
43 res.bottom_screen.left = bottom_border;
44 res.bottom_screen.right = res.bottom_screen.left + bottom_width;
45 res.bottom_screen.top = res.top_screen.bottom;
46 res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2;
47 } else {
48 // Otherwise, apply borders to the left and right sides of the window.
49 int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio));
50
51 res.top_screen.left = (width - viewport_width) / 2;
52 res.top_screen.right = res.top_screen.left + viewport_width;
53 res.top_screen.top = 0;
54 res.top_screen.bottom = res.top_screen.top + height / 2;
55
56 int bottom_width = static_cast<int>((static_cast<float>(VideoCore::kScreenBottomWidth) /
57 VideoCore::kScreenTopWidth) * (res.top_screen.right - res.top_screen.left));
58 int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2;
59
60 res.bottom_screen.left = res.top_screen.left + bottom_border;
61 res.bottom_screen.right = res.bottom_screen.left + bottom_width;
62 res.bottom_screen.top = res.top_screen.bottom;
63 res.bottom_screen.bottom = res.bottom_screen.top + height / 2;
64 }
65
66 return res;
67}
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 1ad4b82a3..b6862030e 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -8,6 +8,7 @@
8#include "common/scm_rev.h" 8#include "common/scm_rev.h"
9#include "common/string_util.h" 9#include "common/string_util.h"
10#include "common/key_map.h" 10#include "common/key_map.h"
11#include "common/math_util.h"
11 12
12/** 13/**
13 * Abstraction class used to provide an interface between emulation code and the frontend 14 * Abstraction class used to provide an interface between emulation code and the frontend
@@ -38,6 +39,23 @@ public:
38 std::pair<unsigned,unsigned> min_client_area_size; 39 std::pair<unsigned,unsigned> min_client_area_size;
39 }; 40 };
40 41
42 /// Describes the layout of the window framebuffer (size and top/bottom screen positions)
43 struct FramebufferLayout {
44
45 /**
46 * Factory method for constructing a default FramebufferLayout
47 * @param width Window framebuffer width in pixels
48 * @param height Window framebuffer height in pixels
49 * @return Newly created FramebufferLayout object with default screen regions initialized
50 */
51 static FramebufferLayout DefaultScreenLayout(int width, int height);
52
53 unsigned width;
54 unsigned height;
55 MathUtil::Rectangle<unsigned> top_screen;
56 MathUtil::Rectangle<unsigned> bottom_screen;
57 };
58
41 /// Swap buffers to display the next frame 59 /// Swap buffers to display the next frame
42 virtual void SwapBuffers() = 0; 60 virtual void SwapBuffers() = 0;
43 61
@@ -75,11 +93,11 @@ public:
75 } 93 }
76 94
77 /** 95 /**
78 * Gets the framebuffer size in pixels. 96 * Gets the framebuffer layout (width, height, and screen regions)
79 * @note This method is thread-safe 97 * @note This method is thread-safe
80 */ 98 */
81 const std::pair<unsigned,unsigned> GetFramebufferSize() const { 99 const FramebufferLayout& GetFramebufferLayout() const {
82 return framebuffer_size; 100 return framebuffer_layout;
83 } 101 }
84 102
85 /** 103 /**
@@ -118,11 +136,11 @@ protected:
118 } 136 }
119 137
120 /** 138 /**
121 * Update internal framebuffer size with the given parameter. 139 * Update framebuffer layout with the given parameter.
122 * @note EmuWindow implementations will usually use this in window resize event handlers. 140 * @note EmuWindow implementations will usually use this in window resize event handlers.
123 */ 141 */
124 void NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) { 142 void NotifyFramebufferLayoutChanged(const FramebufferLayout& layout) {
125 framebuffer_size = size; 143 framebuffer_layout = layout;
126 } 144 }
127 145
128 /** 146 /**
@@ -143,7 +161,7 @@ private:
143 // By default, ignore this request and do nothing. 161 // By default, ignore this request and do nothing.
144 } 162 }
145 163
146 std::pair<unsigned,unsigned> framebuffer_size; 164 FramebufferLayout framebuffer_layout; ///< Current framebuffer layout
147 165
148 unsigned client_area_width; ///< Current client width, should be set by window impl. 166 unsigned client_area_width; ///< Current client width, should be set by window impl.
149 unsigned client_area_height; ///< Current client height, should be set by window impl. 167 unsigned client_area_height; ///< Current client height, should be set by window impl.