From 629c5bf76c7b7ad1133020f1a028b96e29d944c9 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 20 Jan 2017 15:26:41 -0800 Subject: [PATCH] Qt: Fix timing issues on high refresh rate monitors --- CHANGES | 1 + src/platform/qt/DisplayGL.cpp | 11 +++++++++++ src/platform/qt/DisplayGL.h | 3 ++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 9b62df111..6c9392ca9 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ Bugfixes: - Libretro: Fix saving in GB games (fixes mgba.io/i/486) - LR35902: Fix pc overflowing current region off-by-one - GB MBC: Fix ROM bank overflows getting set to bank 0 + - Qt: Fix timing issues on high refresh rate monitors Misc: - Qt: Improved HiDPI support - Feature: Support ImageMagick 7 diff --git a/src/platform/qt/DisplayGL.cpp b/src/platform/qt/DisplayGL.cpp index 986e6eb9a..3d30193c1 100644 --- a/src/platform/qt/DisplayGL.cpp +++ b/src/platform/qt/DisplayGL.cpp @@ -7,6 +7,7 @@ #include #include +#include extern "C" { #include "core/core.h" @@ -319,6 +320,16 @@ void PainterGL::draw() { if (m_queue.isEmpty() || !mCoreThreadIsActive(m_context)) { return; } + if (!m_delayTimer.isValid()) { + m_delayTimer.start(); + } else if (m_delayTimer.elapsed() < 16) { + QMetaObject::invokeMethod(this, "draw", Qt::QueuedConnection); + QThread::usleep(500); + return; + } else { + m_delayTimer.restart(); + } + if (mCoreSyncWaitFrameStart(&m_context->sync) || !m_queue.isEmpty()) { dequeue(); mCoreSyncWaitFrameEnd(&m_context->sync); diff --git a/src/platform/qt/DisplayGL.h b/src/platform/qt/DisplayGL.h index 5803dfd92..ec9cd7581 100644 --- a/src/platform/qt/DisplayGL.h +++ b/src/platform/qt/DisplayGL.h @@ -15,12 +15,12 @@ #endif #endif +#include #include #include #include #include #include -#include extern "C" { #include "platform/video-backend.h" @@ -122,6 +122,7 @@ private: VideoBackend* m_backend; QSize m_size; MessagePainter* m_messagePainter; + QElapsedTimer m_delayTimer; }; }