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 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 x, y, 0)); | 1021 x, y, 0)); |
1022 } | 1022 } |
1023 break; | 1023 break; |
1024 case WebMouseEvent::ButtonNone: | 1024 case WebMouseEvent::ButtonNone: |
1025 break; | 1025 break; |
1026 } | 1026 } |
1027 } | 1027 } |
1028 | 1028 |
1029 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { | 1029 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { |
1030 ForwardMouseEventWithLatencyInfo( | 1030 ForwardMouseEventWithLatencyInfo( |
1031 MouseEventWithLatencyInfo(mouse_event, NewInputLatencyInfo())); | 1031 MouseEventWithLatencyInfo(mouse_event, |
| 1032 CreateRWHLatencyInfoIfNotExist(NULL))); |
1032 } | 1033 } |
1033 | 1034 |
1034 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( | 1035 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( |
1035 const MouseEventWithLatencyInfo& mouse_event) { | 1036 const MouseEventWithLatencyInfo& mouse_event) { |
1036 TRACE_EVENT2("input", | 1037 TRACE_EVENT2("input", |
1037 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", | 1038 "RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo", |
1038 "x", mouse_event.event.x, "y", mouse_event.event.y); | 1039 "x", mouse_event.event.x, "y", mouse_event.event.y); |
1039 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1040 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
1040 return; | 1041 return; |
1041 | 1042 |
(...skipping 13 matching lines...) Expand all Loading... |
1055 return; | 1056 return; |
1056 | 1057 |
1057 ForwardMouseEventImmediately(mouse_event); | 1058 ForwardMouseEventImmediately(mouse_event); |
1058 } | 1059 } |
1059 | 1060 |
1060 void RenderWidgetHostImpl::OnPointerEventActivate() { | 1061 void RenderWidgetHostImpl::OnPointerEventActivate() { |
1061 } | 1062 } |
1062 | 1063 |
1063 void RenderWidgetHostImpl::ForwardWheelEvent( | 1064 void RenderWidgetHostImpl::ForwardWheelEvent( |
1064 const WebMouseWheelEvent& wheel_event) { | 1065 const WebMouseWheelEvent& wheel_event) { |
1065 ForwardWheelEventWithLatencyInfo(wheel_event, NewInputLatencyInfo()); | 1066 ForwardWheelEventWithLatencyInfo(wheel_event, |
| 1067 CreateRWHLatencyInfoIfNotExist(NULL)); |
1066 } | 1068 } |
1067 | 1069 |
1068 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( | 1070 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( |
1069 const WebMouseWheelEvent& wheel_event, | 1071 const WebMouseWheelEvent& wheel_event, |
1070 const ui::LatencyInfo& latency_info) { | 1072 const ui::LatencyInfo& latency_info) { |
1071 TRACE_EVENT0("input", | 1073 TRACE_EVENT0("input", |
1072 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); | 1074 "RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo"); |
1073 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1075 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
1074 return; | 1076 return; |
1075 | 1077 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); | 1131 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); |
1130 } | 1132 } |
1131 | 1133 |
1132 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( | 1134 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( |
1133 const WebKit::WebGestureEvent& gesture_event, | 1135 const WebKit::WebGestureEvent& gesture_event, |
1134 const ui::LatencyInfo& ui_latency) { | 1136 const ui::LatencyInfo& ui_latency) { |
1135 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); | 1137 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); |
1136 if (ignore_input_events_ || process_->IgnoreInputEvents()) | 1138 if (ignore_input_events_ || process_->IgnoreInputEvents()) |
1137 return; | 1139 return; |
1138 | 1140 |
1139 ui::LatencyInfo latency_info; | 1141 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist(&ui_latency); |
1140 // In Aura, gesture event will carry its original touch event's | |
1141 // INPUT_EVENT_LATENCY_RWH_COMPONENT. For non-aura platform, we add the | |
1142 // INPUT_EVENT_LATENCY_RWH_COMPONENT right here. | |
1143 if (!ui_latency.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | |
1144 GetLatencyComponentId(), | |
1145 NULL)) | |
1146 latency_info = NewInputLatencyInfo(); | |
1147 | 1142 |
1148 latency_info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_INJECTED_RWH_COMPONENT, | 1143 if (gesture_event.type == WebKit::WebInputEvent::GestureScrollUpdate) { |
1149 GetLatencyComponentId(), | 1144 latency_info.AddLatencyNumber( |
1150 ++last_input_number_); | 1145 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT, |
1151 latency_info.MergeWith(ui_latency); | 1146 GetLatencyComponentId(), |
| 1147 ++last_input_number_); |
| 1148 |
| 1149 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a |
| 1150 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT. |
| 1151 // So we can track the latency specifically for scroll update events. |
| 1152 ui::LatencyInfo::LatencyComponent original_component; |
| 1153 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 1154 0, |
| 1155 &original_component)) { |
| 1156 latency_info.AddLatencyNumberWithTimestamp( |
| 1157 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 1158 GetLatencyComponentId(), |
| 1159 original_component.sequence_number, |
| 1160 original_component.event_time, |
| 1161 original_component.event_count); |
| 1162 } |
| 1163 } |
1152 | 1164 |
1153 if (!IsInOverscrollGesture() && | 1165 if (!IsInOverscrollGesture() && |
1154 !gesture_event_filter_->ShouldForward( | 1166 !gesture_event_filter_->ShouldForward( |
1155 GestureEventWithLatencyInfo(gesture_event, latency_info))) { | 1167 GestureEventWithLatencyInfo(gesture_event, latency_info))) { |
1156 if (overscroll_controller_.get()) | 1168 if (overscroll_controller_.get()) |
1157 overscroll_controller_->DiscardingGestureEvent(gesture_event); | 1169 overscroll_controller_->DiscardingGestureEvent(gesture_event); |
1158 return; | 1170 return; |
1159 } | 1171 } |
1160 | 1172 |
1161 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), | 1173 ForwardInputEvent(gesture_event, sizeof(WebGestureEvent), |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 // Put all WebKeyboardEvent objects in a queue since we can't trust the | 1298 // Put all WebKeyboardEvent objects in a queue since we can't trust the |
1287 // renderer and we need to give something to the HandleKeyboardEvent | 1299 // renderer and we need to give something to the HandleKeyboardEvent |
1288 // handler. | 1300 // handler. |
1289 key_queue_.push_back(key_event); | 1301 key_queue_.push_back(key_event); |
1290 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); | 1302 HISTOGRAM_COUNTS_100("Renderer.KeyboardQueueSize", key_queue_.size()); |
1291 | 1303 |
1292 gesture_event_filter_->FlingHasBeenHalted(); | 1304 gesture_event_filter_->FlingHasBeenHalted(); |
1293 | 1305 |
1294 // Only forward the non-native portions of our event. | 1306 // Only forward the non-native portions of our event. |
1295 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), | 1307 ForwardInputEvent(key_event, sizeof(WebKeyboardEvent), |
1296 NewInputLatencyInfo(), | 1308 CreateRWHLatencyInfoIfNotExist(NULL), |
1297 is_keyboard_shortcut); | 1309 is_keyboard_shortcut); |
1298 } | 1310 } |
1299 } | 1311 } |
1300 | 1312 |
1301 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { | 1313 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { |
1302 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); | 1314 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); |
1303 } | 1315 } |
1304 | 1316 |
1305 int64 RenderWidgetHostImpl::GetLatencyComponentId() { | 1317 int64 RenderWidgetHostImpl::GetLatencyComponentId() { |
1306 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); | 1318 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); |
1307 } | 1319 } |
1308 | 1320 |
1309 // static | 1321 // static |
1310 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { | 1322 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { |
1311 g_check_for_pending_resize_ack = false; | 1323 g_check_for_pending_resize_ack = false; |
1312 } | 1324 } |
1313 | 1325 |
1314 ui::LatencyInfo RenderWidgetHostImpl::NewInputLatencyInfo() { | 1326 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( |
| 1327 const ui::LatencyInfo* original) { |
1315 ui::LatencyInfo info; | 1328 ui::LatencyInfo info; |
1316 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1329 if (original) |
| 1330 info = *original; |
| 1331 // In Aura, gesture event will already carry its original touch event's |
| 1332 // INPUT_EVENT_LATENCY_RWH_COMPONENT. |
| 1333 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
1317 GetLatencyComponentId(), | 1334 GetLatencyComponentId(), |
1318 ++last_input_number_); | 1335 NULL)) { |
| 1336 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 1337 GetLatencyComponentId(), |
| 1338 ++last_input_number_); |
| 1339 } |
1319 return info; | 1340 return info; |
1320 } | 1341 } |
1321 | 1342 |
1322 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, | 1343 void RenderWidgetHostImpl::SendInputEvent(const WebInputEvent& input_event, |
1323 int event_size, | 1344 int event_size, |
1324 const ui::LatencyInfo& latency_info, | 1345 const ui::LatencyInfo& latency_info, |
1325 bool is_keyboard_shortcut) { | 1346 bool is_keyboard_shortcut) { |
1326 DCHECK(latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1347 DCHECK(latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
1327 GetLatencyComponentId(), | 1348 GetLatencyComponentId(), |
1328 NULL)); | 1349 NULL)); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 // after this line. | 1434 // after this line. |
1414 next_mouse_move_.reset(); | 1435 next_mouse_move_.reset(); |
1415 | 1436 |
1416 StartHangMonitorTimeout( | 1437 StartHangMonitorTimeout( |
1417 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); | 1438 TimeDelta::FromMilliseconds(hung_renderer_delay_ms_)); |
1418 } | 1439 } |
1419 | 1440 |
1420 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( | 1441 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( |
1421 const WebKit::WebTouchEvent& touch_event, | 1442 const WebKit::WebTouchEvent& touch_event, |
1422 const ui::LatencyInfo& ui_latency) { | 1443 const ui::LatencyInfo& ui_latency) { |
1423 ui::LatencyInfo latency_info = NewInputLatencyInfo(); | 1444 ui::LatencyInfo latency_info = CreateRWHLatencyInfoIfNotExist(&ui_latency); |
1424 latency_info.MergeWith(ui_latency); | |
1425 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); | 1445 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info); |
1426 touch_event_queue_->QueueEvent(touch_with_latency); | 1446 touch_event_queue_->QueueEvent(touch_with_latency); |
1427 } | 1447 } |
1428 | 1448 |
1429 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { | 1449 void RenderWidgetHostImpl::AddKeyboardListener(KeyboardListener* listener) { |
1430 keyboard_listeners_.AddObserver(listener); | 1450 keyboard_listeners_.AddObserver(listener); |
1431 } | 1451 } |
1432 | 1452 |
1433 void RenderWidgetHostImpl::RemoveKeyboardListener( | 1453 void RenderWidgetHostImpl::RemoveKeyboardListener( |
1434 KeyboardListener* listener) { | 1454 KeyboardListener* listener) { |
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2653 1000000, | 2673 1000000, |
2654 100); | 2674 100); |
2655 } | 2675 } |
2656 | 2676 |
2657 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2677 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2658 switches::kEnableGpuBenchmarking)) | 2678 switches::kEnableGpuBenchmarking)) |
2659 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2679 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
2660 } | 2680 } |
2661 | 2681 |
2662 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2682 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
2663 ui::LatencyInfo::LatencyMap::const_iterator l = | 2683 ui::LatencyInfo::LatencyComponent rwh_component; |
2664 latency_info.latency_components.find(std::make_pair( | 2684 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, |
2665 ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, GetLatencyComponentId())); | 2685 GetLatencyComponentId(), |
2666 if (l == latency_info.latency_components.end()) | 2686 &rwh_component)) |
2667 return; | 2687 return; |
2668 | 2688 |
2669 rendering_stats_.input_event_count += l->second.event_count; | 2689 rendering_stats_.input_event_count += rwh_component.event_count; |
2670 rendering_stats_.total_input_latency += | 2690 rendering_stats_.total_input_latency += |
2671 l->second.event_count * | 2691 rwh_component.event_count * |
2672 (latency_info.swap_timestamp - l->second.event_time); | 2692 (latency_info.swap_timestamp - rwh_component.event_time); |
| 2693 |
| 2694 ui::LatencyInfo::LatencyComponent original_component; |
| 2695 if (latency_info.FindLatency( |
| 2696 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 2697 GetLatencyComponentId(), |
| 2698 &original_component)) { |
| 2699 // This UMA metric tracks the time from when the original touch event is |
| 2700 // created (averaged if there are multiple) to when the scroll gesture |
| 2701 // results in final frame swap. |
| 2702 base::TimeDelta delta = |
| 2703 latency_info.swap_timestamp - original_component.event_time; |
| 2704 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2705 "Event.Latency.TouchToScrollUpdateSwap", |
| 2706 delta.InMicroseconds(), |
| 2707 0, |
| 2708 1000000, |
| 2709 100); |
| 2710 rendering_stats_.scroll_update_count += original_component.event_count; |
| 2711 rendering_stats_.total_scroll_update_latency += |
| 2712 original_component.event_count * |
| 2713 (latency_info.swap_timestamp - original_component.event_time); |
| 2714 } |
2673 | 2715 |
2674 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2716 if (CommandLine::ForCurrentProcess()->HasSwitch( |
2675 switches::kEnableGpuBenchmarking)) | 2717 switches::kEnableGpuBenchmarking)) |
2676 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2718 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
2677 } | 2719 } |
2678 | 2720 |
2679 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2721 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2680 view_->DidReceiveRendererFrame(); | 2722 view_->DidReceiveRendererFrame(); |
2681 } | 2723 } |
2682 | 2724 |
(...skipping 11 matching lines...) Expand all Loading... |
2694 int process_id = (b->first.second >> 32) & 0xffffffff; | 2736 int process_id = (b->first.second >> 32) & 0xffffffff; |
2695 RenderWidgetHost* rwh = | 2737 RenderWidgetHost* rwh = |
2696 RenderWidgetHost::FromID(process_id, routing_id); | 2738 RenderWidgetHost::FromID(process_id, routing_id); |
2697 if (!rwh) | 2739 if (!rwh) |
2698 continue; | 2740 continue; |
2699 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2741 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
2700 } | 2742 } |
2701 } | 2743 } |
2702 | 2744 |
2703 } // namespace content | 2745 } // namespace content |
OLD | NEW |