animation_throughput_reporter.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_COMPOSITOR_ANIMATION_THROUGHPUT_REPORTER_H_
  5. #define UI_COMPOSITOR_ANIMATION_THROUGHPUT_REPORTER_H_
  6. #include <memory>
  7. #include "base/callback_forward.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "cc/metrics/frame_sequence_metrics.h"
  10. #include "ui/compositor/compositor_export.h"
  11. namespace ui {
  12. class Compositor;
  13. class LayerAnimator;
  14. // Reports cc::FrameSequenceMetrics::ThroughputData of layer animations.
  15. //
  16. // Throughput is defined as the ratio between number frames presented (actual
  17. // screen updates) for the animations and the number frames expected.
  18. // DroppedFrames/SkippedFrames is the other part of the story. It is a ratio
  19. // between dropped/skipped frames over the expected frames.
  20. //
  21. // See also docs/speed/graphics_metrics_definitions.md.
  22. //
  23. // cc::FrameSequenceMetrics::ThroughputData contains the numbers of produced
  24. // frames and expected frames and could be used to calculate the two metrics.
  25. //
  26. // All layer animation sequences created after its construction are consider
  27. // as part of the animation being tracked. Graphics throughput tracking is
  28. // stopped when all relevant layer animation sequences finish. The report
  29. // callback is invoked on the next frame presentation if there is enough data
  30. // and none of the layer animation sequences is aborted.
  31. class COMPOSITOR_EXPORT AnimationThroughputReporter {
  32. public:
  33. using ReportCallback = base::RepeatingCallback<void(
  34. const cc::FrameSequenceMetrics::CustomReportData&)>;
  35. AnimationThroughputReporter(scoped_refptr<LayerAnimator> animator,
  36. ReportCallback report_callback);
  37. AnimationThroughputReporter(const AnimationThroughputReporter&) = delete;
  38. AnimationThroughputReporter& operator=(const AnimationThroughputReporter&) =
  39. delete;
  40. ~AnimationThroughputReporter();
  41. private:
  42. // Tracks when layer animation sequences are scheduled and finished.
  43. class AnimationTracker;
  44. // Returns the relevant compositor of |animator|. Note it could return
  45. // nullptr if |animator| has not attached to an animation timeline.
  46. // Listed here to access LayerAnimator's protected delegate().
  47. static Compositor* GetCompositor(LayerAnimator* animator);
  48. // Whether |animator_| is attached to a timeline.
  49. // List here to access LayerAnimation's private |anmation_| member.
  50. static bool IsAnimatorAttachedToTimeline(LayerAnimator* animator);
  51. scoped_refptr<LayerAnimator> animator_;
  52. std::unique_ptr<AnimationTracker> animation_tracker_;
  53. };
  54. } // namespace ui
  55. #endif // UI_COMPOSITOR_ANIMATION_THROUGHPUT_REPORTER_H_