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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
6 | 6 |
| 7 #include <fstream> |
| 8 #include <iostream> |
| 9 |
7 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
8 #include "base/bind.h" | 11 #include "base/bind.h" |
9 #include "base/command_line.h" | 12 #include "base/command_line.h" |
10 #include "base/logging.h" | 13 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
13 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 #include <android/keycodes.h> | 87 #include <android/keycodes.h> |
85 #include "content/renderer/android/synchronous_compositor_factory.h" | 88 #include "content/renderer/android/synchronous_compositor_factory.h" |
86 #endif | 89 #endif |
87 | 90 |
88 #if defined(OS_POSIX) | 91 #if defined(OS_POSIX) |
89 #include "ipc/ipc_channel_posix.h" | 92 #include "ipc/ipc_channel_posix.h" |
90 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 93 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
91 #include "third_party/skia/include/core/SkPixelRef.h" | 94 #include "third_party/skia/include/core/SkPixelRef.h" |
92 #endif // defined(OS_POSIX) | 95 #endif // defined(OS_POSIX) |
93 | 96 |
| 97 #include "base/threading/platform_thread.h" |
| 98 #include "content/renderer/greenweb_latency_tracking.h" |
94 #include "third_party/WebKit/public/web/WebWidget.h" | 99 #include "third_party/WebKit/public/web/WebWidget.h" |
95 | 100 |
| 101 std::map<int64, GreenWebLatencyComponent> InputLatencyMap; |
| 102 std::map<int64, DOMLatencyMapComponent> DOMLatencyMap; |
| 103 int64 InputLatencyID; |
| 104 |
96 using blink::WebCompositionUnderline; | 105 using blink::WebCompositionUnderline; |
97 using blink::WebCursorInfo; | 106 using blink::WebCursorInfo; |
98 using blink::WebDeviceEmulationParams; | 107 using blink::WebDeviceEmulationParams; |
99 using blink::WebGestureEvent; | 108 using blink::WebGestureEvent; |
100 using blink::WebInputEvent; | 109 using blink::WebInputEvent; |
101 using blink::WebKeyboardEvent; | 110 using blink::WebKeyboardEvent; |
102 using blink::WebMouseEvent; | 111 using blink::WebMouseEvent; |
103 using blink::WebMouseWheelEvent; | 112 using blink::WebMouseWheelEvent; |
104 using blink::WebNavigationPolicy; | 113 using blink::WebNavigationPolicy; |
105 using blink::WebNode; | 114 using blink::WebNode; |
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 1069 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
1061 } | 1070 } |
1062 | 1071 |
1063 void RenderWidget::OnSwapBuffersComplete() { | 1072 void RenderWidget::OnSwapBuffersComplete() { |
1064 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); | 1073 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersComplete"); |
1065 | 1074 |
1066 // Notify subclasses that composited rendering was flushed to the screen. | 1075 // Notify subclasses that composited rendering was flushed to the screen. |
1067 DidFlushPaint(); | 1076 DidFlushPaint(); |
1068 } | 1077 } |
1069 | 1078 |
| 1079 void read_freq_stat(std::map<int64, int64> *stat) |
| 1080 { |
| 1081 std::ifstream freqstat("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_sta
te"); |
| 1082 |
| 1083 int freq, time; |
| 1084 while (freqstat >> freq >> time) |
| 1085 { |
| 1086 (*stat)[freq] = time; |
| 1087 } |
| 1088 |
| 1089 freqstat.close(); |
| 1090 } |
| 1091 |
| 1092 void process_freq_stat(std::map<int64, int64> *startMap, std::map<int64, int64>
*statMap) |
| 1093 { |
| 1094 std::ifstream freqstat("/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_sta
te"); |
| 1095 |
| 1096 int freq, time; |
| 1097 while (freqstat >> freq >> time) |
| 1098 { |
| 1099 (*statMap)[freq] = time - (*startMap)[freq]; |
| 1100 } |
| 1101 |
| 1102 freqstat.close(); |
| 1103 } |
| 1104 |
1070 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, | 1105 void RenderWidget::OnHandleInputEvent(const blink::WebInputEvent* input_event, |
1071 const ui::LatencyInfo& latency_info) { | 1106 const ui::LatencyInfo& latency_info) { |
1072 if (!input_event) | 1107 if (!input_event) |
1073 return; | 1108 return; |
| 1109 |
| 1110 base::TimeTicks callback_start_ts = base::TimeTicks::Now(); |
| 1111 int64 trace_id = latency_info.trace_id(); |
| 1112 InputLatencyID = trace_id; |
| 1113 |
| 1114 read_freq_stat(&(InputLatencyMap[trace_id].FreqStatStartMap)); |
| 1115 |
1074 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_, | 1116 base::AutoReset<bool> handling_input_event_resetter(&handling_input_event_, |
1075 true); | 1117 true); |
1076 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( | 1118 base::AutoReset<WebInputEvent::Type> handling_event_type_resetter( |
1077 &handling_event_type_, input_event->type); | 1119 &handling_event_type_, input_event->type); |
1078 | 1120 |
1079 // Calls into |didOverscroll()| while handling this event will populate | 1121 // Calls into |didOverscroll()| while handling this event will populate |
1080 // |event_overscroll|, which in turn will be bundled with the event ack. | 1122 // |event_overscroll|, which in turn will be bundled with the event ack. |
1081 scoped_ptr<DidOverscrollParams> event_overscroll; | 1123 scoped_ptr<DidOverscrollParams> event_overscroll; |
1082 base::AutoReset<scoped_ptr<DidOverscrollParams>*> | 1124 base::AutoReset<scoped_ptr<DidOverscrollParams>*> |
1083 handling_event_overscroll_resetter(&handling_event_overscroll_, | 1125 handling_event_overscroll_resetter(&handling_event_overscroll_, |
(...skipping 16 matching lines...) Expand all Loading... |
1100 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT && | 1142 key_event.nativeKeyCode != AKEYCODE_DPAD_LEFT && |
1101 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT && | 1143 key_event.nativeKeyCode != AKEYCODE_DPAD_RIGHT && |
1102 key_event.nativeKeyCode != AKEYCODE_DPAD_UP && | 1144 key_event.nativeKeyCode != AKEYCODE_DPAD_UP && |
1103 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN) | 1145 key_event.nativeKeyCode != AKEYCODE_DPAD_DOWN) |
1104 ime_event_guard_maybe.reset(new ImeEventGuard(this)); | 1146 ime_event_guard_maybe.reset(new ImeEventGuard(this)); |
1105 } | 1147 } |
1106 #endif | 1148 #endif |
1107 | 1149 |
1108 base::TimeTicks start_time; | 1150 base::TimeTicks start_time; |
1109 if (base::TimeTicks::IsHighResolution()) | 1151 if (base::TimeTicks::IsHighResolution()) |
1110 start_time = base::TimeTicks::Now(); | 1152 start_time = callback_start_ts; |
| 1153 //start_time = base::TimeTicks::Now(); |
1111 | 1154 |
1112 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", | 1155 TRACE_EVENT1("renderer,benchmark", "RenderWidget::OnHandleInputEvent", |
1113 "event", WebInputEventTraits::GetName(input_event->type)); | 1156 "event", WebInputEventTraits::GetName(input_event->type)); |
1114 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); | 1157 TRACE_EVENT_SYNTHETIC_DELAY_BEGIN("blink.HandleInputEvent"); |
1115 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 1158 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
1116 "LatencyInfo.Flow", | 1159 "LatencyInfo.Flow", |
1117 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), | 1160 TRACE_ID_DONT_MANGLE(latency_info.trace_id()), |
1118 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | 1161 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
1119 "step", "HandleInputEventMain"); | 1162 "step", "HandleInputEventMain"); |
1120 | 1163 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 processed); | 1258 processed); |
1216 } | 1259 } |
1217 | 1260 |
1218 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested(); | 1261 bool frame_pending = compositor_ && compositor_->BeginMainFrameRequested(); |
1219 | 1262 |
1220 // If we don't have a fast and accurate Now(), we assume the input handlers | 1263 // If we don't have a fast and accurate Now(), we assume the input handlers |
1221 // are heavy and rate limit them. | 1264 // are heavy and rate limit them. |
1222 bool rate_limiting_wanted = | 1265 bool rate_limiting_wanted = |
1223 input_event->type == WebInputEvent::MouseMove || | 1266 input_event->type == WebInputEvent::MouseMove || |
1224 input_event->type == WebInputEvent::MouseWheel; | 1267 input_event->type == WebInputEvent::MouseWheel; |
| 1268 base::TimeTicks end_time; |
1225 if (rate_limiting_wanted && !start_time.is_null()) { | 1269 if (rate_limiting_wanted && !start_time.is_null()) { |
1226 base::TimeTicks end_time = base::TimeTicks::Now(); | 1270 end_time = base::TimeTicks::Now(); |
1227 total_input_handling_time_this_frame_ += (end_time - start_time); | 1271 total_input_handling_time_this_frame_ += (end_time - start_time); |
1228 rate_limiting_wanted = | 1272 rate_limiting_wanted = |
1229 total_input_handling_time_this_frame_.InMicroseconds() > | 1273 total_input_handling_time_this_frame_.InMicroseconds() > |
1230 kInputHandlingTimeThrottlingThresholdMicroseconds; | 1274 kInputHandlingTimeThrottlingThresholdMicroseconds; |
1231 } | 1275 } |
1232 | 1276 |
1233 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); | 1277 TRACE_EVENT_SYNTHETIC_DELAY_END("blink.HandleInputEvent"); |
1234 | 1278 |
1235 // Note that we can't use handling_event_type_ here since it will be overriden | 1279 // Note that we can't use handling_event_type_ here since it will be overriden |
1236 // by reentrant calls for events after the paused one. | 1280 // by reentrant calls for events after the paused one. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 | 1341 |
1298 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with | 1342 // TODO(rouslan): Fix ChromeOS and Windows 8 behavior of autofill popup with |
1299 // virtual keyboard. | 1343 // virtual keyboard. |
1300 #if !defined(OS_ANDROID) | 1344 #if !defined(OS_ANDROID) |
1301 // Virtual keyboard is not supported, so react to focus change immediately. | 1345 // Virtual keyboard is not supported, so react to focus change immediately. |
1302 if (processed && (input_event->type == WebInputEvent::TouchEnd || | 1346 if (processed && (input_event->type == WebInputEvent::TouchEnd || |
1303 input_event->type == WebInputEvent::MouseUp)) { | 1347 input_event->type == WebInputEvent::MouseUp)) { |
1304 FocusChangeComplete(); | 1348 FocusChangeComplete(); |
1305 } | 1349 } |
1306 #endif | 1350 #endif |
| 1351 |
| 1352 int64 dom_node = InputLatencyMap[trace_id].dom_node; |
| 1353 if (dom_node) { |
| 1354 base::TimeTicks callback_end_ts = base::TimeTicks::Now(); |
| 1355 base::TimeDelta callback_latency = callback_end_ts - callback_start_ts; |
| 1356 int64 callback_latency_in_ms = callback_latency.InMilliseconds(); |
| 1357 |
| 1358 InputLatencyMap[trace_id].callback_start = callback_start_ts; |
| 1359 InputLatencyMap[trace_id].latency = callback_latency_in_ms; |
| 1360 |
| 1361 DOMLatencyMap[dom_node].latency = InputLatencyMap[trace_id].latency; |
| 1362 |
| 1363 process_freq_stat(&(InputLatencyMap[trace_id].FreqStatStartMap), &(DOMLatenc
yMap[dom_node].FreqStatMap)); |
| 1364 |
| 1365 #ifdef EBS_DEBUG_TRACE_EVENT |
| 1366 TRACE_EVENT2("devtools.timeline", "GreenWeb:Callback", "trace_id", trace_id,
"latency", DOMLatencyMap[dom_node].latency); |
| 1367 std::cout << "Thd: " << base::PlatformThread::CurrentId() << |
| 1368 " (" << base::PlatformThread::GetName() << ")" << |
| 1369 " Callback " |
| 1370 " trace_id " << trace_id << |
| 1371 " dom_node " << dom_node << |
| 1372 " latency " << DOMLatencyMap[dom_node].latency << std::endl; |
| 1373 #endif |
| 1374 } |
1307 } | 1375 } |
1308 | 1376 |
1309 void RenderWidget::OnCursorVisibilityChange(bool is_visible) { | 1377 void RenderWidget::OnCursorVisibilityChange(bool is_visible) { |
1310 if (webwidget_) | 1378 if (webwidget_) |
1311 webwidget_->setCursorVisibilityState(is_visible); | 1379 webwidget_->setCursorVisibilityState(is_visible); |
1312 } | 1380 } |
1313 | 1381 |
1314 void RenderWidget::OnMouseCaptureLost() { | 1382 void RenderWidget::OnMouseCaptureLost() { |
1315 if (webwidget_) | 1383 if (webwidget_) |
1316 webwidget_->mouseCaptureLost(); | 1384 webwidget_->mouseCaptureLost(); |
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2411 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2479 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2412 video_hole_frames_.AddObserver(frame); | 2480 video_hole_frames_.AddObserver(frame); |
2413 } | 2481 } |
2414 | 2482 |
2415 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2483 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2416 video_hole_frames_.RemoveObserver(frame); | 2484 video_hole_frames_.RemoveObserver(frame); |
2417 } | 2485 } |
2418 #endif // defined(VIDEO_HOLE) | 2486 #endif // defined(VIDEO_HOLE) |
2419 | 2487 |
2420 } // namespace content | 2488 } // namespace content |
OLD | NEW |