| OLD | NEW |
| 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 "content/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 25); | 672 25); |
| 673 } | 673 } |
| 674 DoDeferredUpdateAndSendInputAck(); | 674 DoDeferredUpdateAndSendInputAck(); |
| 675 } | 675 } |
| 676 | 676 |
| 677 void RenderWidget::AnimateIfNeeded() { | 677 void RenderWidget::AnimateIfNeeded() { |
| 678 if (!animation_update_pending_) | 678 if (!animation_update_pending_) |
| 679 return; | 679 return; |
| 680 | 680 |
| 681 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off. | 681 // Target 60FPS if vsync is on. Go as fast as we can if vsync is off. |
| 682 int animationInterval = IsRenderingVSynced() ? 16 : 0; | 682 base::TimeDelta animationInterval = IsRenderingVSynced() ? |
| 683 base::TimeDelta::FromMilliseconds(16) : base::TimeDelta(); |
| 683 | 684 |
| 684 base::Time now = base::Time::Now(); | 685 base::Time now = base::Time::Now(); |
| 685 if (now >= animation_floor_time_ || is_accelerated_compositing_active_) { | 686 if (now >= animation_floor_time_ || is_accelerated_compositing_active_) { |
| 686 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") | 687 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
| 687 animation_floor_time_ = now + | 688 animation_floor_time_ = now + animationInterval; |
| 688 base::TimeDelta::FromMilliseconds(animationInterval); | |
| 689 // Set a timer to call us back after animationInterval before | 689 // Set a timer to call us back after animationInterval before |
| 690 // running animation callbacks so that if a callback requests another | 690 // running animation callbacks so that if a callback requests another |
| 691 // we'll be sure to run it at the proper time. | 691 // we'll be sure to run it at the proper time. |
| 692 MessageLoop::current()->PostDelayedTask( | 692 MessageLoop::current()->PostDelayedTask( |
| 693 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), | 693 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), |
| 694 animationInterval); | 694 animationInterval); |
| 695 animation_task_posted_ = true; | 695 animation_task_posted_ = true; |
| 696 animation_update_pending_ = false; | 696 animation_update_pending_ = false; |
| 697 webwidget_->animate(0.0); | 697 webwidget_->animate(0.0); |
| 698 return; | 698 return; |
| 699 } | 699 } |
| 700 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); | 700 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); |
| 701 if (animation_task_posted_) | 701 if (animation_task_posted_) |
| 702 return; | 702 return; |
| 703 // This code uses base::Time::Now() to calculate the floor and next fire | 703 // This code uses base::Time::Now() to calculate the floor and next fire |
| 704 // time because javascript's Date object uses base::Time::Now(). The | 704 // time because javascript's Date object uses base::Time::Now(). The |
| 705 // message loop uses base::TimeTicks, which on windows can have a | 705 // message loop uses base::TimeTicks, which on windows can have a |
| 706 // different granularity than base::Time. | 706 // different granularity than base::Time. |
| 707 // The upshot of all this is that this function might be called before | 707 // The upshot of all this is that this function might be called before |
| 708 // base::Time::Now() has advanced past the animation_floor_time_. To | 708 // base::Time::Now() has advanced past the animation_floor_time_. To |
| 709 // avoid exposing this delay to javascript, we keep posting delayed | 709 // avoid exposing this delay to javascript, we keep posting delayed |
| 710 // tasks until base::Time::Now() has advanced far enough. | 710 // tasks until base::Time::Now() has advanced far enough. |
| 711 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); | 711 base::TimeDelta delay = animation_floor_time_ - now; |
| 712 animation_task_posted_ = true; | 712 animation_task_posted_ = true; |
| 713 MessageLoop::current()->PostDelayedTask( | 713 MessageLoop::current()->PostDelayedTask( |
| 714 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay); | 714 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay); |
| 715 } | 715 } |
| 716 | 716 |
| 717 bool RenderWidget::IsRenderingVSynced() { | 717 bool RenderWidget::IsRenderingVSynced() { |
| 718 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is | 718 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is |
| 719 // not caught by this check. This will lead to artificially low frame rates | 719 // not caught by this check. This will lead to artificially low frame rates |
| 720 // for people who force vsync off at a driver level and expect Chrome to speed | 720 // for people who force vsync off at a driver level and expect Chrome to speed |
| 721 // up. | 721 // up. |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1564 } | 1564 } |
| 1565 } | 1565 } |
| 1566 | 1566 |
| 1567 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 1567 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| 1568 return false; | 1568 return false; |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 1571 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
| 1572 return false; | 1572 return false; |
| 1573 } | 1573 } |
| OLD | NEW |