@@ -52,7 +52,7 @@ void VsyncWaiter::AsyncWaitForVsync(const Callback& callback) {
5252 return ;
5353 }
5454 callback_ = std::move (callback);
55- if (secondary_callback_ ) {
55+ if (!secondary_callbacks_. empty () ) {
5656 // Return directly as `AwaitVSync` is already called by
5757 // `ScheduleSecondaryCallback`.
5858 return ;
@@ -61,7 +61,8 @@ void VsyncWaiter::AsyncWaitForVsync(const Callback& callback) {
6161 AwaitVSync ();
6262}
6363
64- void VsyncWaiter::ScheduleSecondaryCallback (const fml::closure& callback) {
64+ void VsyncWaiter::ScheduleSecondaryCallback (uintptr_t id,
65+ const fml::closure& callback) {
6566 FML_DCHECK (task_runners_.GetUITaskRunner ()->RunsTasksOnCurrentThread ());
6667
6768 if (!callback) {
@@ -72,13 +73,13 @@ void VsyncWaiter::ScheduleSecondaryCallback(const fml::closure& callback) {
7273
7374 {
7475 std::scoped_lock lock (callback_mutex_);
75- if (secondary_callback_) {
76+ auto [_, inserted] = secondary_callbacks_.emplace (id, std::move (callback));
77+ if (!inserted) {
7678 // Multiple schedules must result in a single callback per frame interval.
7779 TRACE_EVENT_INSTANT0 (" flutter" ,
7880 " MultipleCallsToSecondaryVsyncInFrameInterval" );
7981 return ;
8082 }
81- secondary_callback_ = std::move (callback);
8283 if (callback_) {
8384 // Return directly as `AwaitVSync` is already called by
8485 // `AsyncWaitForVsync`.
@@ -91,15 +92,18 @@ void VsyncWaiter::ScheduleSecondaryCallback(const fml::closure& callback) {
9192void VsyncWaiter::FireCallback (fml::TimePoint frame_start_time,
9293 fml::TimePoint frame_target_time) {
9394 Callback callback;
94- fml::closure secondary_callback ;
95+ std::vector< fml::closure> secondary_callbacks ;
9596
9697 {
9798 std::scoped_lock lock (callback_mutex_);
9899 callback = std::move (callback_);
99- secondary_callback = std::move (secondary_callback_);
100+ for (auto & pair : secondary_callbacks_) {
101+ secondary_callbacks.push_back (std::move (pair.second ));
102+ }
103+ secondary_callbacks_.clear ();
100104 }
101105
102- if (!callback && !secondary_callback ) {
106+ if (!callback && secondary_callbacks. empty () ) {
103107 // This means that the vsync waiter implementation fired a callback for a
104108 // request we did not make. This is a paranoid check but we still want to
105109 // make sure we catch misbehaving vsync implementations.
@@ -128,7 +132,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
128132 frame_start_time);
129133 }
130134
131- if ( secondary_callback) {
135+ for ( auto & secondary_callback : secondary_callbacks ) {
132136 task_runners_.GetUITaskRunner ()->PostTaskForTime (
133137 std::move (secondary_callback), frame_start_time);
134138 }
0 commit comments