all repos — mgba @ cade03e10d915de35226aa7ce635d9ef46dbfc4a

mGBA Game Boy Advance Emulator

Qt: Prevent flicker upon pausing the emulator
Jeffrey Pfau jeffrey@endrift.com
Sat, 15 Nov 2014 15:00:27 -0800
commit

cade03e10d915de35226aa7ce635d9ef46dbfc4a

parent

81b85d1843a2e32aab25fd79e9da236e27619436

3 files changed, 45 insertions(+), 0 deletions(-)

jump to
M src/platform/qt/Display.cppsrc/platform/qt/Display.cpp

@@ -66,6 +66,34 @@ }

} } +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 @@ m_gl->swapBuffers();

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(); +}
M src/platform/qt/Display.hsrc/platform/qt/Display.h

@@ -19,6 +19,8 @@

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 @@ void forceDraw();

void draw(); void start(); void stop(); + void pause(); + void unpause(); void resize(const QSize& size); private:
M src/platform/qt/Window.cppsrc/platform/qt/Window.cpp

@@ -52,6 +52,8 @@ connect(m_controller, SIGNAL(gameStarted(GBAThread*)), this, SLOT(gameStarted(GBAThread*)));

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()));