fps_counter.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright 2019 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 ASH_PUBLIC_CPP_FPS_COUNTER_H_
  5. #define ASH_PUBLIC_CPP_FPS_COUNTER_H_
  6. #include "ash/public/cpp/ash_public_export.h"
  7. #include "base/time/time.h"
  8. #include "ui/compositor/compositor_observer.h"
  9. namespace ui {
  10. class Compositor;
  11. }
  12. namespace ash {
  13. // FpsCounter is used to measures the smoothness of animations applied in one
  14. // operation, while AnimationMetricsRepoter measures smoothness of one
  15. // particular animation. For example, overview animation consists of multiple
  16. // animations, such as wallpaper, windows and label etc. This allows us to
  17. // measure such animations as a whole.
  18. class ASH_PUBLIC_EXPORT FpsCounter : public ui::CompositorObserver {
  19. public:
  20. explicit FpsCounter(ui::Compositor* compositor);
  21. FpsCounter(const FpsCounter&) = delete;
  22. FpsCounter& operator=(const FpsCounter&) = delete;
  23. ~FpsCounter() override;
  24. // Comptues smoothness based on the updated frame number in compositor and the
  25. // duration between creation and the invocation time. Returns -1 if it cannot
  26. // compute the smoothness (when frame_count rolled over, or it finihed
  27. // immediately).
  28. int ComputeSmoothness();
  29. // ui::CompositorObserver:
  30. void OnCompositingShuttingDown(ui::Compositor* compositor) override;
  31. // Use this to update histogram even with zero animation.
  32. static void SetForceReportZeroAnimationForTest(bool value);
  33. private:
  34. ui::Compositor* compositor_ = nullptr;
  35. int start_frame_number_ = 0;
  36. base::TimeTicks start_time_;
  37. };
  38. } // namespace ash
  39. #endif // ASH_PUBLIC_CPP_FPS_COUNTER_H_