diff options
author | Mitch Curtis <[email protected]> | 2025-06-24 12:44:56 +0800 |
---|---|---|
committer | Mitch Curtis <[email protected]> | 2025-06-26 17:34:06 +0800 |
commit | a318e331f1387eb3c9d13be96c28619453a35571 (patch) | |
tree | 4fd26d8148e9921de7df6eaebfa62e8dcdfe266c | |
parent | 8def878a59982d9a378cf0e3975cda86627f086e (diff) |
Speeding up animations in tst_qquickpopup by 5 times results in a
reduction of its execution time from 9.8 to 7.9 minutes: a 20%
improvement.
This patch:
- Renames setSlowdownFactor to setSpeedModifier.
- Removes setSlowModeEnabled. There's no need for two functions if
we can just set a speed directly.
Task-number: QTBUG-137919
Change-Id: I04eb5d962c818da5d36f8f4cb5a2404977b78deb
Reviewed-by: Thiago Macieira <[email protected]>
-rw-r--r-- | src/corelib/animation/qabstractanimation.cpp | 12 | ||||
-rw-r--r-- | src/corelib/animation/qabstractanimation_p.h | 14 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index 789b9aaef44..d74894e1e42 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -179,9 +179,9 @@ typedef QList<QAbstractAnimation*>::ConstIterator AnimationListConstIt; QUnifiedTimer::QUnifiedTimer() : QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), - currentAnimationIdx(0), insideTick(false), insideRestart(false), consistentTiming(false), slowMode(false), + currentAnimationIdx(0), insideTick(false), insideRestart(false), consistentTiming(false), startTimersPending(false), stopTimerPending(false), allowNegativeDelta(false), - slowdownFactor(5.0f), profilerCallback(nullptr), + speedModifier(1), profilerCallback(nullptr), driverStartTime(0), temporalDrift(0) { time.invalidate(); @@ -265,9 +265,11 @@ void QUnifiedTimer::updateAnimationTimers() // ignore consistentTiming in case the pause timer is active qint64 delta = (consistentTiming && !pauseTimer.isActive()) ? timingInterval : totalElapsed - lastTick; - if (slowMode) { - if (slowdownFactor > 0) - delta = qRound(delta / slowdownFactor); + // Don't use qFuzzyCompare because this won't be set frequently enough + // that floating point error can accumulate. + if (speedModifier != 1) { + if (speedModifier > 0) + delta = qRound(delta / speedModifier); else delta = 0; } diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index cbe3f6339e7..d6c245f36f0 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -150,9 +150,9 @@ public: */ void setConsistentTiming(bool consistent) { consistentTiming = consistent; } - //these facilitate fine-tuning of complex animations - void setSlowModeEnabled(bool enabled) { slowMode = enabled; } - void setSlowdownFactor(qreal factor) { slowdownFactor = factor; } + // This facilitates both fine-tuning of complex animations by slowing them + // them down, and reducing execution time of auto tests by speeding them up. + void setSpeedModifier(qreal speed) { speedModifier = speed; } void installAnimationDriver(QAnimationDriver *driver); void uninstallAnimationDriver(QAnimationDriver *driver); @@ -194,15 +194,13 @@ private: bool insideTick; bool insideRestart; bool consistentTiming; - bool slowMode; bool startTimersPending; bool stopTimerPending; bool allowNegativeDelta; - // This factor will be used to divide the DEFAULT_TIMER_INTERVAL at each tick - // when slowMode is enabled. Setting it to 0 or higher than DEFAULT_TIMER_INTERVAL (16) - // stops all animations. - qreal slowdownFactor; + // This factor will be used to multiply the DEFAULT_TIMER_INTERVAL (16) at each tick + // if it's not equal to 1. Setting it to less than 1 / 16 (0.0625) stops all animations. + qreal speedModifier; QList<QAbstractAnimationTimer*> animationTimers, animationTimersToStart; QList<QAbstractAnimationTimer*> pausedAnimationTimers; |