diff --git a/src/platform/qt/Display.cpp b/src/platform/qt/Display.cpp index 8d08e9026..266d2e6c4 100644 --- a/src/platform/qt/Display.cpp +++ b/src/platform/qt/Display.cpp @@ -66,6 +66,34 @@ void Display::stopDrawing() { } } +void Display::pauseDrawing() { + if (m_drawThread) { + if (GBAThreadIsActive(m_context)) { + GBAThreadInterrupt(m_context); + GBASyncSuspendDrawing(&m_context->sync); + } + QMetaObject::invokeMethod(m_painter, "pause", Qt::BlockingQueuedConnection); + if (GBAThreadIsActive(m_context)) { + GBASyncResumeDrawing(&m_context->sync); + GBAThreadContinue(m_context); + } + } +} + +void Display::unpauseDrawing() { + if (m_drawThread) { + if (GBAThreadIsActive(m_context)) { + GBAThreadInterrupt(m_context); + GBASyncSuspendDrawing(&m_context->sync); + } + QMetaObject::invokeMethod(m_painter, "unpause", Qt::BlockingQueuedConnection); + if (GBAThreadIsActive(m_context)) { + GBASyncResumeDrawing(&m_context->sync); + GBAThreadContinue(m_context); + } + } +} + void Display::forceDraw() { if (m_drawThread) { QMetaObject::invokeMethod(m_painter, "forceDraw", Qt::QueuedConnection); @@ -182,3 +210,14 @@ void Painter::stop() { m_gl->doneCurrent(); m_gl->context()->moveToThread(QApplication::instance()->thread()); } + +void Painter::pause() { + m_drawTimer->stop(); + // Make sure both buffers are filled + forceDraw(); + forceDraw(); +} + +void Painter::unpause() { + m_drawTimer->start(); +} diff --git a/src/platform/qt/Display.h b/src/platform/qt/Display.h index 7e38c08fc..a1c629eb4 100644 --- a/src/platform/qt/Display.h +++ b/src/platform/qt/Display.h @@ -19,6 +19,8 @@ public: public slots: void startDrawing(const uint32_t* buffer, GBAThread* context); void stopDrawing(); + void pauseDrawing(); + void unpauseDrawing(); void forceDraw(); #ifdef USE_PNG void screenshot(); @@ -49,6 +51,8 @@ public slots: void draw(); void start(); void stop(); + void pause(); + void unpause(); void resize(const QSize& size); private: diff --git a/src/platform/qt/Window.cpp b/src/platform/qt/Window.cpp index 9fe07d466..3398540bc 100644 --- a/src/platform/qt/Window.cpp +++ b/src/platform/qt/Window.cpp @@ -52,6 +52,8 @@ Window::Window(ConfigController* config, QWidget* parent) connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing())); connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped())); connect(m_controller, SIGNAL(stateLoaded(GBAThread*)), m_display, SLOT(forceDraw())); + connect(m_controller, SIGNAL(gamePaused(GBAThread*)), m_display, SLOT(pauseDrawing())); + connect(m_controller, SIGNAL(gameUnpaused(GBAThread*)), m_display, SLOT(unpauseDrawing())); connect(m_controller, SIGNAL(postLog(int, const QString&)), m_logView, SLOT(postLog(int, const QString&))); connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection); connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing()));