diff options
author | Gunnar Sletta <gunnar.sletta@jollamobile.com> | 2014-01-15 10:55:54 +0100 |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@jollamobile.com> | 2014-01-15 11:05:19 +0100 |
commit | ac2783136030bae18a33b3543ef68474b504cac2 (patch) | |
tree | 72eeb00162c8bfece5eb9c523cba07ebda73afda | |
parent | cfa774511982fef1f56ec14a09a4620d887b4f9d (diff) |
Make animation catchup plain and simple
Change-Id: Iee2ff60e9f3c6509cb16ab7410fbe994ee0c5256
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
-rw-r--r-- | customcontext/animation/animationdriver.cpp | 55 | ||||
-rw-r--r-- | customcontext/animation/animationdriver.h | 5 |
2 files changed, 9 insertions, 51 deletions
diff --git a/customcontext/animation/animationdriver.cpp b/customcontext/animation/animationdriver.cpp index 4092b66..bf84b6d 100644 --- a/customcontext/animation/animationdriver.cpp +++ b/customcontext/animation/animationdriver.cpp @@ -48,30 +48,12 @@ namespace CustomContext { -float get_env_float(const char *name, float defaultValue) -{ - QByteArray content = qgetenv(name); - - bool ok = false; - float value = content.toFloat(&ok); - return ok ? value : defaultValue; -} - - AnimationDriver::AnimationDriver() : m_stable_vsync(-1) , m_current_animation_time(0) - , m_current_animation_delay(0) - , m_current_animation_catchup(0) { m_last_updated.invalidate(); m_timer.invalidate(); - - // threshold for doing a non-smooth jump is 250ms - m_threshold_for_catchup = get_env_float("QML_ANIMATION_DRIVER_CATCHUP_THRESHOLD", 250); - - // Try to catch up over 20 frames. - m_catchup_ratio = get_env_float("QML_ANIMATION_DRIVER_CATCHUP_RATIO", 0.05); } void AnimationDriver::maybeUpdateDelta() @@ -79,9 +61,12 @@ void AnimationDriver::maybeUpdateDelta() // No point in updating it too frequently... if (m_last_updated.elapsed() < 30000 && m_last_updated.isValid()) return; - m_stable_vsync = 1000.0 / QGuiApplication::primaryScreen()->refreshRate(); m_last_updated.restart(); + +#ifdef CUSTOMCONTEXT_DEBUG + qDebug("CustomContext: AnimationDriver uses vsync=%f", m_stable_vsync); +#endif } qint64 AnimationDriver::elapsed() const @@ -97,8 +82,6 @@ void AnimationDriver::start() QAnimationDriver::start(); m_timer.restart(); m_current_animation_time = 0; - m_current_animation_delay = 0; - m_current_animation_catchup = 0; } @@ -109,31 +92,11 @@ void AnimationDriver::advance() if (m_stable_vsync < 0) { m_current_animation_time = m_timer.elapsed(); } else { - - m_current_animation_time += m_stable_vsync + m_current_animation_catchup; - m_current_animation_delay -= m_current_animation_catchup; - - if (m_current_animation_delay < m_current_animation_catchup*0.5) { - // Caught up after a dropped frame - m_current_animation_delay = 0.0; - m_current_animation_catchup = 0.0; - } - - if (m_current_animation_time < m_timer.elapsed()) { - m_current_animation_delay = m_timer.elapsed() - m_current_animation_time; -#ifdef CUSTOMCONTEXT_DEBUG - qDebug("CustomContext: animation needs compensation, calculated=%f, real=%f", (float) m_current_animation_time, (float) m_timer.elapsed()); -#endif - m_current_animation_time = qFloor((m_timer.elapsed() / m_stable_vsync) + 1) * m_stable_vsync; - - if (m_current_animation_delay > m_threshold_for_catchup) { - // If we are far behind, don't try the smooth catchup, just jump - m_current_animation_time += m_current_animation_delay; - m_current_animation_delay = 0.0; - } - m_current_animation_catchup = m_current_animation_delay * m_catchup_ratio; // Catch up over 20 frames - } - } + m_current_animation_time += m_stable_vsync; + if (m_current_animation_time + m_stable_vsync < m_timer.elapsed()) { + m_current_animation_time = (qFloor(m_timer.elapsed() / m_stable_vsync) + 1.0f) * m_stable_vsync; + } + } QAnimationDriver::advanceAnimation(startTime() + m_current_animation_time); } diff --git a/customcontext/animation/animationdriver.h b/customcontext/animation/animationdriver.h index 0c9d0fd..e95c847 100644 --- a/customcontext/animation/animationdriver.h +++ b/customcontext/animation/animationdriver.h @@ -70,11 +70,6 @@ private: float m_stable_vsync; float m_current_animation_time; - float m_current_animation_delay; - float m_current_animation_catchup; - - float m_threshold_for_catchup; - float m_catchup_ratio; }; } |