presentation_time_recorder.cc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2022 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. #include "ash/public/cpp/presentation_time_recorder.h"
  5. #include <memory>
  6. #include "ui/aura/window.h"
  7. #include "ui/compositor/layer.h"
  8. #include "ui/compositor/presentation_time_recorder.h"
  9. namespace ash {
  10. namespace {
  11. // Wrapper class of ui::PresentationTimeRecorder that reports latency based
  12. // on ui::Compositor.
  13. class CompositorPresentationTimeRecorder : public PresentationTimeRecorder {
  14. public:
  15. CompositorPresentationTimeRecorder(aura::Window* window,
  16. const char* latency_histogram_name,
  17. const char* max_latency_histogram_name)
  18. : compositor_recorder_(ui::CreatePresentationTimeHistogramRecorder(
  19. window->layer()->GetCompositor(),
  20. latency_histogram_name,
  21. max_latency_histogram_name)) {}
  22. CompositorPresentationTimeRecorder(
  23. const CompositorPresentationTimeRecorder&) = delete;
  24. CompositorPresentationTimeRecorder& operator=(
  25. const CompositorPresentationTimeRecorder&) = delete;
  26. ~CompositorPresentationTimeRecorder() override = default;
  27. // PresentationTimeRecorder:
  28. bool RequestNext() override { return compositor_recorder_->RequestNext(); }
  29. private:
  30. std::unique_ptr<ui::PresentationTimeRecorder> compositor_recorder_;
  31. };
  32. } // namespace
  33. // static
  34. std::unique_ptr<PresentationTimeRecorder>
  35. PresentationTimeRecorder::CreateCompositorRecorder(
  36. aura::Window* window,
  37. const char* latency_histogram_name,
  38. absl::optional<const char*> max_latency_histogram_name) {
  39. return std::make_unique<CompositorPresentationTimeRecorder>(
  40. window, latency_histogram_name,
  41. max_latency_histogram_name.has_value()
  42. ? max_latency_histogram_name.value()
  43. : "");
  44. }
  45. } // namespace ash