OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 return; | 321 return; |
322 DCHECK(running->is_sequence_alive()); | 322 DCHECK(running->is_sequence_alive()); |
323 | 323 |
324 if (running->sequence()->animation_group_id() != event.group_id) | 324 if (running->sequence()->animation_group_id() != event.group_id) |
325 return; | 325 return; |
326 | 326 |
327 running->sequence()->OnThreadedAnimationStarted(event); | 327 running->sequence()->OnThreadedAnimationStarted(event); |
328 if (!running->sequence()->waiting_for_group_start()) | 328 if (!running->sequence()->waiting_for_group_start()) |
329 return; | 329 return; |
330 | 330 |
331 base::TimeTicks start_time = base::TimeTicks::FromInternalValue( | 331 gfx::FrameTime start_time = |
332 event.monotonic_time * base::Time::kMicrosecondsPerSecond); | 332 gfx::FrameTime::Unsafe_FromSecondsF(event.monotonic_time); |
333 | 333 |
334 running->sequence()->set_waiting_for_group_start(false); | 334 running->sequence()->set_waiting_for_group_start(false); |
335 | 335 |
336 // The call to GetRunningAnimation made above already purged deleted | 336 // The call to GetRunningAnimation made above already purged deleted |
337 // animations, so we are guaranteed that all the animations we iterate | 337 // animations, so we are guaranteed that all the animations we iterate |
338 // over now are alive. | 338 // over now are alive. |
339 for (RunningAnimations::iterator iter = running_animations_.begin(); | 339 for (RunningAnimations::iterator iter = running_animations_.begin(); |
340 iter != running_animations_.end(); ++iter) { | 340 iter != running_animations_.end(); ++iter) { |
341 // Ensure that each sequence is only Started once, regardless of the | 341 // Ensure that each sequence is only Started once, regardless of the |
342 // number of sequences in the group that have threaded first elements. | 342 // number of sequences in the group that have threaded first elements. |
343 if (((*iter).sequence()->animation_group_id() == event.group_id) && | 343 if (((*iter).sequence()->animation_group_id() == event.group_id) && |
344 !(*iter).sequence()->IsFirstElementThreaded() && | 344 !(*iter).sequence()->IsFirstElementThreaded() && |
345 (*iter).sequence()->waiting_for_group_start()) { | 345 (*iter).sequence()->waiting_for_group_start()) { |
346 (*iter).sequence()->set_start_time(start_time); | 346 (*iter).sequence()->set_start_time(start_time); |
347 (*iter).sequence()->set_waiting_for_group_start(false); | 347 (*iter).sequence()->set_waiting_for_group_start(false); |
348 (*iter).sequence()->Start(delegate()); | 348 (*iter).sequence()->Start(delegate()); |
349 } | 349 } |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 // LayerAnimator protected ----------------------------------------------------- | 353 // LayerAnimator protected ----------------------------------------------------- |
354 | 354 |
355 void LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, | 355 void LayerAnimator::ProgressAnimation(LayerAnimationSequence* sequence, |
356 base::TimeTicks now) { | 356 gfx::FrameTime now) { |
357 if (!delegate() || sequence->waiting_for_group_start()) | 357 if (!delegate() || sequence->waiting_for_group_start()) |
358 return; | 358 return; |
359 | 359 |
360 sequence->Progress(now, delegate()); | 360 sequence->Progress(now, delegate()); |
361 } | 361 } |
362 | 362 |
363 void LayerAnimator::ProgressAnimationToEnd(LayerAnimationSequence* sequence) { | 363 void LayerAnimator::ProgressAnimationToEnd(LayerAnimationSequence* sequence) { |
364 if (!delegate()) | 364 if (!delegate()) |
365 return; | 365 return; |
366 | 366 |
367 sequence->ProgressToEnd(delegate()); | 367 sequence->ProgressToEnd(delegate()); |
368 } | 368 } |
369 | 369 |
370 bool LayerAnimator::HasAnimation(LayerAnimationSequence* sequence) const { | 370 bool LayerAnimator::HasAnimation(LayerAnimationSequence* sequence) const { |
371 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); | 371 for (AnimationQueue::const_iterator queue_iter = animation_queue_.begin(); |
372 queue_iter != animation_queue_.end(); ++queue_iter) { | 372 queue_iter != animation_queue_.end(); ++queue_iter) { |
373 if ((*queue_iter).get() == sequence) | 373 if ((*queue_iter).get() == sequence) |
374 return true; | 374 return true; |
375 } | 375 } |
376 return false; | 376 return false; |
377 } | 377 } |
378 | 378 |
379 // LayerAnimator private ------------------------------------------------------- | 379 // LayerAnimator private ------------------------------------------------------- |
380 | 380 |
381 void LayerAnimator::Step(base::TimeTicks now) { | 381 void LayerAnimator::Step(gfx::FrameTime now) { |
382 TRACE_EVENT0("ui", "LayerAnimator::Step"); | 382 TRACE_EVENT0("ui", "LayerAnimator::Step"); |
383 scoped_refptr<LayerAnimator> retain(this); | 383 scoped_refptr<LayerAnimator> retain(this); |
384 | 384 |
385 last_step_time_ = now; | 385 last_step_time_ = now; |
386 | 386 |
387 PurgeDeletedAnimations(); | 387 PurgeDeletedAnimations(); |
388 | 388 |
389 // We need to make a copy of the running animations because progressing them | 389 // We need to make a copy of the running animations because progressing them |
390 // and finishing them may indirectly affect the collection of running | 390 // and finishing them may indirectly affect the collection of running |
391 // animations. | 391 // animations. |
392 RunningAnimations running_animations_copy = running_animations_; | 392 RunningAnimations running_animations_copy = running_animations_; |
393 for (size_t i = 0; i < running_animations_copy.size(); ++i) { | 393 for (size_t i = 0; i < running_animations_copy.size(); ++i) { |
394 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) | 394 if (!SAFE_INVOKE_BOOL(HasAnimation, running_animations_copy[i])) |
395 continue; | 395 continue; |
396 | 396 |
397 if (running_animations_copy[i].sequence()->IsFinished(now)) { | 397 if (running_animations_copy[i].sequence()->IsFinished(now)) { |
398 SAFE_INVOKE_VOID(FinishAnimation, running_animations_copy[i], false); | 398 SAFE_INVOKE_VOID(FinishAnimation, running_animations_copy[i], false); |
399 } else { | 399 } else { |
400 SAFE_INVOKE_VOID(ProgressAnimation, running_animations_copy[i], now); | 400 SAFE_INVOKE_VOID(ProgressAnimation, running_animations_copy[i], now); |
401 } | 401 } |
402 } | 402 } |
403 } | 403 } |
404 | 404 |
405 void LayerAnimator::SetStartTime(base::TimeTicks start_time) { | 405 void LayerAnimator::SetStartTime(gfx::FrameTime start_time) { |
406 // Do nothing. | 406 // Do nothing. |
407 } | 407 } |
408 | 408 |
409 base::TimeDelta LayerAnimator::GetTimerInterval() const { | 409 base::TimeDelta LayerAnimator::GetTimerInterval() const { |
410 return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); | 410 return base::TimeDelta::FromMilliseconds(kTimerIntervalMs); |
411 } | 411 } |
412 | 412 |
413 void LayerAnimator::StopAnimatingInternal(bool abort) { | 413 void LayerAnimator::StopAnimatingInternal(bool abort) { |
414 scoped_refptr<LayerAnimator> retain(this); | 414 scoped_refptr<LayerAnimator> retain(this); |
415 while (is_animating()) { | 415 while (is_animating()) { |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 return false; | 757 return false; |
758 } | 758 } |
759 | 759 |
760 // All clear, actually start the sequence. Note: base::TimeTicks::Now has | 760 // All clear, actually start the sequence. Note: base::TimeTicks::Now has |
761 // a resolution that can be as bad as 15ms. If this causes glitches in the | 761 // a resolution that can be as bad as 15ms. If this causes glitches in the |
762 // animations, this can be switched to HighResNow() (animation uses Now() | 762 // animations, this can be switched to HighResNow() (animation uses Now() |
763 // internally). | 763 // internally). |
764 // All LayerAnimators share the same AnimationContainer. Use the | 764 // All LayerAnimators share the same AnimationContainer. Use the |
765 // last_tick_time() from there to ensure animations started during the same | 765 // last_tick_time() from there to ensure animations started during the same |
766 // event complete at the same time. | 766 // event complete at the same time. |
767 base::TimeTicks start_time; | 767 gfx::FrameTime start_time; |
768 if (is_animating() || adding_animations_) | 768 if (is_animating() || adding_animations_) |
769 start_time = last_step_time_; | 769 start_time = last_step_time_; |
770 else if (GetAnimationContainer()->is_running()) | 770 else if (GetAnimationContainer()->is_running()) |
771 start_time = GetAnimationContainer()->last_tick_time(); | 771 start_time = GetAnimationContainer()->last_tick_time(); |
772 else | 772 else |
773 start_time = gfx::FrameTime::Now(); | 773 start_time = gfx::FrameTime::Now(); |
774 | 774 |
775 if (!sequence->animation_group_id()) | 775 if (!sequence->animation_group_id()) |
776 sequence->set_animation_group_id(cc::AnimationIdProvider::NextGroupId()); | 776 sequence->set_animation_group_id(cc::AnimationIdProvider::NextGroupId()); |
777 if (!sequence->waiting_for_group_start() || | 777 if (!sequence->waiting_for_group_start() || |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 } | 846 } |
847 | 847 |
848 LayerAnimator::RunningAnimation::RunningAnimation( | 848 LayerAnimator::RunningAnimation::RunningAnimation( |
849 const base::WeakPtr<LayerAnimationSequence>& sequence) | 849 const base::WeakPtr<LayerAnimationSequence>& sequence) |
850 : sequence_(sequence) { | 850 : sequence_(sequence) { |
851 } | 851 } |
852 | 852 |
853 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 853 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
854 | 854 |
855 } // namespace ui | 855 } // namespace ui |
OLD | NEW |