diff options
author | bunnei <bunneidev@gmail.com> | 2014-08-25 04:25:35 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2014-08-25 04:25:35 +0200 |
commit | 613b0a8df85578c97790c5b116195e8bd2fad6f4 (patch) | |
tree | 64505f9f1dbe1d10b8b15661db8f2dc191d8ca98 /src/citra_qt | |
parent | Merge pull request #73 from yuriks/remove-docs (diff) | |
parent | Pass format to the QGLWidget and use atomic instead of mutex. (diff) | |
download | yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar.gz yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar.bz2 yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar.lz yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar.xz yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.tar.zst yuzu-613b0a8df85578c97790c5b116195e8bd2fad6f4.zip |
Diffstat (limited to 'src/citra_qt')
-rw-r--r-- | src/citra_qt/bootmanager.cpp | 48 | ||||
-rw-r--r-- | src/citra_qt/bootmanager.hxx | 7 | ||||
-rw-r--r-- | src/citra_qt/main.cpp | 3 |
3 files changed, 41 insertions, 17 deletions
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp index b0aa1e561..573060d30 100644 --- a/src/citra_qt/bootmanager.cpp +++ b/src/citra_qt/bootmanager.cpp @@ -1,5 +1,6 @@ #include <QHBoxLayout> #include <QKeyEvent> +#include <QApplication> #include "common/common.h" #include "bootmanager.hxx" @@ -19,7 +20,8 @@ EmuThread::EmuThread(GRenderWindow* render_window) : exec_cpu_step(false), cpu_running(false), - render_window(render_window), filename("") + render_window(render_window), filename(""), + stop_run(false) { } @@ -30,7 +32,8 @@ void EmuThread::SetFilename(std::string filename) void EmuThread::run() { - while (true) + stop_run = false; + while (!stop_run) { for (int tight_loop = 0; tight_loop < 10000; ++tight_loop) { @@ -40,11 +43,14 @@ void EmuThread::run() exec_cpu_step = false; Core::SingleStep(); - if (!cpu_running) + if (!cpu_running) { emit CPUStepped(); + yieldCurrentThread(); + } } } } + render_window->moveContext(); Core::Stop(); } @@ -56,17 +62,21 @@ void EmuThread::Stop() INFO_LOG(MASTER_LOG, "EmuThread::Stop called while emu thread wasn't running, returning..."); return; } + stop_run = true; //core::g_state = core::SYS_DIE; - wait(1000); + wait(500); if (isRunning()) { WARN_LOG(MASTER_LOG, "EmuThread still running, terminating..."); - terminate(); + quit(); wait(1000); if (isRunning()) + { WARN_LOG(MASTER_LOG, "EmuThread STILL running, something is wrong here..."); + terminate(); + } } INFO_LOG(MASTER_LOG, "EmuThread stopped"); } @@ -77,17 +87,13 @@ void EmuThread::Stop() class GGLWidgetInternal : public QGLWidget { public: - GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(parent) + GGLWidgetInternal(QGLFormat fmt, GRenderWindow* parent) : QGLWidget(fmt, parent) { - doneCurrent(); parent_ = parent; } void paintEvent(QPaintEvent* ev) { - // Apparently, Windows doesn't display anything if we don't call this here. - // TODO: Breaks linux though because we aren't calling doneCurrent() ... -.- -// makeCurrent(); } void resizeEvent(QResizeEvent* ev) { parent_->SetClientAreaWidth(size().width()); @@ -118,24 +124,37 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this layout->addWidget(child); layout->setMargin(0); setLayout(layout); + QObject::connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext())); BackupGeometry(); } +void GRenderWindow::moveContext() +{ + DoneCurrent(); + // We need to move GL context to the swapping thread in Qt5 +#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0) + // If the thread started running, move the GL Context to the new thread. Otherwise, move it back. + child->context()->moveToThread((QThread::currentThread() == qApp->thread()) ? &emu_thread : qApp->thread()); +#endif +} + GRenderWindow::~GRenderWindow() { - emu_thread.Stop(); + if (emu_thread.isRunning()) + emu_thread.Stop(); } void GRenderWindow::SwapBuffers() { - child->makeCurrent(); // TODO: Not necessary? + // MakeCurrent is already called in renderer_opengl child->swapBuffers(); } void GRenderWindow::closeEvent(QCloseEvent* event) { - emu_thread.Stop(); + if (emu_thread.isRunning()) + emu_thread.Stop(); QWidget::closeEvent(event); } @@ -212,4 +231,5 @@ void GRenderWindow::keyReleaseEvent(QKeyEvent* event) if (!key_processed) QWidget::keyPressEvent(event); */ -}
\ No newline at end of file +} + diff --git a/src/citra_qt/bootmanager.hxx b/src/citra_qt/bootmanager.hxx index b4005ccbb..51cb781e9 100644 --- a/src/citra_qt/bootmanager.hxx +++ b/src/citra_qt/bootmanager.hxx @@ -1,5 +1,6 @@ #include <QThread> #include <QGLWidget> +#include <atomic> #include "common/common.h" #include "common/emu_window.h" @@ -66,6 +67,7 @@ private: bool exec_cpu_step; bool cpu_running; + std::atomic<bool> stop_run; GRenderWindow* render_window; @@ -81,6 +83,8 @@ signals: class GRenderWindow : public QWidget, public EmuWindow { + Q_OBJECT + public: GRenderWindow(QWidget* parent = NULL); ~GRenderWindow(); @@ -103,6 +107,9 @@ public: void keyPressEvent(QKeyEvent* event); void keyReleaseEvent(QKeyEvent* event); +public slots: + void moveContext(); + private: QGLWidget* child; diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp index e5190d48a..9a16cf92d 100644 --- a/src/citra_qt/main.cpp +++ b/src/citra_qt/main.cpp @@ -142,7 +142,6 @@ void GMainWindow::BootGame(std::string filename) registersWidget->OnCPUStepped(); callstackWidget->OnCPUStepped(); - render_window->DoneCurrent(); // make sure EmuThread can access GL context render_window->GetEmuThread().SetFilename(filename); render_window->GetEmuThread().start(); @@ -204,7 +203,6 @@ void GMainWindow::ToggleWindowMode() ui.horizontalLayout->removeWidget(render_window); render_window->setParent(NULL); render_window->setVisible(true); - render_window->DoneCurrent(); render_window->RestoreGeometry(); } else if (!enable && render_window->parent() == NULL) @@ -212,7 +210,6 @@ void GMainWindow::ToggleWindowMode() render_window->BackupGeometry(); ui.horizontalLayout->addWidget(render_window); render_window->setVisible(true); - render_window->DoneCurrent(); } } |