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