| 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 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2180 if (delegate_ && !processed && !is_hidden() && !event.skip_in_browser) { | 2180 if (delegate_ && !processed && !is_hidden() && !event.skip_in_browser) { |
| 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 MouseWheelEventWithLatencyInfo& wheel_event, |
| 2191 InputEventAckState ack_result) { | 2191 InputEventAckState ack_result) { |
| 2192 if (!wheel_event.latency.FindLatency( |
| 2193 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) { |
| 2194 // MouseWheelEvent latency ends when it is acked but does not cause any |
| 2195 // rendering scheduled. |
| 2196 ui::LatencyInfo latency = wheel_event.latency; |
| 2197 latency.AddLatencyNumber( |
| 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.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.event); |
| 2198 } | 2205 } |
| 2199 | 2206 |
| 2200 void RenderWidgetHostImpl::OnGestureEventAck( | 2207 void RenderWidgetHostImpl::OnGestureEventAck( |
| 2201 const WebKit::WebGestureEvent& event, | 2208 const GestureEventWithLatencyInfo& event, |
| 2202 InputEventAckState ack_result) { | 2209 InputEventAckState ack_result) { |
| 2210 if (!event.latency.FindLatency( |
| 2211 ui::INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT, 0, NULL)) { |
| 2212 // GestureEvent latency ends when it is acked but does not cause any |
| 2213 // rendering scheduled. |
| 2214 ui::LatencyInfo latency = event.latency; |
| 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.event, processed); |
| 2206 | 2221 |
| 2207 if (view_) | 2222 if (view_) |
| 2208 view_->GestureEventAck(event.type, ack_result); | 2223 view_->GestureEventAck(event.event.type, ack_result); |
| 2209 } | 2224 } |
| 2210 | 2225 |
| 2211 void RenderWidgetHostImpl::OnTouchEventAck( | 2226 void RenderWidgetHostImpl::OnTouchEventAck( |
| 2212 const TouchEventWithLatencyInfo& event, | 2227 const TouchEventWithLatencyInfo& event, |
| 2213 InputEventAckState ack_result) { | 2228 InputEventAckState ack_result) { |
| 2214 ComputeTouchLatency(event.latency); | 2229 TouchEventWithLatencyInfo touch_event = event; |
| 2230 // TouchEvent latency does not end when acked since it could later on |
| 2231 // become gesture events. |
| 2232 touch_event.latency.AddLatencyNumber( |
| 2233 ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, 0); |
| 2234 ComputeTouchLatency(touch_event.latency); |
| 2215 if (view_) | 2235 if (view_) |
| 2216 view_->ProcessAckedTouchEvent(event, ack_result); | 2236 view_->ProcessAckedTouchEvent(touch_event, ack_result); |
| 2217 } | 2237 } |
| 2218 | 2238 |
| 2219 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { | 2239 void RenderWidgetHostImpl::OnUnexpectedEventAck(UnexpectedEventAckType type) { |
| 2220 if (type == BAD_ACK_MESSAGE) { | 2240 if (type == BAD_ACK_MESSAGE) { |
| 2221 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); | 2241 RecordAction(UserMetricsAction("BadMessageTerminate_RWH2")); |
| 2222 process_->ReceivedBadMessage(); | 2242 process_->ReceivedBadMessage(); |
| 2223 } else if (type == UNEXPECTED_EVENT_TYPE) { | 2243 } else if (type == UNEXPECTED_EVENT_TYPE) { |
| 2224 suppress_next_char_events_ = false; | 2244 suppress_next_char_events_ = false; |
| 2225 } | 2245 } |
| 2226 } | 2246 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 | 2497 |
| 2478 void RenderWidgetHostImpl::ComputeTouchLatency( | 2498 void RenderWidgetHostImpl::ComputeTouchLatency( |
| 2479 const ui::LatencyInfo& latency_info) { | 2499 const ui::LatencyInfo& latency_info) { |
| 2480 ui::LatencyInfo::LatencyComponent ui_component; | 2500 ui::LatencyInfo::LatencyComponent ui_component; |
| 2481 ui::LatencyInfo::LatencyComponent rwh_component; | 2501 ui::LatencyInfo::LatencyComponent rwh_component; |
| 2482 ui::LatencyInfo::LatencyComponent acked_component; | 2502 ui::LatencyInfo::LatencyComponent acked_component; |
| 2483 | 2503 |
| 2484 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, | 2504 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_UI_COMPONENT, |
| 2485 0, | 2505 0, |
| 2486 &ui_component) || | 2506 &ui_component) || |
| 2487 !latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 2507 !latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 2488 GetLatencyComponentId(), | 2508 GetLatencyComponentId(), |
| 2489 &rwh_component)) | 2509 &rwh_component)) |
| 2490 return; | 2510 return; |
| 2491 | 2511 |
| 2492 DCHECK(ui_component.event_count == 1); | 2512 DCHECK(ui_component.event_count == 1); |
| 2493 DCHECK(rwh_component.event_count == 1); | 2513 DCHECK(rwh_component.event_count == 1); |
| 2494 | 2514 |
| 2495 base::TimeDelta ui_delta = | 2515 base::TimeDelta ui_delta = |
| 2496 rwh_component.event_time - ui_component.event_time; | 2516 rwh_component.event_time - ui_component.event_time; |
| 2497 rendering_stats_.touch_ui_count++; | 2517 rendering_stats_.touch_ui_count++; |
| 2498 rendering_stats_.total_touch_ui_latency += ui_delta; | 2518 rendering_stats_.total_touch_ui_latency += ui_delta; |
| 2499 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2519 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2500 "Event.Latency.Browser.TouchUI", | 2520 "Event.Latency.Browser.TouchUI", |
| 2501 ui_delta.InMicroseconds(), | 2521 ui_delta.InMicroseconds(), |
| 2502 0, | 2522 0, |
| 2503 20000, | 2523 20000, |
| 2504 100); | 2524 100); |
| 2505 | 2525 |
| 2506 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ACKED_COMPONENT, | 2526 if (latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, |
| 2507 0, | 2527 0, |
| 2508 &acked_component)) { | 2528 &acked_component)) { |
| 2509 DCHECK(acked_component.event_count == 1); | 2529 DCHECK(acked_component.event_count == 1); |
| 2510 base::TimeDelta acked_delta = | 2530 base::TimeDelta acked_delta = |
| 2511 acked_component.event_time - rwh_component.event_time; | 2531 acked_component.event_time - rwh_component.event_time; |
| 2512 rendering_stats_.touch_acked_count++; | 2532 rendering_stats_.touch_acked_count++; |
| 2513 rendering_stats_.total_touch_acked_latency += acked_delta; | 2533 rendering_stats_.total_touch_acked_latency += acked_delta; |
| 2514 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2534 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2515 "Event.Latency.Browser.TouchAcked", | 2535 "Event.Latency.Browser.TouchAcked", |
| 2516 acked_delta.InMicroseconds(), | 2536 acked_delta.InMicroseconds(), |
| 2517 0, | 2537 0, |
| 2518 1000000, | 2538 1000000, |
| 2519 100); | 2539 100); |
| 2520 } | 2540 } |
| 2521 | 2541 |
| 2522 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2542 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2523 switches::kEnableGpuBenchmarking)) | 2543 switches::kEnableGpuBenchmarking)) |
| 2524 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2544 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2525 } | 2545 } |
| 2526 | 2546 |
| 2527 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2547 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
| 2528 ui::LatencyInfo::LatencyComponent rwh_component; | 2548 ui::LatencyInfo::LatencyComponent rwh_component; |
| 2529 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_RWH_COMPONENT, | 2549 ui::LatencyInfo::LatencyComponent swap_component; |
| 2550 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 2530 GetLatencyComponentId(), | 2551 GetLatencyComponentId(), |
| 2531 &rwh_component)) | 2552 &rwh_component) || |
| 2553 !latency_info.FindLatency( |
| 2554 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, |
| 2555 0, &swap_component)) { |
| 2532 return; | 2556 return; |
| 2557 } |
| 2533 | 2558 |
| 2534 rendering_stats_.input_event_count += rwh_component.event_count; | 2559 rendering_stats_.input_event_count += rwh_component.event_count; |
| 2535 rendering_stats_.total_input_latency += | 2560 rendering_stats_.total_input_latency += |
| 2536 rwh_component.event_count * | 2561 rwh_component.event_count * |
| 2537 (latency_info.swap_timestamp - rwh_component.event_time); | 2562 (swap_component.event_time - rwh_component.event_time); |
| 2538 | 2563 |
| 2539 ui::LatencyInfo::LatencyComponent original_component; | 2564 ui::LatencyInfo::LatencyComponent original_component; |
| 2540 if (latency_info.FindLatency( | 2565 if (latency_info.FindLatency( |
| 2541 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, | 2566 ui::INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT, |
| 2542 GetLatencyComponentId(), | 2567 GetLatencyComponentId(), |
| 2543 &original_component)) { | 2568 &original_component)) { |
| 2544 // This UMA metric tracks the time from when the original touch event is | 2569 // 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 | 2570 // created (averaged if there are multiple) to when the scroll gesture |
| 2546 // results in final frame swap. | 2571 // results in final frame swap. |
| 2547 base::TimeDelta delta = | 2572 base::TimeDelta delta = |
| 2548 latency_info.swap_timestamp - original_component.event_time; | 2573 swap_component.event_time - original_component.event_time; |
| 2549 for (size_t i = 0; i < original_component.event_count; i++) { | 2574 for (size_t i = 0; i < original_component.event_count; i++) { |
| 2550 UMA_HISTOGRAM_CUSTOM_COUNTS( | 2575 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 2551 "Event.Latency.TouchToScrollUpdateSwap", | 2576 "Event.Latency.TouchToScrollUpdateSwap", |
| 2552 delta.InMicroseconds(), | 2577 delta.InMicroseconds(), |
| 2553 0, | 2578 0, |
| 2554 1000000, | 2579 1000000, |
| 2555 100); | 2580 100); |
| 2556 } | 2581 } |
| 2557 rendering_stats_.scroll_update_count += original_component.event_count; | 2582 rendering_stats_.scroll_update_count += original_component.event_count; |
| 2558 rendering_stats_.total_scroll_update_latency += | 2583 rendering_stats_.total_scroll_update_latency += |
| 2559 original_component.event_count * | 2584 original_component.event_count * |
| 2560 (latency_info.swap_timestamp - original_component.event_time); | 2585 (swap_component.event_time - original_component.event_time); |
| 2561 } | 2586 } |
| 2562 | 2587 |
| 2563 if (CommandLine::ForCurrentProcess()->HasSwitch( | 2588 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2564 switches::kEnableGpuBenchmarking)) | 2589 switches::kEnableGpuBenchmarking)) |
| 2565 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); | 2590 Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); |
| 2566 } | 2591 } |
| 2567 | 2592 |
| 2568 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2593 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2569 view_->DidReceiveRendererFrame(); | 2594 view_->DidReceiveRendererFrame(); |
| 2570 } | 2595 } |
| 2571 | 2596 |
| 2572 // static | 2597 // static |
| 2573 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2598 void RenderWidgetHostImpl::CompositorFrameDrawn( |
| 2574 const ui::LatencyInfo& latency_info) { | 2599 const ui::LatencyInfo& latency_info) { |
| 2575 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2600 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
| 2576 latency_info.latency_components.begin(); | 2601 latency_info.latency_components.begin(); |
| 2577 b != latency_info.latency_components.end(); | 2602 b != latency_info.latency_components.end(); |
| 2578 ++b) { | 2603 ++b) { |
| 2579 if (b->first.first != ui::INPUT_EVENT_LATENCY_RWH_COMPONENT) | 2604 if (b->first.first != ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT) |
| 2580 continue; | 2605 continue; |
| 2581 // Matches with GetLatencyComponentId | 2606 // Matches with GetLatencyComponentId |
| 2582 int routing_id = b->first.second & 0xffffffff; | 2607 int routing_id = b->first.second & 0xffffffff; |
| 2583 int process_id = (b->first.second >> 32) & 0xffffffff; | 2608 int process_id = (b->first.second >> 32) & 0xffffffff; |
| 2584 RenderWidgetHost* rwh = | 2609 RenderWidgetHost* rwh = |
| 2585 RenderWidgetHost::FromID(process_id, routing_id); | 2610 RenderWidgetHost::FromID(process_id, routing_id); |
| 2586 if (!rwh) | 2611 if (!rwh) |
| 2587 continue; | 2612 continue; |
| 2588 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); | 2613 RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); |
| 2589 } | 2614 } |
| 2590 } | 2615 } |
| 2591 | 2616 |
| 2592 } // namespace content | 2617 } // namespace content |
| OLD | NEW |