| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/input/render_widget_host_latency_tracker
.h" | 5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 9 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 | 10 |
| 11 using blink::WebGestureEvent; | 11 using blink::WebGestureEvent; |
| 12 using blink::WebInputEvent; | 12 using blink::WebInputEvent; |
| 13 using blink::WebMouseEvent; | 13 using blink::WebMouseEvent; |
| 14 using blink::WebMouseWheelEvent; | 14 using blink::WebMouseWheelEvent; |
| 15 using blink::WebTouchEvent; | 15 using blink::WebTouchEvent; |
| 16 using ui::LatencyInfo; | 16 using ui::LatencyInfo; |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const uint32 kMaxInputCoordinates = LatencyInfo::kMaxInputCoordinates; | 21 const uint32 kMaxInputCoordinates = LatencyInfo::kMaxInputCoordinates; |
| 22 const size_t kBrowserCompositeLatencyHistorySize = 60; | |
| 23 const double kBrowserCompositeLatencyEstimationPercentile = 90.0; | |
| 24 const double kBrowserCompositeLatencyEstimationSlack = 1.1; | |
| 25 | 22 |
| 26 void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch, | 23 void UpdateLatencyCoordinatesImpl(const blink::WebTouchEvent& touch, |
| 27 LatencyInfo* latency) { | 24 LatencyInfo* latency) { |
| 28 latency->input_coordinates_size = | 25 latency->input_coordinates_size = |
| 29 std::min(kMaxInputCoordinates, touch.touchesLength); | 26 std::min(kMaxInputCoordinates, touch.touchesLength); |
| 30 for (uint32 i = 0; i < latency->input_coordinates_size; ++i) { | 27 for (uint32 i = 0; i < latency->input_coordinates_size; ++i) { |
| 31 latency->input_coordinates[i] = LatencyInfo::InputCoordinate( | 28 latency->input_coordinates[i] = LatencyInfo::InputCoordinate( |
| 32 touch.touches[i].position.x, touch.touches[i].position.y); | 29 touch.touches[i].position.x, touch.touches[i].position.y); |
| 33 } | 30 } |
| 34 } | 31 } |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 latency->latency_components[lc->first] = lc->second; | 281 latency->latency_components[lc->first] = lc->second; |
| 285 } | 282 } |
| 286 } | 283 } |
| 287 | 284 |
| 288 } // namespace | 285 } // namespace |
| 289 | 286 |
| 290 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() | 287 RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker() |
| 291 : last_event_id_(0), | 288 : last_event_id_(0), |
| 292 latency_component_id_(0), | 289 latency_component_id_(0), |
| 293 device_scale_factor_(1), | 290 device_scale_factor_(1), |
| 294 has_seent_first_gesture_scroll_update_(false), | 291 has_seent_first_gesture_scroll_update_(false) { |
| 295 browser_composite_latency_history_(kBrowserCompositeLatencyHistorySize) { | |
| 296 } | 292 } |
| 297 | 293 |
| 298 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() { | 294 RenderWidgetHostLatencyTracker::~RenderWidgetHostLatencyTracker() { |
| 299 } | 295 } |
| 300 | 296 |
| 301 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, | 297 void RenderWidgetHostLatencyTracker::Initialize(int routing_id, |
| 302 int process_id) { | 298 int process_id) { |
| 303 DCHECK_EQ(0, last_event_id_); | 299 DCHECK_EQ(0, last_event_id_); |
| 304 DCHECK_EQ(0, latency_component_id_); | 300 DCHECK_EQ(0, latency_component_id_); |
| 305 last_event_id_ = static_cast<int64>(process_id) << 32; | 301 last_event_id_ = static_cast<int64>(process_id) << 32; |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 433 } |
| 438 | 434 |
| 439 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 435 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 440 latency_component_id_, nullptr)) { | 436 latency_component_id_, nullptr)) { |
| 441 return; | 437 return; |
| 442 } | 438 } |
| 443 | 439 |
| 444 ComputeScrollLatencyHistograms(gpu_swap_begin_component, | 440 ComputeScrollLatencyHistograms(gpu_swap_begin_component, |
| 445 gpu_swap_end_component, latency_component_id_, | 441 gpu_swap_end_component, latency_component_id_, |
| 446 latency); | 442 latency); |
| 447 | |
| 448 LatencyInfo::LatencyComponent browser_swap_component; | |
| 449 if (latency.FindLatency( | |
| 450 ui::INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT, 0, | |
| 451 &browser_swap_component)) { | |
| 452 base::TimeDelta delta = | |
| 453 gpu_swap_begin_component.event_time - browser_swap_component.event_time; | |
| 454 browser_composite_latency_history_.InsertSample(delta); | |
| 455 } | |
| 456 } | |
| 457 | |
| 458 base::TimeDelta | |
| 459 RenderWidgetHostLatencyTracker::GetEstimatedBrowserCompositeTime() const { | |
| 460 // TODO(brianderson): Remove lower bound on estimate once we're sure it won't | |
| 461 // cause regressions. | |
| 462 return std::max( | |
| 463 browser_composite_latency_history_.Percentile( | |
| 464 kBrowserCompositeLatencyEstimationPercentile) * | |
| 465 kBrowserCompositeLatencyEstimationSlack, | |
| 466 base::TimeDelta::FromMicroseconds( | |
| 467 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60))); | |
| 468 } | 443 } |
| 469 | 444 |
| 470 } // namespace content | 445 } // namespace content |
| OLD | NEW |