From e48f83b57aeee90fe63926a95f98e3e5d77654f8 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Tue, 18 Oct 2016 13:55:58 +0200 Subject: Revert "Revert "Redo animator internals"" This reverts commit ac765c4eca202e60f3e28d731f7ba3a77401fef5. Fix for problem in next commit. Change-Id: Ie6b0cb09e38e5063d943662be51952dc6da9a533 Reviewed-by: J-P Nurmi --- src/quick/util/qquickanimatorjob_p.h | 102 ++++++++++++++++++++--------------- 1 file changed, 58 insertions(+), 44 deletions(-) (limited to 'src/quick/util/qquickanimatorjob_p.h') 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 ** 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 &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 m_controller; QQuickAbstractAnimation *m_animation; - QAbstractAnimationJob *m_job; + QSharedPointer 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; -- cgit v1.2.3