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 2 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
9 changes: 6 additions & 3 deletions shell/common/vsync_waiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
#include "flow/frame_timings.h"
#include "flutter/fml/task_runner.h"
#include "flutter/fml/trace_event.h"
#include "fml/logging.h"
#include "fml/message_loop_task_queues.h"
#include "fml/task_queue_id.h"
#include "fml/time/time_point.h"

namespace flutter {

Expand Down Expand Up @@ -95,6 +97,8 @@ void VsyncWaiter::ScheduleSecondaryCallback(uintptr_t id,
void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the headerdocs for this protected method, can you document that this subclasses must invoke this at (or close to because of scheduling overhead), the frame start time? Also, can you drop a note in the PR commit message that says verification of all vsync waiter subclasses was done to account for the new assertion for the start time requirements in FireCallback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! will also add the comment when I merge.

fml::TimePoint frame_target_time,
bool pause_secondary_tasks) {
FML_DCHECK(fml::TimePoint::Now() >= frame_start_time);

Callback callback;
std::vector<fml::closure> secondary_callbacks;

Expand Down Expand Up @@ -137,7 +141,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
ui_task_queue_id = task_runners_.GetUITaskRunner()->GetTaskQueueId();
}

task_runners_.GetUITaskRunner()->PostTaskForTime(
task_runners_.GetUITaskRunner()->PostTask(
[ui_task_queue_id, callback, flow_identifier, frame_start_time,
frame_target_time, pause_secondary_tasks]() {
FML_TRACE_EVENT("flutter", kVsyncTraceName, "StartTime",
Expand All @@ -151,8 +155,7 @@ void VsyncWaiter::FireCallback(fml::TimePoint frame_start_time,
if (pause_secondary_tasks) {
ResumeDartMicroTasks(ui_task_queue_id);
}
},
frame_start_time);
});
}

for (auto& secondary_callback : secondary_callbacks) {
Expand Down
23 changes: 19 additions & 4 deletions shell/common/vsync_waiter_fallback.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#define FML_USED_ON_EMBEDDER

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not in the embedder, it seems odd to lift this gate here. This was done so that custom embedders with no custom event loop integration would continue to function. I think this may not be necessary anymore though.

Anyway, the base fml::TaskRunner has a protected task_runners_ field from you can grab a reference to the task runner you need. No need to use this define to access the current task runner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!


#include "flutter/shell/common/vsync_waiter_fallback.h"

#include <memory>

#include "flutter/fml/logging.h"
#include "flutter/fml/message_loop.h"
#include "flutter/fml/trace_event.h"

namespace flutter {
Expand Down Expand Up @@ -35,11 +40,21 @@ void VsyncWaiterFallback::AwaitVSync() {

constexpr fml::TimeDelta kSingleFrameInterval =
fml::TimeDelta::FromSecondsF(1.0 / 60.0);

auto next =
auto frame_start_time =
SnapToNextTick(fml::TimePoint::Now(), phase_, kSingleFrameInterval);

FireCallback(next, next + kSingleFrameInterval, !for_testing_);
auto frame_target_time = frame_start_time + kSingleFrameInterval;
std::weak_ptr<VsyncWaiterFallback> weak_this =
std::static_pointer_cast<VsyncWaiterFallback>(shared_from_this());

auto current_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
current_task_runner->PostTaskForTime(
[frame_start_time, frame_target_time, weak_this]() {
if (auto vsync_waiter = weak_this.lock()) {
vsync_waiter->FireCallback(frame_start_time, frame_target_time,
!vsync_waiter->for_testing_);
}
},
frame_start_time);
}

} // namespace flutter