• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter 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 
5 #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_VSYNC_RECORDER_H_
6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_VSYNC_RECORDER_H_
7 
8 #include <optional>
9 
10 #include "flutter/fml/time/time_delta.h"
11 #include "flutter/fml/time/time_point.h"
12 #include "lib/ui/scenic/cpp/session.h"
13 
14 namespace flutter_runner {
15 
16 struct VsyncInfo {
17   fml::TimePoint presentation_time;
18   fml::TimeDelta presentation_interval;
19 };
20 
21 class VsyncRecorder {
22  public:
23   static VsyncRecorder& GetInstance();
24 
25   // Retrieve the most recent |PresentationInfo| provided to us by scenic.
26   // This function is safe to call from any thread.
27   VsyncInfo GetCurrentVsyncInfo() const;
28 
29   // Update the current Vsync info to |presentation_info|.  This is expected
30   // to be called in |scenic::Sesssion::Present| callbacks with the
31   // presentation info provided by scenic.  Only the most recent vsync
32   // information will be saved (in order to handle edge cases involving
33   // multiple scenic sessions in the same process).  This function is safe to
34   // call from any thread.
35   void UpdateVsyncInfo(fuchsia::images::PresentationInfo presentation_info);
36 
37  private:
38   VsyncRecorder() = default;
39 
40   std::optional<fuchsia::images::PresentationInfo> last_presentation_info_;
41 
42   // Disallow copy and assignment.
43   VsyncRecorder(const VsyncRecorder&) = delete;
44   VsyncRecorder& operator=(const VsyncRecorder&) = delete;
45 };
46 
47 }  // namespace flutter_runner
48 
49 #endif  // FLUTTER_SHELL_PLATFORM_FUCHSIA_VSYNC_RECORDER_H_
50