From 49e3a6e924c4ee47b3aa5acab2427fab5636793b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 01:49:38 -0400 Subject: 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(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 9e420b359..d9d2a8a4c 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 { -- cgit v1.2.3 From cfb59aad3ff5ab782a0c4212c3085094e15d7ede Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 01:53:30 -0400 Subject: 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 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index d9d2a8a4c..a4b89eed8 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(parent), - &GMainWindow::OnLoadComplete); + connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete); } GRenderWindow::~GRenderWindow() { -- cgit v1.2.3 From 2575403acf52d1f20dac413a9f434e4a36f3647a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 01:57:52 -0400 Subject: 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(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index a4b89eed8..9d5044b8f 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); -- cgit v1.2.3 From 0a650ec99e7141ea0a28b4f196a9b7d3f3bbe24e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 02:02:36 -0400 Subject: yuzu/bootmanager: unsigned -> u32 Same thing (for platforms we support), less reading. --- src/yuzu/bootmanager.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 9d5044b8f..05b2c2bea 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 GRenderWindow::ScaleTouch(const QPointF pos) const { +std::pair GRenderWindow::ScaleTouch(const QPointF pos) const { const qreal pixel_ratio = GetWindowPixelRatio(); - return {static_cast(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), - static_cast(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; + return {static_cast(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), + static_cast(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 minimal_size) { +void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair minimal_size) { setMinimumSize(minimal_size.first, minimal_size.second); } -- cgit v1.2.3 From 536c9cf006750927aa06d842d8bd18d7274c0be6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 02:05:06 -0400 Subject: 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 ++ 1 file changed, 2 insertions(+) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 05b2c2bea..97dee32e1 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(); -- cgit v1.2.3 From e32bf646cfb4a2b86fe2645c20722d55f0f4f96c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 02:14:24 -0400 Subject: 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/yuzu/bootmanager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 97dee32e1..7818b141f 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); -- cgit v1.2.3 From 77ce85f51d54f96472e1c9797a71c36f2ace72f3 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 29 May 2019 02:24:29 -0400 Subject: 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(-) (limited to 'src/yuzu/bootmanager.cpp') diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 7818b141f..afec33b61 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 minimal_size) { -- cgit v1.2.3