1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Gunnar Sletta <gunnar@sletta.org>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtQuick module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QQUICKANIMATORJOB_P_H
42#define QQUICKANIMATORJOB_P_H
43
44//
45// W A R N I N G
46// -------------
47//
48// This file is not part of the Qt API. It exists purely as an
49// implementation detail. This header file may change from version to
50// version without notice, or even be removed.
51//
52// We mean it.
53//
54
55#include <private/qabstractanimationjob_p.h>
56#include <private/qquickanimator_p.h>
57#include <private/qtquickglobal_p.h>
58
59#include <QtQuick/qquickitem.h>
60
61#include <QtCore/qeasingcurve.h>
62
63QT_BEGIN_NAMESPACE
64
65class QQuickAnimator;
66class QQuickWindow;
67class QQuickItem;
68class QQuickAbstractAnimation;
69
70class QQuickAnimatorController;
71class QQuickAnimatorProxyJobPrivate;
72class QQuickOpenGLShaderEffectNode;
73
74class QSGOpacityNode;
75
76class Q_QUICK_PRIVATE_EXPORT QQuickAnimatorProxyJob : public QObject, public QAbstractAnimationJob
77{
78 Q_OBJECT
79
80public:
81 QQuickAnimatorProxyJob(QAbstractAnimationJob *job, QObject *item);
82 ~QQuickAnimatorProxyJob();
83
84 int duration() const override { return m_duration; }
85
86 const QSharedPointer<QAbstractAnimationJob> &job() const { return m_job; }
87
88protected:
89 void updateCurrentTime(int) override;
90 void updateLoopCount(int) override;
91 void updateState(QAbstractAnimationJob::State newState, QAbstractAnimationJob::State oldState) override;
92 void debugAnimation(QDebug d) const override;
93
94public Q_SLOTS:
95 void windowChanged(QQuickWindow *window);
96 void sceneGraphInitialized();
97
98private:
99 void syncBackCurrentValues();
100 void readyToAnimate();
101 void setWindow(QQuickWindow *window);
102 static QObject *findAnimationContext(QQuickAbstractAnimation *);
103
104 QPointer<QQuickAnimatorController> m_controller;
105 QQuickAbstractAnimation *m_animation;
106 QSharedPointer<QAbstractAnimationJob> m_job;
107 int m_duration;
108
109 enum InternalState {
110 State_Starting, // Used when it should be running, but no we're still missing the controller.
111 State_Running,
112 State_Paused,
113 State_Stopped
114 };
115
116 InternalState m_internalState;
117};
118
119class Q_QUICK_PRIVATE_EXPORT QQuickAnimatorJob : public QAbstractAnimationJob
120{
121public:
122 virtual void setTarget(QQuickItem *target);
123 QQuickItem *target() const { return m_target; }
124
125 void setFrom(qreal from) {
126 m_from = from;
127 boundValue();
128 }
129 qreal from() const { return m_from; }
130
131 void setTo(qreal to) {
132 m_to = to;
133 boundValue();
134 }
135 qreal to() const { return m_to; }
136
137 void setDuration(int duration) { m_duration = duration; }
138 int duration() const override { return m_duration; }
139
140 QEasingCurve easingCurve() const { return m_easing; }
141 void setEasingCurve(const QEasingCurve &curve) { m_easing = curve; }
142
143 // Initialize is called on the GUI thread just before it is started
144 // and taken over on the render thread.
145 virtual void initialize(QQuickAnimatorController *controller);
146
147 // Called on the render thread during SG shutdown.
148 virtual void invalidate() = 0;
149
150 // Called on the GUI thread after a complete render thread animation job
151 // has been completed to write back a given animator's result to the
152 // source item.
153 virtual void writeBack() = 0;
154
155 // Called before the SG sync on the render thread. The GUI thread is
156 // locked during this call.
157 virtual void preSync() { }
158
159 // Called after the SG sync on the render thread. The GUI thread is
160 // locked during this call.
161 virtual void postSync() { }
162
163 // Called after animations have ticked on the render thread. No locks are
164 // held at this time, so synchronization needs to be taken into account
165 // if applicable.
166 virtual void commit() { }
167
168 bool isTransform() const { return m_isTransform; }
169 bool isUniform() const { return m_isUniform; }
170
171 qreal value() const;
172
173 QQuickAnimatorController *controller() const { return m_controller; }
174
175protected:
176 QQuickAnimatorJob();
177 void debugAnimation(QDebug d) const override;
178
179 qreal progress(int time) const;
180 void boundValue();
181
182 QPointer<QQuickItem> m_target;
183 QQuickAnimatorController *m_controller;
184
185 qreal m_from;
186 qreal m_to;
187 qreal m_value;
188
189 QEasingCurve m_easing;
190
191 int m_duration;
192
193 uint m_isTransform : 1;
194 uint m_isUniform : 1;
195};
196
197class QQuickTransformAnimatorJob : public QQuickAnimatorJob
198{
199public:
200
201 struct Helper
202 {
203 Helper()
204 : ref(1)
205 , node(nullptr)
206 , ox(0)
207 , oy(0)
208 , dx(0)
209 , dy(0)
210 , scale(1)
211 , rotation(0)
212 , wasSynced(false)
213 , wasChanged(false)
214 {
215 }
216
217 void sync();
218 void commit();
219
220 int ref;
221 QQuickItem *item;
222 QSGTransformNode *node;
223
224 // Origin
225 float ox;
226 float oy;
227
228 float dx;
229 float dy;
230 float scale;
231 float rotation;
232
233 uint wasSynced : 1;
234 uint wasChanged : 1;
235 };
236
237 ~QQuickTransformAnimatorJob();
238
239 void commit() override;
240 void preSync() override;
241
242 void setTarget(QQuickItem *item) override;
243
244protected:
245 QQuickTransformAnimatorJob();
246 void invalidate() override;
247
248 Helper *m_helper;
249};
250
251class Q_QUICK_PRIVATE_EXPORT QQuickScaleAnimatorJob : public QQuickTransformAnimatorJob
252{
253public:
254 void updateCurrentTime(int time) override;
255 void writeBack() override;
256};
257
258class Q_QUICK_PRIVATE_EXPORT QQuickXAnimatorJob : public QQuickTransformAnimatorJob
259{
260public:
261 void updateCurrentTime(int time) override;
262 void writeBack() override;
263};
264
265class Q_QUICK_PRIVATE_EXPORT QQuickYAnimatorJob : public QQuickTransformAnimatorJob
266{
267public:
268 void updateCurrentTime(int time) override;
269 void writeBack() override;
270};
271
272class Q_QUICK_PRIVATE_EXPORT QQuickRotationAnimatorJob : public QQuickTransformAnimatorJob
273{
274public:
275 QQuickRotationAnimatorJob();
276
277 void updateCurrentTime(int time) override;
278 void writeBack() override;
279
280 void setDirection(QQuickRotationAnimator::RotationDirection direction) { m_direction = direction; }
281 QQuickRotationAnimator::RotationDirection direction() const { return m_direction; }
282
283private:
284 QQuickRotationAnimator::RotationDirection m_direction;
285};
286
287class Q_QUICK_PRIVATE_EXPORT QQuickOpacityAnimatorJob : public QQuickAnimatorJob
288{
289public:
290 QQuickOpacityAnimatorJob();
291
292 void invalidate() override;
293 void updateCurrentTime(int time) override;
294 void writeBack() override;
295 void postSync() override;
296
297private:
298 QSGOpacityNode *m_opacityNode;
299};
300#if QT_CONFIG(opengl)
301class Q_QUICK_PRIVATE_EXPORT QQuickUniformAnimatorJob : public QQuickAnimatorJob
302{
303public:
304 QQuickUniformAnimatorJob();
305
306 void setTarget(QQuickItem *target) override;
307
308 void setUniform(const QByteArray &uniform) { m_uniform = uniform; }
309 QByteArray uniform() const { return m_uniform; }
310
311 void postSync() override;
312
313 void updateCurrentTime(int time) override;
314 void writeBack() override;
315
316 void invalidate() override;
317
318private:
319 QByteArray m_uniform;
320 QQuickOpenGLShaderEffectNode *m_node;
321
322 int m_uniformIndex : 8;
323 int m_uniformType : 8;
324};
325#endif
326
327QT_END_NAMESPACE
328
329#endif // QQUICKANIMATORJOB_P_H
330

source code of qtdeclarative/src/quick/util/qquickanimatorjob_p.h