OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 | |
31 #ifndef AnimationTimeline_h | |
32 #define AnimationTimeline_h | |
33 | |
34 #include <memory> | |
35 #include "core/CoreExport.h" | |
36 #include "core/animation/AnimationEffectReadOnly.h" | |
37 #include "core/animation/EffectModel.h" | |
38 #include "core/animation/SuperAnimationTimeline.h" | |
39 #include "core/dom/Element.h" | |
40 #include "core/dom/TaskRunnerHelper.h" | |
41 #include "platform/Timer.h" | |
42 #include "platform/animation/CompositorAnimationTimeline.h" | |
43 #include "platform/bindings/ScriptWrappable.h" | |
44 #include "platform/heap/Handle.h" | |
45 #include "platform/wtf/RefPtr.h" | |
46 #include "platform/wtf/Vector.h" | |
47 | |
48 namespace blink { | |
49 | |
50 class Animation; | |
51 class AnimationEffectReadOnly; | |
52 class Document; | |
53 | |
54 // AnimationTimeline is constructed and owned by Document, and tied to its | |
55 // lifecycle. | |
56 class CORE_EXPORT AnimationTimeline : public SuperAnimationTimeline { | |
57 DEFINE_WRAPPERTYPEINFO(); | |
58 | |
59 public: | |
60 class PlatformTiming : public GarbageCollectedFinalized<PlatformTiming> { | |
61 public: | |
62 // Calls AnimationTimeline's wake() method after duration seconds. | |
63 virtual void WakeAfter(double duration) = 0; | |
64 virtual void ServiceOnNextFrame() = 0; | |
65 virtual ~PlatformTiming() {} | |
66 DEFINE_INLINE_VIRTUAL_TRACE() {} | |
67 }; | |
68 | |
69 static AnimationTimeline* Create(Document*, PlatformTiming* = nullptr); | |
70 | |
71 virtual ~AnimationTimeline() {} | |
72 | |
73 bool IsAnimationTimeline() const final { return true; } | |
74 | |
75 void ServiceAnimations(TimingUpdateReason); | |
76 void ScheduleNextService(); | |
77 | |
78 Animation* Play(AnimationEffectReadOnly*); | |
79 HeapVector<Member<Animation>> getAnimations(); | |
80 | |
81 void AnimationAttached(Animation&); | |
82 | |
83 bool IsActive(); | |
84 bool HasPendingUpdates() const { | |
85 return !animations_needing_update_.IsEmpty(); | |
86 } | |
87 double ZeroTime(); | |
88 double currentTime(bool& is_null) override; | |
89 double currentTime(); | |
90 double CurrentTimeInternal(bool& is_null); | |
91 double CurrentTimeInternal(); | |
92 double EffectiveTime(); | |
93 void PauseAnimationsForTesting(double); | |
94 | |
95 void SetAllCompositorPending(bool source_changed = false); | |
96 void SetOutdatedAnimation(Animation*); | |
97 void ClearOutdatedAnimation(Animation*); | |
98 bool HasOutdatedAnimation() const { return outdated_animation_count_ > 0; } | |
99 bool NeedsAnimationTimingUpdate(); | |
100 void InvalidateKeyframeEffects(const TreeScope&); | |
101 | |
102 void SetPlaybackRate(double); | |
103 double PlaybackRate() const; | |
104 | |
105 CompositorAnimationTimeline* CompositorTimeline() const { | |
106 return compositor_timeline_.get(); | |
107 } | |
108 | |
109 Document* GetDocument() { return document_.Get(); } | |
110 void Wake(); | |
111 void ResetForTesting(); | |
112 | |
113 DECLARE_VIRTUAL_TRACE(); | |
114 | |
115 protected: | |
116 AnimationTimeline(Document*, PlatformTiming*); | |
117 | |
118 private: | |
119 Member<Document> document_; | |
120 double zero_time_; | |
121 bool zero_time_initialized_; | |
122 unsigned outdated_animation_count_; | |
123 // Animations which will be updated on the next frame | |
124 // i.e. current, in effect, or had timing changed | |
125 HeapHashSet<Member<Animation>> animations_needing_update_; | |
126 HeapHashSet<WeakMember<Animation>> animations_; | |
127 | |
128 double playback_rate_; | |
129 | |
130 friend class SMILTimeContainer; | |
131 static const double kMinimumDelay; | |
132 | |
133 Member<PlatformTiming> timing_; | |
134 double last_current_time_internal_; | |
135 | |
136 std::unique_ptr<CompositorAnimationTimeline> compositor_timeline_; | |
137 | |
138 class AnimationTimelineTiming final : public PlatformTiming { | |
139 public: | |
140 AnimationTimelineTiming(AnimationTimeline* timeline) | |
141 : timeline_(timeline), | |
142 timer_(TaskRunnerHelper::Get(TaskType::kUnspecedTimer, | |
143 timeline->GetDocument()), | |
144 this, | |
145 &AnimationTimelineTiming::TimerFired) { | |
146 DCHECK(timeline_); | |
147 } | |
148 | |
149 void WakeAfter(double duration) override; | |
150 void ServiceOnNextFrame() override; | |
151 | |
152 void TimerFired(TimerBase*) { timeline_->Wake(); } | |
153 | |
154 DECLARE_VIRTUAL_TRACE(); | |
155 | |
156 private: | |
157 Member<AnimationTimeline> timeline_; | |
158 TaskRunnerTimer<AnimationTimelineTiming> timer_; | |
159 }; | |
160 | |
161 friend class AnimationAnimationTimelineTest; | |
162 }; | |
163 | |
164 DEFINE_TYPE_CASTS(AnimationTimeline, | |
165 SuperAnimationTimeline, | |
166 timeline, | |
167 timeline->IsAnimationTimeline(), | |
168 timeline.IsAnimationTimeline()); | |
169 | |
170 } // namespace blink | |
171 | |
172 #endif | |
OLD | NEW |