[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / total_frame_counter.h
1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CC_METRICS_TOTAL_FRAME_COUNTER_H_
6 #define CC_METRICS_TOTAL_FRAME_COUNTER_H_
7
8 #include "base/time/time.h"
9 #include "cc/cc_export.h"
10
11 namespace viz {
12 struct BeginFrameArgs;
13 }
14
15 namespace cc {
16
17 // This class keeps track of how many vsyncs (frames) the compositor was visible
18 // for.
19 class CC_EXPORT TotalFrameCounter {
20  public:
21   TotalFrameCounter();
22
23   TotalFrameCounter(const TotalFrameCounter&) = delete;
24   TotalFrameCounter& operator=(const TotalFrameCounter&) = delete;
25
26   void Reset();
27
28   void OnShow(base::TimeTicks timestamp);
29   void OnHide(base::TimeTicks timestamp);
30   void OnBeginFrame(const viz::BeginFrameArgs& args);
31
32   size_t ComputeTotalVisibleFrames(base::TimeTicks until) const;
33
34   size_t total_frames() const { return total_frames_; }
35
36   void set_total_frames_for_testing(size_t total_frames) {
37     total_frames_ = total_frames;
38   }
39
40  private:
41   void UpdateTotalFramesSinceLastVisible(base::TimeTicks until);
42
43   size_t total_frames_ = 0;
44
45   // The most recent vsync-interval set by the display compositor.
46   // Set only if the compositor is currently visible, otherwise not set.
47   base::TimeDelta latest_interval_;
48
49   // The time the compositor was made visible.
50   // Set only if the compositor is currently visible, otherwise not set.
51   base::TimeTicks last_shown_timestamp_;
52 };
53
54 }  // namespace cc
55
56 #endif  // CC_METRICS_TOTAL_FRAME_COUNTER_H_