| OLD | NEW |
| 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.h" | 5 #include "content/browser/renderer_host/render_widget_host.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 WasResized(); | 340 WasResized(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void RenderWidgetHost::WasResized() { | 343 void RenderWidgetHost::WasResized() { |
| 344 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || | 344 if (resize_ack_pending_ || !process_->HasConnection() || !view_ || |
| 345 !renderer_initialized_ || should_auto_resize_) { | 345 !renderer_initialized_ || should_auto_resize_) { |
| 346 return; | 346 return; |
| 347 } | 347 } |
| 348 | 348 |
| 349 #if !defined(OS_MACOSX) | 349 #if !defined(OS_MACOSX) |
| 350 gfx::Size new_size = view_->GetViewBounds().size(); | 350 gfx::Rect view_bounds = view_->GetViewBounds(); |
| 351 #else | 351 #else |
| 352 // When UI scaling is enabled on OS X, allocate a smaller bitmap and | 352 // When UI scaling is enabled on OS X, allocate a smaller bitmap and |
| 353 // pixel-scale it up. | 353 // pixel-scale it up. |
| 354 // TODO(thakis): Use pixel size on mac and set UI scale in renderer. | 354 // TODO(thakis): Use pixel size on mac and set UI scale in renderer. |
| 355 // http://crbug.com/31960 | 355 // http://crbug.com/31960 |
| 356 gfx::Size new_size(view_->GetViewCocoaBounds().size()); | 356 gfx::Rect view_bounds(view_->GetViewCocoaBounds().size()); |
| 357 #endif | 357 #endif |
| 358 gfx::Rect reserved_rect = view_->reserved_contents_rect(); | 358 gfx::Size new_size(view_bounds.size()); |
| 359 | 359 |
| 360 // Avoid asking the RenderWidget to resize to its current size, since it | 360 // Avoid asking the RenderWidget to resize to its current size, since it |
| 361 // won't send us a PaintRect message in that case, unless reserved area is | 361 // won't send us a PaintRect message in that case. |
| 362 // changed, but even in this case PaintRect message won't be sent. | 362 if (new_size == current_size_) |
| 363 if (new_size == current_size_ && reserved_rect == current_reserved_rect_) | |
| 364 return; | 363 return; |
| 365 | 364 |
| 366 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ && | 365 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_) { |
| 367 in_flight_reserved_rect_ == reserved_rect) { | |
| 368 return; | 366 return; |
| 369 } | 367 } |
| 370 | 368 |
| 371 // We don't expect to receive an ACK when the requested size is empty or | 369 // We don't expect to receive an ACK when the requested size is empty. |
| 372 // only reserved area is changed. | 370 if (!new_size.IsEmpty()) |
| 373 resize_ack_pending_ = !new_size.IsEmpty() && new_size != current_size_; | 371 resize_ack_pending_ = true; |
| 374 | 372 |
| 375 if (!Send(new ViewMsg_Resize(routing_id_, new_size, reserved_rect, | 373 if (!Send(new ViewMsg_Resize(routing_id_, new_size, |
| 376 IsFullscreen()))) { | 374 GetRootWindowResizerRect(), IsFullscreen()))) { |
| 377 resize_ack_pending_ = false; | 375 resize_ack_pending_ = false; |
| 378 } else { | 376 } else { |
| 379 if (resize_ack_pending_) { | 377 in_flight_size_ = new_size; |
| 380 in_flight_size_ = new_size; | |
| 381 in_flight_reserved_rect_ = reserved_rect; | |
| 382 } else { | |
| 383 // Message was sent successfully, but we do not expect to receive an ACK, | |
| 384 // so update current values right away. | |
| 385 current_size_ = new_size; | |
| 386 // TODO(alekseys): send a message from renderer to ack a reserved rect | |
| 387 // changes only. | |
| 388 current_reserved_rect_ = reserved_rect; | |
| 389 } | |
| 390 } | 378 } |
| 391 } | 379 } |
| 392 | 380 |
| 393 void RenderWidgetHost::GotFocus() { | 381 void RenderWidgetHost::GotFocus() { |
| 394 Focus(); | 382 Focus(); |
| 395 } | 383 } |
| 396 | 384 |
| 397 void RenderWidgetHost::Focus() { | 385 void RenderWidgetHost::Focus() { |
| 398 Send(new ViewMsg_SetFocus(routing_id_, true)); | 386 Send(new ViewMsg_SetFocus(routing_id_, true)); |
| 399 } | 387 } |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 759 |
| 772 // Must reset these to ensure that keyboard events work with a new renderer. | 760 // Must reset these to ensure that keyboard events work with a new renderer. |
| 773 key_queue_.clear(); | 761 key_queue_.clear(); |
| 774 suppress_next_char_events_ = false; | 762 suppress_next_char_events_ = false; |
| 775 | 763 |
| 776 // Reset some fields in preparation for recovering from a crash. | 764 // Reset some fields in preparation for recovering from a crash. |
| 777 resize_ack_pending_ = false; | 765 resize_ack_pending_ = false; |
| 778 repaint_ack_pending_ = false; | 766 repaint_ack_pending_ = false; |
| 779 | 767 |
| 780 in_flight_size_.SetSize(0, 0); | 768 in_flight_size_.SetSize(0, 0); |
| 781 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); | |
| 782 current_size_.SetSize(0, 0); | 769 current_size_.SetSize(0, 0); |
| 783 current_reserved_rect_.SetRect(0, 0, 0, 0); | |
| 784 is_hidden_ = false; | 770 is_hidden_ = false; |
| 785 is_accelerated_compositing_active_ = false; | 771 is_accelerated_compositing_active_ = false; |
| 786 | 772 |
| 787 if (view_) { | 773 if (view_) { |
| 788 view_->RenderViewGone(status, exit_code); | 774 view_->RenderViewGone(status, exit_code); |
| 789 view_ = NULL; // The View should be deleted by RenderViewGone. | 775 view_ = NULL; // The View should be deleted by RenderViewGone. |
| 790 } | 776 } |
| 791 | 777 |
| 792 BackingStoreManager::RemoveBackingStore(this); | 778 BackingStoreManager::RemoveBackingStore(this); |
| 793 } | 779 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 822 |
| 837 void RenderWidgetHost::ImeConfirmComposition() { | 823 void RenderWidgetHost::ImeConfirmComposition() { |
| 838 ImeConfirmComposition(string16()); | 824 ImeConfirmComposition(string16()); |
| 839 } | 825 } |
| 840 | 826 |
| 841 void RenderWidgetHost::ImeCancelComposition() { | 827 void RenderWidgetHost::ImeCancelComposition() { |
| 842 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), | 828 Send(new ViewMsg_ImeSetComposition(routing_id(), string16(), |
| 843 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); | 829 std::vector<WebKit::WebCompositionUnderline>(), 0, 0)); |
| 844 } | 830 } |
| 845 | 831 |
| 832 gfx::Rect RenderWidgetHost::GetRootWindowResizerRect() const { |
| 833 return gfx::Rect(); |
| 834 } |
| 835 |
| 846 void RenderWidgetHost::RequestToLockMouse() { | 836 void RenderWidgetHost::RequestToLockMouse() { |
| 847 // Directly reject to lock the mouse. Subclass can override this method to | 837 // Directly reject to lock the mouse. Subclass can override this method to |
| 848 // decide whether to allow mouse lock or not. | 838 // decide whether to allow mouse lock or not. |
| 849 GotResponseToLockMouseRequest(false); | 839 GotResponseToLockMouseRequest(false); |
| 850 } | 840 } |
| 851 | 841 |
| 852 void RenderWidgetHost::RejectMouseLockOrUnlockIfNecessary() { | 842 void RenderWidgetHost::RejectMouseLockOrUnlockIfNecessary() { |
| 853 DCHECK(!pending_mouse_lock_request_ || !IsMouseLocked()); | 843 DCHECK(!pending_mouse_lock_request_ || !IsMouseLocked()); |
| 854 if (pending_mouse_lock_request_) { | 844 if (pending_mouse_lock_request_) { |
| 855 pending_mouse_lock_request_ = false; | 845 pending_mouse_lock_request_ = false; |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 bool is_resize_ack = | 992 bool is_resize_ack = |
| 1003 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 993 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
| 1004 | 994 |
| 1005 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since | 995 // resize_ack_pending_ needs to be cleared before we call DidPaintRect, since |
| 1006 // that will end up reaching GetBackingStore. | 996 // that will end up reaching GetBackingStore. |
| 1007 if (is_resize_ack || should_auto_resize_) { | 997 if (is_resize_ack || should_auto_resize_) { |
| 1008 if (is_resize_ack) { | 998 if (is_resize_ack) { |
| 1009 DCHECK(resize_ack_pending_); | 999 DCHECK(resize_ack_pending_); |
| 1010 resize_ack_pending_ = false; | 1000 resize_ack_pending_ = false; |
| 1011 in_flight_size_.SetSize(0, 0); | 1001 in_flight_size_.SetSize(0, 0); |
| 1012 in_flight_reserved_rect_.SetRect(0, 0, 0, 0); | |
| 1013 } | 1002 } |
| 1014 // Update our knowledge of the RenderWidget's resizer rect. | |
| 1015 // ViewMsg_Resize is acknowledged only when view size is actually changed, | |
| 1016 // otherwise current_reserved_rect_ is updated immediately after sending | |
| 1017 // ViewMsg_Resize to the RenderWidget and can be clobbered by | |
| 1018 // OnMsgUpdateRect called for a paint that was initiated before the resize | |
| 1019 // message was sent. | |
| 1020 current_reserved_rect_ = params.resizer_rect; | |
| 1021 } | 1003 } |
| 1022 | 1004 |
| 1023 bool is_repaint_ack = | 1005 bool is_repaint_ack = |
| 1024 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); | 1006 ViewHostMsg_UpdateRect_Flags::is_repaint_ack(params.flags); |
| 1025 if (is_repaint_ack) { | 1007 if (is_repaint_ack) { |
| 1026 repaint_ack_pending_ = false; | 1008 repaint_ack_pending_ = false; |
| 1027 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; | 1009 TimeDelta delta = TimeTicks::Now() - repaint_start_time_; |
| 1028 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); | 1010 UMA_HISTOGRAM_TIMES("MPArch.RWH_RepaintDelta", delta); |
| 1029 } | 1011 } |
| 1030 | 1012 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1130 | 1112 |
| 1131 content::NotificationService::current()->Notify( | 1113 content::NotificationService::current()->Notify( |
| 1132 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, | 1114 content::NOTIFICATION_RENDER_WIDGET_HOST_DID_PAINT, |
| 1133 content::Source<RenderWidgetHost>(this), | 1115 content::Source<RenderWidgetHost>(this), |
| 1134 content::NotificationService::NoDetails()); | 1116 content::NotificationService::NoDetails()); |
| 1135 | 1117 |
| 1136 // If we got a resize ack, then perhaps we have another resize to send? | 1118 // If we got a resize ack, then perhaps we have another resize to send? |
| 1137 bool is_resize_ack = | 1119 bool is_resize_ack = |
| 1138 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 1120 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
| 1139 if (is_resize_ack && view_) { | 1121 if (is_resize_ack && view_) { |
| 1140 // WasResized checks the current size and sends the resize update only | 1122 gfx::Rect view_bounds = view_->GetViewBounds(); |
| 1141 // when something was actually changed. | 1123 if (current_size_ != view_bounds.size()) |
| 1142 WasResized(); | 1124 WasResized(); |
| 1143 } | 1125 } |
| 1144 | 1126 |
| 1145 // Log the time delta for processing a paint message. | 1127 // Log the time delta for processing a paint message. |
| 1146 TimeTicks now = TimeTicks::Now(); | 1128 TimeTicks now = TimeTicks::Now(); |
| 1147 TimeDelta delta = now - update_start; | 1129 TimeDelta delta = now - update_start; |
| 1148 UMA_HISTOGRAM_TIMES("MPArch.RWH_DidUpdateBackingStore", delta); | 1130 UMA_HISTOGRAM_TIMES("MPArch.RWH_DidUpdateBackingStore", delta); |
| 1149 | 1131 |
| 1150 // Measures the time from receiving the MsgUpdateRect IPC to completing the | 1132 // Measures the time from receiving the MsgUpdateRect IPC to completing the |
| 1151 // DidUpdateBackingStore() method. On platforms which have asynchronous | 1133 // DidUpdateBackingStore() method. On platforms which have asynchronous |
| 1152 // painting, such as Linux, this is the sum of MPArch.RWH_OnMsgUpdateRect, | 1134 // painting, such as Linux, this is the sum of MPArch.RWH_OnMsgUpdateRect, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); | 1532 ui_shim->Send(new AcceleratedSurfaceMsg_BuffersSwappedACK(route_id)); |
| 1551 } | 1533 } |
| 1552 | 1534 |
| 1553 // static | 1535 // static |
| 1554 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, | 1536 void RenderWidgetHost::AcknowledgePostSubBuffer(int32 route_id, |
| 1555 int gpu_host_id) { | 1537 int gpu_host_id) { |
| 1556 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 1538 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
| 1557 if (ui_shim) | 1539 if (ui_shim) |
| 1558 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); | 1540 ui_shim->Send(new AcceleratedSurfaceMsg_PostSubBufferACK(route_id)); |
| 1559 } | 1541 } |
| OLD | NEW |