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

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: make cc::LayerTreeHost getter chromium-style Created 8 years 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/thread.h"
18 #include "cc/thread_impl.h"
17 #include "content/common/swapped_out_messages.h" 19 #include "content/common/swapped_out_messages.h"
18 #include "content/common/view_messages.h" 20 #include "content/common/view_messages.h"
19 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "content/renderer/gpu/compositor_thread.h"
20 #include "content/renderer/render_process.h" 23 #include "content/renderer/render_process.h"
21 #include "content/renderer/render_thread_impl.h" 24 #include "content/renderer/render_thread_impl.h"
22 #include "content/renderer/renderer_webkitplatformsupport_impl.h" 25 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
23 #include "ipc/ipc_sync_message.h" 26 #include "ipc/ipc_sync_message.h"
24 #include "skia/ext/platform_canvas.h" 27 #include "skia/ext/platform_canvas.h"
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHelperPlugin.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h" 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPagePopup.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h" 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h" 32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenuInfo.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h" 33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRange.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h" 35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebPoint.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" 36 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" 37 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return false; 197 return false;
196 } 198 }
197 } 199 }
198 200
199 // This is used to complete pending inits and non-pending inits. 201 // This is used to complete pending inits and non-pending inits.
200 void RenderWidget::CompleteInit() { 202 void RenderWidget::CompleteInit() {
201 DCHECK(routing_id_ != MSG_ROUTING_NONE); 203 DCHECK(routing_id_ != MSG_ROUTING_NONE);
202 204
203 init_complete_ = true; 205 init_complete_ = true;
204 206
205 if (webwidget_) { 207 if (webwidget_ && is_threaded_compositing_enabled_) {
206 webwidget_->setCompositorSurfaceReady(); 208 webwidget_->enterForceCompositingMode(true);
207 if (is_threaded_compositing_enabled_) 209 }
208 webwidget_->enterForceCompositingMode(true); 210 if (web_layer_tree_view_) {
211 web_layer_tree_view_->setSurfaceReady();
209 } 212 }
210 DoDeferredUpdate(); 213 DoDeferredUpdate();
211 214
212 Send(new ViewHostMsg_RenderViewReady(routing_id_)); 215 Send(new ViewHostMsg_RenderViewReady(routing_id_));
213 } 216 }
214 217
215 void RenderWidget::SetSwappedOut(bool is_swapped_out) { 218 void RenderWidget::SetSwappedOut(bool is_swapped_out) {
216 // We should only toggle between states. 219 // We should only toggle between states.
217 DCHECK(is_swapped_out_ != is_swapped_out); 220 DCHECK(is_swapped_out_ != is_swapped_out);
218 is_swapped_out_ = is_swapped_out; 221 is_swapped_out_ = is_swapped_out;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 598 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
596 } 599 }
597 600
598 IPC::Message* response = 601 IPC::Message* response =
599 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, 602 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
600 ack_result); 603 ack_result);
601 bool event_type_gets_rate_limited = 604 bool event_type_gets_rate_limited =
602 input_event->type == WebInputEvent::MouseMove || 605 input_event->type == WebInputEvent::MouseMove ||
603 input_event->type == WebInputEvent::MouseWheel || 606 input_event->type == WebInputEvent::MouseWheel ||
604 WebInputEvent::isTouchEventType(input_event->type); 607 WebInputEvent::isTouchEventType(input_event->type);
608
609 bool frame_pending = paint_aggregator_.HasPendingUpdate();
610 if (is_accelerated_compositing_active_) {
611 frame_pending = web_layer_tree_view_->commitRequested();
612 }
613
605 bool is_input_throttled = 614 bool is_input_throttled =
606 throttle_input_events_ && 615 throttle_input_events_ &&
607 ((webwidget_ ? webwidget_->isInputThrottled() : false) || 616 frame_pending;
608 paint_aggregator_.HasPendingUpdate());
609 617
610 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { 618 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
611 // We want to rate limit the input events in this case, so we'll wait for 619 // We want to rate limit the input events in this case, so we'll wait for
612 // painting to finish before ACKing this message. 620 // painting to finish before ACKing this message.
613 if (pending_input_event_ack_.get()) { 621 if (pending_input_event_ack_.get()) {
614 // As two different kinds of events could cause us to postpone an ack 622 // As two different kinds of events could cause us to postpone an ack
615 // we send it now, if we have one pending. The Browser should never 623 // we send it now, if we have one pending. The Browser should never
616 // send us the same kind of event we are delaying the ack for. 624 // send us the same kind of event we are delaying the ack for.
617 Send(pending_input_event_ack_.release()); 625 Send(pending_input_event_ack_.release());
618 } 626 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { 844 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
837 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") 845 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
838 animation_floor_time_ = now + animationInterval; 846 animation_floor_time_ = now + animationInterval;
839 // Set a timer to call us back after animationInterval before 847 // Set a timer to call us back after animationInterval before
840 // running animation callbacks so that if a callback requests another 848 // running animation callbacks so that if a callback requests another
841 // we'll be sure to run it at the proper time. 849 // we'll be sure to run it at the proper time.
842 animation_timer_.Stop(); 850 animation_timer_.Stop();
843 animation_timer_.Start(FROM_HERE, animationInterval, this, 851 animation_timer_.Start(FROM_HERE, animationInterval, this,
844 &RenderWidget::AnimationCallback); 852 &RenderWidget::AnimationCallback);
845 animation_update_pending_ = false; 853 animation_update_pending_ = false;
846 webwidget_->animate(0.0); 854 if (is_accelerated_compositing_active_) {
855 web_layer_tree_view_->updateAnimations(0.0);
enne (OOO) 2012/12/16 20:02:59 Why is this zero? It seems like if you're hoisting
856 } else {
857 webwidget_->animate(0.0);
858 }
847 return; 859 return;
848 } 860 }
849 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); 861 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
850 if (!animation_timer_.IsRunning()) { 862 if (!animation_timer_.IsRunning()) {
851 // This code uses base::Time::Now() to calculate the floor and next fire 863 // This code uses base::Time::Now() to calculate the floor and next fire
852 // time because javascript's Date object uses base::Time::Now(). The 864 // time because javascript's Date object uses base::Time::Now(). The
853 // message loop uses base::TimeTicks, which on windows can have a 865 // message loop uses base::TimeTicks, which on windows can have a
854 // different granularity than base::Time. 866 // different granularity than base::Time.
855 // The upshot of all this is that this function might be called before 867 // The upshot of all this is that this function might be called before
856 // base::Time::Now() has advanced past the animation_floor_time_. To 868 // base::Time::Now() has advanced past the animation_floor_time_. To
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 } else { // Accelerated compositing path 1075 } else { // Accelerated compositing path
1064 // Begin painting. 1076 // Begin painting.
1065 // If painting is done via the gpu process then we don't set any damage 1077 // If painting is done via the gpu process then we don't set any damage
1066 // rects to save the browser process from doing unecessary work. 1078 // rects to save the browser process from doing unecessary work.
1067 pending_update_params_->bitmap_rect = bounds; 1079 pending_update_params_->bitmap_rect = bounds;
1068 pending_update_params_->scroll_rect = gfx::Rect(); 1080 pending_update_params_->scroll_rect = gfx::Rect();
1069 // We don't need an ack, because we're not sharing a DIB with the browser. 1081 // We don't need an ack, because we're not sharing a DIB with the browser.
1070 // If it needs to (e.g. composited UI), the GPU process does its own ACK 1082 // If it needs to (e.g. composited UI), the GPU process does its own ACK
1071 // with the browser for the GPU surface. 1083 // with the browser for the GPU surface.
1072 pending_update_params_->needs_ack = false; 1084 pending_update_params_->needs_ack = false;
1073 webwidget_->composite(false); 1085 web_layer_tree_view_->composite();
1074 } 1086 }
1075 1087
1076 // If we're holding a pending input event ACK, send the ACK before sending the 1088 // If we're holding a pending input event ACK, send the ACK before sending the
1077 // UpdateReply message so we can receive another input event before the 1089 // UpdateReply message so we can receive another input event before the
1078 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within 1090 // UpdateRect_ACK on platforms where the UpdateRect_ACK is sent from within
1079 // the UpdateRect IPC message handler. 1091 // the UpdateRect IPC message handler.
1080 if (pending_input_event_ack_.get()) 1092 if (pending_input_event_ack_.get())
1081 Send(pending_input_event_ack_.release()); 1093 Send(pending_input_event_ack_.release());
1082 1094
1083 // If composite() called SwapBuffers, pending_update_params_ will be reset (in 1095 // If composite() called SwapBuffers, pending_update_params_ will be reset (in
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and 1239 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1228 // entering force compositing mode at the appropriate times. 1240 // entering force compositing mode at the appropriate times.
1229 if (!is_threaded_compositing_enabled_) 1241 if (!is_threaded_compositing_enabled_)
1230 webwidget_->enterForceCompositingMode(false); 1242 webwidget_->enterForceCompositingMode(false);
1231 } 1243 }
1232 1244
1233 void RenderWidget::initializeLayerTreeView( 1245 void RenderWidget::initializeLayerTreeView(
1234 WebKit::WebLayerTreeViewClient* client, 1246 WebKit::WebLayerTreeViewClient* client,
1235 const WebKit::WebLayer& root_layer, 1247 const WebKit::WebLayer& root_layer,
1236 const WebKit::WebLayerTreeView::Settings& settings) { 1248 const WebKit::WebLayerTreeView::Settings& settings) {
1237 web_layer_tree_view_.reset( 1249 DCHECK(!web_layer_tree_view_);
1238 WebKit::Platform::current()->compositorSupport()->createLayerTreeView( 1250 web_layer_tree_view_.reset(new WebKit::WebLayerTreeViewImpl(client));
1239 client, root_layer, settings)); 1251
1252 scoped_ptr<cc::Thread> impl_thread;
1253 CompositorThread* compositor_thread =
1254 RenderThreadImpl::current()->compositor_thread();
1255 if (compositor_thread)
1256 impl_thread = cc::ThreadImpl::createForDifferentThread(
1257 compositor_thread->message_loop()->message_loop_proxy());
1258 if (!web_layer_tree_view_->initialize(settings, impl_thread.Pass())) {
1259 web_layer_tree_view_.reset();
1260 return;
1261 }
1262 web_layer_tree_view_->setRootLayer(root_layer);
1263 if (init_complete_) {
1264 web_layer_tree_view_->setSurfaceReady();
1265 }
1240 } 1266 }
1241 1267
1242 WebKit::WebLayerTreeView* RenderWidget::layerTreeView() { 1268 WebKit::WebLayerTreeView* RenderWidget::layerTreeView() {
1243 return web_layer_tree_view_.get(); 1269 return web_layer_tree_view_.get();
1244 } 1270 }
1245 1271
1246 void RenderWidget::willBeginCompositorFrame() { 1272 void RenderWidget::willBeginCompositorFrame() {
1247 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); 1273 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1248 1274
1249 DCHECK(RenderThreadImpl::current()->compositor_thread()); 1275 DCHECK(RenderThreadImpl::current()->compositor_thread());
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); 1628 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
1603 } 1629 }
1604 1630
1605 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { 1631 void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) {
1606 // During shutdown we can just ignore this message. 1632 // During shutdown we can just ignore this message.
1607 if (!webwidget_) 1633 if (!webwidget_)
1608 return; 1634 return;
1609 1635
1610 set_next_paint_is_repaint_ack(); 1636 set_next_paint_is_repaint_ack();
1611 if (is_accelerated_compositing_active_) { 1637 if (is_accelerated_compositing_active_) {
1612 webwidget_->setNeedsRedraw(); 1638 web_layer_tree_view_->setNeedsRedraw();
1613 scheduleComposite(); 1639 scheduleComposite();
1614 } else { 1640 } else {
1615 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 1641 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1616 didInvalidateRect(repaint_rect); 1642 didInvalidateRect(repaint_rect);
1617 } 1643 }
1618 } 1644 }
1619 1645
1620 void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) { 1646 void RenderWidget::OnMsgSmoothScrollCompleted(int gesture_id) {
1621 PendingSmoothScrollGestureMap::iterator it = 1647 PendingSmoothScrollGestureMap::iterator it =
1622 pending_smooth_scroll_gestures_.find(gesture_id); 1648 pending_smooth_scroll_gestures_.find(gesture_id);
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 i != plugin_window_moves_.end(); ++i) { 1949 i != plugin_window_moves_.end(); ++i) {
1924 if (i->window == window) { 1950 if (i->window == window) {
1925 plugin_window_moves_.erase(i); 1951 plugin_window_moves_.erase(i);
1926 break; 1952 break;
1927 } 1953 }
1928 } 1954 }
1929 } 1955 }
1930 1956
1931 void RenderWidget::GetRenderingStats( 1957 void RenderWidget::GetRenderingStats(
1932 WebKit::WebRenderingStatsImpl& stats) const { 1958 WebKit::WebRenderingStatsImpl& stats) const {
1933 webwidget()->renderingStats(stats); 1959 if (web_layer_tree_view_)
1960 web_layer_tree_view_->renderingStats(stats);
1934 1961
1935 stats.rendering_stats.numAnimationFrames += 1962 stats.rendering_stats.numAnimationFrames +=
1936 software_stats_.numAnimationFrames; 1963 software_stats_.numAnimationFrames;
1937 stats.rendering_stats.numFramesSentToScreen += 1964 stats.rendering_stats.numFramesSentToScreen +=
1938 software_stats_.numFramesSentToScreen; 1965 software_stats_.numFramesSentToScreen;
1939 stats.rendering_stats.totalPaintTimeInSeconds += 1966 stats.rendering_stats.totalPaintTimeInSeconds +=
1940 software_stats_.totalPaintTimeInSeconds; 1967 software_stats_.totalPaintTimeInSeconds;
1941 stats.rendering_stats.totalPixelsPainted += 1968 stats.rendering_stats.totalPixelsPainted +=
1942 software_stats_.totalPixelsPainted; 1969 software_stats_.totalPixelsPainted;
1943 stats.rendering_stats.totalRasterizeTimeInSeconds += 1970 stats.rendering_stats.totalRasterizeTimeInSeconds +=
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 2011
1985 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { 2012 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1986 return false; 2013 return false;
1987 } 2014 }
1988 2015
1989 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { 2016 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1990 return true; 2017 return true;
1991 } 2018 }
1992 2019
1993 } // namespace content 2020 } // 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