Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions shell/platform/fuchsia/flutter/flatland_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void FlatlandConnection::Present() {
if (present_credits_ > 0) {
DoPresent();
} else {
present_pending_ = true;
present_waiting_for_credit_ = true;
}
}

Expand Down Expand Up @@ -87,25 +87,25 @@ void FlatlandConnection::DoPresent() {
// This method is called from the UI thread.
void FlatlandConnection::AwaitVsync(FireCallbackCallback callback) {
std::scoped_lock<std::mutex> 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;
}
}

Expand All @@ -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) {
Expand All @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions shell/platform/fuchsia/flutter/flatland_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_;

Expand Down