Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: content/renderer/render_widget.cc

Issue 11575049: Make RenderWidget responsible for the composited view's lifetime (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/renderer/render_widget.h ('k') | webkit/compositor_bindings/web_layer_tree_view_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 return false; 243 return false;
240 } 244 }
241 } 245 }
242 246
243 // This is used to complete pending inits and non-pending inits. 247 // This is used to complete pending inits and non-pending inits.
244 void RenderWidget::CompleteInit() { 248 void RenderWidget::CompleteInit() {
245 DCHECK(routing_id_ != MSG_ROUTING_NONE); 249 DCHECK(routing_id_ != MSG_ROUTING_NONE);
246 250
247 init_complete_ = true; 251 init_complete_ = true;
248 252
249 if (webwidget_) { 253 if (webwidget_ && is_threaded_compositing_enabled_) {
250 webwidget_->setCompositorSurfaceReady(); 254 webwidget_->enterForceCompositingMode(true);
251 if (is_threaded_compositing_enabled_) 255 }
252 webwidget_->enterForceCompositingMode(true); 256 if (web_layer_tree_view_) {
257 web_layer_tree_view_->setSurfaceReady();
253 } 258 }
254 DoDeferredUpdate(); 259 DoDeferredUpdate();
255 260
256 Send(new ViewHostMsg_RenderViewReady(routing_id_)); 261 Send(new ViewHostMsg_RenderViewReady(routing_id_));
257 } 262 }
258 263
259 void RenderWidget::SetSwappedOut(bool is_swapped_out) { 264 void RenderWidget::SetSwappedOut(bool is_swapped_out) {
260 // We should only toggle between states. 265 // We should only toggle between states.
261 DCHECK(is_swapped_out_ != is_swapped_out); 266 DCHECK(is_swapped_out_ != is_swapped_out);
262 is_swapped_out_ = is_swapped_out; 267 is_swapped_out_ = is_swapped_out;
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 666 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
662 } 667 }
663 668
664 IPC::Message* response = 669 IPC::Message* response =
665 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, 670 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
666 ack_result); 671 ack_result);
667 bool event_type_gets_rate_limited = 672 bool event_type_gets_rate_limited =
668 input_event->type == WebInputEvent::MouseMove || 673 input_event->type == WebInputEvent::MouseMove ||
669 input_event->type == WebInputEvent::MouseWheel || 674 input_event->type == WebInputEvent::MouseWheel ||
670 WebInputEvent::isTouchEventType(input_event->type); 675 WebInputEvent::isTouchEventType(input_event->type);
676
677 bool frame_pending = paint_aggregator_.HasPendingUpdate();
678 if (is_accelerated_compositing_active_) {
679 frame_pending = web_layer_tree_view_ &&
680 web_layer_tree_view_->commitRequested();
681 }
682
671 bool is_input_throttled = 683 bool is_input_throttled =
672 throttle_input_events_ && 684 throttle_input_events_ &&
673 ((webwidget_ ? webwidget_->isInputThrottled() : false) || 685 frame_pending;
674 paint_aggregator_.HasPendingUpdate());
675 686
676 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { 687 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
677 // We want to rate limit the input events in this case, so we'll wait for 688 // We want to rate limit the input events in this case, so we'll wait for
678 // painting to finish before ACKing this message. 689 // painting to finish before ACKing this message.
679 if (pending_input_event_ack_.get()) { 690 if (pending_input_event_ack_.get()) {
680 // As two different kinds of events could cause us to postpone an ack 691 // As two different kinds of events could cause us to postpone an ack
681 // we send it now, if we have one pending. The Browser should never 692 // we send it now, if we have one pending. The Browser should never
682 // send us the same kind of event we are delaying the ack for. 693 // send us the same kind of event we are delaying the ack for.
683 Send(pending_input_event_ack_.release()); 694 Send(pending_input_event_ack_.release());
684 } 695 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { 913 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
903 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") 914 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
904 animation_floor_time_ = now + animationInterval; 915 animation_floor_time_ = now + animationInterval;
905 // Set a timer to call us back after animationInterval before 916 // Set a timer to call us back after animationInterval before
906 // running animation callbacks so that if a callback requests another 917 // running animation callbacks so that if a callback requests another
907 // we'll be sure to run it at the proper time. 918 // we'll be sure to run it at the proper time.
908 animation_timer_.Stop(); 919 animation_timer_.Stop();
909 animation_timer_.Start(FROM_HERE, animationInterval, this, 920 animation_timer_.Start(FROM_HERE, animationInterval, this,
910 &RenderWidget::AnimationCallback); 921 &RenderWidget::AnimationCallback);
911 animation_update_pending_ = false; 922 animation_update_pending_ = false;
912 webwidget_->animate(0.0); 923 if (is_accelerated_compositing_active_ && web_layer_tree_view_) {
924 web_layer_tree_view_->layer_tree_host()->updateAnimations(
925 base::TimeTicks::Now());
926 } else {
927 webwidget_->animate(0.0);
928 }
913 return; 929 return;
914 } 930 }
915 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); 931 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
916 if (!animation_timer_.IsRunning()) { 932 if (!animation_timer_.IsRunning()) {
917 // This code uses base::Time::Now() to calculate the floor and next fire 933 // This code uses base::Time::Now() to calculate the floor and next fire
918 // time because javascript's Date object uses base::Time::Now(). The 934 // time because javascript's Date object uses base::Time::Now(). The
919 // message loop uses base::TimeTicks, which on windows can have a 935 // message loop uses base::TimeTicks, which on windows can have a
920 // different granularity than base::Time. 936 // different granularity than base::Time.
921 // The upshot of all this is that this function might be called before 937 // The upshot of all this is that this function might be called before
922 // base::Time::Now() has advanced past the animation_floor_time_. To 938 // base::Time::Now() has advanced past the animation_floor_time_. To
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 using_asynchronous_swapbuffers_ = false; 1305 using_asynchronous_swapbuffers_ = false;
1290 1306
1291 // In single-threaded mode, we exit force compositing mode and re-enter in 1307 // In single-threaded mode, we exit force compositing mode and re-enter in
1292 // DoDeferredUpdate() if appropriate. In threaded compositing mode, 1308 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1293 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and 1309 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1294 // entering force compositing mode at the appropriate times. 1310 // entering force compositing mode at the appropriate times.
1295 if (!is_threaded_compositing_enabled_) 1311 if (!is_threaded_compositing_enabled_)
1296 webwidget_->enterForceCompositingMode(false); 1312 webwidget_->enterForceCompositingMode(false);
1297 } 1313 }
1298 1314
1315 void RenderWidget::initializeLayerTreeView(
1316 WebKit::WebLayerTreeViewClient* client,
1317 const WebKit::WebLayer& root_layer,
1318 const WebKit::WebLayerTreeView::Settings& settings) {
1319 DCHECK(!web_layer_tree_view_);
1320 web_layer_tree_view_.reset(new WebKit::WebLayerTreeViewImpl(client));
1321
1322 scoped_ptr<cc::Thread> impl_thread;
1323 CompositorThread* compositor_thread =
1324 RenderThreadImpl::current()->compositor_thread();
1325 if (compositor_thread)
1326 impl_thread = cc::ThreadImpl::createForDifferentThread(
1327 compositor_thread->message_loop()->message_loop_proxy());
1328 if (!web_layer_tree_view_->initialize(settings, impl_thread.Pass())) {
1329 web_layer_tree_view_.reset();
1330 return;
1331 }
1332 web_layer_tree_view_->setRootLayer(root_layer);
1333 if (init_complete_) {
1334 web_layer_tree_view_->setSurfaceReady();
1335 }
1336 }
1337
1338 WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
1339 return web_layer_tree_view_.get();
1340 }
1341
1299 void RenderWidget::willBeginCompositorFrame() { 1342 void RenderWidget::willBeginCompositorFrame() {
1300 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); 1343 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1301 1344
1302 DCHECK(RenderThreadImpl::current()->compositor_thread()); 1345 DCHECK(RenderThreadImpl::current()->compositor_thread());
1303 1346
1304 // The following two can result in further layout and possibly 1347 // The following two can result in further layout and possibly
1305 // enable GPU acceleration so they need to be called before any painting 1348 // enable GPU acceleration so they need to be called before any painting
1306 // is done. 1349 // is done.
1307 UpdateSelectionBounds(); 1350 UpdateSelectionBounds();
1308 1351
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1439 // in Javascript. If we ask the RendwerWidgetHost to close now, the window 1482 // in Javascript. If we ask the RendwerWidgetHost to close now, the window
1440 // could be closed before the JS finishes executing. So instead, post a 1483 // could be closed before the JS finishes executing. So instead, post a
1441 // message back to the message loop, which won't run until the JS is 1484 // message back to the message loop, which won't run until the JS is
1442 // complete, and then the Close message can be sent. 1485 // complete, and then the Close message can be sent.
1443 MessageLoop::current()->PostTask( 1486 MessageLoop::current()->PostTask(
1444 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); 1487 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
1445 } 1488 }
1446 1489
1447 void RenderWidget::Close() { 1490 void RenderWidget::Close() {
1448 if (webwidget_) { 1491 if (webwidget_) {
1492 webwidget_->willCloseLayerTreeView();
1493 web_layer_tree_view_.reset();
1449 webwidget_->close(); 1494 webwidget_->close();
1450 webwidget_ = NULL; 1495 webwidget_ = NULL;
1451 } 1496 }
1452 } 1497 }
1453 1498
1454 WebRect RenderWidget::windowRect() { 1499 WebRect RenderWidget::windowRect() {
1455 if (pending_window_rect_count_) 1500 if (pending_window_rect_count_)
1456 return pending_window_rect_; 1501 return pending_window_rect_;
1457 1502
1458 return view_screen_rect_; 1503 return view_screen_rect_;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); 1698 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
1654 } 1699 }
1655 1700
1656 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { 1701 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
1657 // During shutdown we can just ignore this message. 1702 // During shutdown we can just ignore this message.
1658 if (!webwidget_) 1703 if (!webwidget_)
1659 return; 1704 return;
1660 1705
1661 set_next_paint_is_repaint_ack(); 1706 set_next_paint_is_repaint_ack();
1662 if (is_accelerated_compositing_active_) { 1707 if (is_accelerated_compositing_active_) {
1663 webwidget_->setNeedsRedraw(); 1708 if (web_layer_tree_view_)
1709 web_layer_tree_view_->setNeedsRedraw();
1664 scheduleComposite(); 1710 scheduleComposite();
1665 } else { 1711 } else {
1666 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 1712 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1667 didInvalidateRect(repaint_rect); 1713 didInvalidateRect(repaint_rect);
1668 } 1714 }
1669 } 1715 }
1670 1716
1671 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) { 1717 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
1672 PendingSmoothScrollGestureMap::iterator it = 1718 PendingSmoothScrollGestureMap::iterator it =
1673 pending_smooth_scroll_gestures_.find(gesture_id); 1719 pending_smooth_scroll_gestures_.find(gesture_id);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1987 i != plugin_window_moves_.end(); ++i) { 2033 i != plugin_window_moves_.end(); ++i) {
1988 if (i->window == window) { 2034 if (i->window == window) {
1989 plugin_window_moves_.erase(i); 2035 plugin_window_moves_.erase(i);
1990 break; 2036 break;
1991 } 2037 }
1992 } 2038 }
1993 } 2039 }
1994 2040
1995 void RenderWidget::GetRenderingStats( 2041 void RenderWidget::GetRenderingStats(
1996 WebKit::WebRenderingStatsImpl& stats) const { 2042 WebKit::WebRenderingStatsImpl& stats) const {
1997 webwidget()->renderingStats(stats); 2043 if (web_layer_tree_view_)
2044 web_layer_tree_view_->renderingStats(stats);
1998 2045
1999 stats.rendering_stats.numAnimationFrames += 2046 stats.rendering_stats.numAnimationFrames +=
2000 software_stats_.numAnimationFrames; 2047 software_stats_.numAnimationFrames;
2001 stats.rendering_stats.numFramesSentToScreen += 2048 stats.rendering_stats.numFramesSentToScreen +=
2002 software_stats_.numFramesSentToScreen; 2049 software_stats_.numFramesSentToScreen;
2003 stats.rendering_stats.totalPaintTimeInSeconds += 2050 stats.rendering_stats.totalPaintTimeInSeconds +=
2004 software_stats_.totalPaintTimeInSeconds; 2051 software_stats_.totalPaintTimeInSeconds;
2005 stats.rendering_stats.totalPixelsPainted += 2052 stats.rendering_stats.totalPixelsPainted +=
2006 software_stats_.totalPixelsPainted; 2053 software_stats_.totalPixelsPainted;
2007 stats.rendering_stats.totalRasterizeTimeInSeconds += 2054 stats.rendering_stats.totalRasterizeTimeInSeconds +=
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2048 2095
2049 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { 2096 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
2050 return false; 2097 return false;
2051 } 2098 }
2052 2099
2053 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { 2100 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
2054 return true; 2101 return true;
2055 } 2102 }
2056 2103
2057 } // namespace content 2104 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_widget.h ('k') | webkit/compositor_bindings/web_layer_tree_view_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698