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// FLUTTER_NOLINT
5
6#include "flutter/shell/common/vsync_waiter_fallback.h"
7
8#include "flutter/fml/logging.h"
9
10namespace flutter {
11namespace {
12
13static fml::TimePoint SnapToNextTick(fml::TimePoint value,
14 fml::TimePoint tick_phase,
15 fml::TimeDelta tick_interval) {
16 fml::TimeDelta offset = (tick_phase - value) % tick_interval;
17 if (offset != fml::TimeDelta::Zero())
18 offset = offset + tick_interval;
19 return value + offset;
20}
21
22} // namespace
23
24VsyncWaiterFallback::VsyncWaiterFallback(TaskRunners task_runners)
25 : VsyncWaiter(std::move(task_runners)), phase_(fml::TimePoint::Now()) {}
26
27VsyncWaiterFallback::~VsyncWaiterFallback() = default;
28
29// |VsyncWaiter|
30void VsyncWaiterFallback::AwaitVSync() {
31 constexpr fml::TimeDelta kSingleFrameInterval =
32 fml::TimeDelta::FromSecondsF(1.0 / 60.0);
33
34 auto next =
35 SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
36
37 FireCallback(next, next + kSingleFrameInterval);
38}
39
40} // namespace flutter
41