Avoid advancing animations outside the animation "tick"
authorGunnar Sletta <gunnar.sletta@nokia.com>
Wed, 8 Feb 2012 09:16:37 +0000 (10:16 +0100)
committerQt by Nokia <qt-info@nokia.com>
Wed, 8 Feb 2012 23:32:41 +0000 (00:32 +0100)
We have logic to prevent animations from starting in the middle of
an animation as a result of a previously slow frame. This was
based on current time, not the animation driver time and would
cause severe jumping when custom animation drivers were being used.

Also, this logic would trigger multiple animation runs per frame,
which is very bad for performance, so this change introduces a
threshold of 50ms to compensate for that. 50ms because that is
triplebuffer limit.

Change-Id: I1c7ebac30060e849d03c14d62411c2b953854d98
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
src/corelib/animation/qabstractanimation.cpp
src/corelib/animation/qabstractanimation.h
src/corelib/animation/qabstractanimation_p.h

index 30f0714..04df52c 100644 (file)
@@ -248,6 +248,12 @@ QUnifiedTimer *QUnifiedTimer::instance()
     return instance(true);
 }
 
+void QUnifiedTimer::maybeUpdateAnimationsToCurrentTime()
+{
+    if (time.elapsed() - lastTick > 50)
+        updateAnimationTimers(driver->elapsed());
+}
+
 void QUnifiedTimer::updateAnimationTimers(qint64 currentTick)
 {
     //setCurrentTime can get this called again while we're the for loop. At least with pauseAnimations
@@ -590,7 +596,7 @@ void QAnimationTimer::startAnimations()
     startAnimationPending = false;
     //force timer to update, which prevents large deltas for our newly added animations
     if (!animations.isEmpty())
-        QUnifiedTimer::instance()->updateAnimationTimers(-1);
+        QUnifiedTimer::instance()->maybeUpdateAnimationsToCurrentTime();
 
     //we transfer the waiting animations into the "really running" state
     animations += animationsToStart;
index 70200c4..34ddbc6 100644 (file)
@@ -149,7 +149,7 @@ public:
 
     bool isRunning() const;
 
-    qint64 elapsed() const;
+    virtual qint64 elapsed() const;
 
 Q_SIGNALS:
     void started();
index c4d5334..02a3c02 100644 (file)
@@ -185,6 +185,7 @@ public:
     bool canUninstallAnimationDriver(QAnimationDriver *driver);
 
     void restart();
+    void maybeUpdateAnimationsToCurrentTime();
     void updateAnimationTimers(qint64 currentTick);
 
     //useful for profiling/debugging