[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / jank_injector.h
1 // Copyright 2021 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_JANK_INJECTOR_H_
6 #define CC_METRICS_JANK_INJECTOR_H_
7
8 #include "base/task/single_thread_task_runner.h"
9 #include "cc/cc_export.h"
10 #include "components/viz/common/frame_sinks/begin_frame_args.h"
11
12 class GURL;
13
14 namespace cc {
15
16 class CC_EXPORT ScopedJankInjectionEnabler {
17  public:
18   ScopedJankInjectionEnabler();
19   ~ScopedJankInjectionEnabler();
20
21   ScopedJankInjectionEnabler(const ScopedJankInjectionEnabler&) = delete;
22   ScopedJankInjectionEnabler& operator=(const ScopedJankInjectionEnabler&) =
23       delete;
24 };
25
26 class CC_EXPORT JankInjector {
27  public:
28   struct CC_EXPORT JankConfig {
29     uint32_t target_dropped_frames_percent = 10;
30
31     // How many consecutive frames to drop (when a frame is dropped).
32     uint32_t dropped_frame_cluster_size = 1;
33   };
34
35   // Jank injection.
36   JankInjector();
37   ~JankInjector();
38
39   JankInjector(const JankInjector&) = delete;
40   JankInjector& operator=(const JankInjector&) = delete;
41
42   static bool IsEnabled(const GURL& url);
43
44   void ScheduleJankIfNeeded(const viz::BeginFrameArgs& args,
45                             base::SingleThreadTaskRunner* task_runner);
46
47   const JankConfig& config() const { return config_; }
48
49  private:
50   bool ShouldJankCurrentFrame(const viz::BeginFrameArgs& args) const;
51   void ScheduleJank(const viz::BeginFrameArgs& args,
52                     base::SingleThreadTaskRunner* task_runner);
53   void SignalJank();
54
55   JankConfig config_;
56
57   uint64_t total_frames_ = 0;
58   uint64_t janked_frames_ = 0;
59   bool did_jank_last_time_ = false;
60 };
61
62 }  // namespace cc
63
64 #endif  // CC_METRICS_JANK_INJECTOR_H_