diff options
author | Gunnar Sletta <gunnar.sletta@digia.com> | 2013-09-18 20:16:16 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-21 22:23:13 +0200 |
commit | a0f8be4021caa9bb5055923f0eea3bee0e345235 (patch) | |
tree | cf33dd92e8284f5692e65b1a574749d50da4a3f0 /src/quick/util/qquickanimation.cpp | |
parent | 0fc040ef70513ccaeb9e96f7ca05a3df4d6c7879 (diff) |
Animators - Render thread animation system
This introduces 6 new QML types for animating state in the
scene graph when the UI thread is blocked. The QObject property
being animated is updated after the animation completes.
It works also with the "windows" and "basic" render loops, but
offer litte benefit then compared to in the "threaded" case.
Change-Id: Ic19e47c898c0b8bd53e457db922b3c9c457c8147
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/quick/util/qquickanimation.cpp')
-rw-r--r-- | src/quick/util/qquickanimation.cpp | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/src/quick/util/qquickanimation.cpp b/src/quick/util/qquickanimation.cpp index c05b254b51..904842b91e 100644 --- a/src/quick/util/qquickanimation.cpp +++ b/src/quick/util/qquickanimation.cpp @@ -42,6 +42,8 @@ #include "qquickanimation_p.h" #include "qquickanimation_p_p.h" +#include "qquickanimatorjob_p.h" + #include <private/qquickstatechangescript_p.h> #include <private/qqmlcontext_p.h> @@ -171,8 +173,11 @@ void QQuickAbstractAnimationPrivate::commence() delete oldInstance; if (animationInstance) { - if (oldInstance != animationInstance) + if (oldInstance != animationInstance) { + if (q->threadingModel() == QQuickAbstractAnimation::RenderThread) + animationInstance = new QQuickAnimatorProxyJob(animationInstance, q); animationInstance->addAnimationChangeListener(this, QAbstractAnimationJob::Completion); + } animationInstance->start(); if (animationInstance->isStopped()) { running = false; @@ -643,6 +648,11 @@ void QQuickAbstractAnimationPrivate::animationFinished(QAbstractAnimationJob*) } } +QQuickAbstractAnimation::ThreadingModel QQuickAbstractAnimation::threadingModel() const +{ + return GuiThread; +} + /*! \qmltype PauseAnimation \instantiates QQuickPauseAnimation @@ -1713,6 +1723,21 @@ QQuickSequentialAnimation::~QQuickSequentialAnimation() { } +QQuickAbstractAnimation::ThreadingModel QQuickSequentialAnimation::threadingModel() const +{ + Q_D(const QQuickAnimationGroup); + + ThreadingModel style = AnyThread; + for (int i=0; i<d->animations.size(); ++i) { + ThreadingModel ces = d->animations.at(i)->threadingModel(); + if (ces == GuiThread) + return GuiThread; + else if (ces == RenderThread) + style = RenderThread; + } + return style; +} + QAbstractAnimationJob* QQuickSequentialAnimation::transition(QQuickStateActions &actions, QQmlProperties &modified, TransitionDirection direction, @@ -1729,14 +1754,19 @@ QAbstractAnimationJob* QQuickSequentialAnimation::transition(QQuickStateActions from = d->animations.count() - 1; } + ThreadingModel execution = threadingModel(); + bool valid = d->defaultProperty.isValid(); QAbstractAnimationJob* anim; for (int ii = from; ii < d->animations.count() && ii >= 0; ii += inc) { if (valid) d->animations.at(ii)->setDefaultTarget(d->defaultProperty); anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget); - if (anim) + if (anim) { + if (d->animations.at(ii)->threadingModel() == RenderThread && execution != RenderThread) + anim = new QQuickAnimatorProxyJob(anim, this); inc == -1 ? ag->prependAnimation(anim) : ag->appendAnimation(anim); + } } return initInstance(ag); @@ -1782,6 +1812,23 @@ QQuickParallelAnimation::~QQuickParallelAnimation() { } +QQuickAbstractAnimation::ThreadingModel QQuickParallelAnimation::threadingModel() const +{ + Q_D(const QQuickAnimationGroup); + + ThreadingModel style = AnyThread; + for (int i=0; i<d->animations.size(); ++i) { + ThreadingModel ces = d->animations.at(i)->threadingModel(); + if (ces == GuiThread) + return GuiThread; + else if (ces == RenderThread) + style = RenderThread; + } + return style; +} + + + QAbstractAnimationJob* QQuickParallelAnimation::transition(QQuickStateActions &actions, QQmlProperties &modified, TransitionDirection direction, @@ -1790,14 +1837,19 @@ QAbstractAnimationJob* QQuickParallelAnimation::transition(QQuickStateActions &a Q_D(QQuickAnimationGroup); QParallelAnimationGroupJob *ag = new QParallelAnimationGroupJob; + ThreadingModel style = threadingModel(); + bool valid = d->defaultProperty.isValid(); QAbstractAnimationJob* anim; for (int ii = 0; ii < d->animations.count(); ++ii) { if (valid) d->animations.at(ii)->setDefaultTarget(d->defaultProperty); anim = d->animations.at(ii)->transition(actions, modified, direction, defaultTarget); - if (anim) + if (anim) { + if (d->animations.at(ii)->threadingModel() == RenderThread && style != RenderThread) + anim = new QQuickAnimatorProxyJob(anim, this); ag->appendAnimation(anim); + } } return initInstance(ag); } @@ -2034,6 +2086,8 @@ void QQuickPropertyAnimation::setTo(const QVariant &t) \qmlproperty real QtQuick2::PropertyAnimation::easing.overshoot \qmlproperty real QtQuick2::PropertyAnimation::easing.period \qmlproperty list<real> QtQuick2::PropertyAnimation::easing.bezierCurve + +//! propertyanimation.easing \brief Specifies the easing curve used for the animation To specify an easing curve you need to specify at least the type. For some curves you can also specify @@ -2235,6 +2289,7 @@ void QQuickPropertyAnimation::setTo(const QVariant &t) See the \l {qml/animation/easing}{easing} example for a demonstration of the different easing settings. +//! propertyanimation.easing */ QEasingCurve QQuickPropertyAnimation::easing() const { |