OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKER_H
_ | 5 #ifndef UI_LATENCY_LATENCY_TRACKER_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKER_H
_ | 6 #define UI_LATENCY_LATENCY_TRACKER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "content/browser/renderer_host/event_with_latency_info.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/common/input/input_event_ack_state.h" | |
16 #include "ui/latency/latency_info.h" | 13 #include "ui/latency/latency_info.h" |
17 | 14 |
18 namespace content { | 15 namespace ui { |
19 | 16 |
20 class RenderWidgetHostDelegate; | 17 // Utility class for tracking the latency of events. |
21 | 18 class LatencyTracker { |
22 // Utility class for tracking the latency of events passing through | |
23 // a given RenderWidgetHost. | |
24 class CONTENT_EXPORT RenderWidgetHostLatencyTracker { | |
25 public: | 19 public: |
26 explicit RenderWidgetHostLatencyTracker(); | 20 LatencyTracker() = default; |
27 ~RenderWidgetHostLatencyTracker(); | 21 ~LatencyTracker() = default; |
28 | |
29 // Associates the latency tracker with a given route and process. | |
30 // Called once after the RenderWidgetHost is fully initialized. | |
31 void Initialize(int routing_id, int process_id); | |
32 | |
33 void ComputeInputLatencyHistograms(blink::WebInputEvent::Type type, | |
34 int64_t latency_component_id, | |
35 const ui::LatencyInfo& latency, | |
36 InputEventAckState ack_result); | |
37 | |
38 // Populates the LatencyInfo with relevant entries for latency tracking. | |
39 // Called when an event is received by the RenderWidgetHost, prior to | |
40 // that event being forwarded to the renderer (via the InputRouter). | |
41 void OnInputEvent(const blink::WebInputEvent& event, | |
42 ui::LatencyInfo* latency); | |
43 | |
44 // Populates the LatencyInfo with relevant entries for latency tracking, also | |
45 // terminating latency tracking for events that did not trigger rendering and | |
46 // performing relevant UMA latency reporting. Called when an event is ack'ed | |
47 // to the RenderWidgetHost (from the InputRouter). | |
48 void OnInputEventAck(const blink::WebInputEvent& event, | |
49 ui::LatencyInfo* latency, | |
50 InputEventAckState ack_result); | |
51 | |
52 // Populates renderer-created LatencyInfo entries with the appropriate latency | |
53 // component id. Called when the RenderWidgetHost receives a compositor swap | |
54 // update from the renderer. | |
55 void OnSwapCompositorFrame(std::vector<ui::LatencyInfo>* latencies); | |
56 | 22 |
57 // Terminates latency tracking for events that triggered rendering, also | 23 // Terminates latency tracking for events that triggered rendering, also |
58 // performing relevant UMA latency reporting. | 24 // performing relevant UMA latency reporting. |
59 // Called when the RenderWidgetHost receives a swap update from the GPU. | 25 // Called when GPU buffers swap completes. |
60 void OnGpuSwapBuffersCompleted(const ui::LatencyInfo& latency); | 26 void OnGpuSwapBuffersCompleted(const LatencyInfo& latency); |
61 | 27 |
62 // WebInputEvent coordinates are in DPIs, while LatencyInfo expects | 28 protected: |
63 // coordinates in device pixels. | 29 virtual void ReportRapporScrollLatency( |
64 void set_device_scale_factor(float device_scale_factor) { | 30 const std::string& name, |
65 device_scale_factor_ = device_scale_factor; | 31 const LatencyInfo::LatencyComponent& start_component, |
66 } | 32 const LatencyInfo::LatencyComponent& end_component); |
67 | |
68 // Returns the ID that uniquely describes this component to the latency | |
69 // subsystem. | |
70 int64_t latency_component_id() const { return latency_component_id_; } | |
71 | |
72 // A delegate is used to get the url to be stored in Rappor Sample. | |
73 // If delegate is null no Rappor sample will be reported. | |
74 void SetDelegate(RenderWidgetHostDelegate*); | |
75 | 33 |
76 private: | 34 private: |
77 int64_t last_event_id_; | 35 void ComputeTouchAndWheelScrollLatencyHistograms( |
78 int64_t latency_component_id_; | 36 const LatencyInfo::LatencyComponent& gpu_swap_begin_component, |
79 float device_scale_factor_; | 37 const LatencyInfo::LatencyComponent& gpu_swap_end_component, |
80 bool has_seen_first_gesture_scroll_update_; | 38 const LatencyInfo& latency); |
81 // Whether the current stream of touch events includes more than one active | |
82 // touch point. This is set in OnInputEvent, and cleared in OnInputEventAck. | |
83 bool active_multi_finger_gesture_; | |
84 // Whether the touch start for the current stream of touch events had its | |
85 // default action prevented. Only valid for single finger gestures. | |
86 bool touch_start_default_prevented_; | |
87 | 39 |
88 RenderWidgetHostDelegate* render_widget_host_delegate_; | 40 DISALLOW_COPY_AND_ASSIGN(LatencyTracker); |
89 | |
90 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTracker); | |
91 }; | 41 }; |
92 | 42 |
93 } // namespace content | 43 } // namespace latency |
94 | 44 |
95 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKE
R_H_ | 45 #endif // UI_LATENCY_LATENCY_TRACKER_H_ |
OLD | NEW |