mirror of https://github.com/mgba-emu/mgba.git
Merge branch 'feature/redo-sync'
This commit is contained in:
commit
982408281e
|
@ -781,20 +781,12 @@ bool GBASyncDrawingFrame(struct GBASync* sync) {
|
||||||
return sync->videoFrameSkip <= 0;
|
return sync->videoFrameSkip <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncSuspendDrawing(struct GBASync* sync) {
|
void GBASyncSetVideoSync(struct GBASync* sync, bool wait) {
|
||||||
if (!sync) {
|
if (!sync) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_changeVideoSync(sync, false);
|
_changeVideoSync(sync, wait);
|
||||||
}
|
|
||||||
|
|
||||||
void GBASyncResumeDrawing(struct GBASync* sync) {
|
|
||||||
if (!sync) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_changeVideoSync(sync, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
void GBASyncProduceAudio(struct GBASync* sync, bool wait) {
|
||||||
|
|
|
@ -146,9 +146,7 @@ void GBASyncForceFrame(struct GBASync* sync);
|
||||||
bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
|
bool GBASyncWaitFrameStart(struct GBASync* sync, int frameskip);
|
||||||
void GBASyncWaitFrameEnd(struct GBASync* sync);
|
void GBASyncWaitFrameEnd(struct GBASync* sync);
|
||||||
bool GBASyncDrawingFrame(struct GBASync* sync);
|
bool GBASyncDrawingFrame(struct GBASync* sync);
|
||||||
|
void GBASyncSetVideoSync(struct GBASync* sync, bool wait);
|
||||||
void GBASyncSuspendDrawing(struct GBASync* sync);
|
|
||||||
void GBASyncResumeDrawing(struct GBASync* sync);
|
|
||||||
|
|
||||||
void GBASyncProduceAudio(struct GBASync* sync, bool wait);
|
void GBASyncProduceAudio(struct GBASync* sync, bool wait);
|
||||||
void GBASyncLockAudio(struct GBASync* sync);
|
void GBASyncLockAudio(struct GBASync* sync);
|
||||||
|
|
|
@ -43,6 +43,7 @@ void DisplayGL::startDrawing(GBAThread* thread) {
|
||||||
m_painter->moveToThread(m_drawThread);
|
m_painter->moveToThread(m_drawThread);
|
||||||
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
|
connect(m_drawThread, SIGNAL(started()), m_painter, SLOT(start()));
|
||||||
m_drawThread->start();
|
m_drawThread->start();
|
||||||
|
GBASyncSetVideoSync(&m_context->sync, false);
|
||||||
|
|
||||||
lockAspectRatio(m_lockAspectRatio);
|
lockAspectRatio(m_lockAspectRatio);
|
||||||
filter(m_filter);
|
filter(m_filter);
|
||||||
|
@ -53,13 +54,11 @@ void DisplayGL::stopDrawing() {
|
||||||
if (m_drawThread) {
|
if (m_drawThread) {
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBAThreadInterrupt(m_context);
|
GBAThreadInterrupt(m_context);
|
||||||
GBASyncSuspendDrawing(&m_context->sync);
|
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(m_painter, "stop", Qt::BlockingQueuedConnection);
|
||||||
m_drawThread->exit();
|
m_drawThread->exit();
|
||||||
m_drawThread = nullptr;
|
m_drawThread = nullptr;
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBASyncResumeDrawing(&m_context->sync);
|
|
||||||
GBAThreadContinue(m_context);
|
GBAThreadContinue(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,11 +68,9 @@ void DisplayGL::pauseDrawing() {
|
||||||
if (m_drawThread) {
|
if (m_drawThread) {
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBAThreadInterrupt(m_context);
|
GBAThreadInterrupt(m_context);
|
||||||
GBASyncSuspendDrawing(&m_context->sync);
|
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(m_painter, "pause", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(m_painter, "pause", Qt::BlockingQueuedConnection);
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBASyncResumeDrawing(&m_context->sync);
|
|
||||||
GBAThreadContinue(m_context);
|
GBAThreadContinue(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,11 +80,9 @@ void DisplayGL::unpauseDrawing() {
|
||||||
if (m_drawThread) {
|
if (m_drawThread) {
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBAThreadInterrupt(m_context);
|
GBAThreadInterrupt(m_context);
|
||||||
GBASyncSuspendDrawing(&m_context->sync);
|
|
||||||
}
|
}
|
||||||
QMetaObject::invokeMethod(m_painter, "unpause", Qt::BlockingQueuedConnection);
|
QMetaObject::invokeMethod(m_painter, "unpause", Qt::BlockingQueuedConnection);
|
||||||
if (GBAThreadIsActive(m_context)) {
|
if (GBAThreadIsActive(m_context)) {
|
||||||
GBASyncResumeDrawing(&m_context->sync);
|
|
||||||
GBAThreadContinue(m_context);
|
GBAThreadContinue(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +133,7 @@ void DisplayGL::resizePainter() {
|
||||||
|
|
||||||
PainterGL::PainterGL(QGLWidget* parent)
|
PainterGL::PainterGL(QGLWidget* parent)
|
||||||
: m_gl(parent)
|
: m_gl(parent)
|
||||||
, m_drawTimer(nullptr)
|
, m_active(false)
|
||||||
, m_messageTimer(this)
|
, m_messageTimer(this)
|
||||||
, m_context(nullptr)
|
, m_context(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -167,6 +162,9 @@ void PainterGL::setContext(GBAThread* context) {
|
||||||
void PainterGL::setBacking(const uint32_t* backing) {
|
void PainterGL::setBacking(const uint32_t* backing) {
|
||||||
m_gl->makeCurrent();
|
m_gl->makeCurrent();
|
||||||
m_backend.d.postFrame(&m_backend.d, backing);
|
m_backend.d.postFrame(&m_backend.d, backing);
|
||||||
|
if (m_active) {
|
||||||
|
draw();
|
||||||
|
}
|
||||||
m_gl->doneCurrent();
|
m_gl->doneCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,21 +185,21 @@ void PainterGL::resize(const QSize& size) {
|
||||||
m_world.translate((w - drawW) / 2, (h - drawH) / 2);
|
m_world.translate((w - drawW) / 2, (h - drawH) / 2);
|
||||||
m_world.scale(qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, qreal(drawH) / VIDEO_VERTICAL_PIXELS);
|
m_world.scale(qreal(drawW) / VIDEO_HORIZONTAL_PIXELS, qreal(drawH) / VIDEO_VERTICAL_PIXELS);
|
||||||
m_message.prepare(m_world, m_messageFont);
|
m_message.prepare(m_world, m_messageFont);
|
||||||
if (m_drawTimer) {
|
if (m_active) {
|
||||||
forceDraw();
|
forceDraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::lockAspectRatio(bool lock) {
|
void PainterGL::lockAspectRatio(bool lock) {
|
||||||
m_backend.d.lockAspectRatio = lock;
|
m_backend.d.lockAspectRatio = lock;
|
||||||
if (m_drawTimer) {
|
if (m_active) {
|
||||||
forceDraw();
|
forceDraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::filter(bool filter) {
|
void PainterGL::filter(bool filter) {
|
||||||
m_backend.d.filter = filter;
|
m_backend.d.filter = filter;
|
||||||
if (m_drawTimer) {
|
if (m_active) {
|
||||||
forceDraw();
|
forceDraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,21 +208,19 @@ void PainterGL::start() {
|
||||||
m_gl->makeCurrent();
|
m_gl->makeCurrent();
|
||||||
m_backend.d.init(&m_backend.d, reinterpret_cast<WHandle>(m_gl->winId()));
|
m_backend.d.init(&m_backend.d, reinterpret_cast<WHandle>(m_gl->winId()));
|
||||||
m_gl->doneCurrent();
|
m_gl->doneCurrent();
|
||||||
|
m_active = true;
|
||||||
m_drawTimer = new QTimer;
|
|
||||||
m_drawTimer->moveToThread(QThread::currentThread());
|
|
||||||
m_drawTimer->setInterval(0);
|
|
||||||
connect(m_drawTimer, SIGNAL(timeout()), this, SLOT(draw()));
|
|
||||||
m_drawTimer->start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::draw() {
|
void PainterGL::draw() {
|
||||||
GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip);
|
if (GBASyncWaitFrameStart(&m_context->sync, m_context->frameskip)) {
|
||||||
m_painter.begin(m_gl->context()->device());
|
m_painter.begin(m_gl->context()->device());
|
||||||
performDraw();
|
performDraw();
|
||||||
m_painter.end();
|
m_painter.end();
|
||||||
GBASyncWaitFrameEnd(&m_context->sync);
|
GBASyncWaitFrameEnd(&m_context->sync);
|
||||||
m_backend.d.swap(&m_backend.d);
|
m_backend.d.swap(&m_backend.d);
|
||||||
|
} else {
|
||||||
|
GBASyncWaitFrameEnd(&m_context->sync);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::forceDraw() {
|
void PainterGL::forceDraw() {
|
||||||
|
@ -235,9 +231,7 @@ void PainterGL::forceDraw() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::stop() {
|
void PainterGL::stop() {
|
||||||
m_drawTimer->stop();
|
m_active = false;
|
||||||
delete m_drawTimer;
|
|
||||||
m_drawTimer = nullptr;
|
|
||||||
m_gl->makeCurrent();
|
m_gl->makeCurrent();
|
||||||
m_backend.d.clear(&m_backend.d);
|
m_backend.d.clear(&m_backend.d);
|
||||||
m_backend.d.swap(&m_backend.d);
|
m_backend.d.swap(&m_backend.d);
|
||||||
|
@ -248,14 +242,14 @@ void PainterGL::stop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::pause() {
|
void PainterGL::pause() {
|
||||||
m_drawTimer->stop();
|
m_active = false;
|
||||||
// Make sure both buffers are filled
|
// Make sure both buffers are filled
|
||||||
forceDraw();
|
forceDraw();
|
||||||
forceDraw();
|
forceDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::unpause() {
|
void PainterGL::unpause() {
|
||||||
m_drawTimer->start();
|
m_active = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterGL::performDraw() {
|
void PainterGL::performDraw() {
|
||||||
|
|
|
@ -95,7 +95,7 @@ private:
|
||||||
QStaticText m_message;
|
QStaticText m_message;
|
||||||
QGLWidget* m_gl;
|
QGLWidget* m_gl;
|
||||||
QThread* m_thread;
|
QThread* m_thread;
|
||||||
QTimer* m_drawTimer;
|
bool m_active;
|
||||||
QTimer m_messageTimer;
|
QTimer m_messageTimer;
|
||||||
GBAThread* m_context;
|
GBAThread* m_context;
|
||||||
GBAGLContext m_backend;
|
GBAGLContext m_backend;
|
||||||
|
|
Loading…
Reference in New Issue