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" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "cc/layer_tree_host.h" | |
18 #include "cc/thread.h" | |
19 #include "cc/thread_impl.h" | |
20 #include "content/common/swapped_out_messages.h" | 17 #include "content/common/swapped_out_messages.h" |
21 #include "content/common/view_messages.h" | 18 #include "content/common/view_messages.h" |
22 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
23 #include "content/renderer/gpu/compositor_thread.h" | |
24 #include "content/renderer/render_process.h" | 20 #include "content/renderer/render_process.h" |
25 #include "content/renderer/render_thread_impl.h" | 21 #include "content/renderer/render_thread_impl.h" |
26 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 22 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
27 #include "ipc/ipc_sync_message.h" | 23 #include "ipc/ipc_sync_message.h" |
28 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" |
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" |
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 return false; | 236 return false; |
241 } | 237 } |
242 } | 238 } |
243 | 239 |
244 // This is used to complete pending inits and non-pending inits. | 240 // This is used to complete pending inits and non-pending inits. |
245 void RenderWidget::CompleteInit() { | 241 void RenderWidget::CompleteInit() { |
246 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 242 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
247 | 243 |
248 init_complete_ = true; | 244 init_complete_ = true; |
249 | 245 |
250 if (webwidget_ && is_threaded_compositing_enabled_) { | 246 if (webwidget_) { |
251 webwidget_->enterForceCompositingMode(true); | 247 webwidget_->setCompositorSurfaceReady(); |
252 } | 248 if (is_threaded_compositing_enabled_) |
253 if (web_layer_tree_view_) { | 249 webwidget_->enterForceCompositingMode(true); |
254 web_layer_tree_view_->setSurfaceReady(); | |
255 } | 250 } |
256 DoDeferredUpdate(); | 251 DoDeferredUpdate(); |
257 | 252 |
258 Send(new ViewHostMsg_RenderViewReady(routing_id_)); | 253 Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
259 } | 254 } |
260 | 255 |
261 void RenderWidget::SetSwappedOut(bool is_swapped_out) { | 256 void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
262 // We should only toggle between states. | 257 // We should only toggle between states. |
263 DCHECK(is_swapped_out_ != is_swapped_out); | 258 DCHECK(is_swapped_out_ != is_swapped_out); |
264 is_swapped_out_ = is_swapped_out; | 259 is_swapped_out_ = is_swapped_out; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 658 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
664 } | 659 } |
665 | 660 |
666 IPC::Message* response = | 661 IPC::Message* response = |
667 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, | 662 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, |
668 ack_result); | 663 ack_result); |
669 bool event_type_gets_rate_limited = | 664 bool event_type_gets_rate_limited = |
670 input_event->type == WebInputEvent::MouseMove || | 665 input_event->type == WebInputEvent::MouseMove || |
671 input_event->type == WebInputEvent::MouseWheel || | 666 input_event->type == WebInputEvent::MouseWheel || |
672 WebInputEvent::isTouchEventType(input_event->type); | 667 WebInputEvent::isTouchEventType(input_event->type); |
673 | |
674 bool frame_pending = paint_aggregator_.HasPendingUpdate(); | |
675 if (is_accelerated_compositing_active_) { | |
676 frame_pending = web_layer_tree_view_ && | |
677 web_layer_tree_view_->commitRequested(); | |
678 } | |
679 | |
680 bool is_input_throttled = | 668 bool is_input_throttled = |
681 throttle_input_events_ && | 669 throttle_input_events_ && |
682 frame_pending; | 670 ((webwidget_ ? webwidget_->isInputThrottled() : false) || |
| 671 paint_aggregator_.HasPendingUpdate()); |
683 | 672 |
684 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { | 673 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { |
685 // We want to rate limit the input events in this case, so we'll wait for | 674 // We want to rate limit the input events in this case, so we'll wait for |
686 // painting to finish before ACKing this message. | 675 // painting to finish before ACKing this message. |
687 if (pending_input_event_ack_.get()) { | 676 if (pending_input_event_ack_.get()) { |
688 // As two different kinds of events could cause us to postpone an ack | 677 // As two different kinds of events could cause us to postpone an ack |
689 // we send it now, if we have one pending. The Browser should never | 678 // we send it now, if we have one pending. The Browser should never |
690 // send us the same kind of event we are delaying the ack for. | 679 // send us the same kind of event we are delaying the ack for. |
691 Send(pending_input_event_ack_.release()); | 680 Send(pending_input_event_ack_.release()); |
692 } | 681 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { | 899 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { |
911 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") | 900 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
912 animation_floor_time_ = now + animationInterval; | 901 animation_floor_time_ = now + animationInterval; |
913 // Set a timer to call us back after animationInterval before | 902 // Set a timer to call us back after animationInterval before |
914 // running animation callbacks so that if a callback requests another | 903 // running animation callbacks so that if a callback requests another |
915 // we'll be sure to run it at the proper time. | 904 // we'll be sure to run it at the proper time. |
916 animation_timer_.Stop(); | 905 animation_timer_.Stop(); |
917 animation_timer_.Start(FROM_HERE, animationInterval, this, | 906 animation_timer_.Start(FROM_HERE, animationInterval, this, |
918 &RenderWidget::AnimationCallback); | 907 &RenderWidget::AnimationCallback); |
919 animation_update_pending_ = false; | 908 animation_update_pending_ = false; |
920 if (is_accelerated_compositing_active_ && web_layer_tree_view_) { | 909 webwidget_->animate(0.0); |
921 web_layer_tree_view_->layer_tree_host()->updateAnimations( | |
922 base::TimeTicks::Now()); | |
923 } else { | |
924 webwidget_->animate(0.0); | |
925 } | |
926 return; | 910 return; |
927 } | 911 } |
928 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); | 912 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); |
929 if (!animation_timer_.IsRunning()) { | 913 if (!animation_timer_.IsRunning()) { |
930 // This code uses base::Time::Now() to calculate the floor and next fire | 914 // This code uses base::Time::Now() to calculate the floor and next fire |
931 // time because javascript's Date object uses base::Time::Now(). The | 915 // time because javascript's Date object uses base::Time::Now(). The |
932 // message loop uses base::TimeTicks, which on windows can have a | 916 // message loop uses base::TimeTicks, which on windows can have a |
933 // different granularity than base::Time. | 917 // different granularity than base::Time. |
934 // The upshot of all this is that this function might be called before | 918 // The upshot of all this is that this function might be called before |
935 // base::Time::Now() has advanced past the animation_floor_time_. To | 919 // base::Time::Now() has advanced past the animation_floor_time_. To |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 using_asynchronous_swapbuffers_ = false; | 1286 using_asynchronous_swapbuffers_ = false; |
1303 | 1287 |
1304 // In single-threaded mode, we exit force compositing mode and re-enter in | 1288 // In single-threaded mode, we exit force compositing mode and re-enter in |
1305 // DoDeferredUpdate() if appropriate. In threaded compositing mode, | 1289 // DoDeferredUpdate() if appropriate. In threaded compositing mode, |
1306 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and | 1290 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and |
1307 // entering force compositing mode at the appropriate times. | 1291 // entering force compositing mode at the appropriate times. |
1308 if (!is_threaded_compositing_enabled_) | 1292 if (!is_threaded_compositing_enabled_) |
1309 webwidget_->enterForceCompositingMode(false); | 1293 webwidget_->enterForceCompositingMode(false); |
1310 } | 1294 } |
1311 | 1295 |
1312 void RenderWidget::initializeLayerTreeView( | |
1313 WebKit::WebLayerTreeViewClient* client, | |
1314 const WebKit::WebLayer& root_layer, | |
1315 const WebKit::WebLayerTreeView::Settings& settings) { | |
1316 DCHECK(!web_layer_tree_view_); | |
1317 web_layer_tree_view_.reset(new WebKit::WebLayerTreeViewImpl(client)); | |
1318 | |
1319 scoped_ptr<cc::Thread> impl_thread; | |
1320 CompositorThread* compositor_thread = | |
1321 RenderThreadImpl::current()->compositor_thread(); | |
1322 if (compositor_thread) | |
1323 impl_thread = cc::ThreadImpl::createForDifferentThread( | |
1324 compositor_thread->message_loop()->message_loop_proxy()); | |
1325 if (!web_layer_tree_view_->initialize(settings, impl_thread.Pass())) { | |
1326 web_layer_tree_view_.reset(); | |
1327 return; | |
1328 } | |
1329 web_layer_tree_view_->setRootLayer(root_layer); | |
1330 if (init_complete_) { | |
1331 web_layer_tree_view_->setSurfaceReady(); | |
1332 } | |
1333 } | |
1334 | |
1335 WebKit::WebLayerTreeView* RenderWidget::layerTreeView() { | |
1336 return web_layer_tree_view_.get(); | |
1337 } | |
1338 | |
1339 void RenderWidget::willBeginCompositorFrame() { | 1296 void RenderWidget::willBeginCompositorFrame() { |
1340 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); | 1297 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
1341 | 1298 |
1342 DCHECK(RenderThreadImpl::current()->compositor_thread()); | 1299 DCHECK(RenderThreadImpl::current()->compositor_thread()); |
1343 | 1300 |
1344 // The following two can result in further layout and possibly | 1301 // The following two can result in further layout and possibly |
1345 // enable GPU acceleration so they need to be called before any painting | 1302 // enable GPU acceleration so they need to be called before any painting |
1346 // is done. | 1303 // is done. |
1347 UpdateSelectionBounds(); | 1304 UpdateSelectionBounds(); |
1348 | 1305 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 // in Javascript. If we ask the RendwerWidgetHost to close now, the window | 1436 // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
1480 // could be closed before the JS finishes executing. So instead, post a | 1437 // could be closed before the JS finishes executing. So instead, post a |
1481 // message back to the message loop, which won't run until the JS is | 1438 // message back to the message loop, which won't run until the JS is |
1482 // complete, and then the Close message can be sent. | 1439 // complete, and then the Close message can be sent. |
1483 MessageLoop::current()->PostTask( | 1440 MessageLoop::current()->PostTask( |
1484 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); | 1441 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
1485 } | 1442 } |
1486 | 1443 |
1487 void RenderWidget::Close() { | 1444 void RenderWidget::Close() { |
1488 if (webwidget_) { | 1445 if (webwidget_) { |
1489 web_layer_tree_view_.reset(); | |
1490 webwidget_->close(); | 1446 webwidget_->close(); |
1491 webwidget_ = NULL; | 1447 webwidget_ = NULL; |
1492 } | 1448 } |
1493 } | 1449 } |
1494 | 1450 |
1495 WebRect RenderWidget::windowRect() { | 1451 WebRect RenderWidget::windowRect() { |
1496 if (pending_window_rect_count_) | 1452 if (pending_window_rect_count_) |
1497 return pending_window_rect_; | 1453 return pending_window_rect_; |
1498 | 1454 |
1499 return view_screen_rect_; | 1455 return view_screen_rect_; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); | 1650 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
1695 } | 1651 } |
1696 | 1652 |
1697 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { | 1653 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { |
1698 // During shutdown we can just ignore this message. | 1654 // During shutdown we can just ignore this message. |
1699 if (!webwidget_) | 1655 if (!webwidget_) |
1700 return; | 1656 return; |
1701 | 1657 |
1702 set_next_paint_is_repaint_ack(); | 1658 set_next_paint_is_repaint_ack(); |
1703 if (is_accelerated_compositing_active_) { | 1659 if (is_accelerated_compositing_active_) { |
1704 if (web_layer_tree_view_) | 1660 webwidget_->setNeedsRedraw(); |
1705 web_layer_tree_view_->setNeedsRedraw(); | |
1706 scheduleComposite(); | 1661 scheduleComposite(); |
1707 } else { | 1662 } else { |
1708 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); | 1663 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
1709 didInvalidateRect(repaint_rect); | 1664 didInvalidateRect(repaint_rect); |
1710 } | 1665 } |
1711 } | 1666 } |
1712 | 1667 |
1713 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) { | 1668 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) { |
1714 PendingSmoothScrollGestureMap::iterator it = | 1669 PendingSmoothScrollGestureMap::iterator it = |
1715 pending_smooth_scroll_gestures_.find(gesture_id); | 1670 pending_smooth_scroll_gestures_.find(gesture_id); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2029 i != plugin_window_moves_.end(); ++i) { | 1984 i != plugin_window_moves_.end(); ++i) { |
2030 if (i->window == window) { | 1985 if (i->window == window) { |
2031 plugin_window_moves_.erase(i); | 1986 plugin_window_moves_.erase(i); |
2032 break; | 1987 break; |
2033 } | 1988 } |
2034 } | 1989 } |
2035 } | 1990 } |
2036 | 1991 |
2037 void RenderWidget::GetRenderingStats( | 1992 void RenderWidget::GetRenderingStats( |
2038 WebKit::WebRenderingStatsImpl& stats) const { | 1993 WebKit::WebRenderingStatsImpl& stats) const { |
2039 if (web_layer_tree_view_) | 1994 webwidget()->renderingStats(stats); |
2040 web_layer_tree_view_->renderingStats(stats); | |
2041 | 1995 |
2042 stats.rendering_stats.numAnimationFrames += | 1996 stats.rendering_stats.numAnimationFrames += |
2043 software_stats_.numAnimationFrames; | 1997 software_stats_.numAnimationFrames; |
2044 stats.rendering_stats.numFramesSentToScreen += | 1998 stats.rendering_stats.numFramesSentToScreen += |
2045 software_stats_.numFramesSentToScreen; | 1999 software_stats_.numFramesSentToScreen; |
2046 stats.rendering_stats.totalPaintTimeInSeconds += | 2000 stats.rendering_stats.totalPaintTimeInSeconds += |
2047 software_stats_.totalPaintTimeInSeconds; | 2001 software_stats_.totalPaintTimeInSeconds; |
2048 stats.rendering_stats.totalPixelsPainted += | 2002 stats.rendering_stats.totalPixelsPainted += |
2049 software_stats_.totalPixelsPainted; | 2003 software_stats_.totalPixelsPainted; |
2050 stats.rendering_stats.totalRasterizeTimeInSeconds += | 2004 stats.rendering_stats.totalRasterizeTimeInSeconds += |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 | 2045 |
2092 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 2046 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
2093 return false; | 2047 return false; |
2094 } | 2048 } |
2095 | 2049 |
2096 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { | 2050 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
2097 return true; | 2051 return true; |
2098 } | 2052 } |
2099 | 2053 |
2100 } // namespace content | 2054 } // namespace content |
OLD | NEW |