Qt: Prevent flicker upon pausing the emulator

This commit is contained in:
Jeffrey Pfau 2014-11-15 15:00:27 -08:00
parent 81b85d1843
commit cade03e10d
3 changed files with 45 additions and 0 deletions

View File

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

View File

@ -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:

View File

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