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