From 49e3a6e924c4ee47b3aa5acab2427fab5636793b Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 01:49:38 -0400
Subject: [PATCH 1/7] yuzu/bootmanager: Remove unnecessary pointer casts

We can just invoke these functions by qualifying the object name before
the function.
---
 src/yuzu/bootmanager.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 9e420b3591..d9d2a8a4c1 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -266,7 +266,7 @@ void GRenderWindow::ForwardKeyReleaseEvent(QKeyEvent* event) {
 }
 
 void GRenderWindow::BackupGeometry() {
-    geometry = ((QWidget*)this)->saveGeometry();
+    geometry = QWidget::saveGeometry();
 }
 
 void GRenderWindow::RestoreGeometry() {
@@ -283,10 +283,11 @@ void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
 QByteArray GRenderWindow::saveGeometry() {
     // If we are a top-level widget, store the current geometry
     // otherwise, store the last backup
-    if (parent() == nullptr)
-        return ((QWidget*)this)->saveGeometry();
-    else
-        return geometry;
+    if (parent() == nullptr) {
+        return QWidget::saveGeometry();
+    }
+
+    return geometry;
 }
 
 qreal GRenderWindow::GetWindowPixelRatio() const {

From cfb59aad3ff5ab782a0c4212c3085094e15d7ede Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 01:53:30 -0400
Subject: [PATCH 2/7] yuzu/bootmanager: Remove pointer downcast in
 GRenderWindow's constructor

We can just pass a pointer to GMainWindow directly and make it a
requirement of the interface. This makes the interface a little safer,
since this would technically otherwise allow any random QWidget to be
the parent of a render window, downcasting it to GMainWindow (which is
undefined behavior).
---
 src/yuzu/bootmanager.cpp | 5 ++---
 src/yuzu/bootmanager.h   | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index d9d2a8a4c1..a4b89eed8f 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -185,7 +185,7 @@ private:
     bool do_painting;
 };
 
-GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
+GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread)
     : QWidget(parent), emu_thread(emu_thread) {
     setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
                        .arg(QString::fromUtf8(Common::g_build_name),
@@ -194,8 +194,7 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
     setAttribute(Qt::WA_AcceptTouchEvents);
 
     InputCommon::Init();
-    connect(this, &GRenderWindow::FirstFrameDisplayed, static_cast<GMainWindow*>(parent),
-            &GMainWindow::OnLoadComplete);
+    connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
 }
 
 GRenderWindow::~GRenderWindow() {
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 7f9f8e8e34..5a1ebd0fe7 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -114,7 +114,7 @@ class GRenderWindow : public QWidget, public Core::Frontend::EmuWindow {
     Q_OBJECT
 
 public:
-    GRenderWindow(QWidget* parent, EmuThread* emu_thread);
+    GRenderWindow(GMainWindow* parent, EmuThread* emu_thread);
     ~GRenderWindow() override;
 
     // EmuWindow implementation

From 2575403acf52d1f20dac413a9f434e4a36f3647a Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 01:57:52 -0400
Subject: [PATCH 3/7] yuzu/bootmanager: Change false literal to 0 for
 setSwapInterval()

This function is defined as taking an int, not a bool.
---
 src/yuzu/bootmanager.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index a4b89eed8f..9d5044b8f8 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -394,7 +394,7 @@ void GRenderWindow::InitRenderTarget() {
     context->setShareContext(shared_context.get());
     context->setFormat(fmt);
     context->create();
-    fmt.setSwapInterval(false);
+    fmt.setSwapInterval(0);
 
     child = new GGLWidgetInternal(this, shared_context.get());
     container = QWidget::createWindowContainer(child, this);

From 0a650ec99e7141ea0a28b4f196a9b7d3f3bbe24e Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 02:02:36 -0400
Subject: [PATCH 4/7] yuzu/bootmanager: unsigned -> u32

Same thing (for platforms we support), less reading.
---
 src/yuzu/bootmanager.cpp | 16 ++++++++--------
 src/yuzu/bootmanager.h   |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 9d5044b8f8..05b2c2bead 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -246,9 +246,9 @@ void GRenderWindow::PollEvents() {}
 void GRenderWindow::OnFramebufferSizeChanged() {
     // Screen changes potentially incur a change in screen DPI, hence we should update the
     // framebuffer size
-    qreal pixelRatio = GetWindowPixelRatio();
-    unsigned width = child->QPaintDevice::width() * pixelRatio;
-    unsigned height = child->QPaintDevice::height() * pixelRatio;
+    const qreal pixel_ratio = GetWindowPixelRatio();
+    const u32 width = child->QPaintDevice::width() * pixel_ratio;
+    const u32 height = child->QPaintDevice::height() * pixel_ratio;
     UpdateCurrentFramebufferLayout(width, height);
 }
 
@@ -294,10 +294,10 @@ qreal GRenderWindow::GetWindowPixelRatio() const {
     return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
 }
 
-std::pair<unsigned, unsigned> GRenderWindow::ScaleTouch(const QPointF pos) const {
+std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF pos) const {
     const qreal pixel_ratio = GetWindowPixelRatio();
-    return {static_cast<unsigned>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
-            static_cast<unsigned>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
+    return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
+            static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
 }
 
 void GRenderWindow::closeEvent(QCloseEvent* event) {
@@ -353,7 +353,7 @@ void GRenderWindow::focusOutEvent(QFocusEvent* event) {
     InputCommon::GetKeyboard()->ReleaseAllKeys();
 }
 
-void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {
+void GRenderWindow::OnClientAreaResized(u32 width, u32 height) {
     NotifyClientAreaSizeChanged(std::make_pair(width, height));
 }
 
@@ -440,7 +440,7 @@ void GRenderWindow::CaptureScreenshot(u16 res_scale, const QString& screenshot_p
                                layout);
 }
 
-void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) {
+void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
     setMinimumSize(minimal_size.first, minimal_size.second);
 }
 
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 5a1ebd0fe7..85c0800007 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -133,13 +133,13 @@ public:
     QByteArray saveGeometry();                        // overridden
 
     qreal GetWindowPixelRatio() const;
-    std::pair<unsigned, unsigned> ScaleTouch(const QPointF pos) const;
+    std::pair<u32, u32> ScaleTouch(QPointF pos) const;
 
     void closeEvent(QCloseEvent* event) override;
     bool event(QEvent* event) override;
     void focusOutEvent(QFocusEvent* event) override;
 
-    void OnClientAreaResized(unsigned width, unsigned height);
+    void OnClientAreaResized(u32 width, u32 height);
 
     void InitRenderTarget();
 
@@ -162,7 +162,7 @@ private:
     void TouchUpdateEvent(const QTouchEvent* event);
     void TouchEndEvent();
 
-    void OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) override;
+    void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
 
     QWidget* container = nullptr;
     GGLWidgetInternal* child = nullptr;

From 536c9cf006750927aa06d842d8bd18d7274c0be6 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 02:05:06 -0400
Subject: [PATCH 5/7] yuzu/bootmanager: Default EmuThread's destructor in the
 cpp file

This class contains non-trivial members, so we should default the
destructor's definition within the cpp file.
---
 src/yuzu/bootmanager.cpp | 2 ++
 src/yuzu/bootmanager.h   | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 05b2c2bead..97dee32e1b 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -26,6 +26,8 @@
 
 EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {}
 
+EmuThread::~EmuThread() = default;
+
 void EmuThread::run() {
     render_window->MakeCurrent();
 
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 85c0800007..21b4958ff8 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -27,11 +27,12 @@ namespace VideoCore {
 enum class LoadCallbackStage;
 }
 
-class EmuThread : public QThread {
+class EmuThread final : public QThread {
     Q_OBJECT
 
 public:
     explicit EmuThread(GRenderWindow* render_window);
+    ~EmuThread() override;
 
     /**
      * Start emulation (on new thread)

From e32bf646cfb4a2b86fe2645c20722d55f0f4f96c Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 02:14:24 -0400
Subject: [PATCH 6/7] yuzu/bootmanager: Treat the resolution factor as a u32

Treating it as a u16 can result in a sign-conversion warning when
performing arithmetic with it, as u16 promotes to an int when aritmetic
is performed on it, not unsigned int.

This also makes the interface more uniform, as the layout interface now
operates on u32 across the board.
---
 src/core/frontend/framebuffer_layout.cpp | 13 +++++++------
 src/core/frontend/framebuffer_layout.h   | 21 ++++++++++++++-------
 src/yuzu/bootmanager.cpp                 |  5 +++--
 src/yuzu/bootmanager.h                   |  2 +-
 4 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp
index a1357179fa..d6d2cf3f00 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,
                                 static_cast<T>(std::round(scale * screen_aspect_ratio))};
 }
 
-FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
+FramebufferLayout DefaultFrameLayout(u32 width, u32 height) {
     ASSERT(width > 0);
     ASSERT(height > 0);
     // The drawing code needs at least somewhat valid values for both screens
@@ -29,22 +29,23 @@ FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
 
     const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
                                        ScreenUndocked::Width};
-    Common::Rectangle<unsigned> screen_window_area{0, 0, width, height};
-    Common::Rectangle<unsigned> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
+    const auto window_aspect_ratio = static_cast<float>(height) / width;
 
-    float window_aspect_ratio = static_cast<float>(height) / width;
+    const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
+    Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
 
     if (window_aspect_ratio < emulation_aspect_ratio) {
         screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
     } else {
         screen = screen.TranslateY((height - screen.GetHeight()) / 2);
     }
+
     res.screen = screen;
     return res;
 }
 
-FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale) {
-    int width, height;
+FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) {
+    u32 width, height;
 
     if (Settings::values.use_docked_mode) {
         width = ScreenDocked::WidthDocked * res_scale;
diff --git a/src/core/frontend/framebuffer_layout.h b/src/core/frontend/framebuffer_layout.h
index c2c63d08c3..d2370added 100644
--- a/src/core/frontend/framebuffer_layout.h
+++ b/src/core/frontend/framebuffer_layout.h
@@ -8,15 +8,22 @@
 
 namespace Layout {
 
-enum ScreenUndocked : unsigned { Width = 1280, Height = 720 };
-enum ScreenDocked : unsigned { WidthDocked = 1920, HeightDocked = 1080 };
+enum ScreenUndocked : u32 {
+    Width = 1280,
+    Height = 720,
+};
+
+enum ScreenDocked : u32 {
+    WidthDocked = 1920,
+    HeightDocked = 1080,
+};
 
 /// Describes the layout of the window framebuffer
 struct FramebufferLayout {
-    unsigned width{ScreenUndocked::Width};
-    unsigned height{ScreenUndocked::Height};
+    u32 width{ScreenUndocked::Width};
+    u32 height{ScreenUndocked::Height};
 
-    Common::Rectangle<unsigned> screen;
+    Common::Rectangle<u32> screen;
 
     /**
      * Returns the ration of pixel size of the screen, compared to the native size of the undocked
@@ -33,12 +40,12 @@ struct FramebufferLayout {
  * @param height Window framebuffer height in pixels
  * @return Newly created FramebufferLayout object with default screen regions initialized
  */
-FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height);
+FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
 
 /**
  * Convenience method to get frame layout by resolution scale
  * @param res_scale resolution scale factor
  */
-FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale);
+FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
 
 } // namespace Layout
diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 97dee32e1b..7818b141f9 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -426,11 +426,12 @@ void GRenderWindow::InitRenderTarget() {
     BackupGeometry();
 }
 
-void GRenderWindow::CaptureScreenshot(u16 res_scale, const QString& screenshot_path) {
+void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_path) {
     auto& renderer = Core::System::GetInstance().Renderer();
 
-    if (!res_scale)
+    if (res_scale == 0) {
         res_scale = VideoCore::GetResolutionScaleFactor(renderer);
+    }
 
     const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
     screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h
index 21b4958ff8..2fc64895f6 100644
--- a/src/yuzu/bootmanager.h
+++ b/src/yuzu/bootmanager.h
@@ -144,7 +144,7 @@ public:
 
     void InitRenderTarget();
 
-    void CaptureScreenshot(u16 res_scale, const QString& screenshot_path);
+    void CaptureScreenshot(u32 res_scale, const QString& screenshot_path);
 
 public slots:
     void moveContext(); // overridden

From 77ce85f51d54f96472e1c9797a71c36f2ace72f3 Mon Sep 17 00:00:00 2001
From: Lioncash <mathew1800@gmail.com>
Date: Wed, 29 May 2019 02:24:29 -0400
Subject: [PATCH 7/7] yuzu/bootmanager: Log out screenshot destination path

We can make this message more meaningful by indicating the location the
screenshot has been saved to. We can also log out whenever a screenshot
could not be saved (e.g. due to filesystem permissions or some other
reason).
---
 src/yuzu/bootmanager.cpp | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp
index 7818b141f9..afec33b619 100644
--- a/src/yuzu/bootmanager.cpp
+++ b/src/yuzu/bootmanager.cpp
@@ -435,12 +435,17 @@ void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_p
 
     const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
     screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
-    renderer.RequestScreenshot(screenshot_image.bits(),
-                               [=] {
-                                   screenshot_image.mirrored(false, true).save(screenshot_path);
-                                   LOG_INFO(Frontend, "The screenshot is saved.");
-                               },
-                               layout);
+    renderer.RequestScreenshot(
+        screenshot_image.bits(),
+        [=] {
+            const std::string std_screenshot_path = screenshot_path.toStdString();
+            if (screenshot_image.mirrored(false, true).save(screenshot_path)) {
+                LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
+            } else {
+                LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
+            }
+        },
+        layout);
 }
 
 void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {