| 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 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 x, y, 0)); | 1019 x, y, 0)); |
| 1020 } | 1020 } |
| 1021 break; | 1021 break; |
| 1022 case WebMouseEvent::ButtonNone: | 1022 case WebMouseEvent::ButtonNone: |
| 1023 break; | 1023 break; |
| 1024 } | 1024 } |
| 1025 } | 1025 } |
| 1026 | 1026 |
| 1027 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 1027 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
| 1028 ForwardMouseEventWithLatencyInfo( | 1028 ForwardMouseEventWithLatencyInfo( |
| 1029 MouseEventWithLatencyInfo(mouse_event, NewInputLatencyInfo())); | 1029 MouseEventWithLatencyInfo(mouse_event, NewInputLatencyInfo(NULL))); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( | 1032 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( |
| 1033 const MouseEventWithLatencyInfo& mouse_event) { | 1033 const MouseEventWithLatencyInfo& mouse_event) { |
| 1034 TRACE_EVENT2("input", | 1034 TRACE_EVENT2("input", |
| 1035 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", | 1035 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", |
| 1036 "x", mouse_event.event.x, "y", mouse_event.event.y); | 1036 "x", mouse_event.event.x, "y", mouse_event.event.y); |
| 1037 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1037 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1038 return; | 1038 return; |
| 1039 | 1039 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1053 return; | 1053 return; |
| 1054 | 1054 |
| 1055 ForwardMouseEventImmediately(mouse_event); | 1055 ForwardMouseEventImmediately(mouse_event); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 void RenderWidgetHostImpl::OnPointerEventActivate() { | 1058 void RenderWidgetHostImpl::OnPointerEventActivate() { |
| 1059 } | 1059 } |
| 1060 | 1060 |
| 1061 void RenderWidgetHostImpl::ForwardWheelEvent( | 1061 void RenderWidgetHostImpl::ForwardWheelEvent( |
| 1062 const WebMouseWheelEvent& wheel_event) { | 1062 const WebMouseWheelEvent& wheel_event) { |
| 1063 ForwardWheelEventWithLatencyInfo(wheel_event, NewInputLatencyInfo()); | 1063 ForwardWheelEventWithLatencyInfo(wheel_event, NewInputLatencyInfo(NULL)); |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( | 1066 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( |
| 1067 const WebMouseWheelEvent& wheel_event, | 1067 const WebMouseWheelEvent& wheel_event, |
| 1068 const ui::LatencyInfo& latency_info) { | 1068 const ui::LatencyInfo& latency_info) { |
| 1069 TRACE_EVENT0("input", | 1069 TRACE_EVENT0("input", |
| 1070 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); | 1070 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); |
| 1071 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1071 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1072 return; | 1072 return; |
| 1073 | 1073 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); | 1127 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); |
| 1128 } | 1128 } |
| 1129 | 1129 |
| 1130 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( | 1130 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( |
| 1131 const WebKit::WebGestureEvent& gesture_event, | 1131 const WebKit::WebGestureEvent& gesture_event, |
| 1132 const ui::LatencyInfo& ui_latency) { | 1132 const ui::LatencyInfo& ui_latency) { |
| 1133 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); | 1133 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); |
| 1134 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1134 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
| 1135 return; | 1135 return; |
| 1136 | 1136 |
| 1137 ui::LatencyInfo latency_info; | 1137 ui::LatencyInfo latency_info = NewInputLatencyInfo(&ui_latency); |
| 1138 // In Aura, gesture event will carry its original touch event's | |
| 1139 // INPUT_EVENT_LATENCY_RWH_COMPONENT. For non-aura platform, we add the | |
| 1140 // INPUT_EVENT_LATENCY_RWH_COMPONENT right here. | |
| 1141 if (!ui_latency.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | |
| 1142 GetLatencyComponentId(), | |
| 1143 NULL)) | |
| 1144 latency_info = NewInputLatencyInfo(); | |
| 1145 | 1138 |
| 1146 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_INJECTED_RWH_COMPONENT, | 1139 WebKit::WebInputEvent::Type type = gesture_event.type; |
| 1147 GetLatencyComponentId(), | 1140 if (type == WebKit::WebInputEvent::GestureScrollBegin || |
| 1148 ++last_input_number_); | 1141 type == WebKit::WebInputEvent::GestureScrollUpdate || |
| 1149 latency_info.MergeWith(ui_latency); | 1142 type == WebKit::WebInputEvent::GestureScrollUpdateWithoutPropagation) { |
| 1143 latency_info.AddLatencyNumber( |
| 1144 ui::INPUT_EVENT_LATENCY_GESTURE_SCROLL_RWH_COMPONENT, |
| 1145 GetLatencyComponentId(), |
| 1146 ++last_input_number_); |
| 1147 } |
| 1150 | 1148 |
| 1151 if (!IsInOverscrollGesture() && | 1149 if (!IsInOverscrollGesture() && |
| 1152 !gesture_event_filter_->ShouldForward( | 1150 !gesture_event_filter_->ShouldForward( |
| 1153 GestureEventWithLatencyInfo(gesture_event, latency_info))) { | 1151 GestureEventWithLatencyInfo(gesture_event, latency_info))) { |
| 1154 if (overscroll_controller_.get()) | 1152 if (overscroll_controller_.get()) |
| 1155 overscroll_controller_->DiscardingGestureEvent(gesture_event); | 1153 overscroll_controller_->DiscardingGestureEvent(gesture_event); |
| 1156 return; | 1154 return; |
| 1157 } | 1155 } |
| 1158 | 1156 |
| 1159 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), | 1157 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 1282 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
| 1285 // renderer and we need to give something to the HandleKeyboardEvent | 1283 // renderer and we need to give something to the HandleKeyboardEvent |
| 1286 // handler. | 1284 // handler. |
| 1287 key_queue_.push_back(key_event); | 1285 key_queue_.push_back(key_event); |
| 1288 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 1286 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
| 1289 | 1287 |
| 1290 gesture_event_filter_->FlingHasBeenHalted(); | 1288 gesture_event_filter_->FlingHasBeenHalted(); |
| 1291 | 1289 |
| 1292 // Only forward the non-native portions of our event. | 1290 // Only forward the non-native portions of our event. |
| 1293 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1291 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
| 1294 NewInputLatencyInfo(), | 1292 NewInputLatencyInfo(NULL), |
| 1295 is_keyboard_shortcut); | 1293 is_keyboard_shortcut); |
| 1296 } | 1294 } |
| 1297 } | 1295 } |
| 1298 | 1296 |
| 1299 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { | 1297 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { |
| 1300 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); | 1298 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); |
| 1301 } | 1299 } |
| 1302 | 1300 |
| 1303 int64 RenderWidgetHostImpl::GetLatencyComponentId() { | 1301 int64 RenderWidgetHostImpl::GetLatencyComponentId() { |
| 1304 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); | 1302 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); |
| 1305 } | 1303 } |
| 1306 | 1304 |
| 1307 // static | 1305 // static |
| 1308 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { | 1306 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { |
| 1309 g_check_for_pending_resize_ack = false; | 1307 g_check_for_pending_resize_ack = false; |
| 1310 } | 1308 } |
| 1311 | 1309 |
| 1312 ui::LatencyInfo RenderWidgetHostImpl::NewInputLatencyInfo() { | 1310 ui::LatencyInfo RenderWidgetHostImpl::NewInputLatencyInfo( |
| 1311 const ui::LatencyInfo* original) { |
| 1313 ui::LatencyInfo info; | 1312 ui::LatencyInfo info; |
| 1314 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1313 if (original) |
| 1314 info = *original; |
| 1315 // In Aura, gesture event will already carry its original touch event's |
| 1316 // INPUT_EVENT_LATENCY_RWH_COMPONENT. |
| 1317 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 1315 GetLatencyComponentId(), | 1318 GetLatencyComponentId(), |
| 1316 ++last_input_number_); | 1319 NULL)) { |
| 1320 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 1321 GetLatencyComponentId(), |
| 1322 ++last_input_number_); |
| 1323 } |
| 1317 return info; | 1324 return info; |
| 1318 } | 1325 } |
| 1319 | 1326 |
| 1320 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1327 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
| 1321 int event_size, | 1328 int event_size, |
| 1322 const ui::LatencyInfo& latency_info, | 1329 const ui::LatencyInfo& latency_info, |
| 1323 bool is_keyboard_shortcut) { | 1330 bool is_keyboard_shortcut) { |
| 1324 DCHECK(latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1331 DCHECK(latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 1325 GetLatencyComponentId(), | 1332 GetLatencyComponentId(), |
| 1326 NULL)); | 1333 NULL)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 // after this line. | 1418 // after this line. |
| 1412 next_mouse_move_.reset(); | 1419 next_mouse_move_.reset(); |
| 1413 | 1420 |
| 1414 StartHangMonitorTimeout( | 1421 StartHangMonitorTimeout( |
| 1415 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); | 1422 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); |
| 1416 } | 1423 } |
| 1417 | 1424 |
| 1418 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( | 1425 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( |
| 1419 const WebKit::WebTouchEvent& touch_event, | 1426 const WebKit::WebTouchEvent& touch_event, |
| 1420 const ui::LatencyInfo& ui_latency) { | 1427 const ui::LatencyInfo& ui_latency) { |
| 1421 ui::LatencyInfo latency_info = NewInputLatencyInfo(); | 1428 ui::LatencyInfo latency_info = NewInputLatencyInfo(&ui_latency); |
| 1422 latency_info.MergeWith(ui_latency); | |
| 1423 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); | 1429 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); |
| 1424 touch_event_queue_->QueueEvent(touch_with_latency); | 1430 touch_event_queue_->QueueEvent(touch_with_latency); |
| 1425 } | 1431 } |
| 1426 | 1432 |
| 1427 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { | 1433 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { |
| 1428 keyboard_listeners_.AddObserver(listener); | 1434 keyboard_listeners_.AddObserver(listener); |
| 1429 } | 1435 } |
| 1430 | 1436 |
| 1431 void RenderWidgetHostImpl::RemoveKeyboardListener( | 1437 void RenderWidgetHostImpl::RemoveKeyboardListener( |
| 1432 KeyboardListener* listener) { | 1438 KeyboardListener* listener) { |
| (...skipping 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2647 1000000, | 2653 1000000, |
| 2648 100); | 2654 100); |
| 2649 } | 2655 } |
| 2650 | 2656 |
| 2651 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2657 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2652 switches::kEnableGpuBenchmarking)) | 2658 switches::kEnableGpuBenchmarking)) |
| 2653 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2659 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2654 } | 2660 } |
| 2655 | 2661 |
| 2656 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2662 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
| 2657 ui::LatencyInfo::LatencyMap::const_iterator l = | 2663 ui::LatencyInfo::LatencyComponent rwh_component; |
| 2658 latency_info.latency_components.find(std::make_pair( | 2664 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 2659 ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, GetLatencyComponentId())); | 2665 GetLatencyComponentId(), |
| 2660 if (l == latency_info.latency_components.end()) | 2666 &rwh_component)) |
| 2661 return; | 2667 return; |
| 2662 | 2668 |
| 2663 rendering_stats_.input_event_count += l->second.event_count; | 2669 rendering_stats_.input_event_count += rwh_component.event_count; |
| 2664 rendering_stats_.total_input_latency += | 2670 rendering_stats_.total_input_latency += |
| 2665 l->second.event_count * | 2671 rwh_component.event_count * |
| 2666 (latency_info.swap_timestamp - l->second.event_time); | 2672 (latency_info.swap_timestamp - rwh_component.event_time); |
| 2673 |
| 2674 ui::LatencyInfo::LatencyComponent original_component; |
| 2675 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 2676 0, |
| 2677 &original_component) && |
| 2678 latency_info.FindLatency( |
| 2679 ui::INPUT_EVENT_LATENCY_GESTURE_SCROLL_RWH_COMPONENT, |
| 2680 GetLatencyComponentId(), |
| 2681 NULL)) { |
| 2682 // This UMA metric tracks the time from when the original touch event is |
| 2683 // created (averaged if there are multiple) to when the scroll gesture |
| 2684 // results in final frame swap. |
| 2685 base::TimeDelta delta = |
| 2686 latency_info.swap_timestamp - original_component.event_time; |
| 2687 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2688 "Event.Latency.Browser.TouchToScroll", |
| 2689 delta.InMicroseconds(), |
| 2690 0, |
| 2691 1000000, |
| 2692 100); |
| 2693 rendering_stats_.scroll_event_count += original_component.event_count; |
| 2694 rendering_stats_.total_scroll_latency += |
| 2695 original_component.event_count * |
| 2696 (latency_info.swap_timestamp - original_component.event_time); |
| 2697 } |
| 2667 | 2698 |
| 2668 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2699 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2669 switches::kEnableGpuBenchmarking)) | 2700 switches::kEnableGpuBenchmarking)) |
| 2670 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2701 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2671 } | 2702 } |
| 2672 | 2703 |
| 2673 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2704 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2674 view_->DidReceiveRendererFrame(); | 2705 view_->DidReceiveRendererFrame(); |
| 2675 } | 2706 } |
| 2676 | 2707 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2688 int process_id = (b->first.second >> 32) & 0xffffffff; | 2719 int process_id = (b->first.second >> 32) & 0xffffffff; |
| 2689 RenderWidgetHost* rwh = | 2720 RenderWidgetHost* rwh = |
| 2690 RenderWidgetHost::FromID(process_id, routing_id); | 2721 RenderWidgetHost::FromID(process_id, routing_id); |
| 2691 if (!rwh) | 2722 if (!rwh) |
| 2692 continue; | 2723 continue; |
| 2693 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2724 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
| 2694 } | 2725 } |
| 2695 } | 2726 } |
| 2696 | 2727 |
| 2697 } // namespace content | 2728 } // namespace content |
| OLD | NEW |