aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickanimatorjob_p.h
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar@sletta.org>2016-08-23 12:38:14 +0200
committerGunnar Sletta <gunnar@sletta.org>2016-10-12 18:12:28 +0000
commitae80962806f44fc9f58de14d62229771b836cb93 (patch)
treee73a36fb943640a66e14c15a3582265ebbe9e306 /src/quick/util/qquickanimatorjob_p.h
parentebb8e81050b40645f0e80f0ec59773790928df75 (diff)
Redo animator internals
The animators have suffered from crashes at runtime and instability during testing which have led them to not live up to their potential. This change brings some new concepts to try to make the situation a bit better: Firstly, the ownership of the render thread animation job is maintained using a QSharedPointer, greatly simplifying the management of that object. For the most part it will be deleted on the render thread, but if not, then that is ok too. Secondly, the proxy job is no longer tied to the animation controller. It simply starts the job on the render thread and polls to see if it has completed and only then performs the write back into the source item. Thirdly, the transform helper object which unifies x, y, scale and rotation animators into one matrix has been moved out of the controller and is striclty managed by the transform jobs. Finally, the qmlbench testcase indicates this new implementation is almost 10% faster than the old one, so the addition of shared pointers have not caused any significant performance additions. Change-Id: I51bbc43f716f8635fea97a08f2367e10cde95499 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Anton Kudryavtsev <a.kudryavtsev@netris.ru>
Diffstat (limited to 'src/quick/util/qquickanimatorjob_p.h')
-rw-r--r--src/quick/util/qquickanimatorjob_p.h102
1 files changed, 58 insertions, 44 deletions
diff --git a/src/quick/util/qquickanimatorjob_p.h b/src/quick/util/qquickanimatorjob_p.h
index 64e849d322..d7aaa988a9 100644
--- a/src/quick/util/qquickanimatorjob_p.h
+++ b/src/quick/util/qquickanimatorjob_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtQuick module of the Qt Toolkit.
@@ -80,25 +81,20 @@ public:
QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObject *item);
~QQuickAnimatorProxyJob();
- int duration() const Q_DECL_OVERRIDE { return m_duration; }
+ int duration() const override { return m_duration; }
- QAbstractAnimationJob *job() const { return m_job; }
-
- void startedByController();
- void controllerWasDeleted();
- void markJobManagedByController() { m_jobManagedByController = true; }
+ const QSharedPointer<QAbstractAnimationJob> &job() const { return m_job; }
protected:
- void updateCurrentTime(int) Q_DECL_OVERRIDE;
- void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) Q_DECL_OVERRIDE;
- void debugAnimation(QDebug d) const Q_DECL_OVERRIDE;
+ void updateCurrentTime(int) override;
+ void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
+ void debugAnimation(QDebug d) const override;
public Q_SLOTS:
void windowChanged(QQuickWindow *window);
void sceneGraphInitialized();
private:
- void deleteJob();
void syncBackCurrentValues();
void readyToAnimate();
void setWindow(QQuickWindow *window);
@@ -106,7 +102,7 @@ private:
QPointer<QQuickAnimatorController> m_controller;
QQuickAbstractAnimation *m_animation;
- QAbstractAnimationJob *m_job;
+ QSharedPointer<QAbstractAnimationJob> m_job;
int m_duration;
enum InternalState {
@@ -117,7 +113,6 @@ private:
};
InternalState m_internalState;
- bool m_jobManagedByController;
};
class Q_QUICK_PRIVATE_EXPORT QQuickAnimatorJob : public QAbstractAnimationJob
@@ -126,37 +121,53 @@ public:
virtual void setTarget(QQuickItem *target);
QQuickItem *target() const { return m_target; }
- void setFrom(qreal scale) { m_from = scale; }
+ void setFrom(qreal from) { m_from = from; }
qreal from() const { return m_from; }
void setTo(qreal to) { m_to = to; }
qreal to() const { return m_to; }
void setDuration(int duration) { m_duration = duration; }
- int duration() const Q_DECL_OVERRIDE { return m_duration; }
+ int duration() const override { return m_duration; }
QEasingCurve easingCurve() const { return m_easing; }
void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; }
- virtual void targetWasDeleted();
+ // Initialize is called on the GUI thread just before it is started
+ // and taken over on the render thread.
virtual void initialize(QQuickAnimatorController *controller);
+
+ // Called on the render thread during SG shutdown.
+ virtual void invalidate() = 0;
+
+ // Called on the GUI thread after a complete render thread animation job
+ // has been completed to write back a given animator's result to the
+ // source item.
virtual void writeBack() = 0;
- virtual void nodeWasDestroyed() = 0;
- virtual void afterNodeSync() { }
+
+ // Called before the SG sync on the render thread. The GUI thread is
+ // locked during this call.
+ virtual void preSync() { }
+
+ // Called after the SG sync on the render thread. The GUI thread is
+ // locked during this call.
+ virtual void postSync() { }
+
+ // Called after animations have ticked on the render thread. No locks are
+ // held at this time, so synchronization needs to be taken into account
+ // if applicable.
+ virtual void commit() { }
bool isTransform() const { return m_isTransform; }
bool isUniform() const { return m_isUniform; }
- bool hasBeenRunning() const { return m_hasBeenRunning; }
- void setHasBeenRunning(bool has) { m_hasBeenRunning = has; }
-
qreal value() const;
QQuickAnimatorController *controller() const { return m_controller; }
protected:
QQuickAnimatorJob();
- void debugAnimation(QDebug d) const Q_DECL_OVERRIDE;
+ void debugAnimation(QDebug d) const override;
qreal progress(int time) const;
@@ -173,7 +184,6 @@ protected:
uint m_isTransform : 1;
uint m_isUniform : 1;
- uint m_hasBeenRunning : 1;
};
class QQuickTransformAnimatorJob : public QQuickAnimatorJob
@@ -197,7 +207,7 @@ public:
}
void sync();
- void apply();
+ void commit();
int ref;
QQuickItem *item;
@@ -217,13 +227,16 @@ public:
};
~QQuickTransformAnimatorJob();
- Helper *transformHelper() const { return m_helper; }
+
+ void commit() override;
+ void preSync() override;
+
+ void setTarget(QQuickItem *item) override;
protected:
QQuickTransformAnimatorJob();
- void initialize(QQuickAnimatorController *controller) Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
- void targetWasDeleted() Q_DECL_OVERRIDE;
+ void postSync() override;
+ void invalidate() override;
Helper *m_helper;
};
@@ -231,22 +244,22 @@ protected:
class Q_QUICK_PRIVATE_EXPORT QQuickScaleAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickXAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickYAnimatorJob : public QQuickTransformAnimatorJob
{
public:
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
};
class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimatorJob : public QQuickTransformAnimatorJob
@@ -254,8 +267,8 @@ class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimatorJob : public QQuickTransformA
public:
QQuickRotationAnimatorJob();
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
void setDirection(QQuickRotationAnimator::RotationDirection direction) { m_direction = direction; }
QQuickRotationAnimator::RotationDirection direction() const { return m_direction; }
@@ -269,10 +282,10 @@ class Q_QUICK_PRIVATE_EXPORT QQuickOpacityAnimatorJob : public QQuickAnimatorJob
public:
QQuickOpacityAnimatorJob();
- void initialize(QQuickAnimatorController *controller) Q_DECL_OVERRIDE;
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
+ void invalidate() override;
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
+ void postSync() override;
private:
QSGOpacityNode *m_opacityNode;
@@ -283,16 +296,17 @@ class Q_QUICK_PRIVATE_EXPORT QQuickUniformAnimatorJob : public QQuickAnimatorJob
public:
QQuickUniformAnimatorJob();
- void setTarget(QQuickItem *target) Q_DECL_OVERRIDE;
+ void setTarget(QQuickItem *target) override;
void setUniform(const QByteArray &uniform) { m_uniform = uniform; }
QByteArray uniform() const { return m_uniform; }
- void afterNodeSync() Q_DECL_OVERRIDE;
+ void postSync() override;
+
+ void updateCurrentTime(int time) override;
+ void writeBack() override;
- void updateCurrentTime(int time) Q_DECL_OVERRIDE;
- void writeBack() Q_DECL_OVERRIDE;
- void nodeWasDestroyed() Q_DECL_OVERRIDE;
+ void invalidate() override;
private:
QByteArray m_uniform;