From 56921b1f885152e338f726bc5042b479a54944c5 Mon Sep 17 00:00:00 2001 From: Christiaan Janssen Date: Fri, 7 Oct 2011 14:58:50 +0200 Subject: [PATCH] QUnifiedTimer: Add callback for timer ticks. Used for profiling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ia7cf823dee7f0b491db2f041d29cdfc0e385f18e Reviewed-on: http://codereview.qt-project.org/6253 Reviewed-by: Kai Koehne Sanity-Review: Qt Sanity Bot Reviewed-by: Samuel Rødal --- src/corelib/animation/qabstractanimation.cpp | 10 +++++++++- src/corelib/animation/qabstractanimation_p.h | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/corelib/animation/qabstractanimation.cpp b/src/corelib/animation/qabstractanimation.cpp index fd63b25a762..830c5da6b6c 100644 --- a/src/corelib/animation/qabstractanimation.cpp +++ b/src/corelib/animation/qabstractanimation.cpp @@ -168,7 +168,7 @@ Q_GLOBAL_STATIC(QThreadStorage, unifiedTimer) QUnifiedTimer::QUnifiedTimer() : QObject(), defaultDriver(this), lastTick(0), timingInterval(DEFAULT_TIMER_INTERVAL), currentAnimationIdx(0), insideTick(false), consistentTiming(false), slowMode(false), - slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0) + slowdownFactor(5.0f), isPauseTimerActive(false), runningLeafAnimations(0), profilerCallback(0) { time.invalidate(); driver = &defaultDriver; @@ -234,12 +234,20 @@ void QUnifiedTimer::updateAnimationsTime(qint64 timeStep) int elapsed = QAbstractAnimationPrivate::get(animation)->totalCurrentTime + (animation->direction() == QAbstractAnimation::Forward ? delta : -delta); animation->setCurrentTime(elapsed); + + if (profilerCallback) + profilerCallback(delta); } insideTick = false; currentAnimationIdx = 0; } } +void QUnifiedTimer::registerProfilerCallback(void (*cb)(qint64)) +{ + profilerCallback = cb; +} + void QUnifiedTimer::updateAnimationTimer() { QUnifiedTimer *inst = QUnifiedTimer::instance(false); diff --git a/src/corelib/animation/qabstractanimation_p.h b/src/corelib/animation/qabstractanimation_p.h index 1de1225e753..7e7571bc58f 100644 --- a/src/corelib/animation/qabstractanimation_p.h +++ b/src/corelib/animation/qabstractanimation_p.h @@ -189,6 +189,7 @@ public: //useful for profiling/debugging int runningAnimationCount() { return animations.count(); } + void registerProfilerCallback(void (*cb)(qint64)); protected: void timerEvent(QTimerEvent *); @@ -231,6 +232,8 @@ private: void unregisterRunningAnimation(QAbstractAnimation *animation); int closestPauseAnimationTimeToFinish(); + + void (*profilerCallback)(qint64); }; QT_END_NAMESPACE