OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
15 #include "content/common/swapped_out_messages.h" | 16 #include "content/common/swapped_out_messages.h" |
16 #include "content/common/view_messages.h" | 17 #include "content/common/view_messages.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 246 |
246 // Browser correspondence is no longer needed at this point. | 247 // Browser correspondence is no longer needed at this point. |
247 if (routing_id_ != MSG_ROUTING_NONE) { | 248 if (routing_id_ != MSG_ROUTING_NONE) { |
248 RenderThread::Get()->RemoveRoute(routing_id_); | 249 RenderThread::Get()->RemoveRoute(routing_id_); |
249 SetHidden(false); | 250 SetHidden(false); |
250 } | 251 } |
251 | 252 |
252 // If there is a Send call on the stack, then it could be dangerous to close | 253 // If there is a Send call on the stack, then it could be dangerous to close |
253 // now. Post a task that only gets invoked when there are no nested message | 254 // now. Post a task that only gets invoked when there are no nested message |
254 // loops. | 255 // loops. |
255 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | 256 MessageLoop::current()->PostNonNestableTask( |
256 NewRunnableMethod(this, &RenderWidget::Close)); | 257 FROM_HERE, base::Bind(&RenderWidget::Close, this)); |
257 | 258 |
258 // Balances the AddRef taken when we called AddRoute. | 259 // Balances the AddRef taken when we called AddRoute. |
259 Release(); | 260 Release(); |
260 } | 261 } |
261 | 262 |
262 void RenderWidget::OnResize(const gfx::Size& new_size, | 263 void RenderWidget::OnResize(const gfx::Size& new_size, |
263 const gfx::Rect& resizer_rect, | 264 const gfx::Rect& resizer_rect, |
264 bool is_fullscreen) { | 265 bool is_fullscreen) { |
265 // During shutdown we can just ignore this message. | 266 // During shutdown we can just ignore this message. |
266 if (!webwidget_) | 267 if (!webwidget_) |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 int animationInterval = IsRenderingVSynced() ? 16 : 0; | 654 int animationInterval = IsRenderingVSynced() ? 16 : 0; |
654 | 655 |
655 base::Time now = base::Time::Now(); | 656 base::Time now = base::Time::Now(); |
656 if (now >= animation_floor_time_) { | 657 if (now >= animation_floor_time_) { |
657 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") | 658 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
658 animation_floor_time_ = now + | 659 animation_floor_time_ = now + |
659 base::TimeDelta::FromMilliseconds(animationInterval); | 660 base::TimeDelta::FromMilliseconds(animationInterval); |
660 // Set a timer to call us back after animationInterval before | 661 // Set a timer to call us back after animationInterval before |
661 // running animation callbacks so that if a callback requests another | 662 // running animation callbacks so that if a callback requests another |
662 // we'll be sure to run it at the proper time. | 663 // we'll be sure to run it at the proper time. |
663 MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( | 664 MessageLoop::current()->PostDelayedTask( |
664 this, &RenderWidget::AnimationCallback), animationInterval); | 665 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), |
| 666 animationInterval); |
665 animation_task_posted_ = true; | 667 animation_task_posted_ = true; |
666 animation_update_pending_ = false; | 668 animation_update_pending_ = false; |
667 webwidget_->animate(0.0); | 669 webwidget_->animate(0.0); |
668 return; | 670 return; |
669 } | 671 } |
670 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); | 672 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); |
671 if (animation_task_posted_) | 673 if (animation_task_posted_) |
672 return; | 674 return; |
673 // This code uses base::Time::Now() to calculate the floor and next fire | 675 // This code uses base::Time::Now() to calculate the floor and next fire |
674 // time because javascript's Date object uses base::Time::Now(). The | 676 // time because javascript's Date object uses base::Time::Now(). The |
675 // message loop uses base::TimeTicks, which on windows can have a | 677 // message loop uses base::TimeTicks, which on windows can have a |
676 // different granularity than base::Time. | 678 // different granularity than base::Time. |
677 // The upshot of all this is that this function might be called before | 679 // The upshot of all this is that this function might be called before |
678 // base::Time::Now() has advanced past the animation_floor_time_. To | 680 // base::Time::Now() has advanced past the animation_floor_time_. To |
679 // avoid exposing this delay to javascript, we keep posting delayed | 681 // avoid exposing this delay to javascript, we keep posting delayed |
680 // tasks until base::Time::Now() has advanced far enough. | 682 // tasks until base::Time::Now() has advanced far enough. |
681 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); | 683 int64 delay = (animation_floor_time_ - now).InMillisecondsRoundedUp(); |
682 animation_task_posted_ = true; | 684 animation_task_posted_ = true; |
683 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 685 MessageLoop::current()->PostDelayedTask( |
684 NewRunnableMethod(this, &RenderWidget::AnimationCallback), delay); | 686 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this), delay); |
685 } | 687 } |
686 | 688 |
687 bool RenderWidget::IsRenderingVSynced() { | 689 bool RenderWidget::IsRenderingVSynced() { |
688 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is | 690 // TODO(nduca): Forcing a driver to disable vsync (e.g. in a control panel) is |
689 // not caught by this check. This will lead to artificially low frame rates | 691 // not caught by this check. This will lead to artificially low frame rates |
690 // for people who force vsync off at a driver level and expect Chrome to speed | 692 // for people who force vsync off at a driver level and expect Chrome to speed |
691 // up. | 693 // up. |
692 return !has_disable_gpu_vsync_switch_; | 694 return !has_disable_gpu_vsync_switch_; |
693 } | 695 } |
694 | 696 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 // a single update. | 893 // a single update. |
892 if (is_accelerated_compositing_active_ && animation_task_posted_) | 894 if (is_accelerated_compositing_active_ && animation_task_posted_) |
893 return; | 895 return; |
894 | 896 |
895 // Perform updating asynchronously. This serves two purposes: | 897 // Perform updating asynchronously. This serves two purposes: |
896 // 1) Ensures that we call WebView::Paint without a bunch of other junk | 898 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
897 // on the call stack. | 899 // on the call stack. |
898 // 2) Allows us to collect more damage rects before painting to help coalesce | 900 // 2) Allows us to collect more damage rects before painting to help coalesce |
899 // the work that we will need to do. | 901 // the work that we will need to do. |
900 invalidation_task_posted_ = true; | 902 invalidation_task_posted_ = true; |
901 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 903 MessageLoop::current()->PostTask( |
902 this, &RenderWidget::InvalidationCallback)); | 904 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
903 } | 905 } |
904 | 906 |
905 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { | 907 void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { |
906 // Drop scrolls on the floor when we are in compositing mode. | 908 // Drop scrolls on the floor when we are in compositing mode. |
907 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. | 909 // TODO(nduca): stop WebViewImpl from sending scrolls in the first place. |
908 if (is_accelerated_compositing_active_) | 910 if (is_accelerated_compositing_active_) |
909 return; | 911 return; |
910 | 912 |
911 // The scrolled rect might be outside the bounds of the view. | 913 // The scrolled rect might be outside the bounds of the view. |
912 gfx::Rect view_rect(size_); | 914 gfx::Rect view_rect(size_); |
(...skipping 16 matching lines...) Expand all Loading... |
929 // a single update. | 931 // a single update. |
930 if (is_accelerated_compositing_active_ && animation_task_posted_) | 932 if (is_accelerated_compositing_active_ && animation_task_posted_) |
931 return; | 933 return; |
932 | 934 |
933 // Perform updating asynchronously. This serves two purposes: | 935 // Perform updating asynchronously. This serves two purposes: |
934 // 1) Ensures that we call WebView::Paint without a bunch of other junk | 936 // 1) Ensures that we call WebView::Paint without a bunch of other junk |
935 // on the call stack. | 937 // on the call stack. |
936 // 2) Allows us to collect more damage rects before painting to help coalesce | 938 // 2) Allows us to collect more damage rects before painting to help coalesce |
937 // the work that we will need to do. | 939 // the work that we will need to do. |
938 invalidation_task_posted_ = true; | 940 invalidation_task_posted_ = true; |
939 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 941 MessageLoop::current()->PostTask( |
940 this, &RenderWidget::InvalidationCallback)); | 942 FROM_HERE, base::Bind(&RenderWidget::InvalidationCallback, this)); |
941 } | 943 } |
942 | 944 |
943 void RenderWidget::didActivateCompositor(int compositor_identifier) { | 945 void RenderWidget::didActivateCompositor(int compositor_identifier) { |
944 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); | 946 TRACE_EVENT0("gpu", "RenderWidget::didActivateCompositor"); |
945 | 947 |
946 CompositorThread* compositor_thread = | 948 CompositorThread* compositor_thread = |
947 RenderThreadImpl::current()->compositor_thread(); | 949 RenderThreadImpl::current()->compositor_thread(); |
948 if (compositor_thread) | 950 if (compositor_thread) |
949 compositor_thread->AddCompositor(routing_id_, compositor_identifier); | 951 compositor_thread->AddCompositor(routing_id_, compositor_identifier); |
950 | 952 |
(...skipping 30 matching lines...) Expand all Loading... |
981 didInvalidateRect(WebRect(0, 0, 1, 1)); | 983 didInvalidateRect(WebRect(0, 0, 1, 1)); |
982 } | 984 } |
983 } | 985 } |
984 | 986 |
985 void RenderWidget::scheduleAnimation() { | 987 void RenderWidget::scheduleAnimation() { |
986 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation"); | 988 TRACE_EVENT0("gpu", "RenderWidget::scheduleAnimation"); |
987 if (!animation_update_pending_) { | 989 if (!animation_update_pending_) { |
988 animation_update_pending_ = true; | 990 animation_update_pending_ = true; |
989 if (!animation_task_posted_) { | 991 if (!animation_task_posted_) { |
990 animation_task_posted_ = true; | 992 animation_task_posted_ = true; |
991 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 993 MessageLoop::current()->PostTask( |
992 this, &RenderWidget::AnimationCallback)); | 994 FROM_HERE, base::Bind(&RenderWidget::AnimationCallback, this)); |
993 } | 995 } |
994 } | 996 } |
995 } | 997 } |
996 | 998 |
997 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 999 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
998 // TODO(darin): Eliminate this temporary. | 1000 // TODO(darin): Eliminate this temporary. |
999 WebCursor cursor(cursor_info); | 1001 WebCursor cursor(cursor_info); |
1000 | 1002 |
1001 // Only send a SetCursor message if we need to make a change. | 1003 // Only send a SetCursor message if we need to make a change. |
1002 if (!current_cursor_.IsEqual(cursor)) { | 1004 if (!current_cursor_.IsEqual(cursor)) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 | 1042 |
1041 void RenderWidget::closeWidgetSoon() { | 1043 void RenderWidget::closeWidgetSoon() { |
1042 // If a page calls window.close() twice, we'll end up here twice, but that's | 1044 // If a page calls window.close() twice, we'll end up here twice, but that's |
1043 // OK. It is safe to send multiple Close messages. | 1045 // OK. It is safe to send multiple Close messages. |
1044 | 1046 |
1045 // Ask the RenderWidgetHost to initiate close. We could be called from deep | 1047 // Ask the RenderWidgetHost to initiate close. We could be called from deep |
1046 // in Javascript. If we ask the RendwerWidgetHost to close now, the window | 1048 // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
1047 // could be closed before the JS finishes executing. So instead, post a | 1049 // could be closed before the JS finishes executing. So instead, post a |
1048 // message back to the message loop, which won't run until the JS is | 1050 // message back to the message loop, which won't run until the JS is |
1049 // complete, and then the Close message can be sent. | 1051 // complete, and then the Close message can be sent. |
1050 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 1052 MessageLoop::current()->PostTask( |
1051 this, &RenderWidget::DoDeferredClose)); | 1053 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
1052 } | 1054 } |
1053 | 1055 |
1054 void RenderWidget::Close() { | 1056 void RenderWidget::Close() { |
1055 if (webwidget_) { | 1057 if (webwidget_) { |
1056 webwidget_->close(); | 1058 webwidget_->close(); |
1057 webwidget_ = NULL; | 1059 webwidget_ = NULL; |
1058 } | 1060 } |
1059 } | 1061 } |
1060 | 1062 |
1061 WebRect RenderWidget::windowRect() { | 1063 WebRect RenderWidget::windowRect() { |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1475 } | 1477 } |
1476 } | 1478 } |
1477 | 1479 |
1478 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { | 1480 bool RenderWidget::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
1479 return false; | 1481 return false; |
1480 } | 1482 } |
1481 | 1483 |
1482 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 1484 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
1483 return false; | 1485 return false; |
1484 } | 1486 } |
OLD | NEW |