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

Commit 04f2767

Browse files
committed
Add a test for vsync_waiter
1 parent 175bff4 commit 04f2767

File tree

4 files changed

+63
-1
lines changed

4 files changed

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

0 commit comments

Comments
 (0)