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

Unified Diff: chrome/renderer/render_widget.cc

Issue 6409007: Calculate animation_floor_time_ only when actually updating animations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rely only on timer to avoid multiple callbacks per paint Created 9 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/render_widget.cc
diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc
index 5f66e49987ccf8a3709caac736a76c0726d45cad..21b4395763afbf429171e40bae576f20446169e0 100644
--- a/chrome/renderer/render_widget.cc
+++ b/chrome/renderer/render_widget.cc
@@ -488,10 +488,13 @@ void RenderWidget::CallDoDeferredUpdate() {
}
void RenderWidget::UpdateAnimationsIfNeeded() {
+ static const int64 kMinimumAnimationDelay = 16; // Target 60 FPS.
if (!is_hidden() && animation_update_pending_) {
base::Time now = base::Time::Now();
if (now >= animation_floor_time_) {
animation_update_pending_ = false;
+ animation_floor_time_ = base::Time::Now() +
+ base::TimeDelta::FromMilliseconds(kMinimumAnimationDelay);
webwidget_->animate();
} else {
// This code uses base::Time::Now() to calculate the floor and next fire
@@ -501,8 +504,10 @@ void RenderWidget::UpdateAnimationsIfNeeded() {
// The upshot of all this is that this function might be called before
// base::Time::Now() has advanced past the animation_floor_time_. To
// avoid exposing this delay to javascript, we keep posting delayed
- // tasks until we observe base::Time::Now() advancing far enough.
- int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp();
+ // tasks until base::Time::Now() has advanced far enough.
+ int64 delay = std::min(
+ (animation_floor_time_ - now).InMillisecondsRoundedUp(),
+ kMinimumAnimationDelay);
MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
this, &RenderWidget::UpdateAnimationsIfNeeded), delay);
}
@@ -520,9 +525,6 @@ void RenderWidget::DoDeferredUpdate() {
return;
}
- if (base::Time::Now() > animation_floor_time_)
- UpdateAnimationsIfNeeded();
darin (slow to review) 2011/01/31 19:01:09 it seems like you should still consider calling We
-
// Layout may generate more invalidation. It may also enable the
// GPU acceleration, so make sure to run layout before we send the
// GpuRenderingActivated message.
@@ -717,10 +719,8 @@ void RenderWidget::scheduleComposite() {
void RenderWidget::scheduleAnimation() {
if (!animation_update_pending_) {
animation_update_pending_ = true;
- animation_floor_time_ =
- base::Time::Now() + base::TimeDelta::FromMilliseconds(10);
- MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod(
- this, &RenderWidget::UpdateAnimationsIfNeeded), 10);
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &RenderWidget::UpdateAnimationsIfNeeded));
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698