Chromium Code Reviews| Index: content/renderer/render_widget.cc |
| diff --git a/content/renderer/render_widget.cc b/content/renderer/render_widget.cc |
| index 98d6a4dd19488ec36b28747b2e5fb6bb12d118ad..c3cb6b664432d7df27eb307578a2434ef0388b7d 100644 |
| --- a/content/renderer/render_widget.cc |
| +++ b/content/renderer/render_widget.cc |
| @@ -30,6 +30,7 @@ |
| #include "ui/gfx/point.h" |
| #include "ui/gfx/size.h" |
| #include "ui/gfx/surface/transport_dib.h" |
| +#include "ui/gfx/gl/gl_switches.h" |
| #include "webkit/glue/webkit_glue.h" |
| #include "webkit/plugins/npapi/webplugin.h" |
| #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| @@ -585,7 +586,7 @@ void RenderWidget::AnimationCallback() { |
| animation_task_posted_ = false; |
| if (!animation_update_pending_) |
| return; |
| - if (!animation_floor_time_.is_null()) { |
| + if (!animation_floor_time_.is_null() && IsRenderingVSyncd()) { |
| // Record when we fired (according to base::Time::Now()) relative to when |
| // we posted the task to quantify how much the base::Time/base::TimeTicks |
| // skew is affecting animations. |
| @@ -603,37 +604,65 @@ void RenderWidget::AnimationCallback() { |
| void RenderWidget::AnimateIfNeeded() { |
| if (!animation_update_pending_) |
| return; |
| - base::Time now = base::Time::Now(); |
| - if (now >= animation_floor_time_) { |
| - animation_floor_time_ = now + base::TimeDelta::FromMilliseconds(16); |
| - // Set a timer to call us back after 16ms (targetting 60FPS) before |
| - // running animation callbacks so that if a callback requests another |
| - // we'll be sure to run it at the proper time. |
| - MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| - this, &RenderWidget::AnimationCallback), 16); |
| + if(IsRenderingVSyncd()) { |
| + base::Time now = base::Time::Now(); |
| + if (now >= animation_floor_time_) { |
| + animation_floor_time_ = now + base::TimeDelta::FromMilliseconds(16); |
| + // Set a timer to call us back after 16ms (targetting 60FPS) before |
| + // running animation callbacks so that if a callback requests another |
| + // we'll be sure to run it at the proper time. |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| + this, &RenderWidget::AnimationCallback), 16); |
|
jamesr
2011/05/26 02:20:15
would it be sufficient to leave this function unch
|
| + animation_task_posted_ = true; |
| + animation_update_pending_ = false; |
| + #ifdef WEBWIDGET_HAS_ANIMATE_CHANGES |
| + webwidget_->animate(0.0); |
| + #else |
| + webwidget_->animate(); |
| + #endif |
| + return; |
| + } |
| + TRACE_EVENT0("renderer", "EarlyOut_AnimatedInLast16ms"); |
| + if (animation_task_posted_) |
| + return; |
| + // This code uses base::Time::Now() to calculate the floor and next fire |
| + // time because javascript's Date object uses base::Time::Now(). The |
| + // message loop uses base::TimeTicks, which on windows can have a |
| + // different granularity than base::Time. |
| + // 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 base::Time::Now() has advanced far enough. |
| + int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); |
| animation_task_posted_ = true; |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| + NewRunnableMethod(this, &RenderWidget::AnimationCallback), delay); |
| + } else { |
| animation_update_pending_ = false; |
| #ifdef WEBWIDGET_HAS_ANIMATE_CHANGES |
| webwidget_->animate(0.0); |
| #else |
| webwidget_->animate(); |
| #endif |
| - return; |
| + // Set a delayed task to call us back "immediately" if more animation is |
| + // requested, using delayed tasks to keep scheduling consistent. If we have |
| + // hit the throttling threshold for swapbuffers, this task will be harmless. |
| + // so that we get equivalent scheduling to the non-vsync'd case. |
| + if(animation_update_pending_) { |
| + MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( |
| + this, &RenderWidget::AnimationCallback), 0); |
| + animation_task_posted_ = true; |
| + } |
| } |
| - if (animation_task_posted_) |
| - return; |
| - // This code uses base::Time::Now() to calculate the floor and next fire |
| - // time because javascript's Date object uses base::Time::Now(). The |
| - // message loop uses base::TimeTicks, which on windows can have a |
| - // different granularity than base::Time. |
| - // 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 base::Time::Now() has advanced far enough. |
| - int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); |
| - animation_task_posted_ = true; |
| - MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| - NewRunnableMethod(this, &RenderWidget::AnimationCallback), delay); |
| +} |
| + |
| +bool RenderWidget::IsRenderingVSyncd() { |
| + // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is |
| + // not caught by this check. This will lead to artificially low frame rates |
| + // for people who force vsync off at a driver level and expect Chrome to speed |
| + // up. |
| + return !CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableGpuVsync); |
| } |
| void RenderWidget::InvalidationCallback() { |