[M108 Migration][VD] Avoid pending frame counter becoming negative
[platform/framework/web/chromium-efl.git] / cc / metrics / average_lag_tracking_manager.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_AVERAGE_LAG_TRACKING_MANAGER_H_
6 #define CC_METRICS_AVERAGE_LAG_TRACKING_MANAGER_H_
7
8 #include <utility>
9 #include <vector>
10
11 #include "base/containers/circular_deque.h"
12 #include "cc/cc_export.h"
13 #include "cc/metrics/average_lag_tracker.h"
14 #include "cc/metrics/event_metrics.h"
15
16 namespace viz {
17 struct FrameTimingDetails;
18 }  // namespace viz
19
20 namespace cc {
21
22 // A helper to decouple the `EventMetrics` and the `AverageLagTracker`.
23 class CC_EXPORT AverageLagTrackingManager {
24  public:
25   AverageLagTrackingManager();
26   ~AverageLagTrackingManager();
27
28   // Disallow copy and assign.
29   AverageLagTrackingManager(const AverageLagTrackingManager&) = delete;
30   AverageLagTrackingManager& operator=(AverageLagTrackingManager const&) =
31       delete;
32
33   // Adds all the eligible events in the collection |infos| to the |frame_token|
34   // wait list.
35   void CollectScrollEventsFromFrame(uint32_t frame_token,
36                                     const EventMetricsSet& events_metrics);
37
38   // Sends all pending events in the |frame_token| list to the
39   // AverageLagTracker, given its |frame_details|.
40   void DidPresentCompositorFrame(uint32_t frame_token,
41                                  const viz::FrameTimingDetails& frame_details);
42
43   // Clears the list of events |frame_token_to_info_| if the current frames wont
44   // receive a presentation feedback (e.g. LayerTreeFrameSink loses context)
45   void Clear();
46
47  private:
48   // Tracker for the AverageLagPresentation metrics that uses the presentation
49   // feedback time as an approximation for the time the users sees the frame on
50   // the screen.
51   AverageLagTracker lag_tracker_;
52
53   // List of events (vector) per frame (uint32_t |frame_token|) to submit to the
54   // lag trackers when DidPresentCompositorFrame is called for a |frame_token|.
55   base::circular_deque<
56       std::pair<uint32_t, std::vector<AverageLagTracker::EventInfo>>>
57       frame_token_to_info_;
58 };
59
60 }  // namespace cc
61
62 #endif  // CC_METRICS_AVERAGE_LAG_TRACKING_MANAGER_H_