Chromium Code Reviews| 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 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1157 g_check_for_pending_resize_ack = false; | 1157 g_check_for_pending_resize_ack = false; |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( | 1160 ui::LatencyInfo RenderWidgetHostImpl::CreateRWHLatencyInfoIfNotExist( |
| 1161 const ui::LatencyInfo* original) { | 1161 const ui::LatencyInfo* original) { |
| 1162 ui::LatencyInfo info; | 1162 ui::LatencyInfo info; |
| 1163 if (original) | 1163 if (original) |
| 1164 info = *original; | 1164 info = *original; |
| 1165 // In Aura, gesture event will already carry its original touch event's | 1165 // In Aura, gesture event will already carry its original touch event's |
| 1166 // INPUT_EVENT_LATENCY_RWH_COMPONENT. | 1166 // INPUT_EVENT_LATENCY_RWH_COMPONENT. |
| 1167 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1167 if (!info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 1168 GetLatencyComponentId(), | 1168 GetLatencyComponentId(), |
| 1169 NULL)) { | 1169 NULL)) { |
| 1170 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 1170 info.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 1171 GetLatencyComponentId(), | 1171 GetLatencyComponentId(), |
| 1172 ++last_input_number_); | 1172 ++last_input_number_); |
| 1173 } | 1173 } |
| 1174 return info; | 1174 return info; |
| 1175 } | 1175 } |
| 1176 | 1176 |
| 1177 | 1177 |
| 1178 void RenderWidgetHostImpl::AddKeyPressEventCallback( | 1178 void RenderWidgetHostImpl::AddKeyPressEventCallback( |
| 1179 const KeyPressEventCallback& callback) { | 1179 const KeyPressEventCallback& callback) { |
| 1180 key_press_event_callbacks_.push_back(callback); | 1180 key_press_event_callbacks_.push_back(callback); |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2181 delegate_->HandleKeyboardEvent(event); | 2181 delegate_->HandleKeyboardEvent(event); |
| 2182 | 2182 |
| 2183 // WARNING: This RenderWidgetHostImpl can be deallocated at this point | 2183 // WARNING: This RenderWidgetHostImpl can be deallocated at this point |
| 2184 // (i.e. in the case of Ctrl+W, where the call to | 2184 // (i.e. in the case of Ctrl+W, where the call to |
| 2185 // HandleKeyboardEvent destroys this RenderWidgetHostImpl). | 2185 // HandleKeyboardEvent destroys this RenderWidgetHostImpl). |
| 2186 } | 2186 } |
| 2187 } | 2187 } |
| 2188 | 2188 |
| 2189 void RenderWidgetHostImpl::OnWheelEventAck( | 2189 void RenderWidgetHostImpl::OnWheelEventAck( |
| 2190 const WebKit::WebMouseWheelEvent& wheel_event, | 2190 const WebKit::WebMouseWheelEvent& wheel_event, |
| 2191 InputEventAckState ack_result) { | 2191 InputEventAckState ack_result, |
| 2192 ui::LatencyInfo* latency) { | |
| 2193 if (!latency->FindLatency( | |
| 2194 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) { | |
| 2195 // MouseWheelEvent latency ends when it is acked but does not cause any | |
| 2196 // rendering scheduled. | |
| 2197 latency->AddLatencyNumber( | |
|
jdduke (slow)
2013/10/08 16:28:08
Please revert the arg changes and just copy the ui
Yufeng Shen (Slow to review)
2013/10/08 19:35:59
Done.
| |
| 2198 ui::INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT, 0, 0); | |
| 2199 } | |
| 2192 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); | 2200 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); |
| 2193 if (overscroll_controller_) | 2201 if (overscroll_controller_) |
| 2194 overscroll_controller_->ReceivedEventACK(wheel_event, processed); | 2202 overscroll_controller_->ReceivedEventACK(wheel_event, processed); |
| 2195 | |
| 2196 if (!processed && !is_hidden() && view_) | 2203 if (!processed && !is_hidden() && view_) |
| 2197 view_->UnhandledWheelEvent(wheel_event); | 2204 view_->UnhandledWheelEvent(wheel_event); |
| 2198 } | 2205 } |
| 2199 | 2206 |
| 2200 void RenderWidgetHostImpl::OnGestureEventAck( | 2207 void RenderWidgetHostImpl::OnGestureEventAck( |
| 2201 const WebKit::WebGestureEvent& event, | 2208 const WebKit::WebGestureEvent& event, |
| 2202 InputEventAckState ack_result) { | 2209 InputEventAckState ack_result, |
| 2210 ui::LatencyInfo* latency) { | |
|
jdduke (slow)
2013/10/08 16:28:08
Same as above.
Yufeng Shen (Slow to review)
2013/10/08 19:35:59
Done.
| |
| 2211 if (!latency->FindLatency( | |
| 2212 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) { | |
| 2213 // GestureEvent latency ends when it is acked but does not cause any | |
| 2214 // rendering scheduled. | |
| 2215 latency->AddLatencyNumber( | |
| 2216 ui::INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT, 0 ,0); | |
| 2217 } | |
| 2203 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); | 2218 const bool processed = (INPUT_EVENT_ACK_STATE_CONSUMED == ack_result); |
| 2204 if (overscroll_controller_) | 2219 if (overscroll_controller_) |
| 2205 overscroll_controller_->ReceivedEventACK(event, processed); | 2220 overscroll_controller_->ReceivedEventACK(event, processed); |
| 2206 | 2221 |
| 2207 if (view_) | 2222 if (view_) |
| 2208 view_->GestureEventAck(event.type, ack_result); | 2223 view_->GestureEventAck(event.type, ack_result); |
| 2209 } | 2224 } |
| 2210 | 2225 |
| 2211 void RenderWidgetHostImpl::OnTouchEventAck( | 2226 void RenderWidgetHostImpl::OnTouchEventAck( |
| 2212 const TouchEventWithLatencyInfo& event, | 2227 const WebKit::WebTouchEvent& event, |
| 2213 InputEventAckState ack_result) { | 2228 InputEventAckState ack_result, |
| 2214 ComputeTouchLatency(event.latency); | 2229 ui::LatencyInfo* latency) { |
| 2230 // TouchEvent latency does not end when acked since it could later on | |
| 2231 // become gesture events. | |
| 2232 latency->AddLatencyNumber(ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, | |
|
jdduke (slow)
2013/10/08 16:28:08
Ditto.
Yufeng Shen (Slow to review)
2013/10/08 19:35:59
Done.
| |
| 2233 0, 0); | |
| 2234 ComputeTouchLatency(*latency); | |
| 2215 if (view_) | 2235 if (view_) |
| 2216 view_->ProcessAckedTouchEvent(event, ack_result); | 2236 view_->ProcessAckedTouchEvent(TouchEventWithLatencyInfo(event, *latency), |
| 2237 ack_result); | |
| 2217 } | 2238 } |
| 2218 | 2239 |
| 2219 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { | 2240 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { |
| 2220 if (type == BAD_ACK_MESSAGE) { | 2241 if (type == BAD_ACK_MESSAGE) { |
| 2221 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 2242 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 2222 process_->ReceivedBadMessage(); | 2243 process_->ReceivedBadMessage(); |
| 2223 } else if (type == UNEXPECTED_EVENT_TYPE) { | 2244 } else if (type == UNEXPECTED_EVENT_TYPE) { |
| 2224 suppress_next_char_events_ = false; | 2245 suppress_next_char_events_ = false; |
| 2225 } | 2246 } |
| 2226 } | 2247 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2477 | 2498 |
| 2478 void RenderWidgetHostImpl::ComputeTouchLatency( | 2499 void RenderWidgetHostImpl::ComputeTouchLatency( |
| 2479 const ui::LatencyInfo& latency_info) { | 2500 const ui::LatencyInfo& latency_info) { |
| 2480 ui::LatencyInfo::LatencyComponent ui_component; | 2501 ui::LatencyInfo::LatencyComponent ui_component; |
| 2481 ui::LatencyInfo::LatencyComponent rwh_component; | 2502 ui::LatencyInfo::LatencyComponent rwh_component; |
| 2482 ui::LatencyInfo::LatencyComponent acked_component; | 2503 ui::LatencyInfo::LatencyComponent acked_component; |
| 2483 | 2504 |
| 2484 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, | 2505 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, |
| 2485 0, | 2506 0, |
| 2486 &ui_component) || | 2507 &ui_component) || |
| 2487 !latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 2508 !latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 2488 GetLatencyComponentId(), | 2509 GetLatencyComponentId(), |
| 2489 &rwh_component)) | 2510 &rwh_component)) |
| 2490 return; | 2511 return; |
| 2491 | 2512 |
| 2492 DCHECK(ui_component.event_count == 1); | 2513 DCHECK(ui_component.event_count == 1); |
| 2493 DCHECK(rwh_component.event_count == 1); | 2514 DCHECK(rwh_component.event_count == 1); |
| 2494 | 2515 |
| 2495 base::TimeDelta ui_delta = | 2516 base::TimeDelta ui_delta = |
| 2496 rwh_component.event_time - ui_component.event_time; | 2517 rwh_component.event_time - ui_component.event_time; |
| 2497 rendering_stats_.touch_ui_count++; | 2518 rendering_stats_.touch_ui_count++; |
| 2498 rendering_stats_.total_touch_ui_latency += ui_delta; | 2519 rendering_stats_.total_touch_ui_latency += ui_delta; |
| 2499 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2520 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2500 "Event.Latency.Browser.TouchUI", | 2521 "Event.Latency.Browser.TouchUI", |
| 2501 ui_delta.InMicroseconds(), | 2522 ui_delta.InMicroseconds(), |
| 2502 0, | 2523 0, |
| 2503 20000, | 2524 20000, |
| 2504 100); | 2525 100); |
| 2505 | 2526 |
| 2506 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ACKED_COMPONENT, | 2527 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, |
| 2507 0, | 2528 0, |
| 2508 &acked_component)) { | 2529 &acked_component)) { |
| 2509 DCHECK(acked_component.event_count == 1); | 2530 DCHECK(acked_component.event_count == 1); |
| 2510 base::TimeDelta acked_delta = | 2531 base::TimeDelta acked_delta = |
| 2511 acked_component.event_time - rwh_component.event_time; | 2532 acked_component.event_time - rwh_component.event_time; |
| 2512 rendering_stats_.touch_acked_count++; | 2533 rendering_stats_.touch_acked_count++; |
| 2513 rendering_stats_.total_touch_acked_latency += acked_delta; | 2534 rendering_stats_.total_touch_acked_latency += acked_delta; |
| 2514 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2535 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2515 "Event.Latency.Browser.TouchAcked", | 2536 "Event.Latency.Browser.TouchAcked", |
| 2516 acked_delta.InMicroseconds(), | 2537 acked_delta.InMicroseconds(), |
| 2517 0, | 2538 0, |
| 2518 1000000, | 2539 1000000, |
| 2519 100); | 2540 100); |
| 2520 } | 2541 } |
| 2521 | 2542 |
| 2522 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2543 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2523 switches::kEnableGpuBenchmarking)) | 2544 switches::kEnableGpuBenchmarking)) |
| 2524 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2545 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2525 } | 2546 } |
| 2526 | 2547 |
| 2527 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2548 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
| 2528 ui::LatencyInfo::LatencyComponent rwh_component; | 2549 ui::LatencyInfo::LatencyComponent rwh_component; |
| 2529 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 2550 ui::LatencyInfo::LatencyComponent swap_component; |
| 2551 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | |
| 2530 GetLatencyComponentId(), | 2552 GetLatencyComponentId(), |
| 2531 &rwh_component)) | 2553 &rwh_component) || |
| 2554 !latency_info.FindLatency( | |
| 2555 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, | |
| 2556 0, &swap_component)) { | |
| 2532 return; | 2557 return; |
| 2558 } | |
| 2533 | 2559 |
| 2534 rendering_stats_.input_event_count += rwh_component.event_count; | 2560 rendering_stats_.input_event_count += rwh_component.event_count; |
| 2535 rendering_stats_.total_input_latency += | 2561 rendering_stats_.total_input_latency += |
| 2536 rwh_component.event_count * | 2562 rwh_component.event_count * |
| 2537 (latency_info.swap_timestamp - rwh_component.event_time); | 2563 (swap_component.event_time - rwh_component.event_time); |
| 2538 | 2564 |
| 2539 ui::LatencyInfo::LatencyComponent original_component; | 2565 ui::LatencyInfo::LatencyComponent original_component; |
| 2540 if (latency_info.FindLatency( | 2566 if (latency_info.FindLatency( |
| 2541 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 2567 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 2542 GetLatencyComponentId(), | 2568 GetLatencyComponentId(), |
| 2543 &original_component)) { | 2569 &original_component)) { |
| 2544 // This UMA metric tracks the time from when the original touch event is | 2570 // This UMA metric tracks the time from when the original touch event is |
| 2545 // created (averaged if there are multiple) to when the scroll gesture | 2571 // created (averaged if there are multiple) to when the scroll gesture |
| 2546 // results in final frame swap. | 2572 // results in final frame swap. |
| 2547 base::TimeDelta delta = | 2573 base::TimeDelta delta = |
| 2548 latency_info.swap_timestamp - original_component.event_time; | 2574 swap_component.event_time - original_component.event_time; |
| 2549 for (size_t i = 0; i < original_component.event_count; i++) { | 2575 for (size_t i = 0; i < original_component.event_count; i++) { |
| 2550 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2576 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2551 "Event.Latency.TouchToScrollUpdateSwap", | 2577 "Event.Latency.TouchToScrollUpdateSwap", |
| 2552 delta.InMicroseconds(), | 2578 delta.InMicroseconds(), |
| 2553 0, | 2579 0, |
| 2554 1000000, | 2580 1000000, |
| 2555 100); | 2581 100); |
| 2556 } | 2582 } |
| 2557 rendering_stats_.scroll_update_count += original_component.event_count; | 2583 rendering_stats_.scroll_update_count += original_component.event_count; |
| 2558 rendering_stats_.total_scroll_update_latency += | 2584 rendering_stats_.total_scroll_update_latency += |
| 2559 original_component.event_count * | 2585 original_component.event_count * |
| 2560 (latency_info.swap_timestamp - original_component.event_time); | 2586 (swap_component.event_time - original_component.event_time); |
| 2561 } | 2587 } |
| 2562 | 2588 |
| 2563 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2589 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2564 switches::kEnableGpuBenchmarking)) | 2590 switches::kEnableGpuBenchmarking)) |
| 2565 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2591 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2566 } | 2592 } |
| 2567 | 2593 |
| 2568 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2594 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2569 view_->DidReceiveRendererFrame(); | 2595 view_->DidReceiveRendererFrame(); |
| 2570 } | 2596 } |
| 2571 | 2597 |
| 2572 // static | 2598 // static |
| 2573 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2599 void RenderWidgetHostImpl::CompositorFrameDrawn( |
| 2574 const ui::LatencyInfo& latency_info) { | 2600 const ui::LatencyInfo& latency_info) { |
| 2575 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2601 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
| 2576 latency_info.latency_components.begin(); | 2602 latency_info.latency_components.begin(); |
| 2577 b != latency_info.latency_components.end(); | 2603 b != latency_info.latency_components.end(); |
| 2578 ++b) { | 2604 ++b) { |
| 2579 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) | 2605 if (b->first.first != ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) |
| 2580 continue; | 2606 continue; |
| 2581 // Matches with GetLatencyComponentId | 2607 // Matches with GetLatencyComponentId |
| 2582 int routing_id = b->first.second & 0xffffffff; | 2608 int routing_id = b->first.second & 0xffffffff; |
| 2583 int process_id = (b->first.second >> 32) & 0xffffffff; | 2609 int process_id = (b->first.second >> 32) & 0xffffffff; |
| 2584 RenderWidgetHost* rwh = | 2610 RenderWidgetHost* rwh = |
| 2585 RenderWidgetHost::FromID(process_id, routing_id); | 2611 RenderWidgetHost::FromID(process_id, routing_id); |
| 2586 if (!rwh) | 2612 if (!rwh) |
| 2587 continue; | 2613 continue; |
| 2588 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2614 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
| 2589 } | 2615 } |
| 2590 } | 2616 } |
| 2591 | 2617 |
| 2592 } // namespace content | 2618 } // namespace content |
| OLD | NEW |