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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_
10 #include "base/basictypes.h"
11 #include "content/browser/renderer_host/event_with_latency_info.h"
12 #include "content/common/content_export.h"
13 #include "ui/events/latency_info.h"
17 // Utility class for tracking the latency of events passing through
18 // a given RenderWidgetHost.
19 class CONTENT_EXPORT RenderWidgetHostLatencyTracker
{
21 RenderWidgetHostLatencyTracker();
22 ~RenderWidgetHostLatencyTracker();
24 // Associates the latency tracker with a given route and process.
25 // Called once after the RenderWidgetHost is fully initialized.
26 void Initialize(int routing_id
, int process_id
);
28 // Populates the LatencyInfo with relevant entries for latency tracking.
29 // Called when an event is received by the RenderWidgetHost, prior to
30 // that event being forwarded to the renderer (via the InputRouter).
31 void OnInputEvent(const blink::WebInputEvent
& event
,
32 ui::LatencyInfo
* latency
);
34 // Populates the LatencyInfo with relevant entries for latency tracking, also
35 // terminating latency tracking for events that did not trigger rendering and
36 // performing relevant UMA latency reporting. Called when an event is ack'ed
37 // to the RenderWidgetHost (from the InputRouter).
38 void OnInputEventAck(const blink::WebInputEvent
& event
,
39 ui::LatencyInfo
* latency
);
41 // Populates renderer-created LatencyInfo entries with the appropriate latency
42 // component id. Called when the RenderWidgetHost receives a compositor swap
43 // update from the renderer.
44 void OnSwapCompositorFrame(std::vector
<ui::LatencyInfo
>* latencies
);
46 // Terminates latency tracking for events that triggered rendering, also
47 // performing relevant UMA latency reporting.
48 // Called when the RenderWidgetHost receives a swap update from the GPU.
49 void OnFrameSwapped(const ui::LatencyInfo
& latency
);
51 // WebInputEvent coordinates are in DPIs, while LatencyInfo expects
52 // coordinates in device pixels.
53 void set_device_scale_factor(float device_scale_factor
) {
54 device_scale_factor_
= device_scale_factor
;
57 // Returns the ID that uniquely describes this component to the latency
59 int64
latency_component_id() const { return latency_component_id_
; }
63 int64 latency_component_id_
;
64 float device_scale_factor_
;
65 bool has_seent_first_gesture_scroll_update_
;
67 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostLatencyTracker
);
70 } // namespace content
72 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_RENDER_WIDGET_HOST_LATENCY_TRACKER_H_