Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(860)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 779763002: Factor out latency tracking from RenderWidgetHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 in_get_backing_store_(false), 176 in_get_backing_store_(false),
177 ignore_input_events_(false), 177 ignore_input_events_(false),
178 input_method_active_(false), 178 input_method_active_(false),
179 text_direction_updated_(false), 179 text_direction_updated_(false),
180 text_direction_(blink::WebTextDirectionLeftToRight), 180 text_direction_(blink::WebTextDirectionLeftToRight),
181 text_direction_canceled_(false), 181 text_direction_canceled_(false),
182 suppress_next_char_events_(false), 182 suppress_next_char_events_(false),
183 pending_mouse_lock_request_(false), 183 pending_mouse_lock_request_(false),
184 allow_privileged_mouse_lock_(false), 184 allow_privileged_mouse_lock_(false),
185 has_touch_handler_(false), 185 has_touch_handler_(false),
186 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32),
187 subscribe_uniform_enabled_(false), 186 subscribe_uniform_enabled_(false),
188 next_browser_snapshot_id_(1), 187 next_browser_snapshot_id_(1),
189 weak_factory_(this) { 188 weak_factory_(this) {
190 CHECK(delegate_); 189 CHECK(delegate_);
191 if (routing_id_ == MSG_ROUTING_NONE) { 190 if (routing_id_ == MSG_ROUTING_NONE) {
192 routing_id_ = process_->GetNextRoutingID(); 191 routing_id_ = process_->GetNextRoutingID();
193 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( 192 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
194 process_->GetID(), 193 process_->GetID(),
195 routing_id_); 194 routing_id_);
196 } else { 195 } else {
(...skipping 14 matching lines...) Expand all
211 g_routing_id_widget_map.Get().insert(std::make_pair( 210 g_routing_id_widget_map.Get().insert(std::make_pair(
212 RenderWidgetHostID(process->GetID(), routing_id_), this)); 211 RenderWidgetHostID(process->GetID(), routing_id_), this));
213 CHECK(result.second) << "Inserting a duplicate item!"; 212 CHECK(result.second) << "Inserting a duplicate item!";
214 process_->AddRoute(routing_id_, this); 213 process_->AddRoute(routing_id_, this);
215 214
216 // If we're initially visible, tell the process host that we're alive. 215 // If we're initially visible, tell the process host that we're alive.
217 // Otherwise we'll notify the process host when we are first shown. 216 // Otherwise we'll notify the process host when we are first shown.
218 if (!hidden) 217 if (!hidden)
219 process_->WidgetRestored(); 218 process_->WidgetRestored();
220 219
220 latency_tracker_.Initialize(routing_id, GetProcess()->GetID());
221
221 input_router_.reset(new InputRouterImpl( 222 input_router_.reset(new InputRouterImpl(
222 process_, this, this, routing_id_, GetInputRouterConfigForPlatform())); 223 process_, this, this, routing_id_, GetInputRouterConfigForPlatform()));
223 224
224 touch_emulator_.reset(); 225 touch_emulator_.reset();
225 226
226 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( 227 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
227 IsRenderView() ? RenderViewHost::From(this) : NULL); 228 IsRenderView() ? RenderViewHost::From(this) : NULL);
228 if (BrowserPluginGuest::IsGuest(rvh) || 229 if (BrowserPluginGuest::IsGuest(rvh) ||
229 !base::CommandLine::ForCurrentProcess()->HasSwitch( 230 !base::CommandLine::ForCurrentProcess()->HasSwitch(
230 switches::kDisableHangMonitor)) { 231 switches::kDisableHangMonitor)) {
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 876
876 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) { 877 void RenderWidgetHostImpl::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
877 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo()); 878 ForwardMouseEventWithLatencyInfo(mouse_event, ui::LatencyInfo());
878 } 879 }
879 880
880 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo( 881 void RenderWidgetHostImpl::ForwardMouseEventWithLatencyInfo(
881 const blink::WebMouseEvent& mouse_event, 882 const blink::WebMouseEvent& mouse_event,
882 const ui::LatencyInfo& ui_latency) { 883 const ui::LatencyInfo& ui_latency) {
883 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent", 884 TRACE_EVENT2("input", "RenderWidgetHostImpl::ForwardMouseEvent",
884 "x", mouse_event.x, "y", mouse_event.y); 885 "x", mouse_event.x, "y", mouse_event.y);
885 ui::LatencyInfo::InputCoordinate logical_coordinate(mouse_event.x,
886 mouse_event.y);
887
888 ui::LatencyInfo latency_info = CreateInputEventLatencyInfoIfNotExist(
889 &ui_latency, mouse_event.type, &logical_coordinate, 1);
890 886
891 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) { 887 for (size_t i = 0; i < mouse_event_callbacks_.size(); ++i) {
892 if (mouse_event_callbacks_[i].Run(mouse_event)) 888 if (mouse_event_callbacks_[i].Run(mouse_event))
893 return; 889 return;
894 } 890 }
895 891
896 if (IgnoreInputEvents()) 892 if (IgnoreInputEvents())
897 return; 893 return;
898 894
899 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event)) 895 if (touch_emulator_ && touch_emulator_->HandleMouseEvent(mouse_event))
900 return; 896 return;
901 897
902 input_router_->SendMouseEvent(MouseEventWithLatencyInfo(mouse_event, 898 MouseEventWithLatencyInfo mouse_with_latency(mouse_event, ui_latency);
903 latency_info)); 899 StartTrackingInputEventLatency(mouse_event, &mouse_with_latency.latency);
900 input_router_->SendMouseEvent(mouse_with_latency);
904 901
905 // Pass mouse state to gpu service if the subscribe uniform 902 // Pass mouse state to gpu service if the subscribe uniform
906 // extension is enabled. 903 // extension is enabled.
907 // TODO(orglofch): Only pass mouse information if one of the GL Contexts 904 // TODO(orglofch): Only pass mouse information if one of the GL Contexts
908 // is subscribed to GL_MOUSE_POSITION_CHROMIUM 905 // is subscribed to GL_MOUSE_POSITION_CHROMIUM
909 if (subscribe_uniform_enabled_) { 906 if (subscribe_uniform_enabled_) {
910 gpu::ValueState state; 907 gpu::ValueState state;
911 state.int_value[0] = mouse_event.x; 908 state.int_value[0] = mouse_event.x;
912 state.int_value[1] = mouse_event.y; 909 state.int_value[1] = mouse_event.y;
913 GpuProcessHost::SendOnIO( 910 GpuProcessHost::SendOnIO(
(...skipping 10 matching lines...) Expand all
924 void RenderWidgetHostImpl::ForwardWheelEvent( 921 void RenderWidgetHostImpl::ForwardWheelEvent(
925 const WebMouseWheelEvent& wheel_event) { 922 const WebMouseWheelEvent& wheel_event) {
926 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo()); 923 ForwardWheelEventWithLatencyInfo(wheel_event, ui::LatencyInfo());
927 } 924 }
928 925
929 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo( 926 void RenderWidgetHostImpl::ForwardWheelEventWithLatencyInfo(
930 const blink::WebMouseWheelEvent& wheel_event, 927 const blink::WebMouseWheelEvent& wheel_event,
931 const ui::LatencyInfo& ui_latency) { 928 const ui::LatencyInfo& ui_latency) {
932 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent"); 929 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardWheelEvent");
933 930
934 ui::LatencyInfo::InputCoordinate logical_coordinate(wheel_event.x,
935 wheel_event.y);
936
937 ui::LatencyInfo latency_info = CreateInputEventLatencyInfoIfNotExist(
938 &ui_latency, wheel_event.type, &logical_coordinate, 1);
939
940 if (IgnoreInputEvents()) 931 if (IgnoreInputEvents())
941 return; 932 return;
942 933
943 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event)) 934 if (touch_emulator_ && touch_emulator_->HandleMouseWheelEvent(wheel_event))
944 return; 935 return;
945 936
946 input_router_->SendWheelEvent(MouseWheelEventWithLatencyInfo(wheel_event, 937 MouseWheelEventWithLatencyInfo wheel_with_latency(wheel_event, ui_latency);
947 latency_info)); 938 StartTrackingInputEventLatency(wheel_event, &wheel_with_latency.latency);
939 input_router_->SendWheelEvent(wheel_with_latency);
948 } 940 }
949 941
950 void RenderWidgetHostImpl::ForwardGestureEvent( 942 void RenderWidgetHostImpl::ForwardGestureEvent(
951 const blink::WebGestureEvent& gesture_event) { 943 const blink::WebGestureEvent& gesture_event) {
952 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo()); 944 ForwardGestureEventWithLatencyInfo(gesture_event, ui::LatencyInfo());
953 } 945 }
954 946
955 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo( 947 void RenderWidgetHostImpl::ForwardGestureEventWithLatencyInfo(
956 const blink::WebGestureEvent& gesture_event, 948 const blink::WebGestureEvent& gesture_event,
957 const ui::LatencyInfo& ui_latency) { 949 const ui::LatencyInfo& ui_latency) {
958 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent"); 950 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardGestureEvent");
959 // Early out if necessary, prior to performing latency logic. 951 // Early out if necessary, prior to performing latency logic.
960 if (IgnoreInputEvents()) 952 if (IgnoreInputEvents())
961 return; 953 return;
962 954
963 if (delegate_->PreHandleGestureEvent(gesture_event)) 955 if (delegate_->PreHandleGestureEvent(gesture_event))
964 return; 956 return;
965 957
966 ui::LatencyInfo::InputCoordinate logical_coordinate(gesture_event.x, 958 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, ui_latency);
967 gesture_event.y); 959 StartTrackingInputEventLatency(gesture_event, &gesture_with_latency.latency);
968
969 ui::LatencyInfo latency_info = CreateInputEventLatencyInfoIfNotExist(
970 &ui_latency, gesture_event.type, &logical_coordinate, 1);
971
972 if (gesture_event.type == blink::WebInputEvent::GestureScrollUpdate) {
973 latency_info.AddLatencyNumber(
974 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT,
975 GetLatencyComponentId(),
976 ++last_input_number_);
977
978 // Make a copy of the INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT with a
979 // different name INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT.
980 // So we can track the latency specifically for scroll update events.
981 ui::LatencyInfo::LatencyComponent original_component;
982 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
983 0,
984 &original_component)) {
985 latency_info.AddLatencyNumberWithTimestamp(
986 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
987 GetLatencyComponentId(),
988 original_component.sequence_number,
989 original_component.event_time,
990 original_component.event_count);
991 }
992 }
993
994 GestureEventWithLatencyInfo gesture_with_latency(gesture_event, latency_info);
995 input_router_->SendGestureEvent(gesture_with_latency); 960 input_router_->SendGestureEvent(gesture_with_latency);
996 } 961 }
997 962
998 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent( 963 void RenderWidgetHostImpl::ForwardEmulatedTouchEvent(
999 const blink::WebTouchEvent& touch_event) { 964 const blink::WebTouchEvent& touch_event) {
1000 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent"); 965 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardEmulatedTouchEvent");
1001 966
1002 ui::LatencyInfo::InputCoordinate 967 TouchEventWithLatencyInfo touch_with_latency(touch_event);
1003 logical_coordinates[ui::LatencyInfo::kMaxInputCoordinates]; 968 StartTrackingInputEventLatency(touch_event, &touch_with_latency.latency);
1004 size_t logical_coordinates_size =
1005 std::min(arraysize(logical_coordinates),
1006 static_cast<size_t>(touch_event.touchesLength));
1007 for (size_t i = 0; i < logical_coordinates_size; i++) {
1008 logical_coordinates[i] = ui::LatencyInfo::InputCoordinate(
1009 touch_event.touches[i].position.x, touch_event.touches[i].position.y);
1010 }
1011
1012 ui::LatencyInfo latency_info = CreateInputEventLatencyInfoIfNotExist(
1013 NULL, touch_event.type, logical_coordinates, logical_coordinates_size);
1014 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
1015 input_router_->SendTouchEvent(touch_with_latency); 969 input_router_->SendTouchEvent(touch_with_latency);
1016 } 970 }
1017 971
1018 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo( 972 void RenderWidgetHostImpl::ForwardTouchEventWithLatencyInfo(
1019 const blink::WebTouchEvent& touch_event, 973 const blink::WebTouchEvent& touch_event,
1020 const ui::LatencyInfo& ui_latency) { 974 const ui::LatencyInfo& ui_latency) {
1021 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent"); 975 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardTouchEvent");
1022 976
1023 // Always forward TouchEvents for touch stream consistency. They will be 977 // Always forward TouchEvents for touch stream consistency. They will be
1024 // ignored if appropriate in FilterInputEvent(). 978 // ignored if appropriate in FilterInputEvent().
1025 979
1026 ui::LatencyInfo::InputCoordinate 980 TouchEventWithLatencyInfo touch_with_latency(touch_event, ui_latency);
1027 logical_coordinates[ui::LatencyInfo::kMaxInputCoordinates];
1028 size_t logical_coordinates_size =
1029 std::min(arraysize(logical_coordinates),
1030 static_cast<size_t>(touch_event.touchesLength));
1031 for (size_t i = 0; i < logical_coordinates_size; i++) {
1032 logical_coordinates[i] = ui::LatencyInfo::InputCoordinate(
1033 touch_event.touches[i].position.x, touch_event.touches[i].position.y);
1034 }
1035
1036 ui::LatencyInfo latency_info = CreateInputEventLatencyInfoIfNotExist(
1037 &ui_latency,
1038 touch_event.type,
1039 logical_coordinates,
1040 logical_coordinates_size);
1041 TouchEventWithLatencyInfo touch_with_latency(touch_event, latency_info);
1042
1043 if (touch_emulator_ && 981 if (touch_emulator_ &&
1044 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) { 982 touch_emulator_->HandleTouchEvent(touch_with_latency.event)) {
1045 if (view_) { 983 if (view_) {
1046 view_->ProcessAckedTouchEvent( 984 view_->ProcessAckedTouchEvent(
1047 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED); 985 touch_with_latency, INPUT_EVENT_ACK_STATE_CONSUMED);
1048 } 986 }
1049 return; 987 return;
1050 } 988 }
1051 989
990 StartTrackingInputEventLatency(touch_event, &touch_with_latency.latency);
1052 input_router_->SendTouchEvent(touch_with_latency); 991 input_router_->SendTouchEvent(touch_with_latency);
1053 } 992 }
1054 993
1055 void RenderWidgetHostImpl::ForwardKeyboardEvent( 994 void RenderWidgetHostImpl::ForwardKeyboardEvent(
1056 const NativeWebKeyboardEvent& key_event) { 995 const NativeWebKeyboardEvent& key_event) {
1057 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent"); 996 TRACE_EVENT0("input", "RenderWidgetHostImpl::ForwardKeyboardEvent");
1058 if (IgnoreInputEvents()) 997 if (IgnoreInputEvents())
1059 return; 998 return;
1060 999
1061 if (!process_->HasConnection()) 1000 if (!process_->HasConnection())
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut)) 1048 if (delegate_->PreHandleKeyboardEvent(key_event, &is_shortcut))
1110 return; 1049 return;
1111 1050
1112 if (key_event.type == WebKeyboardEvent::RawKeyDown) 1051 if (key_event.type == WebKeyboardEvent::RawKeyDown)
1113 suppress_next_char_events_ = false; 1052 suppress_next_char_events_ = false;
1114 } 1053 }
1115 1054
1116 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event)) 1055 if (touch_emulator_ && touch_emulator_->HandleKeyboardEvent(key_event))
1117 return; 1056 return;
1118 1057
1119 input_router_->SendKeyboardEvent( 1058 ui::LatencyInfo latency;
1120 key_event, 1059 StartTrackingInputEventLatency(key_event, &latency);
1121 CreateInputEventLatencyInfoIfNotExist(NULL, key_event.type, NULL, 0), 1060 input_router_->SendKeyboardEvent(key_event, latency, is_shortcut);
1122 is_shortcut);
1123 } 1061 }
1124 1062
1125 void RenderWidgetHostImpl::QueueSyntheticGesture( 1063 void RenderWidgetHostImpl::QueueSyntheticGesture(
1126 scoped_ptr<SyntheticGesture> synthetic_gesture, 1064 scoped_ptr<SyntheticGesture> synthetic_gesture,
1127 const base::Callback<void(SyntheticGesture::Result)>& on_complete) { 1065 const base::Callback<void(SyntheticGesture::Result)>& on_complete) {
1128 if (!synthetic_gesture_controller_ && view_) { 1066 if (!synthetic_gesture_controller_ && view_) {
1129 synthetic_gesture_controller_.reset( 1067 synthetic_gesture_controller_.reset(
1130 new SyntheticGestureController( 1068 new SyntheticGestureController(
1131 view_->CreateSyntheticGestureTarget().Pass())); 1069 view_->CreateSyntheticGestureTarget().Pass()));
1132 } 1070 }
(...skipping 12 matching lines...) Expand all
1145 void RenderWidgetHostImpl::ShowContextMenuAtPoint(const gfx::Point& point) { 1083 void RenderWidgetHostImpl::ShowContextMenuAtPoint(const gfx::Point& point) {
1146 Send(new ViewMsg_ShowContextMenu( 1084 Send(new ViewMsg_ShowContextMenu(
1147 GetRoutingID(), ui::MENU_SOURCE_MOUSE, point)); 1085 GetRoutingID(), ui::MENU_SOURCE_MOUSE, point));
1148 } 1086 }
1149 1087
1150 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) { 1088 void RenderWidgetHostImpl::SendCursorVisibilityState(bool is_visible) {
1151 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible)); 1089 Send(new InputMsg_CursorVisibilityChange(GetRoutingID(), is_visible));
1152 } 1090 }
1153 1091
1154 int64 RenderWidgetHostImpl::GetLatencyComponentId() const { 1092 int64 RenderWidgetHostImpl::GetLatencyComponentId() const {
1155 return GetRoutingID() | (static_cast<int64>(GetProcess()->GetID()) << 32); 1093 return latency_tracker_.latency_component_id();
1156 } 1094 }
1157 1095
1158 // static 1096 // static
1159 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() { 1097 void RenderWidgetHostImpl::DisableResizeAckCheckForTesting() {
1160 g_check_for_pending_resize_ack = false; 1098 g_check_for_pending_resize_ack = false;
1161 } 1099 }
1162 1100
1163 ui::LatencyInfo RenderWidgetHostImpl::CreateInputEventLatencyInfoIfNotExist(
1164 const ui::LatencyInfo* original,
1165 WebInputEvent::Type type,
1166 const ui::LatencyInfo::InputCoordinate* logical_coordinates,
1167 size_t logical_coordinates_size) {
1168 ui::LatencyInfo info;
1169 if (original)
1170 info = *original;
1171 // In Aura, gesture event will already carry its original touch event's
1172 // INPUT_EVENT_LATENCY_RWH_COMPONENT.
1173 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1174 GetLatencyComponentId(),
1175 NULL)) {
1176 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
1177 GetLatencyComponentId(),
1178 ++last_input_number_);
1179 info.TraceEventType(WebInputEventTraits::GetName(type));
1180
1181 // Convert logical coordinates to physical coordinates, based on the
1182 // device scale factor.
1183 float device_scale_factor =
1184 screen_info_ ? screen_info_->deviceScaleFactor : 1;
1185 DCHECK(logical_coordinates_size <= ui::LatencyInfo::kMaxInputCoordinates);
1186 info.input_coordinates_size = logical_coordinates_size;
1187 for (size_t i = 0; i < info.input_coordinates_size; i++) {
1188 info.input_coordinates[i].x =
1189 logical_coordinates[i].x * device_scale_factor;
1190 info.input_coordinates[i].y =
1191 logical_coordinates[i].y * device_scale_factor;
1192 }
1193 }
1194
1195 return info;
1196 }
1197
1198
1199 void RenderWidgetHostImpl::AddKeyPressEventCallback( 1101 void RenderWidgetHostImpl::AddKeyPressEventCallback(
1200 const KeyPressEventCallback& callback) { 1102 const KeyPressEventCallback& callback) {
1201 key_press_event_callbacks_.push_back(callback); 1103 key_press_event_callbacks_.push_back(callback);
1202 } 1104 }
1203 1105
1204 void RenderWidgetHostImpl::RemoveKeyPressEventCallback( 1106 void RenderWidgetHostImpl::RemoveKeyPressEventCallback(
1205 const KeyPressEventCallback& callback) { 1107 const KeyPressEventCallback& callback) {
1206 for (size_t i = 0; i < key_press_event_callbacks_.size(); ++i) { 1108 for (size_t i = 0; i < key_press_event_callbacks_.size(); ++i) {
1207 if (key_press_event_callbacks_[i].Equals(callback)) { 1109 if (key_press_event_callbacks_[i].Equals(callback)) {
1208 key_press_event_callbacks_.erase( 1110 key_press_event_callbacks_.erase(
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame")); 1433 TRACE_DISABLED_BY_DEFAULT("OnSwapCompositorFrame"));
1532 ViewHostMsg_SwapCompositorFrame::Param param; 1434 ViewHostMsg_SwapCompositorFrame::Param param;
1533 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param)) 1435 if (!ViewHostMsg_SwapCompositorFrame::Read(&message, &param))
1534 return false; 1436 return false;
1535 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame); 1437 scoped_ptr<cc::CompositorFrame> frame(new cc::CompositorFrame);
1536 uint32 output_surface_id = param.a; 1438 uint32 output_surface_id = param.a;
1537 param.b.AssignTo(frame.get()); 1439 param.b.AssignTo(frame.get());
1538 std::vector<IPC::Message> messages_to_deliver_with_frame; 1440 std::vector<IPC::Message> messages_to_deliver_with_frame;
1539 messages_to_deliver_with_frame.swap(param.c); 1441 messages_to_deliver_with_frame.swap(param.c);
1540 1442
1541 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) 1443 latency_tracker_.OnSwapCompositorFrame(&frame->metadata.latency_info);
1542 AddLatencyInfoComponentIds(&frame->metadata.latency_info[i]);
1543 1444
1544 input_router_->OnViewUpdated( 1445 input_router_->OnViewUpdated(
1545 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata)); 1446 GetInputRouterViewFlagsFromCompositorFrameMetadata(frame->metadata));
1546 1447
1547 if (view_) { 1448 if (view_) {
1548 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass()); 1449 view_->OnSwapCompositorFrame(output_surface_id, frame.Pass());
1549 view_->DidReceiveRendererFrame(); 1450 view_->DidReceiveRendererFrame();
1550 } else { 1451 } else {
1551 cc::CompositorFrameAck ack; 1452 cc::CompositorFrameAck ack;
1552 if (frame->gl_frame_data) { 1453 if (frame->gl_frame_data) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 1825
1925 // WARNING: This RenderWidgetHostImpl can be deallocated at this point 1826 // WARNING: This RenderWidgetHostImpl can be deallocated at this point
1926 // (i.e. in the case of Ctrl+W, where the call to 1827 // (i.e. in the case of Ctrl+W, where the call to
1927 // HandleKeyboardEvent destroys this RenderWidgetHostImpl). 1828 // HandleKeyboardEvent destroys this RenderWidgetHostImpl).
1928 } 1829 }
1929 } 1830 }
1930 1831
1931 void RenderWidgetHostImpl::OnWheelEventAck( 1832 void RenderWidgetHostImpl::OnWheelEventAck(
1932 const MouseWheelEventWithLatencyInfo& wheel_event, 1833 const MouseWheelEventWithLatencyInfo& wheel_event,
1933 InputEventAckState ack_result) { 1834 InputEventAckState ack_result) {
1934 ui::LatencyInfo latency = wheel_event.latency; 1835 latency_tracker_.OnInputEventAck(wheel_event.event, &wheel_event.latency);
1935 latency.AddLatencyNumber(
1936 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0);
1937 if (!wheel_event.latency.FindLatency(
1938 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) {
1939 // MouseWheelEvent latency ends when it is acked but does not cause any
1940 // rendering scheduled.
1941 latency.AddLatencyNumber(
1942 ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, 0);
1943 }
1944 ComputeInputLatencyHistograms(blink::WebInputEvent::MouseWheel, latency);
1945 1836
1946 if (!is_hidden() && view_) { 1837 if (!is_hidden() && view_) {
1947 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED && 1838 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED &&
1948 delegate_->HandleWheelEvent(wheel_event.event)) { 1839 delegate_->HandleWheelEvent(wheel_event.event)) {
1949 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED; 1840 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED;
1950 } 1841 }
1951 view_->WheelEventAck(wheel_event.event, ack_result); 1842 view_->WheelEventAck(wheel_event.event, ack_result);
1952 } 1843 }
1953 } 1844 }
1954 1845
1955 void RenderWidgetHostImpl::OnGestureEventAck( 1846 void RenderWidgetHostImpl::OnGestureEventAck(
1956 const GestureEventWithLatencyInfo& event, 1847 const GestureEventWithLatencyInfo& event,
1957 InputEventAckState ack_result) { 1848 InputEventAckState ack_result) {
1958 if (!event.latency.FindLatency( 1849 latency_tracker_.OnInputEventAck(event.event, &event.latency);
1959 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) {
1960 // GestureEvent latency ends when it is acked but does not cause any
1961 // rendering scheduled.
1962 ui::LatencyInfo latency = event.latency;
1963 latency.AddLatencyNumber(
1964 ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0 ,0);
1965 }
1966 1850
1967 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED) { 1851 if (ack_result != INPUT_EVENT_ACK_STATE_CONSUMED) {
1968 if (delegate_->HandleGestureEvent(event.event)) 1852 if (delegate_->HandleGestureEvent(event.event))
1969 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED; 1853 ack_result = INPUT_EVENT_ACK_STATE_CONSUMED;
1970 } 1854 }
1971 1855
1972 if (view_) 1856 if (view_)
1973 view_->GestureEventAck(event.event, ack_result); 1857 view_->GestureEventAck(event.event, ack_result);
1974 } 1858 }
1975 1859
1976 void RenderWidgetHostImpl::OnTouchEventAck( 1860 void RenderWidgetHostImpl::OnTouchEventAck(
1977 const TouchEventWithLatencyInfo& event, 1861 const TouchEventWithLatencyInfo& event,
1978 InputEventAckState ack_result) { 1862 InputEventAckState ack_result) {
1979 TouchEventWithLatencyInfo touch_event = event; 1863 latency_tracker_.OnInputEventAck(event.event, &event.latency);
1980 touch_event.latency.AddLatencyNumber(
1981 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0);
1982 // TouchEvent latency ends at ack if it didn't cause any rendering.
1983 if (!touch_event.latency.FindLatency(
1984 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) {
1985 touch_event.latency.AddLatencyNumber(
1986 ui::INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT, 0, 0);
1987 }
1988 ComputeInputLatencyHistograms(
1989 blink::WebInputEvent::TouchTypeFirst, touch_event.latency);
1990 1864
1991 if (touch_emulator_ && 1865 if (touch_emulator_ &&
1992 touch_emulator_->HandleTouchEventAck(event.event, ack_result)) { 1866 touch_emulator_->HandleTouchEventAck(event.event, ack_result)) {
1993 return; 1867 return;
1994 } 1868 }
1995 1869
1996 if (view_) 1870 if (view_)
1997 view_->ProcessAckedTouchEvent(touch_event, ack_result); 1871 view_->ProcessAckedTouchEvent(event, ack_result);
1998 } 1872 }
1999 1873
2000 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { 1874 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) {
2001 if (type == BAD_ACK_MESSAGE) { 1875 if (type == BAD_ACK_MESSAGE) {
2002 RecordAction(base::UserMetricsAction("BadMessageTerminate_RWH2")); 1876 RecordAction(base::UserMetricsAction("BadMessageTerminate_RWH2"));
2003 process_->ReceivedBadMessage(); 1877 process_->ReceivedBadMessage();
2004 } else if (type == UNEXPECTED_EVENT_TYPE) { 1878 } else if (type == UNEXPECTED_EVENT_TYPE) {
2005 suppress_next_char_events_ = false; 1879 suppress_next_char_events_ = false;
2006 } 1880 }
2007 } 1881 }
2008 1882
1883 void RenderWidgetHostImpl::StartTrackingInputEventLatency(
1884 const blink::WebInputEvent& event,
1885 ui::LatencyInfo* latency) {
1886 latency_tracker_.OnInputEvent(
1887 event, screen_info_ ? screen_info_->deviceScaleFactor : 1, latency);
1888 }
Yufeng Shen (Slow to review) 2014/12/04 23:18:57 It looks like RenderWidgetHostImpl::GetWebScreenIn
jdduke (slow) 2014/12/05 18:36:10 Done.
1889
2009 void RenderWidgetHostImpl::OnSyntheticGestureCompleted( 1890 void RenderWidgetHostImpl::OnSyntheticGestureCompleted(
2010 SyntheticGesture::Result result) { 1891 SyntheticGesture::Result result) {
2011 Send(new InputMsg_SyntheticGestureCompleted(GetRoutingID())); 1892 Send(new InputMsg_SyntheticGestureCompleted(GetRoutingID()));
2012 } 1893 }
2013 1894
2014 bool RenderWidgetHostImpl::IgnoreInputEvents() const { 1895 bool RenderWidgetHostImpl::IgnoreInputEvents() const {
2015 return ignore_input_events_ || process_->IgnoreInputEvents(); 1896 return ignore_input_events_ || process_->IgnoreInputEvents();
2016 } 1897 }
2017 1898
2018 bool RenderWidgetHostImpl::ShouldForwardTouchEvent() const { 1899 bool RenderWidgetHostImpl::ShouldForwardTouchEvent() const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 if (!auto_resize_enabled_) 1991 if (!auto_resize_enabled_)
2111 return; 1992 return;
2112 1993
2113 OnRenderAutoResized(new_size); 1994 OnRenderAutoResized(new_size);
2114 } 1995 }
2115 1996
2116 void RenderWidgetHostImpl::DetachDelegate() { 1997 void RenderWidgetHostImpl::DetachDelegate() {
2117 delegate_ = NULL; 1998 delegate_ = NULL;
2118 } 1999 }
2119 2000
2120 void RenderWidgetHostImpl::ComputeInputLatencyHistograms(
2121 blink::WebInputEvent::Type type,
2122 const ui::LatencyInfo& latency_info) const {
2123 ui::LatencyInfo::LatencyComponent rwh_component;
2124 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
2125 GetLatencyComponentId(),
2126 &rwh_component))
2127 return;
2128 DCHECK_EQ(rwh_component.event_count, 1u);
2129
2130 ui::LatencyInfo::LatencyComponent ui_component;
2131 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT,
2132 0,
2133 &ui_component)) {
2134 DCHECK_EQ(ui_component.event_count, 1u);
2135 base::TimeDelta ui_delta =
2136 rwh_component.event_time - ui_component.event_time;
2137 switch (type) {
2138 case blink::WebInputEvent::MouseWheel:
2139 UMA_HISTOGRAM_CUSTOM_COUNTS(
2140 "Event.Latency.Browser.WheelUI",
2141 ui_delta.InMicroseconds(), 1, 20000, 100);
2142 break;
2143 case blink::WebInputEvent::TouchTypeFirst:
2144 UMA_HISTOGRAM_CUSTOM_COUNTS(
2145 "Event.Latency.Browser.TouchUI",
2146 ui_delta.InMicroseconds(), 1, 20000, 100);
2147 break;
2148 default:
2149 NOTREACHED();
2150 break;
2151 }
2152 }
2153
2154 ui::LatencyInfo::LatencyComponent acked_component;
2155 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT,
2156 0,
2157 &acked_component)) {
2158 DCHECK_EQ(acked_component.event_count, 1u);
2159 base::TimeDelta acked_delta =
2160 acked_component.event_time - rwh_component.event_time;
2161 switch (type) {
2162 case blink::WebInputEvent::MouseWheel:
2163 UMA_HISTOGRAM_CUSTOM_COUNTS(
2164 "Event.Latency.Browser.WheelAcked",
2165 acked_delta.InMicroseconds(), 1, 1000000, 100);
2166 break;
2167 case blink::WebInputEvent::TouchTypeFirst:
2168 UMA_HISTOGRAM_CUSTOM_COUNTS(
2169 "Event.Latency.Browser.TouchAcked",
2170 acked_delta.InMicroseconds(), 1, 1000000, 100);
2171 break;
2172 default:
2173 NOTREACHED();
2174 break;
2175 }
2176 }
2177 }
2178
2179 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2001 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2180 ui::LatencyInfo::LatencyComponent window_snapshot_component; 2002 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2181 if (latency_info.FindLatency(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT, 2003 if (latency_info.FindLatency(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2182 GetLatencyComponentId(), 2004 GetLatencyComponentId(),
2183 &window_snapshot_component)) { 2005 &window_snapshot_component)) {
2184 WindowOldSnapshotReachedScreen( 2006 WindowOldSnapshotReachedScreen(
2185 static_cast<int>(window_snapshot_component.sequence_number)); 2007 static_cast<int>(window_snapshot_component.sequence_number));
2186 } 2008 }
2187 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 2009 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2188 GetLatencyComponentId(), 2010 GetLatencyComponentId(),
2189 &window_snapshot_component)) { 2011 &window_snapshot_component)) {
2190 int sequence_number = static_cast<int>( 2012 int sequence_number = static_cast<int>(
2191 window_snapshot_component.sequence_number); 2013 window_snapshot_component.sequence_number);
2192 #if defined(OS_MACOSX) 2014 #if defined(OS_MACOSX)
2193 // On Mac, when using CoreAnmation, there is a delay between when content 2015 // On Mac, when using CoreAnmation, there is a delay between when content
2194 // is drawn to the screen, and when the snapshot will actually pick up 2016 // is drawn to the screen, and when the snapshot will actually pick up
2195 // that content. Insert a manual delay of 1/6th of a second (to simulate 2017 // that content. Insert a manual delay of 1/6th of a second (to simulate
2196 // 10 frames at 60 fps) before actually taking the snapshot. 2018 // 10 frames at 60 fps) before actually taking the snapshot.
2197 base::MessageLoop::current()->PostDelayedTask( 2019 base::MessageLoop::current()->PostDelayedTask(
2198 FROM_HERE, 2020 FROM_HERE,
2199 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, 2021 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen,
2200 weak_factory_.GetWeakPtr(), 2022 weak_factory_.GetWeakPtr(),
2201 sequence_number), 2023 sequence_number),
2202 base::TimeDelta::FromSecondsD(1. / 6)); 2024 base::TimeDelta::FromSecondsD(1. / 6));
2203 #else 2025 #else
2204 WindowSnapshotReachedScreen(sequence_number); 2026 WindowSnapshotReachedScreen(sequence_number);
2205 #endif 2027 #endif
2206 } 2028 }
2207 2029
2208 ui::LatencyInfo::LatencyComponent swap_component; 2030 latency_tracker_.OnFrameSwapped(latency_info);
2209 if (!latency_info.FindLatency(
2210 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
2211 0,
2212 &swap_component)) {
2213 return;
2214 }
2215 ui::LatencyInfo::LatencyComponent tab_switch_component;
2216 if (latency_info.FindLatency(ui::TAB_SHOW_COMPONENT,
2217 GetLatencyComponentId(),
2218 &tab_switch_component)) {
2219 base::TimeDelta delta =
2220 swap_component.event_time - tab_switch_component.event_time;
2221 for (size_t i = 0; i < tab_switch_component.event_count; i++) {
2222 UMA_HISTOGRAM_TIMES("MPArch.RWH_TabSwitchPaintDuration", delta);
2223 }
2224 }
2225
2226 ui::LatencyInfo::LatencyComponent rwh_component;
2227 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
2228 GetLatencyComponentId(),
2229 &rwh_component)) {
2230 return;
2231 }
2232
2233 ui::LatencyInfo::LatencyComponent original_component;
2234 if (latency_info.FindLatency(
2235 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
2236 GetLatencyComponentId(),
2237 &original_component)) {
2238 // This UMA metric tracks the time from when the original touch event is
2239 // created (averaged if there are multiple) to when the scroll gesture
2240 // results in final frame swap.
2241 base::TimeDelta delta =
2242 swap_component.event_time - original_component.event_time;
2243 for (size_t i = 0; i < original_component.event_count; i++) {
2244 UMA_HISTOGRAM_CUSTOM_COUNTS(
2245 "Event.Latency.TouchToScrollUpdateSwap",
2246 delta.InMicroseconds(),
2247 1,
2248 1000000,
2249 100);
2250 }
2251 }
2252 } 2031 }
2253 2032
2254 void RenderWidgetHostImpl::DidReceiveRendererFrame() { 2033 void RenderWidgetHostImpl::DidReceiveRendererFrame() {
2255 view_->DidReceiveRendererFrame(); 2034 view_->DidReceiveRendererFrame();
2256 } 2035 }
2257 2036
2258 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( 2037 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback(
2259 int routing_id, 2038 int routing_id,
2260 int snapshot_id, 2039 int snapshot_id,
2261 gfx::Size snapshot_size, 2040 gfx::Size snapshot_size,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
2377 continue; 2156 continue;
2378 } 2157 }
2379 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); 2158 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
2380 if (rwhi_set.insert(rwhi).second) 2159 if (rwhi_set.insert(rwhi).second)
2381 rwhi->FrameSwapped(latency_info[i]); 2160 rwhi->FrameSwapped(latency_info[i]);
2382 } 2161 }
2383 } 2162 }
2384 } 2163 }
2385 } 2164 }
2386 2165
2387 void RenderWidgetHostImpl::AddLatencyInfoComponentIds(
2388 ui::LatencyInfo* latency_info) {
2389 ui::LatencyInfo::LatencyMap new_components;
2390 ui::LatencyInfo::LatencyMap::iterator lc =
2391 latency_info->latency_components.begin();
2392 while (lc != latency_info->latency_components.end()) {
2393 ui::LatencyComponentType component_type = lc->first.first;
2394 if (component_type == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT ||
2395 component_type == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT) {
2396 // Generate a new component entry with the correct component ID
2397 ui::LatencyInfo::LatencyMap::key_type key =
2398 std::make_pair(component_type, GetLatencyComponentId());
2399 new_components[key] = lc->second;
2400
2401 // Remove the old entry
2402 latency_info->latency_components.erase(lc++);
2403 } else {
2404 ++lc;
2405 }
2406 }
2407
2408 // Add newly generated components into the latency info
2409 for (lc = new_components.begin(); lc != new_components.end(); ++lc) {
2410 latency_info->latency_components[lc->first] = lc->second;
2411 }
2412 }
2413
2414 BrowserAccessibilityManager* 2166 BrowserAccessibilityManager*
2415 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() { 2167 RenderWidgetHostImpl::GetRootBrowserAccessibilityManager() {
2416 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL; 2168 return delegate_ ? delegate_->GetRootBrowserAccessibilityManager() : NULL;
2417 } 2169 }
2418 2170
2419 BrowserAccessibilityManager* 2171 BrowserAccessibilityManager*
2420 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() { 2172 RenderWidgetHostImpl::GetOrCreateRootBrowserAccessibilityManager() {
2421 return delegate_ ? 2173 return delegate_ ?
2422 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL; 2174 delegate_->GetOrCreateRootBrowserAccessibilityManager() : NULL;
2423 } 2175 }
2424 2176
2425 #if defined(OS_WIN) 2177 #if defined(OS_WIN)
2426 gfx::NativeViewAccessible 2178 gfx::NativeViewAccessible
2427 RenderWidgetHostImpl::GetParentNativeViewAccessible() { 2179 RenderWidgetHostImpl::GetParentNativeViewAccessible() {
2428 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL; 2180 return delegate_ ? delegate_->GetParentNativeViewAccessible() : NULL;
2429 } 2181 }
2430 #endif 2182 #endif
2431 2183
2432 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { 2184 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() {
2433 if (view_) 2185 if (view_)
2434 return view_->PreferredReadbackFormat(); 2186 return view_->PreferredReadbackFormat();
2435 return kN32_SkColorType; 2187 return kN32_SkColorType;
2436 } 2188 }
2437 2189
2438 } // namespace content 2190 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698