forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsync_waiters_test.h
62 lines (46 loc) · 1.71 KB
/
vsync_waiters_test.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// 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.
#define FML_USED_ON_EMBEDDER
#ifndef FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_
#define FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_
#include "flutter/shell/common/shell.h"
namespace flutter {
namespace testing {
using CreateVsyncWaiter = std::function<std::unique_ptr<VsyncWaiter>()>;
class ShellTestVsyncClock {
public:
/// Simulate that a vsync signal is triggered.
void SimulateVSync();
/// A future that will return the index the next vsync signal.
std::future<int> NextVSync();
private:
std::mutex mutex_;
std::vector<std::promise<int>> vsync_promised_;
size_t vsync_issued_ = 0;
};
class ShellTestVsyncWaiter : public VsyncWaiter {
public:
ShellTestVsyncWaiter(TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> clock)
: VsyncWaiter(std::move(task_runners)), clock_(clock) {}
protected:
void AwaitVSync() override;
private:
std::shared_ptr<ShellTestVsyncClock> clock_;
};
class ConstantFiringVsyncWaiter : public VsyncWaiter {
public:
// both of these are set in the past so as to fire immediately.
static constexpr fml::TimePoint frame_begin_time =
fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromSeconds(0));
static constexpr fml::TimePoint frame_target_time =
fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromSeconds(100));
ConstantFiringVsyncWaiter(TaskRunners task_runners)
: VsyncWaiter(std::move(task_runners)) {}
protected:
void AwaitVSync() override;
};
} // namespace testing
} // namespace flutter
#endif // FLUTTER_SHELL_COMMON_VSYNC_WAITERS_TEST_H_