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