Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure the secondary vsync callback is called after the vsync callback #31513

Merged
merged 2 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/common/fixtures/shell_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void canReceiveArgumentsWhenEngineSpawn(List<String> args) {
}

@pragma('vm:entry-point')
void canScheduleFrameFromPlatform() {
void onBeginFrameWithNotifyNativeMain() {
PlatformDispatcher.instance.onBeginFrame = (Duration beginTime) {
nativeOnBeginFrame(beginTime.inMicroseconds);
};
Expand Down
46 changes: 45 additions & 1 deletion shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ TEST_F(ShellTest, CanScheduleFrameFromPlatform) {
ASSERT_TRUE(shell->IsSetup());

auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("canScheduleFrameFromPlatform");
configuration.SetEntrypoint("onBeginFrameWithNotifyNativeMain");
RunEngine(shell.get(), std::move(configuration));

// Wait for the application to attach the listener.
Expand All @@ -1860,6 +1860,50 @@ TEST_F(ShellTest, CanScheduleFrameFromPlatform) {
DestroyShell(std::move(shell), std::move(task_runners));
}

TEST_F(ShellTest, SecondaryVsyncCallbackShouldBeCalledAfterVsyncCallback) {
bool is_on_begin_frame_called = false;
bool is_secondary_callback_called = false;
Settings settings = CreateSettingsForFixture();
TaskRunners task_runners = GetTaskRunnersForFixture();
fml::AutoResetWaitableEvent latch;
AddNativeCallback(
"NotifyNative",
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
fml::CountDownLatch count_down_latch(2);
AddNativeCallback("NativeOnBeginFrame",
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
EXPECT_FALSE(is_on_begin_frame_called);
EXPECT_FALSE(is_secondary_callback_called);
is_on_begin_frame_called = true;
count_down_latch.CountDown();
}));
std::unique_ptr<Shell> shell =
CreateShell(std::move(settings), std::move(task_runners));
ASSERT_TRUE(shell->IsSetup());

auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("onBeginFrameWithNotifyNativeMain");
RunEngine(shell.get(), std::move(configuration));

// Wait for the application to attach the listener.
latch.Wait();

fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetUITaskRunner(), [&]() {
shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
EXPECT_TRUE(is_on_begin_frame_called);
EXPECT_FALSE(is_secondary_callback_called);
is_secondary_callback_called = true;
count_down_latch.CountDown();
});
shell->GetEngine()->ScheduleFrame();
});
count_down_latch.Wait();
EXPECT_TRUE(is_on_begin_frame_called);
EXPECT_TRUE(is_secondary_callback_called);
DestroyShell(std::move(shell), std::move(task_runners));
}

static void LogSkData(sk_sp<SkData> data, const char* title) {
FML_LOG(ERROR) << "---------- " << title;
std::ostringstream ostr;
Expand Down
3 changes: 1 addition & 2 deletions shell/common/vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
}

for (auto& secondary_callback : secondary_callbacks) {
task_runners_.GetUITaskRunner()->PostTaskForTime(
std::move(secondary_callback), frame_start_time);
task_runners_.GetUITaskRunner()->PostTask(std::move(secondary_callback));
}
}

Expand Down