Make sure the secondary vsync callback is called after the vsync callback (flutter/engine#31513)
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user