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