• 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 // 2021.2.10 Framework adapted to ACE.
5 //           Copyright (c) 2021 Huawei Device Co., Ltd. All rights reserved.
6 
7 #include "flutter/shell/common/vsync_waiter_fallback.h"
8 
9 #include "flutter/fml/logging.h"
10 
11 namespace flutter {
12 namespace {
13 
SnapToNextTick(fml::TimePoint value,fml::TimePoint tick_phase,fml::TimeDelta tick_interval)14 static fml::TimePoint SnapToNextTick(fml::TimePoint value,
15                                      fml::TimePoint tick_phase,
16                                      fml::TimeDelta tick_interval) {
17   fml::TimeDelta offset = (tick_phase - value) % tick_interval;
18   if (offset != fml::TimeDelta::Zero())
19     offset = offset + tick_interval;
20   return value + offset;
21 }
22 
23 }  // namespace
24 
VsyncWaiterFallback(TaskRunners task_runners)25 VsyncWaiterFallback::VsyncWaiterFallback(TaskRunners task_runners)
26     : VsyncWaiter(std::move(task_runners)), phase_(fml::TimePoint::Now()) {}
27 
28 VsyncWaiterFallback::~VsyncWaiterFallback() = default;
29 
30 // |VsyncWaiter|
AwaitVSync()31 void VsyncWaiterFallback::AwaitVSync() {
32 // ACE PC preview
33 #if defined(PREVIEW)
34   constexpr fml::TimeDelta kSingleFrameInterval =
35       fml::TimeDelta::FromSecondsF(1.0 / 30.0);
36 #else
37   constexpr fml::TimeDelta kSingleFrameInterval =
38       fml::TimeDelta::FromSecondsF(1.0 / 60.0);
39 #endif
40 
41   auto next =
42       SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);
43 
44   FireCallback(next, next + kSingleFrameInterval);
45 }
46 
47 }  // namespace flutter
48