diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-03 03:51:39 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-03 03:51:39 +0000 |
commit | d2544cd5b4360b61eca1da74e71a5a1fc0925ef2 (patch) | |
tree | ec38d88ed6b80e5b82664ad1b599ba48a031d386 | |
parent | 1c5fe5c35c2c6b49ca8af0434eb9447747968f7d (diff) | |
download | chromium_src-d2544cd5b4360b61eca1da74e71a5a1fc0925ef2.zip chromium_src-d2544cd5b4360b61eca1da74e71a5a1fc0925ef2.tar.gz chromium_src-d2544cd5b4360b61eca1da74e71a5a1fc0925ef2.tar.bz2 |
Animations: animate to current time, rather than a set number of frames.
This will cut down on the number of total frames shown for slow animations; should have no effect on fast animations.
This makes the following animations much snappier (as seen on Linux):
- download shelf opening
- bookmark bar opening at large browser width
- new tab animation
BUG=all animation jank bugs
TEST=if you put a Sleep(1000) in an AnimationProgressed callback, you will actually get called back fewer times.
TEST=looked at all the animations I could think of to make sure they still work right.
Review URL: http://codereview.chromium.org/257038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27935 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | app/animation.cc | 36 | ||||
-rw-r--r-- | app/animation.h | 13 |
2 files changed, 22 insertions, 27 deletions
diff --git a/app/animation.cc b/app/animation.cc index 1ef905d..94c99c2 100644 --- a/app/animation.cc +++ b/app/animation.cc @@ -10,6 +10,7 @@ #include "base/win_util.h" #endif +using base::Time; using base::TimeDelta; Animation::Animation(int frame_rate, @@ -17,9 +18,6 @@ Animation::Animation(int frame_rate, : animating_(false), frame_rate_(frame_rate), timer_interval_(CalculateInterval(frame_rate)), - duration_(0), - iteration_count_(0), - current_iteration_(0), state_(0.0), delegate_(delegate) { } @@ -30,9 +28,7 @@ Animation::Animation(int duration, : animating_(false), frame_rate_(frame_rate), timer_interval_(CalculateInterval(frame_rate)), - duration_(0), - iteration_count_(0), - current_iteration_(0), + duration_(TimeDelta::FromMilliseconds(duration)), state_(0.0), delegate_(delegate) { @@ -43,7 +39,7 @@ Animation::~Animation() { } void Animation::Reset() { - current_iteration_ = 0; + start_time_ = Time::Now(); } double Animation::GetCurrentValue() const { @@ -53,8 +49,8 @@ double Animation::GetCurrentValue() const { void Animation::Start() { if (!animating_) { - timer_.Start(TimeDelta::FromMilliseconds(timer_interval_), this, - &Animation::Run); + start_time_ = Time::Now(); + timer_.Start(timer_interval_, this, &Animation::Run); animating_ = true; if (delegate_) @@ -92,18 +88,16 @@ bool Animation::IsAnimating() const { } void Animation::SetDuration(int duration) { - duration_ = duration; + duration_ = TimeDelta::FromMilliseconds(duration); if (duration_ < timer_interval_) duration_ = timer_interval_; - iteration_count_ = duration_ / timer_interval_; - - // Changing the number of iterations forces us to reset the - // animation to the first iteration. - current_iteration_ = 0; + start_time_ = Time::Now(); } void Animation::Step() { - state_ = static_cast<double>(++current_iteration_) / iteration_count_; + TimeDelta elapsed_time = Time::Now() - start_time_; + state_ = static_cast<double>(elapsed_time.InMicroseconds()) / + static_cast<double>(duration_.InMicroseconds()); if (state_ >= 1.0) state_ = 1.0; @@ -120,11 +114,11 @@ void Animation::Run() { Step(); } -int Animation::CalculateInterval(int frame_rate) { - int timer_interval = 1000 / frame_rate; - if (timer_interval < 10) - timer_interval = 10; - return timer_interval; +TimeDelta Animation::CalculateInterval(int frame_rate) { + int timer_interval = 1000000 / frame_rate; + if (timer_interval < 10000) + timer_interval = 10000; + return TimeDelta::FromMicroseconds(timer_interval); } // static diff --git a/app/animation.h b/app/animation.h index 811c038..e6877b6 100644 --- a/app/animation.h +++ b/app/animation.h @@ -6,6 +6,7 @@ #ifndef APP_ANIMATION_H_ #define APP_ANIMATION_H_ +#include "base/time.h" #include "base/timer.h" class Animation; @@ -99,20 +100,20 @@ class Animation { virtual void Step(); // Calculates the timer interval from the constructor list. - int CalculateInterval(int frame_rate); + base::TimeDelta CalculateInterval(int frame_rate); // Whether or not we are currently animating. bool animating_; int frame_rate_; - int timer_interval_; - int duration_; + base::TimeDelta timer_interval_; + base::TimeDelta duration_; - // For determining state. - int iteration_count_; - int current_iteration_; + // Current state, on a scale from 0.0 to 1.0. double state_; + base::Time start_time_; + AnimationDelegate* delegate_; base::RepeatingTimer<Animation> timer_; |