forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vsync_waiters_test.cc
69 lines (58 loc) · 2.42 KB
/
vsync_waiters_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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
#include "flutter/shell/common/shell_test.h"
#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/mapping.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/testing/testing.h"
namespace flutter {
namespace testing {
void ShellTestVsyncClock::SimulateVSync() {
std::scoped_lock lock(mutex_);
if (vsync_issued_ >= vsync_promised_.size()) {
vsync_promised_.emplace_back();
}
FML_CHECK(vsync_issued_ < vsync_promised_.size());
vsync_promised_[vsync_issued_].set_value(vsync_issued_);
vsync_issued_ += 1;
}
std::future<int> ShellTestVsyncClock::NextVSync() {
std::scoped_lock lock(mutex_);
vsync_promised_.emplace_back();
return vsync_promised_.back().get_future();
}
void ShellTestVsyncWaiter::AwaitVSync() {
FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
auto vsync_future = clock_->NextVSync();
auto async_wait = std::async([&vsync_future, this]() {
vsync_future.wait();
// Post the `FireCallback` to the Platform thread so earlier Platform tasks
// (specifically, the `VSyncFlush` call) will be finished before
// `FireCallback` is executed. This is only needed for our unit tests.
//
// Without this, the repeated VSYNC signals in `VSyncFlush` may start both
// the current frame in the UI thread and the next frame in the secondary
// callback (both of them are waiting for VSYNCs). That breaks the unit
// test's assumption that each frame's VSYNC must be issued by different
// `VSyncFlush` call (which resets the `will_draw_new_frame` bit).
//
// For example, HandlesActualIphoneXsInputEvents will fail without this.
task_runners_.GetPlatformTaskRunner()->PostTask([this]() {
FireCallback(fml::TimePoint::Now(), fml::TimePoint::Now());
});
});
}
void ConstantFiringVsyncWaiter::AwaitVSync() {
FML_DCHECK(task_runners_.GetUITaskRunner()->RunsTasksOnCurrentThread());
auto async_wait = std::async([this]() {
task_runners_.GetPlatformTaskRunner()->PostTask(
[this]() { FireCallback(frame_begin_time, frame_target_time); });
});
}
} // namespace testing
} // namespace flutter