diff --git a/shell/platform/fuchsia/flutter/flatland_connection.cc b/shell/platform/fuchsia/flutter/flatland_connection.cc index 500783e20b370..df0014f719ab5 100644 --- a/shell/platform/fuchsia/flutter/flatland_connection.cc +++ b/shell/platform/fuchsia/flutter/flatland_connection.cc @@ -56,7 +56,7 @@ void FlatlandConnection::Present() { if (present_credits_ > 0) { DoPresent(); } else { - present_pending_ = true; + present_waiting_for_credit_ = true; } } @@ -87,25 +87,25 @@ void FlatlandConnection::DoPresent() { // This method is called from the UI thread. void FlatlandConnection::AwaitVsync(FireCallbackCallback callback) { std::scoped_lock lock(threadsafe_state_.mutex_); + const fml::TimePoint now = fml::TimePoint::Now(); // Immediately fire callbacks until the first Present. We might receive // multiple requests for AwaitVsync() until the first Present, which relies on // receiving size on FlatlandPlatformView::OnGetLayout() at an uncertain time. if (!threadsafe_state_.first_present_called_) { - fml::TimePoint now = fml::TimePoint::Now(); callback(now, now + kDefaultFlatlandPresentationInterval); return; } threadsafe_state_.fire_callback_ = callback; - if (threadsafe_state_.fire_callback_pending_) { - const fml::TimePoint now = fml::TimePoint::Now(); + // Immediately fire callback if OnNextFrameBegin() is already called. + if (threadsafe_state_.on_next_frame_pending_) { threadsafe_state_.fire_callback_( now, GetNextPresentationTime( now, threadsafe_state_.next_presentation_time_)); threadsafe_state_.fire_callback_ = nullptr; - threadsafe_state_.fire_callback_pending_ = false; + threadsafe_state_.on_next_frame_pending_ = false; } } @@ -129,9 +129,9 @@ void FlatlandConnection::OnNextFrameBegin( fuchsia::ui::composition::OnNextFrameBeginValues values) { present_credits_ += values.additional_present_credits(); - if (present_pending_ && present_credits_ > 0) { + if (present_waiting_for_credit_ && present_credits_ > 0) { DoPresent(); - present_pending_ = false; + present_waiting_for_credit_ = false; } if (present_credits_ > 0) { @@ -148,9 +148,9 @@ void FlatlandConnection::OnNextFrameBegin( /*frame_target=*/next_presentation_time); threadsafe_state_.fire_callback_ = nullptr; } else { - threadsafe_state_.fire_callback_pending_ = true; - threadsafe_state_.next_presentation_time_ = next_presentation_time; + threadsafe_state_.on_next_frame_pending_ = true; } + threadsafe_state_.next_presentation_time_ = next_presentation_time; } } diff --git a/shell/platform/fuchsia/flutter/flatland_connection.h b/shell/platform/fuchsia/flutter/flatland_connection.h index b66c8f99fabd5..2d894de6cd09d 100644 --- a/shell/platform/fuchsia/flutter/flatland_connection.h +++ b/shell/platform/fuchsia/flutter/flatland_connection.h @@ -79,7 +79,7 @@ class FlatlandConnection final { on_frame_presented_event on_frame_presented_callback_; uint32_t present_credits_ = 1; - bool present_pending_ = false; + bool present_waiting_for_credit_ = false; // A flow event trace id for following |Flatland::Present| calls into Scenic. uint64_t next_present_trace_id_ = 0; @@ -90,8 +90,8 @@ class FlatlandConnection final { struct { std::mutex mutex_; FireCallbackCallback fire_callback_; - bool fire_callback_pending_ = false; bool first_present_called_ = false; + bool on_next_frame_pending_ = false; fml::TimePoint next_presentation_time_; } threadsafe_state_;