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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
194 return false; | 198 return false; |
195 } | 199 } |
196 } | 200 } |
197 | 201 |
198 // This is used to complete pending inits and non-pending inits. | 202 // This is used to complete pending inits and non-pending inits. |
199 void RenderWidget::CompleteInit() { | 203 void RenderWidget::CompleteInit() { |
200 DCHECK(routing_id_ != MSG_ROUTING_NONE); | 204 DCHECK(routing_id_ != MSG_ROUTING_NONE); |
201 | 205 |
202 init_complete_ = true; | 206 init_complete_ = true; |
203 | 207 |
204 if (webwidget_) { | 208 if (webwidget_ && is_threaded_compositing_enabled_) { |
205 webwidget_->setCompositorSurfaceReady(); | 209 webwidget_->enterForceCompositingMode(true); |
206 if (is_threaded_compositing_enabled_) | 210 } |
207 webwidget_->enterForceCompositingMode(true); | 211 if (web_layer_tree_view_) { |
212 web_layer_tree_view_->setSurfaceReady(); | |
208 } | 213 } |
209 DoDeferredUpdate(); | 214 DoDeferredUpdate(); |
210 | 215 |
211 Send(new ViewHostMsg_RenderViewReady(routing_id_)); | 216 Send(new ViewHostMsg_RenderViewReady(routing_id_)); |
212 } | 217 } |
213 | 218 |
214 void RenderWidget::SetSwappedOut(bool is_swapped_out) { | 219 void RenderWidget::SetSwappedOut(bool is_swapped_out) { |
215 // We should only toggle between states. | 220 // We should only toggle between states. |
216 DCHECK(is_swapped_out_ != is_swapped_out); | 221 DCHECK(is_swapped_out_ != is_swapped_out); |
217 is_swapped_out_ = is_swapped_out; | 222 is_swapped_out_ = is_swapped_out; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
594 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; | 599 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; |
595 } | 600 } |
596 | 601 |
597 IPC::Message* response = | 602 IPC::Message* response = |
598 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, | 603 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, |
599 ack_result); | 604 ack_result); |
600 bool event_type_gets_rate_limited = | 605 bool event_type_gets_rate_limited = |
601 input_event->type == WebInputEvent::MouseMove || | 606 input_event->type == WebInputEvent::MouseMove || |
602 input_event->type == WebInputEvent::MouseWheel || | 607 input_event->type == WebInputEvent::MouseWheel || |
603 WebInputEvent::isTouchEventType(input_event->type); | 608 WebInputEvent::isTouchEventType(input_event->type); |
609 | |
610 bool frame_pending = paint_aggregator_.HasPendingUpdate(); | |
611 if (is_accelerated_compositing_active_) { | |
612 frame_pending = web_layer_tree_view_->commitRequested(); | |
613 } | |
614 | |
604 bool is_input_throttled = | 615 bool is_input_throttled = |
605 throttle_input_events_ && | 616 throttle_input_events_ && |
606 ((webwidget_ ? webwidget_->isInputThrottled() : false) || | 617 frame_pending; |
607 paint_aggregator_.HasPendingUpdate()); | |
608 | 618 |
609 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { | 619 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { |
610 // We want to rate limit the input events in this case, so we'll wait for | 620 // We want to rate limit the input events in this case, so we'll wait for |
611 // painting to finish before ACKing this message. | 621 // painting to finish before ACKing this message. |
612 if (pending_input_event_ack_.get()) { | 622 if (pending_input_event_ack_.get()) { |
613 // As two different kinds of events could cause us to postpone an ack | 623 // As two different kinds of events could cause us to postpone an ack |
614 // we send it now, if we have one pending. The Browser should never | 624 // we send it now, if we have one pending. The Browser should never |
615 // send us the same kind of event we are delaying the ack for. | 625 // send us the same kind of event we are delaying the ack for. |
616 Send(pending_input_event_ack_.release()); | 626 Send(pending_input_event_ack_.release()); |
617 } | 627 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
835 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { | 845 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { |
836 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") | 846 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") |
837 animation_floor_time_ = now + animationInterval; | 847 animation_floor_time_ = now + animationInterval; |
838 // Set a timer to call us back after animationInterval before | 848 // Set a timer to call us back after animationInterval before |
839 // running animation callbacks so that if a callback requests another | 849 // running animation callbacks so that if a callback requests another |
840 // we'll be sure to run it at the proper time. | 850 // we'll be sure to run it at the proper time. |
841 animation_timer_.Stop(); | 851 animation_timer_.Stop(); |
842 animation_timer_.Start(FROM_HERE, animationInterval, this, | 852 animation_timer_.Start(FROM_HERE, animationInterval, this, |
843 &RenderWidget::AnimationCallback); | 853 &RenderWidget::AnimationCallback); |
844 animation_update_pending_ = false; | 854 animation_update_pending_ = false; |
845 webwidget_->animate(0.0); | 855 if (is_accelerated_compositing_active_) { |
856 web_layer_tree_view_->layer_tree_host()->updateAnimations( | |
857 base::TimeTicks::Now()); | |
858 } else { | |
859 webwidget_->animate(0.0); | |
860 } | |
846 return; | 861 return; |
847 } | 862 } |
848 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); | 863 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); |
849 if (!animation_timer_.IsRunning()) { | 864 if (!animation_timer_.IsRunning()) { |
850 // This code uses base::Time::Now() to calculate the floor and next fire | 865 // This code uses base::Time::Now() to calculate the floor and next fire |
851 // time because javascript's Date object uses base::Time::Now(). The | 866 // time because javascript's Date object uses base::Time::Now(). The |
852 // message loop uses base::TimeTicks, which on windows can have a | 867 // message loop uses base::TimeTicks, which on windows can have a |
853 // different granularity than base::Time. | 868 // different granularity than base::Time. |
854 // The upshot of all this is that this function might be called before | 869 // The upshot of all this is that this function might be called before |
855 // base::Time::Now() has advanced past the animation_floor_time_. To | 870 // base::Time::Now() has advanced past the animation_floor_time_. To |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1062 } else { // Accelerated compositing path | 1077 } else { // Accelerated compositing path |
1063 // Begin painting. | 1078 // Begin painting. |
1064 // If painting is done via the gpu process then we don't set any damage | 1079 // If painting is done via the gpu process then we don't set any damage |
1065 // rects to save the browser process from doing unecessary work. | 1080 // rects to save the browser process from doing unecessary work. |
1066 pending_update_params_->bitmap_rect = bounds; | 1081 pending_update_params_->bitmap_rect = bounds; |
1067 pending_update_params_->scroll_rect = gfx::Rect(); | 1082 pending_update_params_->scroll_rect = gfx::Rect(); |
1068 // We don't need an ack, because we're not sharing a DIB with the browser. | 1083 // We don't need an ack, because we're not sharing a DIB with the browser. |
1069 // If it needs to (e.g. composited UI), the GPU process does its own ACK | 1084 // If it needs to (e.g. composited UI), the GPU process does its own ACK |
1070 // with the browser for the GPU surface. | 1085 // with the browser for the GPU surface. |
1071 pending_update_params_->needs_ack = false; | 1086 pending_update_params_->needs_ack = false; |
1072 webwidget_->composite(false); | 1087 web_layer_tree_view_->composite(); |
jamesr
2013/01/04 19:24:48
oh snap, this change might break render_widget_ful
| |
1073 } | 1088 } |
1074 | 1089 |
1075 // If we're holding a pending input event ACK, send the ACK before sending the | 1090 // If we're holding a pending input event ACK, send the ACK before sending the |
1076 // UpdateReply message so we can receive another input event before the | 1091 // UpdateReply message so we can receive another input event before the |
1077 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within | 1092 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within |
1078 // the UpdateRect IPC message handler. | 1093 // the UpdateRect IPC message handler. |
1079 if (pending_input_event_ack_.get()) | 1094 if (pending_input_event_ack_.get()) |
1080 Send(pending_input_event_ack_.release()); | 1095 Send(pending_input_event_ack_.release()); |
1081 | 1096 |
1082 // If composite() called SwapBuffers, pending_update_params_ will be reset (in | 1097 // If composite() called SwapBuffers, pending_update_params_ will be reset (in |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1222 using_asynchronous_swapbuffers_ = false; | 1237 using_asynchronous_swapbuffers_ = false; |
1223 | 1238 |
1224 // In single-threaded mode, we exit force compositing mode and re-enter in | 1239 // In single-threaded mode, we exit force compositing mode and re-enter in |
1225 // DoDeferredUpdate() if appropriate. In threaded compositing mode, | 1240 // DoDeferredUpdate() if appropriate. In threaded compositing mode, |
1226 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and | 1241 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and |
1227 // entering force compositing mode at the appropriate times. | 1242 // entering force compositing mode at the appropriate times. |
1228 if (!is_threaded_compositing_enabled_) | 1243 if (!is_threaded_compositing_enabled_) |
1229 webwidget_->enterForceCompositingMode(false); | 1244 webwidget_->enterForceCompositingMode(false); |
1230 } | 1245 } |
1231 | 1246 |
1247 void RenderWidget::initializeLayerTreeView( | |
1248 WebKit::WebLayerTreeViewClient* client, | |
1249 const WebKit::WebLayer& root_layer, | |
1250 const WebKit::WebLayerTreeView::Settings& settings) { | |
1251 DCHECK(!web_layer_tree_view_); | |
1252 web_layer_tree_view_.reset(new WebKit::WebLayerTreeViewImpl(client)); | |
1253 | |
1254 scoped_ptr<cc::Thread> impl_thread; | |
1255 CompositorThread* compositor_thread = | |
1256 RenderThreadImpl::current()->compositor_thread(); | |
1257 if (compositor_thread) | |
1258 impl_thread = cc::ThreadImpl::createForDifferentThread( | |
1259 compositor_thread->message_loop()->message_loop_proxy()); | |
1260 if (!web_layer_tree_view_->initialize(settings, impl_thread.Pass())) { | |
1261 web_layer_tree_view_.reset(); | |
1262 return; | |
1263 } | |
1264 web_layer_tree_view_->setRootLayer(root_layer); | |
1265 if (init_complete_) { | |
1266 web_layer_tree_view_->setSurfaceReady(); | |
1267 } | |
1268 } | |
1269 | |
1270 WebKit::WebLayerTreeView* RenderWidget::layerTreeView() { | |
1271 return web_layer_tree_view_.get(); | |
1272 } | |
1273 | |
1232 void RenderWidget::willBeginCompositorFrame() { | 1274 void RenderWidget::willBeginCompositorFrame() { |
1233 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); | 1275 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); |
1234 | 1276 |
1235 DCHECK(RenderThreadImpl::current()->compositor_thread()); | 1277 DCHECK(RenderThreadImpl::current()->compositor_thread()); |
1236 | 1278 |
1237 // The following two can result in further layout and possibly | 1279 // The following two can result in further layout and possibly |
1238 // enable GPU acceleration so they need to be called before any painting | 1280 // enable GPU acceleration so they need to be called before any painting |
1239 // is done. | 1281 // is done. |
1240 UpdateTextInputState(DO_NOT_SHOW_IME); | 1282 UpdateTextInputState(DO_NOT_SHOW_IME); |
1241 UpdateSelectionBounds(); | 1283 UpdateSelectionBounds(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1373 // in Javascript. If we ask the RendwerWidgetHost to close now, the window | 1415 // in Javascript. If we ask the RendwerWidgetHost to close now, the window |
1374 // could be closed before the JS finishes executing. So instead, post a | 1416 // could be closed before the JS finishes executing. So instead, post a |
1375 // message back to the message loop, which won't run until the JS is | 1417 // message back to the message loop, which won't run until the JS is |
1376 // complete, and then the Close message can be sent. | 1418 // complete, and then the Close message can be sent. |
1377 MessageLoop::current()->PostTask( | 1419 MessageLoop::current()->PostTask( |
1378 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); | 1420 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); |
1379 } | 1421 } |
1380 | 1422 |
1381 void RenderWidget::Close() { | 1423 void RenderWidget::Close() { |
1382 if (webwidget_) { | 1424 if (webwidget_) { |
1425 web_layer_tree_view_.reset(); | |
1383 webwidget_->close(); | 1426 webwidget_->close(); |
1384 webwidget_ = NULL; | 1427 webwidget_ = NULL; |
1385 } | 1428 } |
1386 } | 1429 } |
1387 | 1430 |
1388 WebRect RenderWidget::windowRect() { | 1431 WebRect RenderWidget::windowRect() { |
1389 if (pending_window_rect_count_) | 1432 if (pending_window_rect_count_) |
1390 return pending_window_rect_; | 1433 return pending_window_rect_; |
1391 | 1434 |
1392 return view_screen_rect_; | 1435 return view_screen_rect_; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1587 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); | 1630 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); |
1588 } | 1631 } |
1589 | 1632 |
1590 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { | 1633 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { |
1591 // During shutdown we can just ignore this message. | 1634 // During shutdown we can just ignore this message. |
1592 if (!webwidget_) | 1635 if (!webwidget_) |
1593 return; | 1636 return; |
1594 | 1637 |
1595 set_next_paint_is_repaint_ack(); | 1638 set_next_paint_is_repaint_ack(); |
1596 if (is_accelerated_compositing_active_) { | 1639 if (is_accelerated_compositing_active_) { |
1597 webwidget_->setNeedsRedraw(); | 1640 web_layer_tree_view_->setNeedsRedraw(); |
1598 scheduleComposite(); | 1641 scheduleComposite(); |
1599 } else { | 1642 } else { |
1600 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); | 1643 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); |
1601 didInvalidateRect(repaint_rect); | 1644 didInvalidateRect(repaint_rect); |
1602 } | 1645 } |
1603 } | 1646 } |
1604 | 1647 |
1605 void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) { | 1648 void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) { |
1606 PendingSmoothScrollGestureMap::iterator it = | 1649 PendingSmoothScrollGestureMap::iterator it = |
1607 pending_smooth_scroll_gestures_.find(gesture_id); | 1650 pending_smooth_scroll_gestures_.find(gesture_id); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1921 i != plugin_window_moves_.end(); ++i) { | 1964 i != plugin_window_moves_.end(); ++i) { |
1922 if (i->window == window) { | 1965 if (i->window == window) { |
1923 plugin_window_moves_.erase(i); | 1966 plugin_window_moves_.erase(i); |
1924 break; | 1967 break; |
1925 } | 1968 } |
1926 } | 1969 } |
1927 } | 1970 } |
1928 | 1971 |
1929 void RenderWidget::GetRenderingStats( | 1972 void RenderWidget::GetRenderingStats( |
1930 WebKit::WebRenderingStatsImpl& stats) const { | 1973 WebKit::WebRenderingStatsImpl& stats) const { |
1931 webwidget()->renderingStats(stats); | 1974 if (web_layer_tree_view_) |
1975 web_layer_tree_view_->renderingStats(stats); | |
1932 | 1976 |
1933 stats.rendering_stats.numAnimationFrames += | 1977 stats.rendering_stats.numAnimationFrames += |
1934 software_stats_.numAnimationFrames; | 1978 software_stats_.numAnimationFrames; |
1935 stats.rendering_stats.numFramesSentToScreen += | 1979 stats.rendering_stats.numFramesSentToScreen += |
1936 software_stats_.numFramesSentToScreen; | 1980 software_stats_.numFramesSentToScreen; |
1937 stats.rendering_stats.totalPaintTimeInSeconds += | 1981 stats.rendering_stats.totalPaintTimeInSeconds += |
1938 software_stats_.totalPaintTimeInSeconds; | 1982 software_stats_.totalPaintTimeInSeconds; |
1939 stats.rendering_stats.totalPixelsPainted += | 1983 stats.rendering_stats.totalPixelsPainted += |
1940 software_stats_.totalPixelsPainted; | 1984 software_stats_.totalPixelsPainted; |
1941 stats.rendering_stats.totalRasterizeTimeInSeconds += | 1985 stats.rendering_stats.totalRasterizeTimeInSeconds += |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1982 | 2026 |
1983 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { | 2027 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { |
1984 return false; | 2028 return false; |
1985 } | 2029 } |
1986 | 2030 |
1987 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { | 2031 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { |
1988 return true; | 2032 return true; |
1989 } | 2033 } |
1990 | 2034 |
1991 } // namespace content | 2035 } // namespace content |
OLD | NEW |