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

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: fixes for render_widget_fullscreen_pepper 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS; 598 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
594 } 599 }
595 600
596 IPC::Message* response = 601 IPC::Message* response =
597 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type, 602 new ViewHostMsg_HandleInputEvent_ACK(routing_id_, input_event->type,
598 ack_result); 603 ack_result);
599 bool event_type_gets_rate_limited = 604 bool event_type_gets_rate_limited =
600 input_event->type == WebInputEvent::MouseMove || 605 input_event->type == WebInputEvent::MouseMove ||
601 input_event->type == WebInputEvent::MouseWheel || 606 input_event->type == WebInputEvent::MouseWheel ||
602 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_ &&
612 web_layer_tree_view_->commitRequested();
613 }
614
603 bool is_input_throttled = 615 bool is_input_throttled =
604 throttle_input_events_ && 616 throttle_input_events_ &&
605 ((webwidget_ ? webwidget_->isInputThrottled() : false) || 617 frame_pending;
606 paint_aggregator_.HasPendingUpdate());
607 618
608 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) { 619 if (event_type_gets_rate_limited && is_input_throttled && !is_hidden_) {
609 // 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
610 // painting to finish before ACKing this message. 621 // painting to finish before ACKing this message.
611 if (pending_input_event_ack_.get()) { 622 if (pending_input_event_ack_.get()) {
612 // 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
613 // 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
614 // 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.
615 Send(pending_input_event_ack_.release()); 626 Send(pending_input_event_ack_.release());
616 } 627 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) { 845 if (now >= animation_floor_time_ || num_swapbuffers_complete_pending_ > 0) {
835 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded") 846 TRACE_EVENT0("renderer", "RenderWidget::AnimateIfNeeded")
836 animation_floor_time_ = now + animationInterval; 847 animation_floor_time_ = now + animationInterval;
837 // Set a timer to call us back after animationInterval before 848 // Set a timer to call us back after animationInterval before
838 // running animation callbacks so that if a callback requests another 849 // running animation callbacks so that if a callback requests another
839 // we'll be sure to run it at the proper time. 850 // we'll be sure to run it at the proper time.
840 animation_timer_.Stop(); 851 animation_timer_.Stop();
841 animation_timer_.Start(FROM_HERE, animationInterval, this, 852 animation_timer_.Start(FROM_HERE, animationInterval, this,
842 &RenderWidget::AnimationCallback); 853 &RenderWidget::AnimationCallback);
843 animation_update_pending_ = false; 854 animation_update_pending_ = false;
844 webwidget_->animate(0.0); 855 if (is_accelerated_compositing_active_ && web_layer_tree_view_) {
856 web_layer_tree_view_->layer_tree_host()->updateAnimations(
857 base::TimeTicks::Now());
858 } else {
859 webwidget_->animate(0.0);
860 }
845 return; 861 return;
846 } 862 }
847 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently"); 863 TRACE_EVENT0("renderer", "EarlyOut_AnimatedTooRecently");
848 if (!animation_timer_.IsRunning()) { 864 if (!animation_timer_.IsRunning()) {
849 // 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
850 // time because javascript's Date object uses base::Time::Now(). The 866 // time because javascript's Date object uses base::Time::Now(). The
851 // message loop uses base::TimeTicks, which on windows can have a 867 // message loop uses base::TimeTicks, which on windows can have a
852 // different granularity than base::Time. 868 // different granularity than base::Time.
853 // 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
854 // base::Time::Now() has advanced past the animation_floor_time_. To 870 // base::Time::Now() has advanced past the animation_floor_time_. To
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 using_asynchronous_swapbuffers_ = false; 1237 using_asynchronous_swapbuffers_ = false;
1222 1238
1223 // 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
1224 // DoDeferredUpdate() if appropriate. In threaded compositing mode, 1240 // DoDeferredUpdate() if appropriate. In threaded compositing mode,
1225 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and 1241 // DoDeferredUpdate() is bypassed and WebKit is responsible for exiting and
1226 // entering force compositing mode at the appropriate times. 1242 // entering force compositing mode at the appropriate times.
1227 if (!is_threaded_compositing_enabled_) 1243 if (!is_threaded_compositing_enabled_)
1228 webwidget_->enterForceCompositingMode(false); 1244 webwidget_->enterForceCompositingMode(false);
1229 } 1245 }
1230 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
1231 void RenderWidget::willBeginCompositorFrame() { 1274 void RenderWidget::willBeginCompositorFrame() {
1232 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame"); 1275 TRACE_EVENT0("gpu", "RenderWidget::willBeginCompositorFrame");
1233 1276
1234 DCHECK(RenderThreadImpl::current()->compositor_thread()); 1277 DCHECK(RenderThreadImpl::current()->compositor_thread());
1235 1278
1236 // The following two can result in further layout and possibly 1279 // The following two can result in further layout and possibly
1237 // 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
1238 // is done. 1281 // is done.
1239 UpdateTextInputState(DO_NOT_SHOW_IME); 1282 UpdateTextInputState(DO_NOT_SHOW_IME);
1240 UpdateSelectionBounds(); 1283 UpdateSelectionBounds();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 // 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
1373 // 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
1374 // 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
1375 // complete, and then the Close message can be sent. 1418 // complete, and then the Close message can be sent.
1376 MessageLoop::current()->PostTask( 1419 MessageLoop::current()->PostTask(
1377 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this)); 1420 FROM_HERE, base::Bind(&RenderWidget::DoDeferredClose, this));
1378 } 1421 }
1379 1422
1380 void RenderWidget::Close() { 1423 void RenderWidget::Close() {
1381 if (webwidget_) { 1424 if (webwidget_) {
1425 web_layer_tree_view_.reset();
1382 webwidget_->close(); 1426 webwidget_->close();
1383 webwidget_ = NULL; 1427 webwidget_ = NULL;
1384 } 1428 }
1385 } 1429 }
1386 1430
1387 WebRect RenderWidget::windowRect() { 1431 WebRect RenderWidget::windowRect() {
1388 if (pending_window_rect_count_) 1432 if (pending_window_rect_count_)
1389 return pending_window_rect_; 1433 return pending_window_rect_;
1390 1434
1391 return view_screen_rect_; 1435 return view_screen_rect_;
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1629
1586 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size())); 1630 Send(new ViewHostMsg_PaintAtSize_ACK(routing_id_, tag, bounds.size()));
1587 } 1631 }
1588 1632
1589 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) { 1633 void RenderWidget::OnRepaint(const gfx::Size& size_to_paint) {
1590 // During shutdown we can just ignore this message. 1634 // During shutdown we can just ignore this message.
1591 if (!webwidget_) 1635 if (!webwidget_)
1592 return; 1636 return;
1593 1637
1594 set_next_paint_is_repaint_ack(); 1638 set_next_paint_is_repaint_ack();
1595 if (is_accelerated_compositing_active_) { 1639 if (is_accelerated_compositing_active_/* && web_layer_tree_view_*/) {
Sami 2013/01/07 14:42:49 Drive by nit: comment left in by mistake?
1596 webwidget_->setNeedsRedraw(); 1640 if (web_layer_tree_view_)
1641 web_layer_tree_view_->setNeedsRedraw();
1597 scheduleComposite(); 1642 scheduleComposite();
1598 } else { 1643 } else {
1599 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); 1644 gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height());
1600 didInvalidateRect(repaint_rect); 1645 didInvalidateRect(repaint_rect);
1601 } 1646 }
1602 } 1647 }
1603 1648
1604 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) { 1649 void RenderWidget::OnSmoothScrollCompleted(int gesture_id) {
1605 PendingSmoothScrollGestureMap::iterator it = 1650 PendingSmoothScrollGestureMap::iterator it =
1606 pending_smooth_scroll_gestures_.find(gesture_id); 1651 pending_smooth_scroll_gestures_.find(gesture_id);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 i != plugin_window_moves_.end(); ++i) { 1965 i != plugin_window_moves_.end(); ++i) {
1921 if (i->window == window) { 1966 if (i->window == window) {
1922 plugin_window_moves_.erase(i); 1967 plugin_window_moves_.erase(i);
1923 break; 1968 break;
1924 } 1969 }
1925 } 1970 }
1926 } 1971 }
1927 1972
1928 void RenderWidget::GetRenderingStats( 1973 void RenderWidget::GetRenderingStats(
1929 WebKit::WebRenderingStatsImpl& stats) const { 1974 WebKit::WebRenderingStatsImpl& stats) const {
1930 webwidget()->renderingStats(stats); 1975 if (web_layer_tree_view_)
1976 web_layer_tree_view_->renderingStats(stats);
1931 1977
1932 stats.rendering_stats.numAnimationFrames += 1978 stats.rendering_stats.numAnimationFrames +=
1933 software_stats_.numAnimationFrames; 1979 software_stats_.numAnimationFrames;
1934 stats.rendering_stats.numFramesSentToScreen += 1980 stats.rendering_stats.numFramesSentToScreen +=
1935 software_stats_.numFramesSentToScreen; 1981 software_stats_.numFramesSentToScreen;
1936 stats.rendering_stats.totalPaintTimeInSeconds += 1982 stats.rendering_stats.totalPaintTimeInSeconds +=
1937 software_stats_.totalPaintTimeInSeconds; 1983 software_stats_.totalPaintTimeInSeconds;
1938 stats.rendering_stats.totalPixelsPainted += 1984 stats.rendering_stats.totalPixelsPainted +=
1939 software_stats_.totalPixelsPainted; 1985 software_stats_.totalPixelsPainted;
1940 stats.rendering_stats.totalRasterizeTimeInSeconds += 1986 stats.rendering_stats.totalRasterizeTimeInSeconds +=
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1981 2027
1982 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const { 2028 bool RenderWidget::WebWidgetHandlesCompositorScheduling() const {
1983 return false; 2029 return false;
1984 } 2030 }
1985 2031
1986 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const { 2032 bool RenderWidget::HasTouchEventHandlersAt(const gfx::Point& point) const {
1987 return true; 2033 return true;
1988 } 2034 }
1989 2035
1990 } // namespace content 2036 } // 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