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.
5 #ifndef CC_METRICS_TOTAL_FRAME_COUNTER_H_
6 #define CC_METRICS_TOTAL_FRAME_COUNTER_H_
8 #include "base/time/time.h"
9 #include "cc/cc_export.h"
12 struct BeginFrameArgs;
17 // This class keeps track of how many vsyncs (frames) the compositor was visible
19 class CC_EXPORT TotalFrameCounter {
23 TotalFrameCounter(const TotalFrameCounter&) = delete;
24 TotalFrameCounter& operator=(const TotalFrameCounter&) = delete;
28 void OnShow(base::TimeTicks timestamp);
29 void OnHide(base::TimeTicks timestamp);
30 void OnBeginFrame(const viz::BeginFrameArgs& args);
32 size_t ComputeTotalVisibleFrames(base::TimeTicks until) const;
34 size_t total_frames() const { return total_frames_; }
36 void set_total_frames_for_testing(size_t total_frames) {
37 total_frames_ = total_frames;
41 void UpdateTotalFramesSinceLastVisible(base::TimeTicks until);
43 size_t total_frames_ = 0;
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_;
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_;
56 #endif // CC_METRICS_TOTAL_FRAME_COUNTER_H_