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

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

Issue 1417613005: Revert of Web Animations: Use a single animation clock (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline()); 82 m_compositorTimeline = adoptPtr(Platform::current()->compositorSupport() ->createAnimationTimeline());
83 } 83 }
84 84
85 ASSERT(document); 85 ASSERT(document);
86 } 86 }
87 87
88 AnimationTimeline::~AnimationTimeline() 88 AnimationTimeline::~AnimationTimeline()
89 { 89 {
90 } 90 }
91 91
92 bool AnimationTimeline::isActive()
93 {
94 return m_document && m_document->page();
95 }
96
97 void AnimationTimeline::animationAttached(Animation& animation) 92 void AnimationTimeline::animationAttached(Animation& animation)
98 { 93 {
99 ASSERT(animation.timeline() == this); 94 ASSERT(animation.timeline() == this);
100 ASSERT(!m_animations.contains(&animation)); 95 ASSERT(!m_animations.contains(&animation));
101 m_animations.add(&animation); 96 m_animations.add(&animation);
102 } 97 }
103 98
104 Animation* AnimationTimeline::play(AnimationEffect* child) 99 Animation* AnimationTimeline::play(AnimationEffect* child)
105 { 100 {
106 if (!m_document) 101 if (!m_document)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 animations.append(animation); 138 animations.append(animation);
144 139
145 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority) ; 140 std::sort(animations.begin(), animations.end(), Animation::hasLowerPriority) ;
146 141
147 for (Animation* animation : animations) { 142 for (Animation* animation : animations) {
148 if (!animation->update(reason)) 143 if (!animation->update(reason))
149 m_animationsNeedingUpdate.remove(animation); 144 m_animationsNeedingUpdate.remove(animation);
150 } 145 }
151 146
152 ASSERT(m_outdatedAnimationCount == 0); 147 ASSERT(m_outdatedAnimationCount == 0);
153 ASSERT(m_lastCurrentTimeInternal == currentTimeInternal() || (std::isnan(cur rentTimeInternal()) && std::isnan(m_lastCurrentTimeInternal))); 148 ASSERT(m_lastCurrentTimeInternal == currentTimeInternal());
154 149
155 #if ENABLE(ASSERT) 150 #if ENABLE(ASSERT)
156 for (const auto& animation : m_animationsNeedingUpdate) 151 for (const auto& animation : m_animationsNeedingUpdate)
157 ASSERT(!animation->outdated()); 152 ASSERT(!animation->outdated());
158 #endif 153 #endif
159 } 154 }
160 155
161 void AnimationTimeline::scheduleNextService() 156 void AnimationTimeline::scheduleNextService()
162 { 157 {
163 ASSERT(m_outdatedAnimationCount == 0); 158 ASSERT(m_outdatedAnimationCount == 0);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 return m_zeroTime; 202 return m_zeroTime;
208 } 203 }
209 204
210 double AnimationTimeline::currentTime(bool& isNull) 205 double AnimationTimeline::currentTime(bool& isNull)
211 { 206 {
212 return currentTimeInternal(isNull) * 1000; 207 return currentTimeInternal(isNull) * 1000;
213 } 208 }
214 209
215 double AnimationTimeline::currentTimeInternal(bool& isNull) 210 double AnimationTimeline::currentTimeInternal(bool& isNull)
216 { 211 {
217 if (!isActive()) { 212 if (!m_document) {
218 isNull = true; 213 isNull = true;
219 return std::numeric_limits<double>::quiet_NaN(); 214 return std::numeric_limits<double>::quiet_NaN();
220 } 215 }
221 double result = m_playbackRate == 0 216 double result = m_playbackRate == 0
222 ? zeroTime() 217 ? zeroTime()
223 : (document()->animationClock().currentTime() - zeroTime()) * m_playback Rate; 218 : (document()->animationClock().currentTime() - zeroTime()) * m_playback Rate;
224 isNull = std::isnan(result); 219 isNull = std::isnan(result);
225 return result; 220 return result;
226 } 221 }
227 222
228 double AnimationTimeline::currentTime() 223 double AnimationTimeline::currentTime()
229 { 224 {
230 return currentTimeInternal() * 1000; 225 return currentTimeInternal() * 1000;
231 } 226 }
232 227
233 double AnimationTimeline::currentTimeInternal() 228 double AnimationTimeline::currentTimeInternal()
234 { 229 {
235 bool isNull; 230 bool isNull;
236 return currentTimeInternal(isNull); 231 return currentTimeInternal(isNull);
237 } 232 }
238 233
239 void AnimationTimeline::setCurrentTime(double currentTime) 234 void AnimationTimeline::setCurrentTime(double currentTime)
240 { 235 {
241 setCurrentTimeInternal(currentTime / 1000); 236 setCurrentTimeInternal(currentTime / 1000);
242 } 237 }
243 238
244 void AnimationTimeline::setCurrentTimeInternal(double currentTime) 239 void AnimationTimeline::setCurrentTimeInternal(double currentTime)
245 { 240 {
246 if (!isActive()) 241 if (!document())
247 return; 242 return;
248 m_zeroTime = m_playbackRate == 0 243 m_zeroTime = m_playbackRate == 0
249 ? currentTime 244 ? currentTime
250 : document()->animationClock().currentTime() - currentTime / m_playbackR ate; 245 : document()->animationClock().currentTime() - currentTime / m_playbackR ate;
251 m_zeroTimeInitialized = true; 246 m_zeroTimeInitialized = true;
252 247
253 for (const auto& animation : m_animations) { 248 for (const auto& animation : m_animations) {
254 // The Player needs a timing update to pick up a new time. 249 // The Player needs a timing update to pick up a new time.
255 animation->setOutdated(); 250 animation->setOutdated();
256 } 251 }
(...skipping 14 matching lines...) Expand all
271 for (const auto& animation : m_animationsNeedingUpdate) 266 for (const auto& animation : m_animationsNeedingUpdate)
272 animation->pauseForTesting(pauseTime); 267 animation->pauseForTesting(pauseTime);
273 serviceAnimations(TimingUpdateOnDemand); 268 serviceAnimations(TimingUpdateOnDemand);
274 } 269 }
275 270
276 bool AnimationTimeline::needsAnimationTimingUpdate() 271 bool AnimationTimeline::needsAnimationTimingUpdate()
277 { 272 {
278 if (currentTimeInternal() == m_lastCurrentTimeInternal) 273 if (currentTimeInternal() == m_lastCurrentTimeInternal)
279 return false; 274 return false;
280 275
281 if (std::isnan(currentTimeInternal()) && std::isnan(m_lastCurrentTimeInterna l))
282 return false;
283
284 // We allow m_lastCurrentTimeInternal to advance here when there 276 // We allow m_lastCurrentTimeInternal to advance here when there
285 // are no animations to allow animations spawned during style 277 // are no animations to allow animations spawned during style
286 // recalc to not invalidate this flag. 278 // recalc to not invalidate this flag.
287 if (m_animationsNeedingUpdate.isEmpty()) 279 if (m_animationsNeedingUpdate.isEmpty())
288 m_lastCurrentTimeInternal = currentTimeInternal(); 280 m_lastCurrentTimeInternal = currentTimeInternal();
289 281
290 return !m_animationsNeedingUpdate.isEmpty(); 282 return !m_animationsNeedingUpdate.isEmpty();
291 } 283 }
292 284
293 void AnimationTimeline::clearOutdatedAnimation(Animation* animation) 285 void AnimationTimeline::clearOutdatedAnimation(Animation* animation)
294 { 286 {
295 ASSERT(!animation->outdated()); 287 ASSERT(!animation->outdated());
296 m_outdatedAnimationCount--; 288 m_outdatedAnimationCount--;
297 } 289 }
298 290
299 void AnimationTimeline::setOutdatedAnimation(Animation* animation) 291 void AnimationTimeline::setOutdatedAnimation(Animation* animation)
300 { 292 {
301 ASSERT(animation->outdated()); 293 ASSERT(animation->outdated());
302 m_outdatedAnimationCount++; 294 m_outdatedAnimationCount++;
303 m_animationsNeedingUpdate.add(animation); 295 m_animationsNeedingUpdate.add(animation);
304 if (isActive() && !m_document->page()->animator().isServicingAnimations()) 296 if (m_document && m_document->page() && !m_document->page()->animator().isSe rvicingAnimations())
305 m_timing->serviceOnNextFrame(); 297 m_timing->serviceOnNextFrame();
306 } 298 }
307 299
308 void AnimationTimeline::setPlaybackRate(double playbackRate) 300 void AnimationTimeline::setPlaybackRate(double playbackRate)
309 { 301 {
310 if (!isActive()) 302 if (!document())
311 return; 303 return;
312 double currentTime = currentTimeInternal(); 304 double currentTime = currentTimeInternal();
313 m_playbackRate = playbackRate; 305 m_playbackRate = playbackRate;
314 m_zeroTime = playbackRate == 0 306 m_zeroTime = playbackRate == 0
315 ? currentTime 307 ? currentTime
316 : document()->animationClock().currentTime() - currentTime / playbackRat e; 308 : document()->animationClock().currentTime() - currentTime / playbackRat e;
317 m_zeroTimeInitialized = true; 309 m_zeroTimeInitialized = true;
318 310
319 // Corresponding compositor animation may need to be restarted to pick up 311 // Corresponding compositor animation may need to be restarted to pick up
320 // the new playback rate. Marking the effect changed forces this. 312 // the new playback rate. Marking the effect changed forces this.
(...skipping 22 matching lines...) Expand all
343 335
344 DEFINE_TRACE(AnimationTimeline) 336 DEFINE_TRACE(AnimationTimeline)
345 { 337 {
346 visitor->trace(m_document); 338 visitor->trace(m_document);
347 visitor->trace(m_timing); 339 visitor->trace(m_timing);
348 visitor->trace(m_animationsNeedingUpdate); 340 visitor->trace(m_animationsNeedingUpdate);
349 visitor->trace(m_animations); 341 visitor->trace(m_animations);
350 } 342 }
351 343
352 } // namespace 344 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698