Use explicit Qt::TimerTypes when starting animation timers.
authorBradley T. Hughes <bradley.hughes@nokia.com>
Mon, 2 Jan 2012 11:47:15 +0000 (12:47 +0100)
committerQt by Nokia <qt-info@nokia.com>
Thu, 5 Jan 2012 14:03:30 +0000 (15:03 +0100)
Similar to commit 4e1ad49998cf782ccc88e7e80fbd05c722658a16, we know that
CoarseTimers are worst in their first firing, so we prefer a
PreciseTimer for short pause animations to avoid inaccuracies. If the
timeout is too big, we use a CoarseTimer anyway (current threshold is
2000ms).

The timer that drives the QDefaultAnimationDriver is always a
PreciseTimer.

Change-Id: I0939357d768b804f9f9bab3adf5ed1d0f7e012e7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/corelib/animation/qabstractanimation.cpp

index 9e4b361..19a9384 100644 (file)
 
 #define DEFAULT_TIMER_INTERVAL 16
 #define STARTSTOP_TIMER_DELAY 0
+#define PAUSE_TIMER_COARSE_THRESHOLD 2000
 
 QT_BEGIN_NAMESPACE
 
@@ -264,7 +265,9 @@ void QUnifiedTimer::restartAnimationTimer()
             qDebug() << closestPauseAnimationTimeToFinish();
         }
         driver->stop();
-        pauseTimer.start(closestTimeToFinish, this);
+        // use a precise timer if the pause will be short
+        Qt::TimerType timerType = closestTimeToFinish < PAUSE_TIMER_COARSE_THRESHOLD ? Qt::PreciseTimer : Qt::CoarseTimer;
+        pauseTimer.start(closestTimeToFinish, timerType, this);
     } else if (!driver->isRunning()) {
         if (pauseTimer.isActive())
             pauseTimer.stop();
@@ -619,7 +622,8 @@ void QDefaultAnimationDriver::timerEvent(QTimerEvent *e)
 
 void QDefaultAnimationDriver::startTimer()
 {
-    m_timer.start(m_unified_timer->timingInterval, this);
+    // always use a precise timer to drive animations
+    m_timer.start(m_unified_timer->timingInterval, Qt::PreciseTimer, this);
 }
 
 void QDefaultAnimationDriver::stopTimer()