Qt: Move EmuThread ownership from render window to main window.
This commit is contained in:
parent
4d30edc11e
commit
762c1a9ff5
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "common/common.h"
|
#include "common/common.h"
|
||||||
#include "bootmanager.h"
|
#include "bootmanager.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#include "core/core.h"
|
#include "core/core.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
|
@ -30,6 +31,7 @@ EmuThread::EmuThread(GRenderWindow* render_window) :
|
||||||
filename(""), exec_cpu_step(false), cpu_running(false),
|
filename(""), exec_cpu_step(false), cpu_running(false),
|
||||||
stop_run(false), render_window(render_window)
|
stop_run(false), render_window(render_window)
|
||||||
{
|
{
|
||||||
|
connect(this, SIGNAL(started()), render_window, SLOT(moveContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmuThread::SetFilename(std::string filename)
|
void EmuThread::SetFilename(std::string filename)
|
||||||
|
@ -133,13 +135,9 @@ private:
|
||||||
GRenderWindow* parent;
|
GRenderWindow* parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
EmuThread& GRenderWindow::GetEmuThread()
|
GRenderWindow::GRenderWindow(QWidget* parent, GMainWindow& main_window) :
|
||||||
{
|
QWidget(parent), main_window(main_window), keyboard_id(0) {
|
||||||
return emu_thread;
|
|
||||||
}
|
|
||||||
|
|
||||||
GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this), keyboard_id(0)
|
|
||||||
{
|
|
||||||
std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
|
std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
|
||||||
setWindowTitle(QString::fromStdString(window_title));
|
setWindowTitle(QString::fromStdString(window_title));
|
||||||
|
|
||||||
|
@ -160,7 +158,6 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
|
||||||
layout->addWidget(child);
|
layout->addWidget(child);
|
||||||
layout->setMargin(0);
|
layout->setMargin(0);
|
||||||
setLayout(layout);
|
setLayout(layout);
|
||||||
connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext()));
|
|
||||||
|
|
||||||
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
|
||||||
|
|
||||||
|
@ -180,29 +177,17 @@ void GRenderWindow::moveContext()
|
||||||
// We need to move GL context to the swapping thread in Qt5
|
// We need to move GL context to the swapping thread in Qt5
|
||||||
#if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
|
#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.
|
// 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());
|
auto thread = QThread::currentThread() == qApp->thread() ? main_window.GetEmuThread() : qApp->thread();
|
||||||
|
child->context()->moveToThread(thread);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GRenderWindow::~GRenderWindow()
|
|
||||||
{
|
|
||||||
if (emu_thread.isRunning())
|
|
||||||
emu_thread.Stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GRenderWindow::SwapBuffers()
|
void GRenderWindow::SwapBuffers()
|
||||||
{
|
{
|
||||||
// MakeCurrent is already called in renderer_opengl
|
// MakeCurrent is already called in renderer_opengl
|
||||||
child->swapBuffers();
|
child->swapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GRenderWindow::closeEvent(QCloseEvent* event)
|
|
||||||
{
|
|
||||||
if (emu_thread.isRunning())
|
|
||||||
emu_thread.Stop();
|
|
||||||
QWidget::closeEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GRenderWindow::MakeCurrent()
|
void GRenderWindow::MakeCurrent()
|
||||||
{
|
{
|
||||||
child->makeCurrent();
|
child->makeCurrent();
|
||||||
|
|
|
@ -14,6 +14,7 @@ class QScreen;
|
||||||
class QKeyEvent;
|
class QKeyEvent;
|
||||||
|
|
||||||
class GRenderWindow;
|
class GRenderWindow;
|
||||||
|
class GMainWindow;
|
||||||
|
|
||||||
class EmuThread : public QThread
|
class EmuThread : public QThread
|
||||||
{
|
{
|
||||||
|
@ -67,7 +68,7 @@ public slots:
|
||||||
void Stop();
|
void Stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class GRenderWindow;
|
friend class GMainWindow;
|
||||||
|
|
||||||
EmuThread(GRenderWindow* render_window);
|
EmuThread(GRenderWindow* render_window);
|
||||||
|
|
||||||
|
@ -100,10 +101,7 @@ class GRenderWindow : public QWidget, public EmuWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GRenderWindow(QWidget* parent = NULL);
|
GRenderWindow(QWidget* parent, GMainWindow& main_window);
|
||||||
~GRenderWindow();
|
|
||||||
|
|
||||||
void closeEvent(QCloseEvent*) override;
|
|
||||||
|
|
||||||
// EmuWindow implementation
|
// EmuWindow implementation
|
||||||
void SwapBuffers() override;
|
void SwapBuffers() override;
|
||||||
|
@ -116,8 +114,6 @@ public:
|
||||||
void restoreGeometry(const QByteArray& geometry); // overridden
|
void restoreGeometry(const QByteArray& geometry); // overridden
|
||||||
QByteArray saveGeometry(); // overridden
|
QByteArray saveGeometry(); // overridden
|
||||||
|
|
||||||
EmuThread& GetEmuThread();
|
|
||||||
|
|
||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
void keyReleaseEvent(QKeyEvent* event) override;
|
void keyReleaseEvent(QKeyEvent* event) override;
|
||||||
|
|
||||||
|
@ -139,10 +135,10 @@ private:
|
||||||
|
|
||||||
QGLWidget* child;
|
QGLWidget* child;
|
||||||
|
|
||||||
EmuThread emu_thread;
|
|
||||||
|
|
||||||
QByteArray geometry;
|
QByteArray geometry;
|
||||||
|
|
||||||
|
GMainWindow& main_window;
|
||||||
|
|
||||||
/// Device id of keyboard for use with KeyMap
|
/// Device id of keyboard for use with KeyMap
|
||||||
int keyboard_id;
|
int keyboard_id;
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "disassembler.h"
|
#include "disassembler.h"
|
||||||
|
|
||||||
|
#include "../main.h"
|
||||||
#include "../bootmanager.h"
|
#include "../bootmanager.h"
|
||||||
#include "../hotkeys.h"
|
#include "../hotkeys.h"
|
||||||
|
|
||||||
|
@ -158,8 +159,9 @@ void DisassemblerModel::SetNextInstruction(unsigned int address) {
|
||||||
emit dataChanged(prev_index, prev_index);
|
emit dataChanged(prev_index, prev_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
DisassemblerWidget::DisassemblerWidget(QWidget* parent, EmuThread& emu_thread) : QDockWidget(parent), base_addr(0), emu_thread(emu_thread)
|
DisassemblerWidget::DisassemblerWidget(QWidget* parent, GMainWindow& main_window) :
|
||||||
{
|
QDockWidget(parent), main_window(main_window), base_addr(0) {
|
||||||
|
|
||||||
disasm_ui.setupUi(this);
|
disasm_ui.setupUi(this);
|
||||||
|
|
||||||
model = new DisassemblerModel(this);
|
model = new DisassemblerModel(this);
|
||||||
|
@ -199,7 +201,7 @@ void DisassemblerWidget::Init()
|
||||||
|
|
||||||
void DisassemblerWidget::OnContinue()
|
void DisassemblerWidget::OnContinue()
|
||||||
{
|
{
|
||||||
emu_thread.SetCpuRunning(true);
|
main_window.GetEmuThread()->SetCpuRunning(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblerWidget::OnStep()
|
void DisassemblerWidget::OnStep()
|
||||||
|
@ -209,13 +211,13 @@ void DisassemblerWidget::OnStep()
|
||||||
|
|
||||||
void DisassemblerWidget::OnStepInto()
|
void DisassemblerWidget::OnStepInto()
|
||||||
{
|
{
|
||||||
emu_thread.SetCpuRunning(false);
|
main_window.GetEmuThread()->SetCpuRunning(false);
|
||||||
emu_thread.ExecStep();
|
main_window.GetEmuThread()->ExecStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblerWidget::OnPause()
|
void DisassemblerWidget::OnPause()
|
||||||
{
|
{
|
||||||
emu_thread.SetCpuRunning(false);
|
main_window.GetEmuThread()->SetCpuRunning(false);
|
||||||
|
|
||||||
// TODO: By now, the CPU might not have actually stopped...
|
// TODO: By now, the CPU might not have actually stopped...
|
||||||
if (Core::g_app_core) {
|
if (Core::g_app_core) {
|
||||||
|
@ -225,7 +227,7 @@ void DisassemblerWidget::OnPause()
|
||||||
|
|
||||||
void DisassemblerWidget::OnToggleStartStop()
|
void DisassemblerWidget::OnToggleStartStop()
|
||||||
{
|
{
|
||||||
emu_thread.SetCpuRunning(!emu_thread.IsCpuRunning());
|
main_window.GetEmuThread()->SetCpuRunning(!main_window.GetEmuThread()->IsCpuRunning());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblerWidget::OnDebugModeEntered()
|
void DisassemblerWidget::OnDebugModeEntered()
|
||||||
|
@ -233,7 +235,7 @@ void DisassemblerWidget::OnDebugModeEntered()
|
||||||
ARMword next_instr = Core::g_app_core->GetPC();
|
ARMword next_instr = Core::g_app_core->GetPC();
|
||||||
|
|
||||||
if (model->GetBreakPoints().IsAddressBreakPoint(next_instr))
|
if (model->GetBreakPoints().IsAddressBreakPoint(next_instr))
|
||||||
emu_thread.SetCpuRunning(false);
|
main_window.GetEmuThread()->SetCpuRunning(false);
|
||||||
|
|
||||||
model->SetNextInstruction(next_instr);
|
model->SetNextInstruction(next_instr);
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "common/break_points.h"
|
#include "common/break_points.h"
|
||||||
|
|
||||||
class QAction;
|
class QAction;
|
||||||
class EmuThread;
|
class GMainWindow;
|
||||||
|
|
||||||
class DisassemblerModel : public QAbstractListModel
|
class DisassemblerModel : public QAbstractListModel
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ class DisassemblerWidget : public QDockWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DisassemblerWidget(QWidget* parent, EmuThread& emu_thread);
|
DisassemblerWidget(QWidget* parent, GMainWindow& main_window);
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
|
@ -75,5 +75,5 @@ private:
|
||||||
|
|
||||||
u32 base_addr;
|
u32 base_addr;
|
||||||
|
|
||||||
EmuThread& emu_thread;
|
GMainWindow& main_window;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
|
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
GMainWindow::GMainWindow()
|
GMainWindow::GMainWindow() : emu_thread(nullptr)
|
||||||
{
|
{
|
||||||
Pica::g_debug_context = Pica::DebugContext::Construct();
|
Pica::g_debug_context = Pica::DebugContext::Construct();
|
||||||
|
|
||||||
|
@ -55,14 +55,15 @@ GMainWindow::GMainWindow()
|
||||||
ui.setupUi(this);
|
ui.setupUi(this);
|
||||||
statusBar()->hide();
|
statusBar()->hide();
|
||||||
|
|
||||||
render_window = new GRenderWindow;
|
render_window = new GRenderWindow(this, *this);
|
||||||
render_window->hide();
|
render_window->hide();
|
||||||
|
emu_thread = new EmuThread(render_window);
|
||||||
|
|
||||||
profilerWidget = new ProfilerWidget(this);
|
profilerWidget = new ProfilerWidget(this);
|
||||||
addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
|
addDockWidget(Qt::BottomDockWidgetArea, profilerWidget);
|
||||||
profilerWidget->hide();
|
profilerWidget->hide();
|
||||||
|
|
||||||
disasmWidget = new DisassemblerWidget(this, render_window->GetEmuThread());
|
disasmWidget = new DisassemblerWidget(this, *this);
|
||||||
addDockWidget(Qt::BottomDockWidgetArea, disasmWidget);
|
addDockWidget(Qt::BottomDockWidgetArea, disasmWidget);
|
||||||
disasmWidget->hide();
|
disasmWidget->hide();
|
||||||
|
|
||||||
|
@ -139,13 +140,13 @@ GMainWindow::GMainWindow()
|
||||||
connect(ui.action_Hotkeys, SIGNAL(triggered()), this, SLOT(OnOpenHotkeysDialog()));
|
connect(ui.action_Hotkeys, SIGNAL(triggered()), this, SLOT(OnOpenHotkeysDialog()));
|
||||||
|
|
||||||
// BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
|
// BlockingQueuedConnection is important here, it makes sure we've finished refreshing our views before the CPU continues
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeEntered()), disasmWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), registersWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeEntered()), registersWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeEntered()), callstackWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeEntered()), callstackWidget, SLOT(OnDebugModeEntered()), Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeLeft()), disasmWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeLeft()), registersWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
||||||
connect(&render_window->GetEmuThread(), SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
connect(emu_thread, SIGNAL(DebugModeLeft()), callstackWidget, SLOT(OnDebugModeLeft()), Qt::BlockingQueuedConnection);
|
||||||
|
|
||||||
// Setup hotkeys
|
// Setup hotkeys
|
||||||
RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
|
RegisterHotkey("Main Window", "Load File", QKeySequence::Open);
|
||||||
|
@ -210,8 +211,8 @@ void GMainWindow::BootGame(std::string filename)
|
||||||
registersWidget->OnDebugModeEntered();
|
registersWidget->OnDebugModeEntered();
|
||||||
callstackWidget->OnDebugModeEntered();
|
callstackWidget->OnDebugModeEntered();
|
||||||
|
|
||||||
render_window->GetEmuThread().SetFilename(filename);
|
emu_thread->SetFilename(filename);
|
||||||
render_window->GetEmuThread().start();
|
emu_thread->start();
|
||||||
|
|
||||||
render_window->show();
|
render_window->show();
|
||||||
OnStartGame();
|
OnStartGame();
|
||||||
|
@ -232,7 +233,7 @@ void GMainWindow::OnMenuLoadSymbolMap() {
|
||||||
|
|
||||||
void GMainWindow::OnStartGame()
|
void GMainWindow::OnStartGame()
|
||||||
{
|
{
|
||||||
render_window->GetEmuThread().SetCpuRunning(true);
|
emu_thread->SetCpuRunning(true);
|
||||||
|
|
||||||
ui.action_Start->setEnabled(false);
|
ui.action_Start->setEnabled(false);
|
||||||
ui.action_Pause->setEnabled(true);
|
ui.action_Pause->setEnabled(true);
|
||||||
|
@ -241,7 +242,7 @@ void GMainWindow::OnStartGame()
|
||||||
|
|
||||||
void GMainWindow::OnPauseGame()
|
void GMainWindow::OnPauseGame()
|
||||||
{
|
{
|
||||||
render_window->GetEmuThread().SetCpuRunning(false);
|
emu_thread->SetCpuRunning(false);
|
||||||
|
|
||||||
ui.action_Start->setEnabled(true);
|
ui.action_Start->setEnabled(true);
|
||||||
ui.action_Pause->setEnabled(false);
|
ui.action_Pause->setEnabled(false);
|
||||||
|
@ -250,7 +251,7 @@ void GMainWindow::OnPauseGame()
|
||||||
|
|
||||||
void GMainWindow::OnStopGame()
|
void GMainWindow::OnStopGame()
|
||||||
{
|
{
|
||||||
render_window->GetEmuThread().SetCpuRunning(false);
|
emu_thread->SetCpuRunning(false);
|
||||||
// TODO: Shutdown core
|
// TODO: Shutdown core
|
||||||
|
|
||||||
ui.action_Start->setEnabled(true);
|
ui.action_Start->setEnabled(true);
|
||||||
|
@ -265,24 +266,22 @@ void GMainWindow::OnOpenHotkeysDialog()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GMainWindow::ToggleWindowMode()
|
void GMainWindow::ToggleWindowMode() {
|
||||||
{
|
if (ui.action_Single_Window_Mode->isChecked()) {
|
||||||
bool enable = ui.action_Single_Window_Mode->isChecked();
|
// Render in the main window...
|
||||||
if (!enable && render_window->parent() != nullptr)
|
|
||||||
{
|
|
||||||
ui.horizontalLayout->removeWidget(render_window);
|
|
||||||
render_window->setParent(nullptr);
|
|
||||||
render_window->setVisible(true);
|
|
||||||
render_window->RestoreGeometry();
|
|
||||||
render_window->setFocusPolicy(Qt::NoFocus);
|
|
||||||
}
|
|
||||||
else if (enable && render_window->parent() == nullptr)
|
|
||||||
{
|
|
||||||
render_window->BackupGeometry();
|
render_window->BackupGeometry();
|
||||||
ui.horizontalLayout->addWidget(render_window);
|
ui.horizontalLayout->addWidget(render_window);
|
||||||
render_window->setVisible(true);
|
render_window->setVisible(true);
|
||||||
render_window->setFocusPolicy(Qt::ClickFocus);
|
render_window->setFocusPolicy(Qt::ClickFocus);
|
||||||
render_window->setFocus();
|
render_window->setFocus();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Render in a separate window...
|
||||||
|
ui.horizontalLayout->removeWidget(render_window);
|
||||||
|
render_window->setParent(nullptr);
|
||||||
|
render_window->setVisible(true);
|
||||||
|
render_window->RestoreGeometry();
|
||||||
|
render_window->setFocusPolicy(Qt::NoFocus);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
class GImageInfo;
|
class GImageInfo;
|
||||||
class GRenderWindow;
|
class GRenderWindow;
|
||||||
|
class EmuThread;
|
||||||
class ProfilerWidget;
|
class ProfilerWidget;
|
||||||
class DisassemblerWidget;
|
class DisassemblerWidget;
|
||||||
class RegistersWidget;
|
class RegistersWidget;
|
||||||
|
@ -34,6 +35,10 @@ public:
|
||||||
GMainWindow();
|
GMainWindow();
|
||||||
~GMainWindow();
|
~GMainWindow();
|
||||||
|
|
||||||
|
EmuThread* GetEmuThread() {
|
||||||
|
return emu_thread;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void BootGame(std::string filename);
|
void BootGame(std::string filename);
|
||||||
|
|
||||||
|
@ -54,6 +59,7 @@ private:
|
||||||
Ui::MainWindow ui;
|
Ui::MainWindow ui;
|
||||||
|
|
||||||
GRenderWindow* render_window;
|
GRenderWindow* render_window;
|
||||||
|
EmuThread* emu_thread;
|
||||||
|
|
||||||
ProfilerWidget* profilerWidget;
|
ProfilerWidget* profilerWidget;
|
||||||
DisassemblerWidget* disasmWidget;
|
DisassemblerWidget* disasmWidget;
|
||||||
|
|
Reference in New Issue