Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Side by Side Diff: Source/core/animation/AnimationTimeline.cpp

Issue 1113173003: Web Animations: Update naming to reflect spec changes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: No, really. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/animation/AnimationTimeline.h ('k') | Source/core/animation/AnimationTimeline.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 29 matching lines...) Expand all
40 #include "platform/RuntimeEnabledFeatures.h" 40 #include "platform/RuntimeEnabledFeatures.h"
41 #include "platform/TraceEvent.h" 41 #include "platform/TraceEvent.h"
42 #include "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
43 #include "public/platform/WebCompositorAnimationTimeline.h" 43 #include "public/platform/WebCompositorAnimationTimeline.h"
44 #include "public/platform/WebCompositorSupport.h" 44 #include "public/platform/WebCompositorSupport.h"
45 45
46 namespace blink { 46 namespace blink {
47 47
48 namespace { 48 namespace {
49 49
50 bool compareAnimationPlayers(const RefPtrWillBeMember<AnimationPlayer>& left, co nst RefPtrWillBeMember<AnimationPlayer>& right) 50 bool compareAnimations(const RefPtrWillBeMember<Animation>& left, const RefPtrWi llBeMember<Animation>& right)
51 { 51 {
52 return AnimationPlayer::hasLowerPriority(left.get(), right.get()); 52 return Animation::hasLowerPriority(left.get(), right.get());
53 } 53 }
54 54
55 } 55 }
56 56
57 // This value represents 1 frame at 30Hz plus a little bit of wiggle room. 57 // This value represents 1 frame at 30Hz plus a little bit of wiggle room.
58 // TODO: Plumb a nominal framerate through and derive this value from that. 58 // TODO: Plumb a nominal framerate through and derive this value from that.
59 const double AnimationTimeline::s_minimumDelay = 0.04; 59 const double AnimationTimeline::s_minimumDelay = 0.04;
60 60
61 61
62 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing) 62 PassRefPtrWillBeRawPtr<AnimationTimeline> AnimationTimeline::create(Document* do cument, PassOwnPtrWillBeRawPtr<PlatformTiming> timing)
(...skipping 15 matching lines...) Expand all
78 78
79 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor m::current()->compositorSupport()) 79 if (RuntimeEnabledFeatures::compositorAnimationTimelinesEnabled() && Platfor m::current()->compositorSupport())
80 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline()); 80 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline());
81 81
82 ASSERT(document); 82 ASSERT(document);
83 } 83 }
84 84
85 AnimationTimeline::~AnimationTimeline() 85 AnimationTimeline::~AnimationTimeline()
86 { 86 {
87 #if !ENABLE(OILPAN) 87 #if !ENABLE(OILPAN)
88 for (const auto& player : m_players) 88 for (const auto& animation : m_animations)
89 player->detachFromTimeline(); 89 animation->detachFromTimeline();
90 #endif 90 #endif
91 } 91 }
92 92
93 void AnimationTimeline::playerAttached(AnimationPlayer& player) 93 void AnimationTimeline::animationAttached(Animation& animation)
94 { 94 {
95 ASSERT(player.timeline() == this); 95 ASSERT(animation.timeline() == this);
96 ASSERT(!m_players.contains(&player)); 96 ASSERT(!m_animations.contains(&animation));
97 m_players.add(&player); 97 m_animations.add(&animation);
98 } 98 }
99 99
100 AnimationPlayer* AnimationTimeline::play(AnimationNode* child) 100 Animation* AnimationTimeline::play(AnimationEffect* child)
101 { 101 {
102 if (!m_document) 102 if (!m_document)
103 return nullptr; 103 return nullptr;
104 104
105 RefPtrWillBeRawPtr<AnimationPlayer> player = AnimationPlayer::create(child, this); 105 RefPtrWillBeRawPtr<Animation> animation = Animation::create(child, this);
106 ASSERT(m_players.contains(player.get())); 106 ASSERT(m_animations.contains(animation.get()));
107 107
108 player->play(); 108 animation->play();
109 ASSERT(m_playersNeedingUpdate.contains(player)); 109 ASSERT(m_animationsNeedingUpdate.contains(animation));
110 110
111 return player.get(); 111 return animation.get();
112 } 112 }
113 113
114 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer>> AnimationTimeline::getAnim ationPlayers() 114 WillBeHeapVector<RefPtrWillBeMember<Animation>> AnimationTimeline::getAnimations ()
115 { 115 {
116 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer>> animationPlayers; 116 WillBeHeapVector<RefPtrWillBeMember<Animation>> animations;
117 for (const auto& player : m_players) { 117 for (const auto& animation : m_animations) {
118 if (player->source() && (player->source()->isCurrent() || player->source ()->isInEffect())) 118 if (animation->source() && (animation->source()->isCurrent() || animatio n->source()->isInEffect()))
119 animationPlayers.append(player); 119 animations.append(animation);
120 } 120 }
121 std::sort(animationPlayers.begin(), animationPlayers.end(), compareAnimation Players); 121 std::sort(animations.begin(), animations.end(), compareAnimations);
122 return animationPlayers; 122 return animations;
123 } 123 }
124 124
125 void AnimationTimeline::wake() 125 void AnimationTimeline::wake()
126 { 126 {
127 m_timing->serviceOnNextFrame(); 127 m_timing->serviceOnNextFrame();
128 } 128 }
129 129
130 void AnimationTimeline::serviceAnimations(TimingUpdateReason reason) 130 void AnimationTimeline::serviceAnimations(TimingUpdateReason reason)
131 { 131 {
132 TRACE_EVENT0("blink", "AnimationTimeline::serviceAnimations"); 132 TRACE_EVENT0("blink", "AnimationTimeline::serviceAnimations");
133 133
134 m_lastCurrentTimeInternal = currentTimeInternal(); 134 m_lastCurrentTimeInternal = currentTimeInternal();
135 135
136 m_timing->cancelWake(); 136 m_timing->cancelWake();
137 137
138 WillBeHeapVector<RawPtrWillBeMember<AnimationPlayer>> players; 138 WillBeHeapVector<RawPtrWillBeMember<Animation>> animations;
139 players.reserveInitialCapacity(m_playersNeedingUpdate.size()); 139 animations.reserveInitialCapacity(m_animationsNeedingUpdate.size());
140 for (RefPtrWillBeMember<AnimationPlayer> player : m_playersNeedingUpdate) 140 for (RefPtrWillBeMember<Animation> animation : m_animationsNeedingUpdate)
141 players.append(player.get()); 141 animations.append(animation.get());
142 142
143 std::sort(players.begin(), players.end(), AnimationPlayer::hasLowerPriority) ; 143 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority) ;
144 144
145 for (AnimationPlayer* player : players) { 145 for (Animation* animation : animations) {
146 if (!player->update(reason)) 146 if (!animation->update(reason))
147 m_playersNeedingUpdate.remove(player); 147 m_animationsNeedingUpdate.remove(animation);
148 } 148 }
149 149
150 ASSERT(!hasOutdatedAnimationPlayer()); 150 ASSERT(!hasOutdatedAnimation());
151 } 151 }
152 152
153 void AnimationTimeline::scheduleNextService() 153 void AnimationTimeline::scheduleNextService()
154 { 154 {
155 ASSERT(!hasOutdatedAnimationPlayer()); 155 ASSERT(!hasOutdatedAnimation());
156 156
157 double timeToNextEffect = std::numeric_limits<double>::infinity(); 157 double timeToNextEffect = std::numeric_limits<double>::infinity();
158 for (const auto& player : m_playersNeedingUpdate) { 158 for (const auto& animation : m_animationsNeedingUpdate) {
159 timeToNextEffect = std::min(timeToNextEffect, player->timeToEffectChange ()); 159 timeToNextEffect = std::min(timeToNextEffect, animation->timeToEffectCha nge());
160 } 160 }
161 161
162 if (timeToNextEffect < s_minimumDelay) { 162 if (timeToNextEffect < s_minimumDelay) {
163 m_timing->serviceOnNextFrame(); 163 m_timing->serviceOnNextFrame();
164 } else if (timeToNextEffect != std::numeric_limits<double>::infinity()) { 164 } else if (timeToNextEffect != std::numeric_limits<double>::infinity()) {
165 m_timing->wakeAfter(timeToNextEffect - s_minimumDelay); 165 m_timing->wakeAfter(timeToNextEffect - s_minimumDelay);
166 } 166 }
167 } 167 }
168 168
169 void AnimationTimeline::AnimationTimelineTiming::wakeAfter(double duration) 169 void AnimationTimeline::AnimationTimelineTiming::wakeAfter(double duration)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 void AnimationTimeline::setCurrentTimeInternal(double currentTime) 234 void AnimationTimeline::setCurrentTimeInternal(double currentTime)
235 { 235 {
236 if (!document()) 236 if (!document())
237 return; 237 return;
238 m_zeroTime = m_playbackRate == 0 238 m_zeroTime = m_playbackRate == 0
239 ? currentTime 239 ? currentTime
240 : document()->animationClock().currentTime() - currentTime / m_playbackR ate; 240 : document()->animationClock().currentTime() - currentTime / m_playbackR ate;
241 m_zeroTimeInitialized = true; 241 m_zeroTimeInitialized = true;
242 242
243 for (const auto& player : m_players) { 243 for (const auto& animation : m_animations) {
244 // The Player needs a timing update to pick up a new time. 244 // The Player needs a timing update to pick up a new time.
245 player->setOutdated(); 245 animation->setOutdated();
246 // Any corresponding compositor animation will need to be restarted. Mar king the 246 // Any corresponding compositor animation will need to be restarted. Mar king the
247 // source changed forces this. 247 // source changed forces this.
248 player->setCompositorPending(true); 248 animation->setCompositorPending(true);
249 } 249 }
250 } 250 }
251 251
252 double AnimationTimeline::effectiveTime() 252 double AnimationTimeline::effectiveTime()
253 { 253 {
254 double time = currentTimeInternal(); 254 double time = currentTimeInternal();
255 return std::isnan(time) ? 0 : time; 255 return std::isnan(time) ? 0 : time;
256 } 256 }
257 257
258 void AnimationTimeline::pauseAnimationsForTesting(double pauseTime) 258 void AnimationTimeline::pauseAnimationsForTesting(double pauseTime)
259 { 259 {
260 for (const auto& player : m_playersNeedingUpdate) 260 for (const auto& animation : m_animationsNeedingUpdate)
261 player->pauseForTesting(pauseTime); 261 animation->pauseForTesting(pauseTime);
262 serviceAnimations(TimingUpdateOnDemand); 262 serviceAnimations(TimingUpdateOnDemand);
263 } 263 }
264 264
265 bool AnimationTimeline::hasOutdatedAnimationPlayer() const 265 bool AnimationTimeline::hasOutdatedAnimation() const
266 { 266 {
267 for (const auto& player : m_playersNeedingUpdate) { 267 for (const auto& animation : m_animationsNeedingUpdate) {
268 if (player->outdated()) 268 if (animation->outdated())
269 return true; 269 return true;
270 } 270 }
271 return false; 271 return false;
272 } 272 }
273 273
274 bool AnimationTimeline::needsAnimationTimingUpdate() 274 bool AnimationTimeline::needsAnimationTimingUpdate()
275 { 275 {
276 return m_playersNeedingUpdate.size() && currentTimeInternal() != m_lastCurre ntTimeInternal; 276 return m_animationsNeedingUpdate.size() && currentTimeInternal() != m_lastCu rrentTimeInternal;
277 } 277 }
278 278
279 void AnimationTimeline::setOutdatedAnimationPlayer(AnimationPlayer* player) 279 void AnimationTimeline::setOutdatedAnimation(Animation* animation)
280 { 280 {
281 ASSERT(player->outdated()); 281 ASSERT(animation->outdated());
282 m_playersNeedingUpdate.add(player); 282 m_animationsNeedingUpdate.add(animation);
283 if (m_document && m_document->page() && !m_document->page()->animator().isSe rvicingAnimations()) 283 if (m_document && m_document->page() && !m_document->page()->animator().isSe rvicingAnimations())
284 m_timing->serviceOnNextFrame(); 284 m_timing->serviceOnNextFrame();
285 } 285 }
286 286
287 void AnimationTimeline::setPlaybackRate(double playbackRate) 287 void AnimationTimeline::setPlaybackRate(double playbackRate)
288 { 288 {
289 if (!document()) 289 if (!document())
290 return; 290 return;
291 double currentTime = currentTimeInternal(); 291 double currentTime = currentTimeInternal();
292 m_playbackRate = playbackRate; 292 m_playbackRate = playbackRate;
293 m_zeroTime = playbackRate == 0 293 m_zeroTime = playbackRate == 0
294 ? currentTime 294 ? currentTime
295 : document()->animationClock().currentTime() - currentTime / playbackRat e; 295 : document()->animationClock().currentTime() - currentTime / playbackRat e;
296 m_zeroTimeInitialized = true; 296 m_zeroTimeInitialized = true;
297 297
298 for (const auto& player : m_players) { 298 for (const auto& animation : m_animations) {
299 // Corresponding compositor animation may need to be restarted to pick u p 299 // Corresponding compositor animation may need to be restarted to pick u p
300 // the new playback rate. Marking the source changed forces this. 300 // the new playback rate. Marking the source changed forces this.
301 player->setCompositorPending(true); 301 animation->setCompositorPending(true);
302 } 302 }
303 } 303 }
304 304
305 double AnimationTimeline::playbackRate() const 305 double AnimationTimeline::playbackRate() const
306 { 306 {
307 return m_playbackRate; 307 return m_playbackRate;
308 } 308 }
309 309
310 #if !ENABLE(OILPAN) 310 #if !ENABLE(OILPAN)
311 void AnimationTimeline::detachFromDocument() 311 void AnimationTimeline::detachFromDocument()
312 { 312 {
313 // FIXME: AnimationTimeline should keep Document alive. 313 // FIXME: AnimationTimeline should keep Document alive.
314 m_document = nullptr; 314 m_document = nullptr;
315 } 315 }
316 #endif 316 #endif
317 317
318 DEFINE_TRACE(AnimationTimeline) 318 DEFINE_TRACE(AnimationTimeline)
319 { 319 {
320 #if ENABLE(OILPAN) 320 #if ENABLE(OILPAN)
321 visitor->trace(m_document); 321 visitor->trace(m_document);
322 visitor->trace(m_timing); 322 visitor->trace(m_timing);
323 visitor->trace(m_playersNeedingUpdate); 323 visitor->trace(m_animationsNeedingUpdate);
324 visitor->trace(m_players); 324 visitor->trace(m_animations);
325 #endif 325 #endif
326 } 326 }
327 327
328 } // namespace 328 } // namespace
OLDNEW
« no previous file with comments | « Source/core/animation/AnimationTimeline.h ('k') | Source/core/animation/AnimationTimeline.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698