Flutter Engine
vsync_recorder.cc
Go to the documentation of this file.
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 #include "vsync_recorder.h"
6 
7 #include <mutex>
8 
9 namespace flutter_runner {
10 
11 namespace {
12 
13 std::mutex g_mutex;
14 
15 // Assume a 60hz refresh rate before we have enough past
16 // |fuchsia::scenic::scheduling::PresentationInfo|s to calculate it ourselves.
17 static constexpr fml::TimeDelta kDefaultPresentationInterval =
18  fml::TimeDelta::FromSecondsF(1.0 / 60.0);
19 
20 } // namespace
21 
23  static VsyncRecorder vsync_recorder;
24  return vsync_recorder;
25 }
26 
28  {
29  std::unique_lock<std::mutex> lock(g_mutex);
31  next_presentation_info_.presentation_time())),
32  kDefaultPresentationInterval};
33  }
34 }
35 
37  fuchsia::scenic::scheduling::FuturePresentationTimes info) {
38  std::unique_lock<std::mutex> lock(g_mutex);
39 
40  auto next_time = next_presentation_info_.presentation_time();
41  // Get the earliest vsync time that is after our recorded |presentation_time|.
42  for (auto& presentation_info : info.future_presentations) {
43  auto current_time = presentation_info.presentation_time();
44 
45  if (current_time > next_time) {
46  next_presentation_info_.set_presentation_time(current_time);
47  return;
48  }
49  }
50 }
51 
52 void VsyncRecorder::UpdateFramePresentedInfo(zx::time presentation_time) {
53  last_presentation_time_ = fml::TimePoint::FromEpochDelta(
54  fml::TimeDelta::FromNanoseconds(presentation_time.get()));
55 }
56 
58  return last_presentation_time_;
59 }
60 
61 } // namespace flutter_runner
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static constexpr TimeDelta FromSecondsF(double seconds)
Definition: time_delta.h:53
void UpdateNextPresentationInfo(fuchsia::scenic::scheduling::FuturePresentationTimes info)
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition: time_point.h:36
void UpdateFramePresentedInfo(zx::time presentation_time)
fml::TimePoint GetLastPresentationTime() const
VsyncInfo GetCurrentVsyncInfo() const
static VsyncRecorder & GetInstance()