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

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: comments and piman feedback Created 8 years, 8 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) { 250 bool RenderWidgetHostImpl::OnMessageReceived(const IPC::Message &msg) {
251 bool handled = true; 251 bool handled = true;
252 bool msg_is_ok = true; 252 bool msg_is_ok = true;
253 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok) 253 IPC_BEGIN_MESSAGE_MAP_EX(RenderWidgetHostImpl, msg, msg_is_ok)
254 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady) 254 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewReady, OnMsgRenderViewReady)
255 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone) 255 IPC_MESSAGE_HANDLER(ViewHostMsg_RenderViewGone, OnMsgRenderViewGone)
256 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose) 256 IPC_MESSAGE_HANDLER(ViewHostMsg_Close, OnMsgClose)
257 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove) 257 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestMove, OnMsgRequestMove)
258 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText) 258 IPC_MESSAGE_HANDLER(ViewHostMsg_SetTooltipText, OnMsgSetTooltipText)
259 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck) 259 IPC_MESSAGE_HANDLER(ViewHostMsg_PaintAtSize_ACK, OnMsgPaintAtSizeAck)
260 IPC_MESSAGE_HANDLER(ViewHostMsg_CompositorSurfaceBuffersSwapped,
261 OnCompositorSurfaceBuffersSwapped)
260 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect) 262 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateRect, OnMsgUpdateRect)
261 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed) 263 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateIsDelayed, OnMsgUpdateIsDelayed)
262 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck) 264 IPC_MESSAGE_HANDLER(ViewHostMsg_HandleInputEvent_ACK, OnMsgInputEventAck)
263 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus) 265 IPC_MESSAGE_HANDLER(ViewHostMsg_Focus, OnMsgFocus)
264 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur) 266 IPC_MESSAGE_HANDLER(ViewHostMsg_Blur, OnMsgBlur)
265 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumTouchEvents, 267 IPC_MESSAGE_HANDLER(ViewHostMsg_DidChangeNumTouchEvents,
266 OnMsgDidChangeNumTouchEvents) 268 OnMsgDidChangeNumTouchEvents)
267 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor) 269 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCursor, OnMsgSetCursor)
268 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged, 270 IPC_MESSAGE_HANDLER(ViewHostMsg_TextInputStateChanged,
269 OnMsgTextInputStateChanged) 271 OnMsgTextInputStateChanged)
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 const gfx::Size& page_size, 570 const gfx::Size& page_size,
569 const gfx::Size& desired_size) { 571 const gfx::Size& desired_size) {
570 // Ask the renderer to create a bitmap regardless of whether it's 572 // Ask the renderer to create a bitmap regardless of whether it's
571 // hidden, being resized, redrawn, etc. It resizes the web widget 573 // hidden, being resized, redrawn, etc. It resizes the web widget
572 // to the page_size and then scales it to the desired_size. 574 // to the page_size and then scales it to the desired_size.
573 Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle, tag, 575 Send(new ViewMsg_PaintAtSize(routing_id_, dib_handle, tag,
574 page_size, desired_size)); 576 page_size, desired_size));
575 } 577 }
576 578
577 BackingStore* RenderWidgetHostImpl::GetBackingStore(bool force_create) { 579 BackingStore* RenderWidgetHostImpl::GetBackingStore(bool force_create) {
580 if (!view_)
581 return NULL;
582
583 // Get the desired size from the current view bounds.
584 gfx::Rect view_rect = view_->GetViewBounds();
585 if (view_rect.IsEmpty())
586 return NULL;
587 gfx::Size view_size = view_rect.size();
588
578 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::GetBackingStore", 589 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::GetBackingStore",
579 "width", base::IntToString(current_size_.width()), 590 "width", base::IntToString(view_size.width()),
580 "height", base::IntToString(current_size_.height())); 591 "height", base::IntToString(view_size.height()));
581 592
582 // We should not be asked to paint while we are hidden. If we are hidden, 593 // 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 594 // 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 595 // force creating the backing store, it's OK since we can feel free to give
585 // out our cached one if we have it. 596 // out our cached one if we have it.
586 DCHECK(!is_hidden_ || !force_create) << 597 DCHECK(!is_hidden_ || !force_create) <<
587 "GetBackingStore called while hidden!"; 598 "GetBackingStore called while hidden!";
588 599
589 // We should never be called recursively; this can theoretically lead to 600 // We should never be called recursively; this can theoretically lead to
590 // infinite recursion and almost certainly leads to lower performance. 601 // infinite recursion and almost certainly leads to lower performance.
591 DCHECK(!in_get_backing_store_) << "GetBackingStore called recursively!"; 602 DCHECK(!in_get_backing_store_) << "GetBackingStore called recursively!";
592 AutoReset<bool> auto_reset_in_get_backing_store(&in_get_backing_store_, true); 603 AutoReset<bool> auto_reset_in_get_backing_store(&in_get_backing_store_, true);
593 604
605 // If there's an accelerated surface, return NULL now. The caller will need
606 // to confirm whether there is an accelerated frame after GetBackingStore
607 // returns.
608 if (view_->HasAcceleratedSurface(view_size))
609 return NULL;
610
594 // We might have a cached backing store that we can reuse! 611 // We might have a cached backing store that we can reuse!
595 BackingStore* backing_store = 612 BackingStore* backing_store =
596 BackingStoreManager::GetBackingStore(this, current_size_); 613 BackingStoreManager::GetBackingStore(this, view_size);
597 if (!force_create) 614 if (!force_create)
598 return backing_store; 615 return backing_store;
599 616
600 // If we fail to find a backing store in the cache, send out a request 617 // If we fail to find a backing store in the cache, send out a request
601 // to the renderer to paint the view if required. 618 // to the renderer to paint the view if required.
602 if (!backing_store && !repaint_ack_pending_ && !resize_ack_pending_ && 619 if (!backing_store && !repaint_ack_pending_ && !resize_ack_pending_ &&
603 !view_being_painted_) { 620 !view_being_painted_) {
604 repaint_start_time_ = TimeTicks::Now(); 621 repaint_start_time_ = TimeTicks::Now();
605 repaint_ack_pending_ = true; 622 repaint_ack_pending_ = true;
606 Send(new ViewMsg_Repaint(routing_id_, current_size_)); 623 Send(new ViewMsg_Repaint(routing_id_, view_size));
607 } 624 }
608 625
609 // When we have asked the RenderWidget to resize, and we are still waiting on 626 // When we have asked the RenderWidget to resize, and we are still waiting on
610 // a response, block for a little while to see if we can't get a response 627 // a response, block for a little while to see if we can't get a response
611 // before returning the old (incorrectly sized) backing store. 628 // before returning the old (incorrectly sized) backing store.
612 if (resize_ack_pending_ || !backing_store) { 629 if (resize_ack_pending_ || !backing_store) {
613 IPC::Message msg; 630 IPC::Message msg;
614 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS); 631 TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS);
615 if (process_->WaitForUpdateMsg(routing_id_, max_delay, &msg)) { 632 TimeTicks end_time = TimeTicks::Now() + max_delay;
616 OnMessageReceived(msg); 633 do {
617 backing_store = BackingStoreManager::GetBackingStore(this, current_size_); 634 TRACE_EVENT0("renderer_host", "GetBackingStore::WaitForUpdate");
618 } 635
636 if (process_->WaitForUpdateMsg(routing_id_, max_delay, &msg)) {
637 OnMessageReceived(msg);
638 // Break now if we got a backing store or accelerated surface of the
639 // correct size.
640 if (view_->HasAcceleratedSurface(view_size))
darin (slow to review) 2012/04/20 17:11:27 nit: this snippet of code can also be found above.
jbates 2012/04/20 23:01:04 Done.
641 return NULL;
642 backing_store = BackingStoreManager::GetBackingStore(this, view_size);
643 if (backing_store)
644 return backing_store;
645 } else {
646 TRACE_EVENT0("renderer_host", "GetBackingStore::Timeout");
647 break;
648 }
649
650 // Loop if we still have time left and haven't gotten a properly sized
651 // frame yet. This is necessary to support the GPU path which typically
652 // has multiple frames pipelined -- we may need to skip one or two
653 // UpdateRects to get to the latest.
654 max_delay = end_time - TimeTicks::Now();
655 } while (max_delay > TimeDelta::FromSeconds(0));
619 } 656 }
620 657
658 // If we have still failed to get a backing store of view_size, fall back on
659 // current_size_ to attempt to avoid a white flash while resizing slow pages.
660 if (!backing_store)
661 backing_store = BackingStoreManager::GetBackingStore(this, current_size_);
662
621 return backing_store; 663 return backing_store;
622 } 664 }
623 665
624 BackingStore* RenderWidgetHostImpl::AllocBackingStore(const gfx::Size& size) { 666 BackingStore* RenderWidgetHostImpl::AllocBackingStore(const gfx::Size& size) {
625 if (!view_) 667 if (!view_)
626 return NULL; 668 return NULL;
627 return view_->AllocBackingStore(size); 669 return view_->AllocBackingStore(size);
628 } 670 }
629 671
630 void RenderWidgetHostImpl::DonePaintingToBackingStore() { 672 void RenderWidgetHostImpl::DonePaintingToBackingStore() {
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 } 1178 }
1137 1179
1138 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) { 1180 void RenderWidgetHostImpl::OnMsgPaintAtSizeAck(int tag, const gfx::Size& size) {
1139 std::pair<int, gfx::Size> details = std::make_pair(tag, size); 1181 std::pair<int, gfx::Size> details = std::make_pair(tag, size);
1140 NotificationService::current()->Notify( 1182 NotificationService::current()->Notify(
1141 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, 1183 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK,
1142 Source<RenderWidgetHost>(this), 1184 Source<RenderWidgetHost>(this),
1143 Details<std::pair<int, gfx::Size> >(&details)); 1185 Details<std::pair<int, gfx::Size> >(&details));
1144 } 1186 }
1145 1187
1188 void RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped(
1189 int32 surface_id,
1190 uint64 surface_handle,
1191 int32 route_id,
1192 int32 gpu_process_host_id) {
1193 TRACE_EVENT0("renderer_host",
1194 "RenderWidgetHostImpl::OnCompositorSurfaceBuffersSwapped");
1195 if (!view_) {
1196 RenderWidgetHostImpl::AcknowledgeSwapBuffers(route_id,
1197 gpu_process_host_id);
1198 return;
1199 }
1200 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params gpu_params;
1201 gpu_params.surface_id = surface_id;
1202 gpu_params.surface_handle = surface_handle;
1203 gpu_params.route_id = route_id;
1204 #if defined(OS_MACOSX)
1205 // Compositor window is always gfx::kNullPluginWindow.
1206 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no
1207 // plugin windows.
1208 gpu_params.window = gfx::kNullPluginWindow;
1209 #endif
1210 view_->AcceleratedSurfaceBuffersSwapped(gpu_params,
1211 gpu_process_host_id);
1212 }
1213
1146 void RenderWidgetHostImpl::OnMsgUpdateRect( 1214 void RenderWidgetHostImpl::OnMsgUpdateRect(
1147 const ViewHostMsg_UpdateRect_Params& params) { 1215 const ViewHostMsg_UpdateRect_Params& params) {
1148 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect"); 1216 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect");
1149 TimeTicks paint_start = TimeTicks::Now(); 1217 TimeTicks paint_start = TimeTicks::Now();
1150 1218
1151 // Update our knowledge of the RenderWidget's size. 1219 // Update our knowledge of the RenderWidget's size.
1152 current_size_ = params.view_size; 1220 current_size_ = params.view_size;
1153 // Update our knowledge of the RenderWidget's scroll offset. 1221 // Update our knowledge of the RenderWidget's scroll offset.
1154 last_scroll_offset_ = params.scroll_offset; 1222 last_scroll_offset_ = params.scroll_offset;
1155 1223
(...skipping 12 matching lines...) Expand all
1168 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); 1236 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags);
1169 if (is_repaint_ack) { 1237 if (is_repaint_ack) {
1170 repaint_ack_pending_ = false; 1238 repaint_ack_pending_ = false;
1171 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; 1239 TimeDelta delta = TimeTicks::Now() - repaint_start_time_;
1172 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); 1240 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta);
1173 } 1241 }
1174 1242
1175 DCHECK(!params.view_size.IsEmpty()); 1243 DCHECK(!params.view_size.IsEmpty());
1176 1244
1177 bool was_async = false; 1245 bool was_async = false;
1178 if (!is_accelerated_compositing_active_) { 1246
jbates 2012/04/20 01:14:04 FYI, this is just a diff failure, almost all this
1247 // If this is a GPU UpdateRect, params.bitmap is invalid and dib will be NULL.
1248 TransportDIB* dib = process_->GetTransportDIB(params.bitmap);
1249
1250 // If gpu process does painting, scroll_rect and copy_rects are always empty
1251 // and backing store is never used.
1252 if (dib) {
1179 DCHECK(!params.bitmap_rect.IsEmpty()); 1253 DCHECK(!params.bitmap_rect.IsEmpty());
1180 const size_t size = params.bitmap_rect.height() * 1254 const size_t size = params.bitmap_rect.height() *
1181 params.bitmap_rect.width() * 4; 1255 params.bitmap_rect.width() * 4;
1182 TransportDIB* dib = process_->GetTransportDIB(params.bitmap); 1256 if (dib->size() < size) {
1257 DLOG(WARNING) << "Transport DIB too small for given rectangle";
1258 RecordAction(UserMetricsAction("BadMessageTerminate_RWH1"));
1259 GetProcess()->ReceivedBadMessage();
1260 } else {
1261 UNSHIPPED_TRACE_EVENT_INSTANT2("test_latency", "UpdateRect",
1262 "x+y", params.bitmap_rect.x() + params.bitmap_rect.y(),
1263 "color", 0xffffff & *static_cast<uint32*>(dib->memory()));
1264 UNSHIPPED_TRACE_EVENT_INSTANT1("test_latency", "UpdateRectWidth",
1265 "width", params.bitmap_rect.width());
1183 1266
1184 // If gpu process does painting, scroll_rect and copy_rects are always empty 1267 // Scroll the backing store.
1185 // and backing store is never used. 1268 if (!params.scroll_rect.IsEmpty()) {
1186 if (dib) { 1269 ScrollBackingStoreRect(params.dx, params.dy,
1187 if (dib->size() < size) { 1270 params.scroll_rect,
1188 DLOG(WARNING) << "Transport DIB too small for given rectangle"; 1271 params.view_size);
1189 RecordAction(UserMetricsAction("BadMessageTerminate_RWH1")); 1272 }
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 1273
1198 // Scroll the backing store. 1274 // Paint the backing store. This will update it with the
1199 if (!params.scroll_rect.IsEmpty()) { 1275 // renderer-supplied bits. The view will read out of the backing store
1200 ScrollBackingStoreRect(params.dx, params.dy, 1276 // later to actually draw to the screen.
1201 params.scroll_rect, 1277 was_async = PaintBackingStoreRect(
1202 params.view_size); 1278 params.bitmap,
1203 } 1279 params.bitmap_rect,
1204 1280 params.copy_rects,
1205 // Paint the backing store. This will update it with the 1281 params.view_size,
1206 // renderer-supplied bits. The view will read out of the backing store 1282 base::Bind(&RenderWidgetHostImpl::DidUpdateBackingStore,
1207 // later to actually draw to the screen. 1283 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 } 1284 }
1217 } 1285 }
1218 1286
1219 if (!was_async) { 1287 if (!was_async) {
1220 DidUpdateBackingStore(params, paint_start); 1288 DidUpdateBackingStore(params, paint_start);
1221 } 1289 }
1222 1290
1223 if (should_auto_resize_) { 1291 if (should_auto_resize_) {
1224 bool post_callback = new_auto_size_.IsEmpty(); 1292 bool post_callback = new_auto_size_.IsEmpty();
1225 new_auto_size_ = params.view_size; 1293 new_auto_size_ = params.view_size;
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 // indicate that no callback is in progress (i.e. without this line 1794 // indicate that no callback is in progress (i.e. without this line
1727 // DelayedAutoResized will not get called again). 1795 // DelayedAutoResized will not get called again).
1728 new_auto_size_.SetSize(0, 0); 1796 new_auto_size_.SetSize(0, 0);
1729 if (!should_auto_resize_) 1797 if (!should_auto_resize_)
1730 return; 1798 return;
1731 1799
1732 OnRenderAutoResized(new_size); 1800 OnRenderAutoResized(new_size);
1733 } 1801 }
1734 1802
1735 } // namespace content 1803 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698