Make sure the secondary vsync callback is called after the vsync callback (flutter/engine#31513)

This commit is contained in:
ColdPaleLight
2022-03-11 09:45:05 +08:00
committed by GitHub
parent 7a40b3a70d
commit fc5766639a
3 changed files with 47 additions and 4 deletions

View File

@@ -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);
};

View File

@@ -1848,7 +1848,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.
@@ -1861,6 +1861,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;

View File

@@ -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));
}
}