forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsync_waiter_fallback.cc
39 lines (28 loc) · 1.17 KB
/
vsync_waiter_fallback.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/shell/common/vsync_waiter_fallback.h"
#include "flutter/fml/logging.h"
namespace flutter {
namespace {
static fml::TimePoint SnapToNextTick(fml::TimePoint value,
fml::TimePoint tick_phase,
fml::TimeDelta tick_interval) {
fml::TimeDelta offset = (tick_phase - value) % tick_interval;
if (offset != fml::TimeDelta::Zero())
offset = offset + tick_interval;
return value + offset;
}
} // namespace
VsyncWaiterFallback::VsyncWaiterFallback(TaskRunners task_runners)
: VsyncWaiter(std::move(task_runners)), phase_(fml::TimePoint::Now()) {}
VsyncWaiterFallback::~VsyncWaiterFallback() = default;
// |VsyncWaiter|
void VsyncWaiterFallback::AwaitVSync() {
constexpr fml::TimeDelta kSingleFrameInterval =
fml::TimeDelta::FromSecondsF(1.0 / 60.0);
auto next =
SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
FireCallback(next, next + kSingleFrameInterval);
}
} // namespace flutter