Flutter Engine
vsync_waiter_fallback.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 "flutter/shell/common/vsync_waiter_fallback.h"
6 
7 #include "flutter/fml/logging.h"
8 
9 namespace flutter {
10 namespace {
11 
12 static fml::TimePoint SnapToNextTick(fml::TimePoint value,
13  fml::TimePoint tick_phase,
14  fml::TimeDelta tick_interval) {
15  fml::TimeDelta offset = (tick_phase - value) % tick_interval;
16  if (offset != fml::TimeDelta::Zero())
17  offset = offset + tick_interval;
18  return value + offset;
19 }
20 
21 } // namespace
22 
24  : VsyncWaiter(std::move(task_runners)), phase_(fml::TimePoint::Now()) {}
25 
27 
28 // |VsyncWaiter|
29 void VsyncWaiterFallback::AwaitVSync() {
30  constexpr fml::TimeDelta kSingleFrameInterval =
31  fml::TimeDelta::FromSecondsF(1.0 / 60.0);
32 
33  auto next =
34  SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
35 
36  FireCallback(next, next + kSingleFrameInterval);
37 }
38 
39 } // namespace flutter
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
static constexpr TimeDelta FromSecondsF(double seconds)
Definition: time_delta.h:53
Definition: ref_ptr.h:252
VsyncWaiterFallback(TaskRunners task_runners)
Definition: ascii_trie.cc:9
uint8_t value
void FireCallback(fml::TimePoint frame_start_time, fml::TimePoint frame_target_time)
Definition: vsync_waiter.cc:91
static TimePoint Now()
Definition: time_point.cc:26