summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Rodrigo Locatti2019-06-04 21:35:56 -0300
committerGravatar GitHub2019-06-04 21:35:56 -0300
commit2ba4aa8a3b5a646e90e3e5437c2c711179c5d849 (patch)
treea738457c959e6b720bd270e228e69b9916544526 /src
parentMerge pull request #2525 from FearlessTobi/remove-unused-settings (diff)
parentyuzu/bootmanager: Log out screenshot destination path (diff)
downloadyuzu-2ba4aa8a3b5a646e90e3e5437c2c711179c5d849.tar.gz
yuzu-2ba4aa8a3b5a646e90e3e5437c2c711179c5d849.tar.xz
yuzu-2ba4aa8a3b5a646e90e3e5437c2c711179c5d849.zip
Merge pull request #2529 from lioncash/boot
yuzu/bootmanager: Minor interface tidying
Diffstat (limited to 'src')
-rw-r--r--src/core/frontend/framebuffer_layout.cpp13
-rw-r--r--src/core/frontend/framebuffer_layout.h21
-rw-r--r--src/yuzu/bootmanager.cpp58
-rw-r--r--src/yuzu/bootmanager.h13
4 files changed, 61 insertions, 44 deletions
diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp
index a1357179f..d6d2cf3f0 100644
--- a/src/core/frontend/framebuffer_layout.cpp
+++ b/src/core/frontend/framebuffer_layout.cpp
@@ -20,7 +20,7 @@ static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area,
20 static_cast<T>(std::round(scale * screen_aspect_ratio))}; 20 static_cast<T>(std::round(scale * screen_aspect_ratio))};
21} 21}
22 22
23FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) { 23FramebufferLayout DefaultFrameLayout(u32 width, u32 height) {
24 ASSERT(width > 0); 24 ASSERT(width > 0);
25 ASSERT(height > 0); 25 ASSERT(height > 0);
26 // The drawing code needs at least somewhat valid values for both screens 26 // The drawing code needs at least somewhat valid values for both screens
@@ -29,22 +29,23 @@ FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
29 29
30 const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) / 30 const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
31 ScreenUndocked::Width}; 31 ScreenUndocked::Width};
32 Common::Rectangle<unsigned> screen_window_area{0, 0, width, height}; 32 const auto window_aspect_ratio = static_cast<float>(height) / width;
33 Common::Rectangle<unsigned> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
34 33
35 float window_aspect_ratio = static_cast<float>(height) / width; 34 const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
35 Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
36 36
37 if (window_aspect_ratio < emulation_aspect_ratio) { 37 if (window_aspect_ratio < emulation_aspect_ratio) {
38 screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2); 38 screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
39 } else { 39 } else {
40 screen = screen.TranslateY((height - screen.GetHeight()) / 2); 40 screen = screen.TranslateY((height - screen.GetHeight()) / 2);
41 } 41 }
42
42 res.screen = screen; 43 res.screen = screen;
43 return res; 44 return res;
44} 45}
45 46
46FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale) { 47FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) {
47 int width, height; 48 u32 width, height;
48 49
49 if (Settings::values.use_docked_mode) { 50 if (Settings::values.use_docked_mode) {
50 width = ScreenDocked::WidthDocked * res_scale; 51 width = ScreenDocked::WidthDocked * res_scale;
diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h
index c2c63d08c..d2370adde 100644
--- a/src/core/frontend/framebuffer_layout.h
+++ b/src/core/frontend/framebuffer_layout.h
@@ -8,15 +8,22 @@
8 8
9namespace Layout { 9namespace Layout {
10 10
11enum ScreenUndocked : unsigned { Width = 1280, Height = 720 }; 11enum ScreenUndocked : u32 {
12enum ScreenDocked : unsigned { WidthDocked = 1920, HeightDocked = 1080 }; 12 Width = 1280,
13 Height = 720,
14};
15
16enum ScreenDocked : u32 {
17 WidthDocked = 1920,
18 HeightDocked = 1080,
19};
13 20
14/// Describes the layout of the window framebuffer 21/// Describes the layout of the window framebuffer
15struct FramebufferLayout { 22struct FramebufferLayout {
16 unsigned width{ScreenUndocked::Width}; 23 u32 width{ScreenUndocked::Width};
17 unsigned height{ScreenUndocked::Height}; 24 u32 height{ScreenUndocked::Height};
18 25
19 Common::Rectangle<unsigned> screen; 26 Common::Rectangle<u32> screen;
20 27
21 /** 28 /**
22 * Returns the ration of pixel size of the screen, compared to the native size of the undocked 29 * Returns the ration of pixel size of the screen, compared to the native size of the undocked
@@ -33,12 +40,12 @@ struct FramebufferLayout {
33 * @param height Window framebuffer height in pixels 40 * @param height Window framebuffer height in pixels
34 * @return Newly created FramebufferLayout object with default screen regions initialized 41 * @return Newly created FramebufferLayout object with default screen regions initialized
35 */ 42 */
36FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height); 43FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
37 44
38/** 45/**
39 * Convenience method to get frame layout by resolution scale 46 * Convenience method to get frame layout by resolution scale
40 * @param res_scale resolution scale factor 47 * @param res_scale resolution scale factor
41 */ 48 */
42FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale); 49FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
43 50
44} // namespace Layout 51} // namespace Layout
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 9e420b359..afec33b61 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -26,6 +26,8 @@
26 26
27EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {} 27EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {}
28 28
29EmuThread::~EmuThread() = default;
30
29void EmuThread::run() { 31void EmuThread::run() {
30 render_window->MakeCurrent(); 32 render_window->MakeCurrent();
31 33
@@ -185,7 +187,7 @@ private:
185 bool do_painting; 187 bool do_painting;
186}; 188};
187 189
188GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) 190GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread)
189 : QWidget(parent), emu_thread(emu_thread) { 191 : QWidget(parent), emu_thread(emu_thread) {
190 setWindowTitle(QStringLiteral("yuzu %1 | %2-%3") 192 setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
191 .arg(QString::fromUtf8(Common::g_build_name), 193 .arg(QString::fromUtf8(Common::g_build_name),
@@ -194,8 +196,7 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
194 setAttribute(Qt::WA_AcceptTouchEvents); 196 setAttribute(Qt::WA_AcceptTouchEvents);
195 197
196 InputCommon::Init(); 198 InputCommon::Init();
197 connect(this, &GRenderWindow::FirstFrameDisplayed, static_cast<GMainWindow*>(parent), 199 connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
198 &GMainWindow::OnLoadComplete);
199} 200}
200 201
201GRenderWindow::~GRenderWindow() { 202GRenderWindow::~GRenderWindow() {
@@ -247,9 +248,9 @@ void GRenderWindow::PollEvents() {}
247void GRenderWindow::OnFramebufferSizeChanged() { 248void GRenderWindow::OnFramebufferSizeChanged() {
248 // Screen changes potentially incur a change in screen DPI, hence we should update the 249 // Screen changes potentially incur a change in screen DPI, hence we should update the
249 // framebuffer size 250 // framebuffer size
250 qreal pixelRatio = GetWindowPixelRatio(); 251 const qreal pixel_ratio = GetWindowPixelRatio();
251 unsigned width = child->QPaintDevice::width() * pixelRatio; 252 const u32 width = child->QPaintDevice::width() * pixel_ratio;
252 unsigned height = child->QPaintDevice::height() * pixelRatio; 253 const u32 height = child->QPaintDevice::height() * pixel_ratio;
253 UpdateCurrentFramebufferLayout(width, height); 254 UpdateCurrentFramebufferLayout(width, height);
254} 255}
255 256
@@ -266,7 +267,7 @@ void GRenderWindow::ForwardKeyReleaseEvent(QKeyEvent* event) {
266} 267}
267 268
268void GRenderWindow::BackupGeometry() { 269void GRenderWindow::BackupGeometry() {
269 geometry = ((QWidget*)this)->saveGeometry(); 270 geometry = QWidget::saveGeometry();
270} 271}
271 272
272void GRenderWindow::RestoreGeometry() { 273void GRenderWindow::RestoreGeometry() {
@@ -283,10 +284,11 @@ void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
283QByteArray GRenderWindow::saveGeometry() { 284QByteArray GRenderWindow::saveGeometry() {
284 // If we are a top-level widget, store the current geometry 285 // If we are a top-level widget, store the current geometry
285 // otherwise, store the last backup 286 // otherwise, store the last backup
286 if (parent() == nullptr) 287 if (parent() == nullptr) {
287 return ((QWidget*)this)->saveGeometry(); 288 return QWidget::saveGeometry();
288 else 289 }
289 return geometry; 290
291 return geometry;
290} 292}
291 293
292qreal GRenderWindow::GetWindowPixelRatio() const { 294qreal GRenderWindow::GetWindowPixelRatio() const {
@@ -294,10 +296,10 @@ qreal GRenderWindow::GetWindowPixelRatio() const {
294 return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; 296 return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
295} 297}
296 298
297std::pair<unsigned, unsigned> GRenderWindow::ScaleTouch(const QPointF pos) const { 299std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF pos) const {
298 const qreal pixel_ratio = GetWindowPixelRatio(); 300 const qreal pixel_ratio = GetWindowPixelRatio();
299 return {static_cast<unsigned>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), 301 return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
300 static_cast<unsigned>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; 302 static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
301} 303}
302 304
303void GRenderWindow::closeEvent(QCloseEvent* event) { 305void GRenderWindow::closeEvent(QCloseEvent* event) {
@@ -353,7 +355,7 @@ void GRenderWindow::focusOutEvent(QFocusEvent* event) {
353 InputCommon::GetKeyboard()->ReleaseAllKeys(); 355 InputCommon::GetKeyboard()->ReleaseAllKeys();
354} 356}
355 357
356void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) { 358void GRenderWindow::OnClientAreaResized(u32 width, u32 height) {
357 NotifyClientAreaSizeChanged(std::make_pair(width, height)); 359 NotifyClientAreaSizeChanged(std::make_pair(width, height));
358} 360}
359 361
@@ -394,7 +396,7 @@ void GRenderWindow::InitRenderTarget() {
394 context->setShareContext(shared_context.get()); 396 context->setShareContext(shared_context.get());
395 context->setFormat(fmt); 397 context->setFormat(fmt);
396 context->create(); 398 context->create();
397 fmt.setSwapInterval(false); 399 fmt.setSwapInterval(0);
398 400
399 child = new GGLWidgetInternal(this, shared_context.get()); 401 child = new GGLWidgetInternal(this, shared_context.get());
400 container = QWidget::createWindowContainer(child, this); 402 container = QWidget::createWindowContainer(child, this);
@@ -424,23 +426,29 @@ void GRenderWindow::InitRenderTarget() {
424 BackupGeometry(); 426 BackupGeometry();
425} 427}
426 428
427void GRenderWindow::CaptureScreenshot(u16 res_scale, const QString& screenshot_path) { 429void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_path) {
428 auto& renderer = Core::System::GetInstance().Renderer(); 430 auto& renderer = Core::System::GetInstance().Renderer();
429 431
430 if (!res_scale) 432 if (res_scale == 0) {
431 res_scale = VideoCore::GetResolutionScaleFactor(renderer); 433 res_scale = VideoCore::GetResolutionScaleFactor(renderer);
434 }
432 435
433 const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)}; 436 const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
434 screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32); 437 screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
435 renderer.RequestScreenshot(screenshot_image.bits(), 438 renderer.RequestScreenshot(
436 [=] { 439 screenshot_image.bits(),
437 screenshot_image.mirrored(false, true).save(screenshot_path); 440 [=] {
438 LOG_INFO(Frontend, "The screenshot is saved."); 441 const std::string std_screenshot_path = screenshot_path.toStdString();
439 }, 442 if (screenshot_image.mirrored(false, true).save(screenshot_path)) {
440 layout); 443 LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
444 } else {
445 LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
446 }
447 },
448 layout);
441} 449}
442 450
443void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) { 451void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
444 setMinimumSize(minimal_size.first, minimal_size.second); 452 setMinimumSize(minimal_size.first, minimal_size.second);
445} 453}
446 454
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 7f9f8e8e3..2fc64895f 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -27,11 +27,12 @@ namespace VideoCore {
27enum class LoadCallbackStage; 27enum class LoadCallbackStage;
28} 28}
29 29
30class EmuThread : public QThread { 30class EmuThread final : public QThread {
31 Q_OBJECT 31 Q_OBJECT
32 32
33public: 33public:
34 explicit EmuThread(GRenderWindow* render_window); 34 explicit EmuThread(GRenderWindow* render_window);
35 ~EmuThread() override;
35 36
36 /** 37 /**
37 * Start emulation (on new thread) 38 * Start emulation (on new thread)
@@ -114,7 +115,7 @@ class GRenderWindow : public QWidget, public Core::Frontend::EmuWindow {
114 Q_OBJECT 115 Q_OBJECT
115 116
116public: 117public:
117 GRenderWindow(QWidget* parent, EmuThread* emu_thread); 118 GRenderWindow(GMainWindow* parent, EmuThread* emu_thread);
118 ~GRenderWindow() override; 119 ~GRenderWindow() override;
119 120
120 // EmuWindow implementation 121 // EmuWindow implementation
@@ -133,17 +134,17 @@ public:
133 QByteArray saveGeometry(); // overridden 134 QByteArray saveGeometry(); // overridden
134 135
135 qreal GetWindowPixelRatio() const; 136 qreal GetWindowPixelRatio() const;
136 std::pair<unsigned, unsigned> ScaleTouch(const QPointF pos) const; 137 std::pair<u32, u32> ScaleTouch(QPointF pos) const;
137 138
138 void closeEvent(QCloseEvent* event) override; 139 void closeEvent(QCloseEvent* event) override;
139 bool event(QEvent* event) override; 140 bool event(QEvent* event) override;
140 void focusOutEvent(QFocusEvent* event) override; 141 void focusOutEvent(QFocusEvent* event) override;
141 142
142 void OnClientAreaResized(unsigned width, unsigned height); 143 void OnClientAreaResized(u32 width, u32 height);
143 144
144 void InitRenderTarget(); 145 void InitRenderTarget();
145 146
146 void CaptureScreenshot(u16 res_scale, const QString& screenshot_path); 147 void CaptureScreenshot(u32 res_scale, const QString& screenshot_path);
147 148
148public slots: 149public slots:
149 void moveContext(); // overridden 150 void moveContext(); // overridden
@@ -162,7 +163,7 @@ private:
162 void TouchUpdateEvent(const QTouchEvent* event); 163 void TouchUpdateEvent(const QTouchEvent* event);
163 void TouchEndEvent(); 164 void TouchEndEvent();
164 165
165 void OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) override; 166 void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
166 167
167 QWidget* container = nullptr; 168 QWidget* container = nullptr;
168 GGLWidgetInternal* child = nullptr; 169 GGLWidgetInternal* child = nullptr;