• 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 #include "vsync_recorder.h"
6 
7 #include <mutex>
8 
9 namespace flutter_runner {
10 
11 namespace {
12 
13 std::mutex g_mutex;
14 
15 // Since we don't have any presentation info until we call |Present| for the
16 // first time, assume a 60hz refresh rate in the meantime.
17 constexpr fml::TimeDelta kDefaultPresentationInterval =
18     fml::TimeDelta::FromSecondsF(1.0 / 60.0);
19 
20 }  // namespace
21 
GetInstance()22 VsyncRecorder& VsyncRecorder::GetInstance() {
23   static VsyncRecorder vsync_recorder;
24   return vsync_recorder;
25 }
26 
GetCurrentVsyncInfo() const27 VsyncInfo VsyncRecorder::GetCurrentVsyncInfo() const {
28   {
29     std::unique_lock<std::mutex> lock(g_mutex);
30     if (last_presentation_info_) {
31       return {fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromNanoseconds(
32                   last_presentation_info_->presentation_time)),
33               fml::TimeDelta::FromNanoseconds(
34                   last_presentation_info_->presentation_interval)};
35     }
36   }
37   return {fml::TimePoint::Now(), kDefaultPresentationInterval};
38 }
39 
UpdateVsyncInfo(fuchsia::images::PresentationInfo presentation_info)40 void VsyncRecorder::UpdateVsyncInfo(
41     fuchsia::images::PresentationInfo presentation_info) {
42   std::unique_lock<std::mutex> lock(g_mutex);
43   if (last_presentation_info_ &&
44       presentation_info.presentation_time >
45           last_presentation_info_->presentation_time) {
46     last_presentation_info_ = presentation_info;
47   } else if (!last_presentation_info_) {
48     last_presentation_info_ = presentation_info;
49   }
50 }
51 
52 }  // namespace flutter_runner
53