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

Commit ebcd86f

Browse files
Make sure the secondary vsync callback is called after the vsync callback (#31513)
1 parent 1a8033c commit ebcd86f

3 files changed

Lines changed: 47 additions & 4 deletions

File tree

‎shell/common/fixtures/shell_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void canReceiveArgumentsWhenEngineSpawn(List<String> args) {
264264
}
265265

266266
@pragma('vm:entry-point')
267-
void canScheduleFrameFromPlatform() {
267+
void onBeginFrameWithNotifyNativeMain() {
268268
PlatformDispatcher.instance.onBeginFrame = (Duration beginTime) {
269269
nativeOnBeginFrame(beginTime.inMicroseconds);
270270
};

‎shell/common/shell_unittests.cc‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1848,7 +1848,7 @@ TEST_F(ShellTest, CanScheduleFrameFromPlatform) {
18481848
ASSERT_TRUE(shell->IsSetup());
18491849

18501850
auto configuration = RunConfiguration::InferFromSettings(settings);
1851-
configuration.SetEntrypoint("canScheduleFrameFromPlatform");
1851+
configuration.SetEntrypoint("onBeginFrameWithNotifyNativeMain");
18521852
RunEngine(shell.get(), std::move(configuration));
18531853

18541854
// Wait for the application to attach the listener.
@@ -1861,6 +1861,50 @@ TEST_F(ShellTest, CanScheduleFrameFromPlatform) {
18611861
DestroyShell(std::move(shell), std::move(task_runners));
18621862
}
18631863

1864+
TEST_F(ShellTest, SecondaryVsyncCallbackShouldBeCalledAfterVsyncCallback) {
1865+
bool is_on_begin_frame_called = false;
1866+
bool is_secondary_callback_called = false;
1867+
Settings settings = CreateSettingsForFixture();
1868+
TaskRunners task_runners = GetTaskRunnersForFixture();
1869+
fml::AutoResetWaitableEvent latch;
1870+
AddNativeCallback(
1871+
"NotifyNative",
1872+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) { latch.Signal(); }));
1873+
fml::CountDownLatch count_down_latch(2);
1874+
AddNativeCallback("NativeOnBeginFrame",
1875+
CREATE_NATIVE_ENTRY([&](Dart_NativeArguments args) {
1876+
EXPECT_FALSE(is_on_begin_frame_called);
1877+
EXPECT_FALSE(is_secondary_callback_called);
1878+
is_on_begin_frame_called = true;
1879+
count_down_latch.CountDown();
1880+
}));
1881+
std::unique_ptr<Shell> shell =
1882+
CreateShell(std::move(settings), std::move(task_runners));
1883+
ASSERT_TRUE(shell->IsSetup());
1884+
1885+
auto configuration = RunConfiguration::InferFromSettings(settings);
1886+
configuration.SetEntrypoint("onBeginFrameWithNotifyNativeMain");
1887+
RunEngine(shell.get(), std::move(configuration));
1888+
1889+
// Wait for the application to attach the listener.
1890+
latch.Wait();
1891+
1892+
fml::TaskRunner::RunNowOrPostTask(
1893+
shell->GetTaskRunners().GetUITaskRunner(), [&]() {
1894+
shell->GetEngine()->ScheduleSecondaryVsyncCallback(0, [&]() {
1895+
EXPECT_TRUE(is_on_begin_frame_called);
1896+
EXPECT_FALSE(is_secondary_callback_called);
1897+
is_secondary_callback_called = true;
1898+
count_down_latch.CountDown();
1899+
});
1900+
shell->GetEngine()->ScheduleFrame();
1901+
});
1902+
count_down_latch.Wait();
1903+
EXPECT_TRUE(is_on_begin_frame_called);
1904+
EXPECT_TRUE(is_secondary_callback_called);
1905+
DestroyShell(std::move(shell), std::move(task_runners));
1906+
}
1907+
18641908
static void LogSkData(sk_sp<SkData> data, const char* title) {
18651909
FML_LOG(ERROR) << "---------- " << title;
18661910
std::ostringstream ostr;

‎shell/common/vsync_waiter.cc‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
154154
}
155155

156156
for (auto& secondary_callback : secondary_callbacks) {
157-
task_runners_.GetUITaskRunner()->PostTaskForTime(
158-
std::move(secondary_callback), frame_start_time);
157+
task_runners_.GetUITaskRunner()->PostTask(std::move(secondary_callback));
159158
}
160159
}
161160

0 commit comments

Comments
 (0)