summaryrefslogtreecommitdiffstats
path: root/ui/base/latency_info.h
blob: 423182a0379ea382d9b40cda4c231511904750ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_BASE_LATENCY_INFO_H_
#define UI_BASE_LATENCY_INFO_H_

#include <map>
#include <utility>

#include "base/basictypes.h"
#include "base/time/time.h"
#include "ui/base/ui_export.h"

namespace ui {

enum LatencyComponentType {
  // Timestamp when the input event is sent from RenderWidgetHost to renderer.
  INPUT_EVENT_LATENCY_RWH_COMPONENT,
  // Timestamp when the injected event is sent from RenderWidgetHost to
  // renderer. For example, in Aura, touch event's LatencyInfo is carried over
  // to the injected gesture event. So gesture event's
  // INPUT_EVENT_LATENCY_RWH_COMPONENT is the timestamp when its original touch
  // events is sent from RWH to renderer. In non-aura platform,
  // INPUT_EVENT_LATENCY_RWH_COMPONENT is the same as
  // INPUT_EVENT_LATENCY_INJECTED_RWH_COMPONENT.
  INPUT_EVENT_LATENCY_INJECTED_RWH_COMPONENT,
  // Original timestamp for input event (e.g. timestamp from kernel).
  INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
  // Timestamp when the UI event is created.
  INPUT_EVENT_LATENCY_UI_COMPONENT,
  // Timestamp when the event is acked from renderer. This is currently set
  // only for touch events.
  INPUT_EVENT_LATENCY_ACKED_COMPONENT
};

struct UI_EXPORT LatencyInfo {
  struct LatencyComponent {
    // Nondecreasing number that can be used to determine what events happened
    // in the component at the time this struct was sent on to the next
    // component.
    int64 sequence_number;
    // Average time of events that happened in this component.
    base::TimeTicks event_time;
    // Count of events that happened in this component
    uint32 event_count;
  };

  // Map a Latency Component (with a component-specific int64 id) to a
  // component info.
  typedef std::map<std::pair<LatencyComponentType, int64>, LatencyComponent>
      LatencyMap;

  LatencyInfo();

  ~LatencyInfo();

  // Merges the contents of another LatencyInfo into this one.
  void MergeWith(const LatencyInfo& other);

  // Modifies the current sequence number for a component, and adds a new
  // sequence number with the current timestamp.
  void AddLatencyNumber(LatencyComponentType component,
                        int64 id,
                        int64 component_sequence_number);

  // Modifies the current sequence number and adds a certain number of events
  // for a specific component.
  void AddLatencyNumberWithTimestamp(LatencyComponentType component,
                                     int64 id,
                                     int64 component_sequence_number,
                                     base::TimeTicks time,
                                     uint32 event_count);

  // Returns true if the a component with |type| and |id| is found in
  // the latency_components and the component is stored to |output| if
  // |output| is not NULL. Returns false if no such component is found.
  bool FindLatency(LatencyComponentType type,
                   int64 id,
                   LatencyComponent* output) const;

  void Clear();

  LatencyMap latency_components;

  // This represents the final time that a frame is displayed it.
  base::TimeTicks swap_timestamp;
};

}  // namespace ui

#endif  // UI_BASE_LATENCY_INFO_H_