5#include "flutter/shell/platform/windows/task_runner.h"
14 : get_current_time_(get_current_time),
15 on_task_expired_(
std::move(on_task_expired)) {
16 main_thread_id_ = GetCurrentThreadId();
18 task_runner_window_->AddDelegate(
this);
22 task_runner_window_->RemoveDelegate(
this);
28 std::vector<Task> expired_tasks;
32 std::lock_guard<std::mutex> lock(task_queue_mutex_);
33 while (!task_queue_.empty()) {
34 const auto& top = task_queue_.top();
37 if (top.fire_time > now) {
45 expired_tasks.push_back(task_queue_.top());
55 for (
const auto& task : expired_tasks) {
56 if (
auto flutter_task = std::get_if<FlutterTask>(&task.variant)) {
57 on_task_expired_(flutter_task);
58 }
else if (
auto closure = std::get_if<TaskClosure>(&task.variant))
65 std::lock_guard<std::mutex> lock(task_queue_mutex_);
67 : task_queue_.top().fire_time;
74 uint64_t flutter_target_time_nanos)
const {
76 const auto flutter_duration = flutter_target_time_nanos - get_current_time_();
77 return now + std::chrono::nanoseconds(flutter_duration);
81 uint64_t flutter_target_time_nanos) {
83 task.fire_time = TimePointFromFlutterTime(flutter_target_time_nanos);
84 task.variant = flutter_task;
85 EnqueueTask(std::move(task));
91 task.variant = std::move(
closure);
92 EnqueueTask(std::move(task));
95void TaskRunner::EnqueueTask(
Task task) {
96 static std::atomic_uint64_t sGlobalTaskOrder(0);
98 task.order = ++sGlobalTaskOrder;
100 std::lock_guard<std::mutex> lock(task_queue_mutex_);
101 task_queue_.push(task);
113 return GetCurrentThreadId() == main_thread_id_;
117 task_runner_window_->WakeUp();
static std::shared_ptr< TaskRunnerWindow > GetSharedInstance()
std::chrono::steady_clock::time_point TaskTimePoint
void PostFlutterTask(FlutterTask flutter_task, uint64_t flutter_target_time_nanos)
TaskRunner(CurrentTimeProc get_current_time, const TaskExpiredCallback &on_task_expired)
virtual bool RunsTasksOnCurrentThread() const
std::function< void(const FlutterTask *)> TaskExpiredCallback
std::function< void()> TaskClosure
void PostTask(TaskClosure task)
virtual TaskTimePoint GetCurrentTimeForTask() const
std::chrono::nanoseconds ProcessTasks()
static float max(float r, float g, float b)
static float min(float r, float g, float b)
uint64_t(* CurrentTimeProc)()
std::function< void()> closure