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

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 9980016: Delete background tab IOSurfaces on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed auto-resize and fullscreen toggle Created 8 years, 7 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
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/browser/renderer_host/render_widget_host_impl.h" 5 #include "content/browser/renderer_host/render_widget_host_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 using WebKit::WebMouseEvent; 58 using WebKit::WebMouseEvent;
59 using WebKit::WebMouseWheelEvent; 59 using WebKit::WebMouseWheelEvent;
60 using WebKit::WebTextDirection; 60 using WebKit::WebTextDirection;
61 61
62 namespace { 62 namespace {
63 63
64 // How long to (synchronously) wait for the renderer to respond with a 64 // How long to (synchronously) wait for the renderer to respond with a
65 // PaintRect message, when our backing-store is invalid, before giving up and 65 // PaintRect message, when our backing-store is invalid, before giving up and
66 // returning a null or incorrectly sized backing-store from GetBackingStore. 66 // returning a null or incorrectly sized backing-store from GetBackingStore.
67 // This timeout impacts the "choppiness" of our window resize perf. 67 // This timeout impacts the "choppiness" of our window resize perf.
68 static const int kPaintMsgTimeoutMS = 40; 68 static const int kPaintMsgTimeoutMS = 50;
69 69
70 // How long to wait before we consider a renderer hung. 70 // How long to wait before we consider a renderer hung.
71 static const int kHungRendererDelayMs = 20000; 71 static const int kHungRendererDelayMs = 20000;
72 72
73 // Returns |true| if the two wheel events should be coalesced. 73 // Returns |true| if the two wheel events should be coalesced.
74 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, 74 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event,
75 const WebMouseWheelEvent& new_event) { 75 const WebMouseWheelEvent& new_event) {
76 return last_event.modifiers == new_event.modifiers && 76 return last_event.modifiers == new_event.modifiers &&
77 last_event.scrollByPage == new_event.scrollByPage && 77 last_event.scrollByPage == new_event.scrollByPage &&
78 last_event.hasPreciseScrollingDeltas 78 last_event.hasPreciseScrollingDeltas
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 is_accelerated_compositing_active_(false), 112 is_accelerated_compositing_active_(false),
113 repaint_ack_pending_(false), 113 repaint_ack_pending_(false),
114 resize_ack_pending_(false), 114 resize_ack_pending_(false),
115 should_auto_resize_(false), 115 should_auto_resize_(false),
116 mouse_move_pending_(false), 116 mouse_move_pending_(false),
117 mouse_wheel_pending_(false), 117 mouse_wheel_pending_(false),
118 needs_repainting_on_restore_(false), 118 needs_repainting_on_restore_(false),
119 is_unresponsive_(false), 119 is_unresponsive_(false),
120 in_flight_event_count_(0), 120 in_flight_event_count_(0),
121 in_get_backing_store_(false), 121 in_get_backing_store_(false),
122 abort_get_backing_store_(false),
122 view_being_painted_(false), 123 view_being_painted_(false),
123 ignore_input_events_(false), 124 ignore_input_events_(false),
124 text_direction_updated_(false), 125 text_direction_updated_(false),
125 text_direction_(WebKit::WebTextDirectionLeftToRight), 126 text_direction_(WebKit::WebTextDirectionLeftToRight),
126 text_direction_canceled_(false), 127 text_direction_canceled_(false),
127 suppress_next_char_events_(false), 128 suppress_next_char_events_(false),
128 pending_mouse_lock_request_(false), 129 pending_mouse_lock_request_(false),
129 has_touch_handler_(false), 130 has_touch_handler_(false),
130 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 131 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
131 tap_suppression_controller_(new TapSuppressionController(this)) { 132 tap_suppression_controller_(new TapSuppressionController(this)) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { 251 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) {
251 bool handled = true; 252 bool handled = true;
252 bool msg_is_ok = true; 253 bool msg_is_ok = true;
253 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok) 254 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok)
254 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) 255 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady)
255 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) 256 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone)
256 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) 257 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose)
257 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) 258 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove)
258 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText) 259 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText)
259 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) 260 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck)
261 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped,
262 OnCompositorSurfaceBuffersSwapped)
260 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) 263 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect)
261 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed) 264 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed)
262 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) 265 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck)
263 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) 266 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus)
264 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) 267 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur)
265 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumTouchEvents, 268 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumTouchEvents,
266 OnMsgDidChangeNumTouchEvents) 269 OnMsgDidChangeNumTouchEvents)
267 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) 270 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor)
268 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, 271 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged,
269 OnMsgTextInputStateChanged) 272 OnMsgTextInputStateChanged)
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 int tag, 570 int tag,
568 const gfx::Size& page_size, 571 const gfx::Size& page_size,
569 const gfx::Size& desired_size) { 572 const gfx::Size& desired_size) {
570 // Ask the renderer to create a bitmap regardless of whether it's 573 // Ask the renderer to create a bitmap regardless of whether it's
571 // hidden, being resized, redrawn, etc. It resizes the web widget 574 // hidden, being resized, redrawn, etc. It resizes the web widget
572 // to the page_size and then scales it to the desired_size. 575 // to the page_size and then scales it to the desired_size.
573 Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle, tag, 576 Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle, tag,
574 page_size, desired_size)); 577 page_size, desired_size));
575 } 578 }
576 579
580 bool RenderWidgetHostImpl::TryGetBackingStore(const gfx::Size& desired_size,
581 BackingStore** backing_store) {
582 // Check if the view has an accelerated surface of the desired size.
583 if (view_->HasAcceleratedSurface(desired_size)) {
584 *backing_store = NULL;
585 return true;
586 }
587
588 // Check for a software backing store of the desired size.
589 *backing_store = BackingStoreManager::GetBackingStore(this, desired_size);
590 return !!*backing_store;
591 }
592
577 BackingStore* RenderWidgetHostImpl::GetBackingStore(bool force_create) { 593 BackingStore* RenderWidgetHostImpl::GetBackingStore(bool force_create) {
594 if (!view_)
595 return NULL;
596
597 // The view_size will be current_size_ for auto-sized views and otherwise the
598 // size of the view_. (For auto-sized views, current_size_ is updated during
599 // UpdateRect messages.)
600 gfx::Size view_size = current_size_;
601 if (!should_auto_resize_) {
602 // Get the desired size from the current view bounds.
603 gfx::Rect view_rect = view_->GetViewBounds();
604 if (view_rect.IsEmpty())
605 return NULL;
606 view_size = view_rect.size();
607 }
608
578 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::GetBackingStore", 609 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::GetBackingStore",
579 "width", base::IntToString(current_size_.width()), 610 "width", base::IntToString(view_size.width()),
580 "height", base::IntToString(current_size_.height())); 611 "height", base::IntToString(view_size.height()));
581 612
582 // We should not be asked to paint while we are hidden. If we are hidden, 613 // We should not be asked to paint while we are hidden. If we are hidden,
583 // then it means that our consumer failed to call WasRestored. If we're not 614 // then it means that our consumer failed to call WasRestored. If we're not
584 // force creating the backing store, it's OK since we can feel free to give 615 // force creating the backing store, it's OK since we can feel free to give
585 // out our cached one if we have it. 616 // out our cached one if we have it.
586 DCHECK(!is_hidden_ || !force_create) << 617 DCHECK(!is_hidden_ || !force_create) <<
587 "GetBackingStore called while hidden!"; 618 "GetBackingStore called while hidden!";
588 619
589 // We should never be called recursively; this can theoretically lead to 620 // We should never be called recursively; this can theoretically lead to
590 // infinite recursion and almost certainly leads to lower performance. 621 // infinite recursion and almost certainly leads to lower performance.
591 DCHECK(!in_get_backing_store_) << "GetBackingStore called recursively!"; 622 DCHECK(!in_get_backing_store_) << "GetBackingStore called recursively!";
592 AutoReset<bool> auto_reset_in_get_backing_store(&in_get_backing_store_, true); 623 AutoReset<bool> auto_reset_in_get_backing_store(&in_get_backing_store_, true);
593 624
594 // We might have a cached backing store that we can reuse! 625 // We might have a cached backing store that we can reuse!
595 BackingStore* backing_store = 626 BackingStore* backing_store = NULL;
596 BackingStoreManager::GetBackingStore(this, current_size_); 627 if (TryGetBackingStore(view_size, &backing_store) || !force_create)
597 if (!force_create)
598 return backing_store; 628 return backing_store;
599 629
600 // If we fail to find a backing store in the cache, send out a request 630 // We do not have a suitable backing store in the cache, so send out a
601 // to the renderer to paint the view if required. 631 // request to the renderer to paint the view if required.
602 if (!backing_store && !repaint_ack_pending_ && !resize_ack_pending_ && 632 if (!repaint_ack_pending_ && !resize_ack_pending_ && !view_being_painted_) {
603 !view_being_painted_) {
604 repaint_start_time_ = TimeTicks::Now(); 633 repaint_start_time_ = TimeTicks::Now();
605 repaint_ack_pending_ = true; 634 repaint_ack_pending_ = true;
606 Send(new ViewMsg_Repaint(routing_id_, current_size_)); 635 Send(new ViewMsg_Repaint(routing_id_, view_size));
607 } 636 }
608 637
609 // When we have asked the RenderWidget to resize, and we are still waiting on 638 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS);
610 // a response, block for a little while to see if we can't get a response 639 TimeTicks end_time = TimeTicks::Now() + max_delay;
611 // before returning the old (incorrectly sized) backing store. 640 do {
612 if (resize_ack_pending_ || !backing_store) { 641 TRACE_EVENT0("renderer_host", "GetBackingStore::WaitForUpdate");
642
643 // When we have asked the RenderWidget to resize, and we are still waiting
644 // on a response, block for a little while to see if we can't get a response
645 // before returning the old (incorrectly sized) backing store.
613 IPC::Message msg; 646 IPC::Message msg;
614 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); 647 if (process_->WaitForBackingStoreMsg(routing_id_, max_delay, &msg)) {
615 if (process_->WaitForUpdateMsg(routing_id_, max_delay, &msg)) {
616 OnMessageReceived(msg); 648 OnMessageReceived(msg);
617 backing_store = BackingStoreManager::GetBackingStore(this, current_size_); 649
650 // For auto-resized views, current_size_ determines the view_size and it
651 // may have changed during the handling of an UpdateRect message.
652 if (should_auto_resize_)
653 view_size = current_size_;
654
655 // Break now if we got a backing store or accelerated surface of the
656 // correct size.
657 if (TryGetBackingStore(view_size, &backing_store) ||
658 abort_get_backing_store_) {
659 abort_get_backing_store_ = false;
660 return backing_store;
661 }
662 } else {
663 TRACE_EVENT0("renderer_host", "GetBackingStore::Timeout");
664 break;
618 } 665 }
619 }
620 666
667 // Loop if we still have time left and haven't gotten a properly sized
668 // BackingStore yet. This is necessary to support the GPU path which
669 // typically has multiple frames pipelined -- we may need to skip one or two
670 // BackingStore messages to get to the latest.
671 max_delay = end_time - TimeTicks::Now();
672 } while (max_delay > TimeDelta::FromSeconds(0));
673
674 // We have failed to get a backing store of view_size. Fall back on
675 // current_size_ to avoid a white flash while resizing slow pages.
676 if (view_size != current_size_)
677 TryGetBackingStore(current_size_, &backing_store);
621 return backing_store; 678 return backing_store;
622 } 679 }
623 680
624 BackingStore* RenderWidgetHostImpl::AllocBackingStore(const gfx::Size& size) { 681 BackingStore* RenderWidgetHostImpl::AllocBackingStore(const gfx::Size& size) {
625 if (!view_) 682 if (!view_)
626 return NULL; 683 return NULL;
627 return view_->AllocBackingStore(size); 684 return view_->AllocBackingStore(size);
628 } 685 }
629 686
630 void RenderWidgetHostImpl::DonePaintingToBackingStore() { 687 void RenderWidgetHostImpl::DonePaintingToBackingStore() {
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 } 1193 }
1137 1194
1138 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { 1195 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) {
1139 std::pair<int, gfx::Size> details = std::make_pair(tag, size); 1196 std::pair<int, gfx::Size> details = std::make_pair(tag, size);
1140 NotificationService::current()->Notify( 1197 NotificationService::current()->Notify(
1141 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, 1198 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
1142 Source<RenderWidgetHost>(this), 1199 Source<RenderWidgetHost>(this),
1143 Details<std::pair<int, gfx::Size> >(&details)); 1200 Details<std::pair<int, gfx::Size> >(&details));
1144 } 1201 }
1145 1202
1203 void RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped(
1204 int32 surface_id,
1205 uint64 surface_handle,
1206 int32 route_id,
1207 int32 gpu_process_host_id) {
1208 TRACE_EVENT0("renderer_host",
1209 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped");
1210 if (!view_) {
1211 RenderWidgetHostImpl::AcknowledgeSwapBuffers(route_id,
1212 gpu_process_host_id);
1213 return;
1214 }
1215 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params gpu_params;
1216 gpu_params.surface_id = surface_id;
1217 gpu_params.surface_handle = surface_handle;
1218 gpu_params.route_id = route_id;
1219 #if defined(OS_MACOSX)
1220 // Compositor window is always gfx::kNullPluginWindow.
1221 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no
1222 // plugin windows.
1223 gpu_params.window = gfx::kNullPluginWindow;
1224 #endif
1225 view_->AcceleratedSurfaceBuffersSwapped(gpu_params,
1226 gpu_process_host_id);
1227 }
1228
1146 void RenderWidgetHostImpl::OnMsgUpdateRect( 1229 void RenderWidgetHostImpl::OnMsgUpdateRect(
1147 const ViewHostMsg_UpdateRect_Params& params) { 1230 const ViewHostMsg_UpdateRect_Params& params) {
1148 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect"); 1231 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect");
1149 TimeTicks paint_start = TimeTicks::Now(); 1232 TimeTicks paint_start = TimeTicks::Now();
1150 1233
1151 // Update our knowledge of the RenderWidget's size. 1234 // Update our knowledge of the RenderWidget's size.
1152 current_size_ = params.view_size; 1235 current_size_ = params.view_size;
1153 // Update our knowledge of the RenderWidget's scroll offset. 1236 // Update our knowledge of the RenderWidget's scroll offset.
1154 last_scroll_offset_ = params.scroll_offset; 1237 last_scroll_offset_ = params.scroll_offset;
1155 1238
(...skipping 12 matching lines...) Expand all
1168 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); 1251 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags);
1169 if (is_repaint_ack) { 1252 if (is_repaint_ack) {
1170 repaint_ack_pending_ = false; 1253 repaint_ack_pending_ = false;
1171 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; 1254 TimeDelta delta = TimeTicks::Now() - repaint_start_time_;
1172 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); 1255 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta);
1173 } 1256 }
1174 1257
1175 DCHECK(!params.view_size.IsEmpty()); 1258 DCHECK(!params.view_size.IsEmpty());
1176 1259
1177 bool was_async = false; 1260 bool was_async = false;
1178 if (!is_accelerated_compositing_active_) { 1261
1262 // If this is a GPU UpdateRect, params.bitmap is invalid and dib will be NULL.
1263 TransportDIB* dib = process_->GetTransportDIB(params.bitmap);
1264
1265 // If gpu process does painting, scroll_rect and copy_rects are always empty
1266 // and backing store is never used.
1267 if (dib) {
1179 DCHECK(!params.bitmap_rect.IsEmpty()); 1268 DCHECK(!params.bitmap_rect.IsEmpty());
1180 const size_t size = params.bitmap_rect.height() * 1269 const size_t size = params.bitmap_rect.height() *
1181 params.bitmap_rect.width() * 4; 1270 params.bitmap_rect.width() * 4;
1182 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); 1271 if (dib->size() < size) {
1272 DLOG(WARNING) << "Transport DIB too small for given rectangle";
1273 RecordAction(UserMetricsAction("BadMessageTerminate_RWH1"));
1274 GetProcess()->ReceivedBadMessage();
1275 } else {
1276 UNSHIPPED_TRACE_EVENT_INSTANT2("test_latency", "UpdateRect",
1277 "x+y", params.bitmap_rect.x() + params.bitmap_rect.y(),
1278 "color", 0xffffff & *static_cast<uint32*>(dib->memory()));
1279 UNSHIPPED_TRACE_EVENT_INSTANT1("test_latency", "UpdateRectWidth",
1280 "width", params.bitmap_rect.width());
1183 1281
1184 // If gpu process does painting, scroll_rect and copy_rects are always empty 1282 // Scroll the backing store.
1185 // and backing store is never used. 1283 if (!params.scroll_rect.IsEmpty()) {
1186 if (dib) { 1284 ScrollBackingStoreRect(params.dx, params.dy,
1187 if (dib->size() < size) { 1285 params.scroll_rect,
1188 DLOG(WARNING) << "Transport DIB too small for given rectangle"; 1286 params.view_size);
1189 RecordAction(UserMetricsAction("BadMessageTerminate_RWH1")); 1287 }
1190 GetProcess()->ReceivedBadMessage();
1191 } else {
1192 UNSHIPPED_TRACE_EVENT_INSTANT2("test_latency", "UpdateRect",
1193 "x+y", params.bitmap_rect.x() + params.bitmap_rect.y(),
1194 "color", 0xffffff & *static_cast<uint32*>(dib->memory()));
1195 UNSHIPPED_TRACE_EVENT_INSTANT1("test_latency", "UpdateRectWidth",
1196 "width", params.bitmap_rect.width());
1197 1288
1198 // Scroll the backing store. 1289 // Paint the backing store. This will update it with the
1199 if (!params.scroll_rect.IsEmpty()) { 1290 // renderer-supplied bits. The view will read out of the backing store
1200 ScrollBackingStoreRect(params.dx, params.dy, 1291 // later to actually draw to the screen.
1201 params.scroll_rect, 1292 was_async = PaintBackingStoreRect(
1202 params.view_size); 1293 params.bitmap,
1203 } 1294 params.bitmap_rect,
1204 1295 params.copy_rects,
1205 // Paint the backing store. This will update it with the 1296 params.view_size,
1206 // renderer-supplied bits. The view will read out of the backing store 1297 base::Bind(&RenderWidgetHostImpl::DidUpdateBackingStore,
1207 // later to actually draw to the screen. 1298 weak_factory_.GetWeakPtr(), params, paint_start));
1208 was_async = PaintBackingStoreRect(
1209 params.bitmap,
1210 params.bitmap_rect,
1211 params.copy_rects,
1212 params.view_size,
1213 base::Bind(&RenderWidgetHostImpl::DidUpdateBackingStore,
1214 weak_factory_.GetWeakPtr(), params, paint_start));
1215 }
1216 } 1299 }
1217 } 1300 }
1218 1301
1219 if (!was_async) { 1302 if (!was_async) {
1220 DidUpdateBackingStore(params, paint_start); 1303 DidUpdateBackingStore(params, paint_start);
1221 } 1304 }
1222 1305
1223 if (should_auto_resize_) { 1306 if (should_auto_resize_) {
1224 bool post_callback = new_auto_size_.IsEmpty(); 1307 bool post_callback = new_auto_size_.IsEmpty();
1225 new_auto_size_ = params.view_size; 1308 new_auto_size_ = params.view_size;
1226 if (post_callback) { 1309 if (post_callback) {
1227 MessageLoop::current()->PostTask( 1310 MessageLoop::current()->PostTask(
1228 FROM_HERE, 1311 FROM_HERE,
1229 base::Bind(&RenderWidgetHostImpl::DelayedAutoResized, 1312 base::Bind(&RenderWidgetHostImpl::DelayedAutoResized,
1230 weak_factory_.GetWeakPtr())); 1313 weak_factory_.GetWeakPtr()));
1231 } 1314 }
1232 } 1315 }
1233 1316
1234 // Log the time delta for processing a paint message. On platforms that don't 1317 // Log the time delta for processing a paint message. On platforms that don't
1235 // support asynchronous painting, this is equivalent to 1318 // support asynchronous painting, this is equivalent to
1236 // MPArch.RWH_TotalPaintTime. 1319 // MPArch.RWH_TotalPaintTime.
1237 TimeDelta delta = TimeTicks::Now() - paint_start; 1320 TimeDelta delta = TimeTicks::Now() - paint_start;
1238 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta); 1321 UMA_HISTOGRAM_TIMES("MPArch.RWH_OnMsgUpdateRect", delta);
1239 } 1322 }
1240 1323
1241 void RenderWidgetHostImpl::OnMsgUpdateIsDelayed() { 1324 void RenderWidgetHostImpl::OnMsgUpdateIsDelayed() {
1242 // Nothing to do, this message was just to unblock the UI thread. 1325 if (in_get_backing_store_)
1326 abort_get_backing_store_ = true;
1243 } 1327 }
1244 1328
1245 void RenderWidgetHostImpl::DidUpdateBackingStore( 1329 void RenderWidgetHostImpl::DidUpdateBackingStore(
1246 const ViewHostMsg_UpdateRect_Params& params, 1330 const ViewHostMsg_UpdateRect_Params& params,
1247 const TimeTicks& paint_start) { 1331 const TimeTicks& paint_start) {
1248 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore"); 1332 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore");
1249 TimeTicks update_start = TimeTicks::Now(); 1333 TimeTicks update_start = TimeTicks::Now();
1250 1334
1251 if (params.needs_ack) { 1335 if (params.needs_ack) {
1252 // ACK early so we can prefetch the next PaintRect if there is a next one. 1336 // ACK early so we can prefetch the next PaintRect if there is a next one.
(...skipping 26 matching lines...) Expand all
1279 } 1363 }
1280 1364
1281 NotificationService::current()->Notify( 1365 NotificationService::current()->Notify(
1282 NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, 1366 NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT,
1283 Source<RenderWidgetHost>(this), 1367 Source<RenderWidgetHost>(this),
1284 NotificationService::NoDetails()); 1368 NotificationService::NoDetails());
1285 1369
1286 // If we got a resize ack, then perhaps we have another resize to send? 1370 // If we got a resize ack, then perhaps we have another resize to send?
1287 bool is_resize_ack = 1371 bool is_resize_ack =
1288 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); 1372 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags);
1289 if (is_resize_ack && view_) { 1373 if (is_resize_ack)
1290 gfx::Rect view_bounds = view_->GetViewBounds(); 1374 WasResized();
1291 if (current_size_ != view_bounds.size())
1292 WasResized();
1293 }
1294 1375
1295 // Log the time delta for processing a paint message. 1376 // Log the time delta for processing a paint message.
1296 TimeTicks now = TimeTicks::Now(); 1377 TimeTicks now = TimeTicks::Now();
1297 TimeDelta delta = now - update_start; 1378 TimeDelta delta = now - update_start;
1298 UMA_HISTOGRAM_TIMES("MPArch.RWH_DidUpdateBackingStore", delta); 1379 UMA_HISTOGRAM_TIMES("MPArch.RWH_DidUpdateBackingStore", delta);
1299 1380
1300 // Measures the time from receiving the MsgUpdateRect IPC to completing the 1381 // Measures the time from receiving the MsgUpdateRect IPC to completing the
1301 // DidUpdateBackingStore() method. On platforms which have asynchronous 1382 // DidUpdateBackingStore() method. On platforms which have asynchronous
1302 // painting, such as Linux, this is the sum of MPArch.RWH_OnMsgUpdateRect, 1383 // painting, such as Linux, this is the sum of MPArch.RWH_OnMsgUpdateRect,
1303 // MPArch.RWH_DidUpdateBackingStore, and the time spent asynchronously 1384 // MPArch.RWH_DidUpdateBackingStore, and the time spent asynchronously
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 // indicate that no callback is in progress (i.e. without this line 1807 // indicate that no callback is in progress (i.e. without this line
1727 // DelayedAutoResized will not get called again). 1808 // DelayedAutoResized will not get called again).
1728 new_auto_size_.SetSize(0, 0); 1809 new_auto_size_.SetSize(0, 0);
1729 if (!should_auto_resize_) 1810 if (!should_auto_resize_)
1730 return; 1811 return;
1731 1812
1732 OnRenderAutoResized(new_size); 1813 OnRenderAutoResized(new_size);
1733 } 1814 }
1734 1815
1735 } // namespace content 1816 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.h ('k') | content/browser/renderer_host/render_widget_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698