From 8db099dffd088646d98a80c201e12d9f77b6cfb4 Mon Sep 17 00:00:00 2001 From: Felipe Archondo Date: Wed, 29 Jan 2020 15:49:07 -0500 Subject: [PATCH] [fuchsia] change kMaxFramesInFlight to 3 To give more flexibiltiy in scheduling, we change the number of frames in flight we can have at one time to 3. We also introduce an offset from VSync that Flutter can use to begin its work at. It is currently set at 0ms, signalling no change from previous behavior. --- shell/platform/fuchsia/flutter/session_connection.h | 2 +- shell/platform/fuchsia/flutter/vsync_waiter.cc | 11 ++++++++++- shell/platform/fuchsia/flutter/vsync_waiter.h | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) 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_;