Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1cad88f

Browse files
committed
Add a test for vsync_waiter
1 parent 056eea4 commit 1cad88f

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/task_runner_adapter.h
14981498
FILE: ../../../flutter/shell/platform/fuchsia/flutter/unique_fdio_ns.h
14991499
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_waiter.cc
15001500
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_waiter.h
1501+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vsync_waiter_unittest.cc
15011502
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vulkan_surface.cc
15021503
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vulkan_surface.h
15031504
FILE: ../../../flutter/shell/platform/fuchsia/flutter/vulkan_surface_pool.cc

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ executable("flutter_runner_unittests") {
485485
"tests/gfx_session_connection_unittests.cc",
486486
"tests/pointer_event_utility.cc",
487487
"tests/pointer_event_utility.h",
488+
"vsync_waiter_unittest.cc",
488489
]
489490

490491
# This is needed for //third_party/googletest for linking zircon symbols.

shell/platform/fuchsia/flutter/vsync_waiter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ class VsyncWaiter final : public flutter::VsyncWaiter {
5555

5656
} // namespace flutter_runner
5757

58-
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VSYNC_WAITER_H_
58+
#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_VSYNC_WAITER_H_
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
#include <gtest/gtest.h>
6+
7+
#include <string>
8+
9+
#include "flutter/fml/task_runner.h"
10+
#include "flutter/shell/common/thread_host.h"
11+
#include "fml/make_copyable.h"
12+
#include "fml/message_loop.h"
13+
#include "fml/synchronization/waitable_event.h"
14+
#include "fml/time/time_delta.h"
15+
#include "fml/time/time_point.h"
16+
#include "vsync_waiter.h"
17+
18+
namespace flutter_runner {
19+
20+
TEST(VSyncWaiterFuchsia, FrameScheduledForStartTime) {
21+
using flutter::ThreadHost;
22+
std::string prefix = "vsync_waiter_test";
23+
24+
fml::MessageLoop::EnsureInitializedForCurrentThread();
25+
auto platform_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
26+
27+
ThreadHost thread_host =
28+
ThreadHost(prefix, flutter::ThreadHost::Type::RASTER |
29+
flutter::ThreadHost::Type::UI |
30+
flutter::ThreadHost::Type::IO);
31+
const flutter::TaskRunners task_runners(
32+
prefix, // Dart thread labels
33+
platform_task_runner, // platform
34+
thread_host.raster_thread->GetTaskRunner(), // raster
35+
thread_host.ui_thread->GetTaskRunner(), // ui
36+
thread_host.io_thread->GetTaskRunner() // io
37+
);
38+
39+
// await vsync will invoke the callback right away, but vsync waiter will post
40+
// the task for frame_start time.
41+
VsyncWaiter vsync_waiter(
42+
[](FireCallbackCallback callback) {
43+
const auto now = fml::TimePoint::Now();
44+
const auto frame_start = now + fml::TimeDelta::FromMilliseconds(20);
45+
const auto frame_end = now + fml::TimeDelta::FromMilliseconds(36);
46+
callback(frame_start, frame_end);
47+
},
48+
/*secondary callback*/ nullptr, task_runners);
49+
50+
fml::AutoResetWaitableEvent latch;
51+
task_runners.GetUITaskRunner()->PostTask([&]() {
52+
vsync_waiter.AsyncWaitForVsync(
53+
[&](std::unique_ptr<flutter::FrameTimingsRecorder> recorder) {
54+
const auto now = fml::TimePoint::Now();
55+
EXPECT_GT(now, recorder->GetVsyncStartTime());
56+
latch.Signal();
57+
});
58+
});
59+
60+
latch.Wait();
61+
}
62+
63+
} // namespace flutter_runner

0 commit comments

Comments
 (0)