all repos — mgba @ 982408281eeaca6ba8a62b23c5abe83ff8888939

mGBA Game Boy Advance Emulator

Merge branch 'feature/redo-sync'
Jeffrey Pfau jeffrey@endrift.com
Sun, 07 Jun 2015 13:37:33 -0700
commit

982408281eeaca6ba8a62b23c5abe83ff8888939

parent

9c0ae33ddd270102785fe450e1b1706d1801466e

M src/gba/supervisor/thread.csrc/gba/supervisor/thread.c

@@ -781,20 +781,12 @@

return sync->videoFrameSkip <= 0; } -void GBASyncSuspendDrawing(struct GBASync* sync) { - if (!sync) { - return; - } - - _changeVideoSync(sync, false); -} - -void GBASyncResumeDrawing(struct GBASync* sync) { +void GBASyncSetVideoSync(struct GBASync* sync, bool wait) { if (!sync) { return; } - _changeVideoSync(sync, true); + _changeVideoSync(sync, wait); } void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
M src/gba/supervisor/thread.hsrc/gba/supervisor/thread.h

@@ -146,9 +146,7 @@ void GBASyncForceFrame(struct GBASync* sync);

bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip); void GBASyncWaitFrameEnd(struct GBASync* sync); bool GBASyncDrawingFrame(struct GBASync* sync); - -void GBASyncSuspendDrawing(struct GBASync* sync); -void GBASyncResumeDrawing(struct GBASync* sync); +void GBASyncSetVideoSync(struct GBASync* sync, bool wait); void GBASyncProduceAudio(struct GBASync* sync, bool wait); void GBASyncLockAudio(struct GBASync* sync);
M src/platform/qt/DisplayGL.cppsrc/platform/qt/DisplayGL.cpp

@@ -43,6 +43,7 @@ m_gl->context()->moveToThread(m_drawThread);

m_painter->moveToThread(m_drawThread); connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start())); m_drawThread->start(); + GBASyncSetVideoSync(&m_context->sync, false); lockAspectRatio(m_lockAspectRatio); filter(m_filter);

@@ -53,13 +54,11 @@ void DisplayGL::stopDrawing() {

if (m_drawThread) { if (GBAThreadIsActive(m_context)) { GBAThreadInterrupt(m_context); - GBASyncSuspendDrawing(&m_context->sync); } QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection); m_drawThread->exit(); m_drawThread = nullptr; if (GBAThreadIsActive(m_context)) { - GBASyncResumeDrawing(&m_context->sync); GBAThreadContinue(m_context); } }

@@ -69,11 +68,9 @@ void DisplayGL::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); } }

@@ -83,11 +80,9 @@ void DisplayGL::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); } }

@@ -138,7 +133,7 @@ }

PainterGL::PainterGL(QGLWidget* parent) : m_gl(parent) - , m_drawTimer(nullptr) + , m_active(false) , m_messageTimer(this) , m_context(nullptr) {

@@ -167,6 +162,9 @@

void PainterGL::setBacking(const uint32_t* backing) { m_gl->makeCurrent(); m_backend.d.postFrame(&m_backend.d, backing); + if (m_active) { + draw(); + } m_gl->doneCurrent(); }

@@ -187,21 +185,21 @@ m_world.reset();

m_world.translate((w - drawW) / 2, (h - drawH) / 2); m_world.scale(qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, qreal(drawH) / VIDEO_VERTICAL_PIXELS); m_message.prepare(m_world, m_messageFont); - if (m_drawTimer) { + if (m_active) { forceDraw(); } } void PainterGL::lockAspectRatio(bool lock) { m_backend.d.lockAspectRatio = lock; - if (m_drawTimer) { + if (m_active) { forceDraw(); } } void PainterGL::filter(bool filter) { m_backend.d.filter = filter; - if (m_drawTimer) { + if (m_active) { forceDraw(); } }

@@ -210,21 +208,19 @@ void PainterGL::start() {

m_gl->makeCurrent(); m_backend.d.init(&m_backend.d, reinterpret_cast<WHandle>(m_gl->winId())); m_gl->doneCurrent(); - - m_drawTimer = new QTimer; - m_drawTimer->moveToThread(QThread::currentThread()); - m_drawTimer->setInterval(0); - connect(m_drawTimer, SIGNAL(timeout()), this, SLOT(draw())); - m_drawTimer->start(); + m_active = true; } void PainterGL::draw() { - GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip); - m_painter.begin(m_gl->context()->device()); - performDraw(); - m_painter.end(); - GBASyncWaitFrameEnd(&m_context->sync); - m_backend.d.swap(&m_backend.d); + if (GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip)) { + m_painter.begin(m_gl->context()->device()); + performDraw(); + m_painter.end(); + GBASyncWaitFrameEnd(&m_context->sync); + m_backend.d.swap(&m_backend.d); + } else { + GBASyncWaitFrameEnd(&m_context->sync); + } } void PainterGL::forceDraw() {

@@ -235,9 +231,7 @@ m_backend.d.swap(&m_backend.d);

} void PainterGL::stop() { - m_drawTimer->stop(); - delete m_drawTimer; - m_drawTimer = nullptr; + m_active = false; m_gl->makeCurrent(); m_backend.d.clear(&m_backend.d); m_backend.d.swap(&m_backend.d);

@@ -248,14 +242,14 @@ moveToThread(m_gl->thread());

} void PainterGL::pause() { - m_drawTimer->stop(); + m_active = false; // Make sure both buffers are filled forceDraw(); forceDraw(); } void PainterGL::unpause() { - m_drawTimer->start(); + m_active = true; } void PainterGL::performDraw() {
M src/platform/qt/DisplayGL.hsrc/platform/qt/DisplayGL.h

@@ -95,7 +95,7 @@ QPainter m_painter;

QStaticText m_message; QGLWidget* m_gl; QThread* m_thread; - QTimer* m_drawTimer; + bool m_active; QTimer m_messageTimer; GBAThread* m_context; GBAGLContext m_backend;