Avoid running anims at 3x speed on Windows
authorLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Mon, 13 Apr 2015 08:18:22 +0000 (10:18 +0200)
committerLaszlo Agocs <laszlo.agocs@theqtcompany.com>
Mon, 13 Apr 2015 10:20:40 +0000 (10:20 +0000)
When there is no render pending, renderWindow() is not called and so
there is no blocking for vsync. Advancing the animations without any
sleep is wrong in this case and results in animations running at 3x
speed in case there is no change in the scenegraph contents.

To solve this, import the threaded render loop's sleep call.

Task-number: QTBUG-42699
Change-Id: I3658a827af12d4bc2ac05c7b0b29c65e9fc99675
Reviewed-by: Gunnar Sletta <gunnar@sletta.org>
src/quick/scenegraph/qsgwindowsrenderloop.cpp

index b88d21ce665a43ce81d7f71b4c0aa937ea0248df..0e22fa8b7bbb832d6bd925920d8d1d05682d949e 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <QtCore/QCoreApplication>
 #include <QtCore/QLibraryInfo>
+#include <QtCore/QThread>
 
 #include <QtGui/QScreen>
 #include <QtGui/QGuiApplication>
@@ -355,13 +356,20 @@ bool QSGWindowsRenderLoop::event(QEvent *event)
 void QSGWindowsRenderLoop::render()
 {
     RLDEBUG("render");
+    bool rendered = false;
     foreach (const WindowData &wd, m_windows) {
         if (wd.pendingUpdate) {
             const_cast<WindowData &>(wd).pendingUpdate = false;
             renderWindow(wd.window);
+            rendered = true;
         }
     }
 
+    if (!rendered) {
+        RLDEBUG("no changes, sleep");
+        QThread::msleep(m_vsyncDelta);
+    }
+
     if (m_animationDriver->isRunning()) {
         RLDEBUG("advancing animations");
         QSG_LOG_TIME_SAMPLE(time_start);