1/*
2 Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20#ifndef TextureMapperAnimation_h
21#define TextureMapperAnimation_h
22
23#include "GraphicsLayer.h"
24
25namespace WebCore {
26
27class TransformationMatrix;
28
29class TextureMapperAnimation {
30public:
31 enum class AnimationState { Playing, Paused, Stopped };
32
33 struct ApplicationResult {
34 Optional<TransformationMatrix> transform;
35 Optional<double> opacity;
36 Optional<FilterOperations> filters;
37 bool hasRunningAnimations { false };
38 };
39
40 TextureMapperAnimation()
41 : m_keyframes(AnimatedPropertyInvalid)
42 { }
43 TextureMapperAnimation(const String&, const KeyframeValueList&, const FloatSize&, const Animation&, bool, MonotonicTime, Seconds, AnimationState);
44 WEBCORE_EXPORT TextureMapperAnimation(const TextureMapperAnimation&);
45
46 void apply(ApplicationResult&, MonotonicTime);
47 void pause(Seconds);
48 void resume();
49 bool isActive() const;
50
51 const String& name() const { return m_name; }
52 const KeyframeValueList& keyframes() const { return m_keyframes; }
53 const RefPtr<Animation> animation() const { return m_animation; }
54 AnimationState state() const { return m_state; }
55
56private:
57 void applyInternal(ApplicationResult&, const AnimationValue& from, const AnimationValue& to, float progress);
58 Seconds computeTotalRunningTime(MonotonicTime);
59
60 String m_name;
61 KeyframeValueList m_keyframes;
62 FloatSize m_boxSize;
63 RefPtr<Animation> m_animation;
64 bool m_listsMatch;
65 MonotonicTime m_startTime;
66 Seconds m_pauseTime;
67 Seconds m_totalRunningTime;
68 MonotonicTime m_lastRefreshedTime;
69 AnimationState m_state;
70};
71
72class TextureMapperAnimations {
73public:
74 TextureMapperAnimations() = default;
75
76 void add(const TextureMapperAnimation&);
77 void remove(const String& name);
78 void remove(const String& name, AnimatedPropertyID);
79 void pause(const String&, Seconds);
80 void suspend(MonotonicTime);
81 void resume();
82
83 void apply(TextureMapperAnimation::ApplicationResult&, MonotonicTime);
84
85 bool isEmpty() const { return m_animations.isEmpty(); }
86 size_t size() const { return m_animations.size(); }
87 const Vector<TextureMapperAnimation>& animations() const { return m_animations; }
88 Vector<TextureMapperAnimation>& animations() { return m_animations; }
89
90 bool hasRunningAnimations() const;
91 bool hasActiveAnimationsOfType(AnimatedPropertyID type) const;
92 TextureMapperAnimations getActiveAnimations() const;
93
94private:
95 Vector<TextureMapperAnimation> m_animations;
96};
97
98}
99
100#endif // TextureMapperAnimation_h
101