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

Side by Side Diff: ui/compositor/layer_animation_element.cc

Issue 26880010: gfx: Add FrameTime and DisplayTime classes (Closed) Base URL: http://git.chromium.org/chromium/src.git@checkHighResNow4
Patch Set: WIP Created 7 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 // 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_animation_element.h" 5 #include "ui/compositor/layer_animation_element.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "cc/animation/animation.h" 8 #include "cc/animation/animation.h"
9 #include "cc/animation/animation_id_provider.h" 9 #include "cc/animation/animation_id_provider.h"
10 #include "ui/compositor/float_animation_curve_adapter.h" 10 #include "ui/compositor/float_animation_curve_adapter.h"
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 407 }
408 } 408 }
409 409
410 virtual void RequestEffectiveStart( 410 virtual void RequestEffectiveStart(
411 LayerAnimationDelegate* delegate) OVERRIDE { 411 LayerAnimationDelegate* delegate) OVERRIDE {
412 DCHECK(animation_group_id()); 412 DCHECK(animation_group_id());
413 if (duration() == base::TimeDelta()) { 413 if (duration() == base::TimeDelta()) {
414 set_effective_start_time(requested_start_time()); 414 set_effective_start_time(requested_start_time());
415 return; 415 return;
416 } 416 }
417 set_effective_start_time(base::TimeTicks()); 417 set_effective_start_time(gfx::FrameTime());
418 scoped_ptr<cc::Animation> animation = CreateCCAnimation(); 418 scoped_ptr<cc::Animation> animation = CreateCCAnimation();
419 animation->set_needs_synchronized_start_time(true); 419 animation->set_needs_synchronized_start_time(true);
420 delegate->AddThreadedAnimation(animation.Pass()); 420 delegate->AddThreadedAnimation(animation.Pass());
421 } 421 }
422 422
423 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0; 423 virtual void OnEnd(LayerAnimationDelegate* delegate) = 0;
424 424
425 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0; 425 virtual scoped_ptr<cc::Animation> CreateCCAnimation() = 0;
426 426
427 private: 427 private:
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 animation_group_id_(element.animation_group_id_), 727 animation_group_id_(element.animation_group_id_),
728 last_progressed_fraction_(element.last_progressed_fraction_), 728 last_progressed_fraction_(element.last_progressed_fraction_),
729 weak_ptr_factory_(this) { 729 weak_ptr_factory_(this) {
730 } 730 }
731 731
732 LayerAnimationElement::~LayerAnimationElement() { 732 LayerAnimationElement::~LayerAnimationElement() {
733 } 733 }
734 734
735 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate, 735 void LayerAnimationElement::Start(LayerAnimationDelegate* delegate,
736 int animation_group_id) { 736 int animation_group_id) {
737 DCHECK(requested_start_time_ != base::TimeTicks()); 737 DCHECK(requested_start_time_ != gfx::FrameTime());
738 DCHECK(first_frame_); 738 DCHECK(first_frame_);
739 animation_group_id_ = animation_group_id; 739 animation_group_id_ = animation_group_id;
740 last_progressed_fraction_ = 0.0; 740 last_progressed_fraction_ = 0.0;
741 OnStart(delegate); 741 OnStart(delegate);
742 RequestEffectiveStart(delegate); 742 RequestEffectiveStart(delegate);
743 first_frame_ = false; 743 first_frame_ = false;
744 } 744 }
745 745
746 bool LayerAnimationElement::Progress(base::TimeTicks now, 746 bool LayerAnimationElement::Progress(gfx::FrameTime now,
747 LayerAnimationDelegate* delegate) { 747 LayerAnimationDelegate* delegate) {
748 DCHECK(requested_start_time_ != base::TimeTicks()); 748 DCHECK(requested_start_time_ != gfx::FrameTime());
749 DCHECK(!first_frame_); 749 DCHECK(!first_frame_);
750 750
751 bool need_draw; 751 bool need_draw;
752 double t = 1.0; 752 double t = 1.0;
753 753
754 if ((effective_start_time_ == base::TimeTicks()) || 754 if ((effective_start_time_ == gfx::FrameTime()) ||
755 (now < effective_start_time_)) { 755 (now < effective_start_time_)) {
756 // This hasn't actually started yet. 756 // This hasn't actually started yet.
757 need_draw = false; 757 need_draw = false;
758 last_progressed_fraction_ = 0.0; 758 last_progressed_fraction_ = 0.0;
759 return need_draw; 759 return need_draw;
760 } 760 }
761 761
762 base::TimeDelta elapsed = now - effective_start_time_; 762 base::TimeDelta elapsed = now - effective_start_time_;
763 if ((duration_ > base::TimeDelta()) && (elapsed < duration_)) 763 if ((duration_ > base::TimeDelta()) && (elapsed < duration_))
764 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF(); 764 t = elapsed.InMillisecondsF() / duration_.InMillisecondsF();
765 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr()); 765 base::WeakPtr<LayerAnimationElement> alive(weak_ptr_factory_.GetWeakPtr());
766 need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate); 766 need_draw = OnProgress(gfx::Tween::CalculateValue(tween_type_, t), delegate);
767 if (!alive) 767 if (!alive)
768 return need_draw; 768 return need_draw;
769 first_frame_ = t == 1.0; 769 first_frame_ = t == 1.0;
770 last_progressed_fraction_ = t; 770 last_progressed_fraction_ = t;
771 return need_draw; 771 return need_draw;
772 } 772 }
773 773
774 bool LayerAnimationElement::IsFinished(base::TimeTicks time, 774 bool LayerAnimationElement::IsFinished(gfx::FrameTime time,
775 base::TimeDelta* total_duration) { 775 base::TimeDelta* total_duration) {
776 // If an effective start has been requested but the effective start time 776 // If an effective start has been requested but the effective start time
777 // hasn't yet been set, the animation is not finished, regardless of the 777 // hasn't yet been set, the animation is not finished, regardless of the
778 // value of |time|. 778 // value of |time|.
779 if (!first_frame_ && (effective_start_time_ == base::TimeTicks())) 779 if (!first_frame_ && (effective_start_time_ == gfx::FrameTime()))
780 return false; 780 return false;
781 781
782 base::TimeDelta queueing_delay; 782 base::TimeDelta queueing_delay;
783 if (!first_frame_) 783 if (!first_frame_)
784 queueing_delay = effective_start_time_ - requested_start_time_; 784 queueing_delay = effective_start_time_ - requested_start_time_;
785 785
786 base::TimeDelta elapsed = time - requested_start_time_; 786 base::TimeDelta elapsed = time - requested_start_time_;
787 if (elapsed >= duration_ + queueing_delay) { 787 if (elapsed >= duration_ + queueing_delay) {
788 *total_duration = duration_ + queueing_delay; 788 *total_duration = duration_ + queueing_delay;
789 return true; 789 return true;
(...skipping 21 matching lines...) Expand all
811 return false; 811 return false;
812 } 812 }
813 813
814 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) { 814 void LayerAnimationElement::Abort(LayerAnimationDelegate* delegate) {
815 OnAbort(delegate); 815 OnAbort(delegate);
816 first_frame_ = true; 816 first_frame_ = true;
817 } 817 }
818 818
819 void LayerAnimationElement::RequestEffectiveStart( 819 void LayerAnimationElement::RequestEffectiveStart(
820 LayerAnimationDelegate* delegate) { 820 LayerAnimationDelegate* delegate) {
821 DCHECK(requested_start_time_ != base::TimeTicks()); 821 DCHECK(requested_start_time_ != gfx::FrameTime());
822 effective_start_time_ = requested_start_time_; 822 effective_start_time_ = requested_start_time_;
823 } 823 }
824 824
825 // static 825 // static
826 LayerAnimationElement::AnimatableProperty 826 LayerAnimationElement::AnimatableProperty
827 LayerAnimationElement::ToAnimatableProperty( 827 LayerAnimationElement::ToAnimatableProperty(
828 cc::Animation::TargetProperty property) { 828 cc::Animation::TargetProperty property) {
829 switch (property) { 829 switch (property) {
830 case cc::Animation::Transform: 830 case cc::Animation::Transform:
831 return TRANSFORM; 831 return TRANSFORM;
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 } 926 }
927 927
928 // static 928 // static
929 LayerAnimationElement* LayerAnimationElement::CreateColorElement( 929 LayerAnimationElement* LayerAnimationElement::CreateColorElement(
930 SkColor color, 930 SkColor color,
931 base::TimeDelta duration) { 931 base::TimeDelta duration) {
932 return new ColorTransition(color, duration); 932 return new ColorTransition(color, duration);
933 } 933 }
934 934
935 } // namespace ui 935 } // namespace ui
OLDNEW
« no previous file with comments | « ui/compositor/layer_animation_element.h ('k') | ui/compositor/layer_animation_element_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698