summaryrefslogtreecommitdiffstats
path: root/app/animation.cc
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-03 03:51:39 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-03 03:51:39 +0000
commitd2544cd5b4360b61eca1da74e71a5a1fc0925ef2 (patch)
treeec38d88ed6b80e5b82664ad1b599ba48a031d386 /app/animation.cc
parent1c5fe5c35c2c6b49ca8af0434eb9447747968f7d (diff)
downloadchromium_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
Diffstat (limited to 'app/animation.cc')
-rw-r--r--app/animation.cc36
1 files changed, 15 insertions, 21 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