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_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, | 92 bool ShouldCoalesceMouseWheelEvents(const WebMouseWheelEvent& last_event, |
93 const WebMouseWheelEvent& new_event) { | 93 const WebMouseWheelEvent& new_event) { |
94 return last_event.modifiers == new_event.modifiers && | 94 return last_event.modifiers == new_event.modifiers && |
95 last_event.scrollByPage == new_event.scrollByPage && | 95 last_event.scrollByPage == new_event.scrollByPage && |
96 last_event.hasPreciseScrollingDeltas | 96 last_event.hasPreciseScrollingDeltas |
97 == new_event.hasPreciseScrollingDeltas && | 97 == new_event.hasPreciseScrollingDeltas && |
98 last_event.phase == new_event.phase && | 98 last_event.phase == new_event.phase && |
99 last_event.momentumPhase == new_event.momentumPhase; | 99 last_event.momentumPhase == new_event.momentumPhase; |
100 } | 100 } |
101 | 101 |
| 102 int64 g_current_input_number; |
| 103 |
102 } // namespace | 104 } // namespace |
103 | 105 |
104 | 106 |
105 // static | 107 // static |
106 void RenderWidgetHost::RemoveAllBackingStores() { | 108 void RenderWidgetHost::RemoveAllBackingStores() { |
107 BackingStoreManager::RemoveAllBackingStores(); | 109 BackingStoreManager::RemoveAllBackingStores(); |
108 } | 110 } |
109 | 111 |
110 // static | 112 // static |
111 size_t RenderWidgetHost::BackingStoreMemorySize() { | 113 size_t RenderWidgetHost::BackingStoreMemorySize() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 text_direction_updated_(false), | 148 text_direction_updated_(false), |
147 text_direction_(WebKit::WebTextDirectionLeftToRight), | 149 text_direction_(WebKit::WebTextDirectionLeftToRight), |
148 text_direction_canceled_(false), | 150 text_direction_canceled_(false), |
149 suppress_next_char_events_(false), | 151 suppress_next_char_events_(false), |
150 pending_mouse_lock_request_(false), | 152 pending_mouse_lock_request_(false), |
151 allow_privileged_mouse_lock_(false), | 153 allow_privileged_mouse_lock_(false), |
152 has_touch_handler_(false), | 154 has_touch_handler_(false), |
153 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 155 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
154 tick_active_smooth_scroll_gestures_task_posted_(false), | 156 tick_active_smooth_scroll_gestures_task_posted_(false), |
155 touch_event_queue_(new TouchEventQueue(this)), | 157 touch_event_queue_(new TouchEventQueue(this)), |
156 gesture_event_filter_(new GestureEventFilter(this)) { | 158 gesture_event_filter_(new GestureEventFilter(this)), |
| 159 incremented_input_number_(false), |
| 160 current_input_number_(0) { |
157 CHECK(delegate_); | 161 CHECK(delegate_); |
158 if (routing_id_ == MSG_ROUTING_NONE) { | 162 if (routing_id_ == MSG_ROUTING_NONE) { |
159 routing_id_ = process_->GetNextRoutingID(); | 163 routing_id_ = process_->GetNextRoutingID(); |
160 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 164 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
161 process_->GetID(), | 165 process_->GetID(), |
162 routing_id_); | 166 routing_id_); |
163 } else { | 167 } else { |
164 // TODO(piman): This is a O(N) lookup, where we could forward the | 168 // TODO(piman): This is a O(N) lookup, where we could forward the |
165 // information from the RenderWidgetHelper. The problem is that doing so | 169 // information from the RenderWidgetHelper. The problem is that doing so |
166 // currently leaks outside of content all the way to chrome classes, and | 170 // currently leaks outside of content all the way to chrome classes, and |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // When accelerated compositing is on, we must always repaint, even when | 438 // When accelerated compositing is on, we must always repaint, even when |
435 // the backing store exists. | 439 // the backing store exists. |
436 bool needs_repainting; | 440 bool needs_repainting; |
437 if (needs_repainting_on_restore_ || !backing_store || | 441 if (needs_repainting_on_restore_ || !backing_store || |
438 is_accelerated_compositing_active()) { | 442 is_accelerated_compositing_active()) { |
439 needs_repainting = true; | 443 needs_repainting = true; |
440 needs_repainting_on_restore_ = false; | 444 needs_repainting_on_restore_ = false; |
441 } else { | 445 } else { |
442 needs_repainting = false; | 446 needs_repainting = false; |
443 } | 447 } |
| 448 |
| 449 SendStartFrame(); |
| 450 |
444 Send(new ViewMsg_WasShown(routing_id_, needs_repainting)); | 451 Send(new ViewMsg_WasShown(routing_id_, needs_repainting)); |
445 | 452 |
446 process_->WidgetRestored(); | 453 process_->WidgetRestored(); |
447 | 454 |
448 bool is_visible = true; | 455 bool is_visible = true; |
449 NotificationService::current()->Notify( | 456 NotificationService::current()->Notify( |
450 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 457 NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
451 Source<RenderWidgetHost>(this), | 458 Source<RenderWidgetHost>(this), |
452 Details<bool>(&is_visible)); | 459 Details<bool>(&is_visible)); |
453 | 460 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 return; | 496 return; |
490 | 497 |
491 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ && | 498 if (in_flight_size_ != gfx::Size() && new_size == in_flight_size_ && |
492 !fullscreen_changed) | 499 !fullscreen_changed) |
493 return; | 500 return; |
494 | 501 |
495 // We don't expect to receive an ACK when the requested size is empty. | 502 // We don't expect to receive an ACK when the requested size is empty. |
496 if (!new_size.IsEmpty() && size_changed) | 503 if (!new_size.IsEmpty() && size_changed) |
497 resize_ack_pending_ = true; | 504 resize_ack_pending_ = true; |
498 | 505 |
| 506 SendStartFrame(); |
499 if (!Send(new ViewMsg_Resize(routing_id_, new_size, | 507 if (!Send(new ViewMsg_Resize(routing_id_, new_size, |
500 GetRootWindowResizerRect(), is_fullscreen_))) { | 508 GetRootWindowResizerRect(), is_fullscreen_))) { |
501 resize_ack_pending_ = false; | 509 resize_ack_pending_ = false; |
502 } else { | 510 } else { |
503 in_flight_size_ = new_size; | 511 in_flight_size_ = new_size; |
504 } | 512 } |
505 } | 513 } |
506 | 514 |
507 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { | 515 void RenderWidgetHostImpl::ResizeRectChanged(const gfx::Rect& new_rect) { |
508 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); | 516 Send(new ViewMsg_ChangeResizeRect(routing_id_, new_rect)); |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 "x", mouse_event.x, "y", mouse_event.y); | 905 "x", mouse_event.x, "y", mouse_event.y); |
898 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 906 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
899 return; | 907 return; |
900 | 908 |
901 if (CommandLine::ForCurrentProcess()->HasSwitch( | 909 if (CommandLine::ForCurrentProcess()->HasSwitch( |
902 switches::kSimulateTouchScreenWithMouse)) { | 910 switches::kSimulateTouchScreenWithMouse)) { |
903 SimulateTouchGestureWithMouse(mouse_event); | 911 SimulateTouchGestureWithMouse(mouse_event); |
904 return; | 912 return; |
905 } | 913 } |
906 | 914 |
| 915 IncrementInputNumber(); |
| 916 |
907 if (mouse_event.type == WebInputEvent::MouseDown && | 917 if (mouse_event.type == WebInputEvent::MouseDown && |
908 gesture_event_filter_->GetTapSuppressionController()-> | 918 gesture_event_filter_->GetTapSuppressionController()-> |
909 ShouldDeferMouseDown(mouse_event)) | 919 ShouldDeferMouseDown(mouse_event)) |
910 return; | 920 return; |
911 if (mouse_event.type == WebInputEvent::MouseUp && | 921 if (mouse_event.type == WebInputEvent::MouseUp && |
912 gesture_event_filter_->GetTapSuppressionController()-> | 922 gesture_event_filter_->GetTapSuppressionController()-> |
913 ShouldSuppressMouseUp()) | 923 ShouldSuppressMouseUp()) |
914 return; | 924 return; |
915 | 925 |
916 ForwardMouseEventImmediately(mouse_event); | 926 ForwardMouseEventImmediately(mouse_event); |
917 } | 927 } |
918 | 928 |
919 void RenderWidgetHostImpl::OnPointerEventActivate() { | 929 void RenderWidgetHostImpl::OnPointerEventActivate() { |
920 } | 930 } |
921 | 931 |
922 void RenderWidgetHostImpl::ForwardWheelEvent( | 932 void RenderWidgetHostImpl::ForwardWheelEvent( |
923 const WebMouseWheelEvent& wheel_event) { | 933 const WebMouseWheelEvent& wheel_event) { |
924 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent"); | 934 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardWheelEvent"); |
925 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 935 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
926 return; | 936 return; |
927 | 937 |
| 938 IncrementInputNumber(); |
928 // If there's already a mouse wheel event waiting to be sent to the renderer, | 939 // If there's already a mouse wheel event waiting to be sent to the renderer, |
929 // add the new deltas to that event. Not doing so (e.g., by dropping the old | 940 // add the new deltas to that event. Not doing so (e.g., by dropping the old |
930 // event, as for mouse moves) results in very slow scrolling on the Mac (on | 941 // event, as for mouse moves) results in very slow scrolling on the Mac (on |
931 // which many, very small wheel events are sent). | 942 // which many, very small wheel events are sent). |
932 if (mouse_wheel_pending_) { | 943 if (mouse_wheel_pending_) { |
933 if (coalesced_mouse_wheel_events_.empty() || | 944 if (coalesced_mouse_wheel_events_.empty() || |
934 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(), | 945 !ShouldCoalesceMouseWheelEvents(coalesced_mouse_wheel_events_.back(), |
935 wheel_event)) { | 946 wheel_event)) { |
936 coalesced_mouse_wheel_events_.push_back(wheel_event); | 947 coalesced_mouse_wheel_events_.push_back(wheel_event); |
937 } else { | 948 } else { |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 1093 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
1083 | 1094 |
1084 gesture_event_filter_->FlingHasBeenHalted(); | 1095 gesture_event_filter_->FlingHasBeenHalted(); |
1085 | 1096 |
1086 // Only forward the non-native portions of our event. | 1097 // Only forward the non-native portions of our event. |
1087 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1098 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
1088 is_keyboard_shortcut); | 1099 is_keyboard_shortcut); |
1089 } | 1100 } |
1090 } | 1101 } |
1091 | 1102 |
| 1103 void RenderWidgetHostImpl::IncrementInputNumber() { |
| 1104 if (incremented_input_number_) |
| 1105 return; |
| 1106 g_current_input_number++; |
| 1107 current_input_number_ = g_current_input_number; |
| 1108 incremented_input_number_ = true; |
| 1109 TRACE_EVENT_ASYNC_BEGIN1("frame", "Input processing", this, |
| 1110 "input_number", current_input_number_); |
| 1111 } |
| 1112 |
| 1113 void RenderWidgetHostImpl::SendStartFrame() { |
| 1114 IncrementInputNumber(); |
| 1115 TRACE_EVENT_ASYNC_END1("frame", "Input processing", this, |
| 1116 "input_number", current_input_number_); |
| 1117 Send(new ViewMsg_StartFrame(routing_id_, current_input_number_)); |
| 1118 incremented_input_number_ = false; |
| 1119 } |
| 1120 |
1092 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1121 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
1093 int event_size, | 1122 int event_size, |
1094 bool is_keyboard_shortcut) { | 1123 bool is_keyboard_shortcut) { |
| 1124 IncrementInputNumber(); |
| 1125 incremented_input_number_ = false; |
| 1126 |
| 1127 TRACE_EVENT_ASYNC_END1("frame", "Input processing", this, |
| 1128 "input_number", current_input_number_); |
| 1129 |
1095 input_event_start_time_ = TimeTicks::Now(); | 1130 input_event_start_time_ = TimeTicks::Now(); |
1096 Send(new ViewMsg_HandleInputEvent( | 1131 Send(new ViewMsg_HandleInputEvent( |
1097 routing_id_, &input_event, is_keyboard_shortcut)); | 1132 routing_id_, current_input_number_, &input_event, is_keyboard_shortcut)); |
1098 increment_in_flight_event_count(); | 1133 increment_in_flight_event_count(); |
1099 } | 1134 } |
1100 | 1135 |
1101 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, | 1136 void RenderWidgetHostImpl::ForwardInputEvent(const WebInputEvent& input_event, |
1102 int event_size, | 1137 int event_size, |
1103 bool is_keyboard_shortcut) { | 1138 bool is_keyboard_shortcut) { |
1104 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); | 1139 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::ForwardInputEvent"); |
1105 | 1140 |
1106 if (!process_->HasConnection()) | 1141 if (!process_->HasConnection()) |
1107 return; | 1142 return; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1520 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no | 1555 // TODO(jbates) http://crbug.com/105344 This will be removed when there are no |
1521 // plugin windows. | 1556 // plugin windows. |
1522 gpu_params.window = gfx::kNullPluginWindow; | 1557 gpu_params.window = gfx::kNullPluginWindow; |
1523 #endif | 1558 #endif |
1524 view_->AcceleratedSurfaceBuffersSwapped(gpu_params, | 1559 view_->AcceleratedSurfaceBuffersSwapped(gpu_params, |
1525 gpu_process_host_id); | 1560 gpu_process_host_id); |
1526 } | 1561 } |
1527 | 1562 |
1528 void RenderWidgetHostImpl::OnMsgUpdateRect( | 1563 void RenderWidgetHostImpl::OnMsgUpdateRect( |
1529 const ViewHostMsg_UpdateRect_Params& params) { | 1564 const ViewHostMsg_UpdateRect_Params& params) { |
1530 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect"); | 1565 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::OnMsgUpdateRect", |
| 1566 "input_number", params.latency_info.inputNumber, |
| 1567 "render_thread_frame_number", |
| 1568 params.latency_info.rendererMainFrameNumber); |
1531 TimeTicks paint_start = TimeTicks::Now(); | 1569 TimeTicks paint_start = TimeTicks::Now(); |
1532 | 1570 |
1533 // Update our knowledge of the RenderWidget's size. | 1571 // Update our knowledge of the RenderWidget's size. |
1534 current_size_ = params.view_size; | 1572 current_size_ = params.view_size; |
1535 // Update our knowledge of the RenderWidget's scroll offset. | 1573 // Update our knowledge of the RenderWidget's scroll offset. |
1536 last_scroll_offset_ = params.scroll_offset; | 1574 last_scroll_offset_ = params.scroll_offset; |
1537 | 1575 |
1538 bool is_resize_ack = | 1576 bool is_resize_ack = |
1539 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); | 1577 ViewHostMsg_UpdateRect_Flags::is_resize_ack(params.flags); |
1540 | 1578 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 } | 1661 } |
1624 | 1662 |
1625 void RenderWidgetHostImpl::OnMsgUpdateIsDelayed() { | 1663 void RenderWidgetHostImpl::OnMsgUpdateIsDelayed() { |
1626 if (in_get_backing_store_) | 1664 if (in_get_backing_store_) |
1627 abort_get_backing_store_ = true; | 1665 abort_get_backing_store_ = true; |
1628 } | 1666 } |
1629 | 1667 |
1630 void RenderWidgetHostImpl::DidUpdateBackingStore( | 1668 void RenderWidgetHostImpl::DidUpdateBackingStore( |
1631 const ViewHostMsg_UpdateRect_Params& params, | 1669 const ViewHostMsg_UpdateRect_Params& params, |
1632 const TimeTicks& paint_start) { | 1670 const TimeTicks& paint_start) { |
1633 TRACE_EVENT0("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore"); | 1671 TRACE_EVENT2("renderer_host", "RenderWidgetHostImpl::DidUpdateBackingStore", |
| 1672 "input_number", params.latency_info.inputNumber, |
| 1673 "render_thread_frame_number", |
| 1674 params.latency_info.rendererMainFrameNumber); |
1634 TimeTicks update_start = TimeTicks::Now(); | 1675 TimeTicks update_start = TimeTicks::Now(); |
1635 | 1676 |
1636 if (params.needs_ack) { | 1677 if (params.needs_ack) { |
1637 // ACK early so we can prefetch the next PaintRect if there is a next one. | 1678 // ACK early so we can prefetch the next PaintRect if there is a next one. |
1638 // This must be done AFTER we're done painting with the bitmap supplied by | 1679 // This must be done AFTER we're done painting with the bitmap supplied by |
1639 // the renderer. This ACK is a signal to the renderer that the backing store | 1680 // the renderer. This ACK is a signal to the renderer that the backing store |
1640 // can be re-used, so the bitmap may be invalid after this call. | 1681 // can be re-used, so the bitmap may be invalid after this call. |
1641 Send(new ViewMsg_UpdateRect_ACK(routing_id_)); | 1682 Send(new ViewMsg_UpdateRect_ACK(routing_id_)); |
1642 } | 1683 } |
1643 | 1684 |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2287 // static | 2328 // static |
2288 void RenderWidgetHostImpl::AcknowledgeBufferPresent( | 2329 void RenderWidgetHostImpl::AcknowledgeBufferPresent( |
2289 int32 route_id, int gpu_host_id, uint64 surface_handle, uint32 sync_point) { | 2330 int32 route_id, int gpu_host_id, uint64 surface_handle, uint32 sync_point) { |
2290 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); | 2331 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
2291 if (ui_shim) | 2332 if (ui_shim) |
2292 ui_shim->Send(new AcceleratedSurfaceMsg_BufferPresented(route_id, | 2333 ui_shim->Send(new AcceleratedSurfaceMsg_BufferPresented(route_id, |
2293 surface_handle, | 2334 surface_handle, |
2294 sync_point)); | 2335 sync_point)); |
2295 } | 2336 } |
2296 | 2337 |
| 2338 void RenderWidgetHostImpl::NotifyFrameDisplayed( |
| 2339 int route_id, int gpu_host_id, |
| 2340 const WebKit::WebLatencyInfoImpl& latency_info) { |
| 2341 GpuProcessHostUIShim* ui_shim = GpuProcessHostUIShim::FromID(gpu_host_id); |
| 2342 if (ui_shim) |
| 2343 ui_shim->Send(new AcceleratedSurfaceMsg_FrameDisplayed(route_id, |
| 2344 latency_info)); |
| 2345 } |
| 2346 |
2297 void RenderWidgetHostImpl::AcknowledgeSwapBuffersToRenderer() { | 2347 void RenderWidgetHostImpl::AcknowledgeSwapBuffersToRenderer() { |
2298 if (!is_threaded_compositing_enabled_) | 2348 if (!is_threaded_compositing_enabled_) |
2299 Send(new ViewMsg_SwapBuffers_ACK(routing_id_)); | 2349 Send(new ViewMsg_SwapBuffers_ACK(routing_id_)); |
2300 } | 2350 } |
2301 | 2351 |
2302 #if defined(USE_AURA) | 2352 #if defined(USE_AURA) |
2303 | 2353 |
2304 void RenderWidgetHostImpl::ParentChanged(gfx::NativeViewId new_parent) { | 2354 void RenderWidgetHostImpl::ParentChanged(gfx::NativeViewId new_parent) { |
2305 #if defined(OS_WIN) | 2355 #if defined(OS_WIN) |
2306 HWND hwnd = reinterpret_cast<HWND>(new_parent); | 2356 HWND hwnd = reinterpret_cast<HWND>(new_parent); |
(...skipping 18 matching lines...) Expand all Loading... |
2325 return; | 2375 return; |
2326 | 2376 |
2327 OnRenderAutoResized(new_size); | 2377 OnRenderAutoResized(new_size); |
2328 } | 2378 } |
2329 | 2379 |
2330 void RenderWidgetHostImpl::DetachDelegate() { | 2380 void RenderWidgetHostImpl::DetachDelegate() { |
2331 delegate_ = NULL; | 2381 delegate_ = NULL; |
2332 } | 2382 } |
2333 | 2383 |
2334 } // namespace content | 2384 } // namespace content |
OLD | NEW |