diff --git a/shell/platform/fuchsia/flutter/session_connection.h b/shell/platform/fuchsia/flutter/session_connection.h index df47764c3a064..e0855753c6b17 100644 --- a/shell/platform/fuchsia/flutter/session_connection.h +++ b/shell/platform/fuchsia/flutter/session_connection.h @@ -94,7 +94,7 @@ class SessionConnection final { // The maximum number of frames Flutter sent to Scenic that it can have // outstanding at any time. This is equivalent to how many times it has // called Present2() before receiving an OnFramePresented() event. - static constexpr int kMaxFramesInFlight = 2; + static constexpr int kMaxFramesInFlight = 3; int frames_in_flight_ = 0; int frames_in_flight_allowed_ = 0; diff --git a/shell/platform/fuchsia/flutter/vsync_waiter.cc b/shell/platform/fuchsia/flutter/vsync_waiter.cc index 7fd7dd342433a..283a33e14a6ad 100644 --- a/shell/platform/fuchsia/flutter/vsync_waiter.cc +++ b/shell/platform/fuchsia/flutter/vsync_waiter.cc @@ -131,6 +131,15 @@ void VsyncWaiter::AwaitVSync() { VsyncRecorder::GetInstance().GetLastPresentationTime(); fml::TimePoint next_vsync = SnapToNextPhase(now, last_presentation_time, vsync_info.presentation_interval); + + auto next_vsync_start_time = next_vsync - vsync_offset; + + if (now >= next_vsync_start_time) + next_vsync_start_time = + next_vsync_start_time + vsync_info.presentation_interval; + + fml::TimeDelta delta = next_vsync_start_time - now; + task_runners_.GetUITaskRunner()->PostDelayedTask( [& weak_factory_ui = this->weak_factory_ui_] { if (!weak_factory_ui) { @@ -143,7 +152,7 @@ void VsyncWaiter::AwaitVSync() { self->FireCallbackWhenSessionAvailable(); } }, - next_vsync - now); + delta); } void VsyncWaiter::FireCallbackWhenSessionAvailable() { diff --git a/shell/platform/fuchsia/flutter/vsync_waiter.h b/shell/platform/fuchsia/flutter/vsync_waiter.h index 96b1cf4cd364c..577a645ac4aba 100644 --- a/shell/platform/fuchsia/flutter/vsync_waiter.h +++ b/shell/platform/fuchsia/flutter/vsync_waiter.h @@ -34,6 +34,9 @@ class VsyncWaiter final : public flutter::VsyncWaiter { async::Wait session_wait_; fml::WeakPtrFactory weak_factory_; + static constexpr fml::TimeDelta vsync_offset = + fml::TimeDelta::FromNanoseconds(0); + // For accessing the VsyncWaiter via the UI thread, necessary for the callback // for AwaitVSync() std::unique_ptr> weak_factory_ui_;