5#include "flutter/shell/common/vsync_waiter.h"
8#include "flutter/fml/task_runner.h"
9#include "flutter/fml/trace_event.h"
35 std::scoped_lock lock(callback_mutex_);
44 if (!secondary_callbacks_.empty()) {
64 std::scoped_lock lock(callback_mutex_);
65 bool secondary_callbacks_originally_empty = secondary_callbacks_.empty();
66 auto [_, inserted] = secondary_callbacks_.emplace(
id,
callback);
70 "MultipleCallsToSecondaryVsyncInFrameInterval");
78 if (!secondary_callbacks_originally_empty) {
89 bool pause_secondary_tasks) {
93 std::vector<fml::closure> secondary_callbacks;
96 std::scoped_lock lock(callback_mutex_);
98 for (
auto& pair : secondary_callbacks_) {
99 secondary_callbacks.push_back(std::move(pair.second));
101 secondary_callbacks_.clear();
104 if (!
callback && secondary_callbacks.empty()) {
114 if (pause_secondary_tasks) {
115 PauseDartEventLoopTasks();
132 [ui_task_queue_id,
callback, flow_identifier, frame_start_time,
133 frame_target_time, pause_secondary_tasks]() {
136 &flow_identifier,
"StartTime", frame_start_time,
137 "TargetTime", frame_target_time);
138 std::unique_ptr<FrameTimingsRecorder> frame_timings_recorder =
139 std::make_unique<FrameTimingsRecorder>();
140 frame_timings_recorder->RecordVsync(frame_start_time,
142 callback(std::move(frame_timings_recorder));
144 if (pause_secondary_tasks) {
145 ResumeDartEventLoopTasks(ui_task_queue_id);
150 for (
auto& secondary_callback : secondary_callbacks) {
155void VsyncWaiter::PauseDartEventLoopTasks() {
158 task_queues->PauseSecondarySource(ui_task_queue_id);
161void VsyncWaiter::ResumeDartEventLoopTasks(
fml::TaskQueueId ui_task_queue_id) {
163 task_queues->ResumeSecondarySource(ui_task_queue_id);
fml::RefPtr< fml::TaskRunner > GetUITaskRunner() const
void ScheduleSecondaryCallback(uintptr_t id, const fml::closure &callback)
std::function< void(std::unique_ptr< FrameTimingsRecorder >)> Callback
VsyncWaiter(const TaskRunners &task_runners)
virtual void AwaitVSync()=0
void AsyncWaitForVsync(const Callback &callback)
void FireCallback(fml::TimePoint frame_start_time, fml::TimePoint frame_target_time, bool pause_secondary_tasks=true)
virtual void AwaitVSyncForSecondaryCallback()
const TaskRunners task_runners_
static MessageLoopTaskQueues * GetInstance()
virtual void PostTask(const fml::closure &task) override
virtual bool RunsTasksOnCurrentThread()
virtual TaskQueueId GetTaskQueueId()
TaskRunners task_runners_
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DCHECK(condition)
static constexpr const char * kVsyncFlowName
static constexpr const char * kVsyncTraceName
std::function< void()> closure
#define TRACE_FLOW_BEGIN(category, name, id)
#define TRACE_EVENT0(category_group, name)
#define FML_TRACE_EVENT_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids,...)
#define TRACE_EVENT_INSTANT0(category_group, name)
#define TRACE_FLOW_END(category, name, id)
#define TRACE_EVENT0_WITH_FLOW_IDS(category_group, name, flow_id_count, flow_ids)