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#define FML_USED_ON_EMBEDDER
6
7#ifndef FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_
8#define FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_
9
10#include "flutter/shell/common/shell.h"
11
12namespace flutter {
13namespace testing {
14
15using CreateVsyncWaiter = std::function<std::unique_ptr<VsyncWaiter>()>;
16
17class ShellTestVsyncClock {
18 public:
19 /// Simulate that a vsync signal is triggered.
20 void SimulateVSync();
21
22 /// A future that will return the index the next vsync signal.
23 std::future<int> NextVSync();
24
25 private:
26 std::mutex mutex_;
27 std::vector<std::promise<int>> vsync_promised_;
28 size_t vsync_issued_ = 0;
29};
30
31class ShellTestVsyncWaiter : public VsyncWaiter {
32 public:
33 ShellTestVsyncWaiter(TaskRunners task_runners,
34 std::shared_ptr<ShellTestVsyncClock> clock)
35 : VsyncWaiter(std::move(task_runners)), clock_(clock) {}
36
37 protected:
38 void AwaitVSync() override;
39
40 private:
41 std::shared_ptr<ShellTestVsyncClock> clock_;
42};
43
44class ConstantFiringVsyncWaiter : public VsyncWaiter {
45 public:
46 // both of these are set in the past so as to fire immediately.
47 static constexpr fml::TimePoint frame_begin_time =
48 fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromSeconds(0));
49 static constexpr fml::TimePoint frame_target_time =
50 fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromSeconds(100));
51
52 ConstantFiringVsyncWaiter(TaskRunners task_runners)
53 : VsyncWaiter(std::move(task_runners)) {}
54
55 protected:
56 void AwaitVSync() override;
57};
58
59} // namespace testing
60} // namespace flutter
61
62#endif // FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_
63