| Flutter Windows Embedder |

Classes | Public Member Functions | Static Public Member Functions | List of all members
flutter::TaskRunnerWindow Class Reference

`#include <task_runner_window.h>`

## Classes
class | Delegate

## Public Member Functions
void | WakeUp ()
void | AddDelegate (Delegate *delegate)
void | RemoveDelegate (Delegate *delegate)
void | PollOnce (std::chrono::milliseconds timeout)
| ~TaskRunnerWindow ()

## Static Public Member Functions
static std::shared_ptr< TaskRunnerWindow > | GetSharedInstance ()

## Detailed Description

Definition at line 20 of file task_runner_window.h.

## Constructor & Destructor Documentation

## ◆ ~TaskRunnerWindow()

flutter::TaskRunnerWindow::~TaskRunnerWindow | ( |  | ) |

Definition at line 53 of file task_runner_window.cc.

53 {
54 SetThreadpoolTimer(timer_, nullptr, 0, 0);
55 // Ensures that no callbacks will run after CloseThreadpoolTimer.
56 // https://learn.microsoft.com/en-us/windows/win32/api/threadpoolapiset/nf-threadpoolapiset-closethreadpooltimer#remarks
57 WaitForThreadpoolTimerCallbacks(timer_, TRUE);
58 CloseThreadpoolTimer(timer_);
59
60 if (window_handle_) {
61 DestroyWindow(window_handle_);
62 window_handle_ = nullptr;
63 }
64 UnregisterClass(window_class_name_.c_str(), nullptr);
65
66 timeEndPeriod(1);
67 }

## Member Function Documentation

## ◆ AddDelegate()

void flutter::TaskRunnerWindow::AddDelegate | ( | Delegate * | delegate | ) |

Definition at line 110 of file task_runner_window.cc.

110 {
111 delegates_.push_back(delegate);
112 SetTimer(std::chrono::nanoseconds::zero());
113 }

## ◆ GetSharedInstance()

std::shared_ptr< TaskRunnerWindow > flutter::TaskRunnerWindow::GetSharedInstance | ( |  | ) |
| static

Definition at line 81 of file task_runner_window.cc.

81 {
82 static std::weak_ptr<TaskRunnerWindow> instance;
83 auto res = instance.lock();
84 if (!res) {
85 // can't use make_shared with private contructor
86 res.reset(new TaskRunnerWindow());
87 instance = res;
88 }
89 return res;
90 }

Referenced by flutter::TaskRunner::TaskRunner().

## ◆ PollOnce()

void flutter::TaskRunnerWindow::PollOnce | ( | std::chrono::milliseconds | timeout | ) |

Definition at line 122 of file task_runner_window.cc.

122 {
123 MSG msg;
124 ::SetTimer(window_handle_, kPollTimeoutTimerId, timeout.count(), nullptr);
125 if (GetMessage(&msg, window_handle_, 0, 0)) {
126 TranslateMessage(&msg);
127 DispatchMessage(&msg);
128 }
129 ::KillTimer(window_handle_, kPollTimeoutTimerId);
130 }
flutter::kPollTimeoutTimerId
static const uintptr_t kPollTimeoutTimerId
Definition: task_runner_window.cc:16

References flutter::kPollTimeoutTimerId.

## ◆ RemoveDelegate()

void flutter::TaskRunnerWindow::RemoveDelegate | ( | Delegate * | delegate | ) |

Definition at line 115 of file task_runner_window.cc.

115 {
116 auto i = std::find(delegates_.begin(), delegates_.end(), delegate);
117 if (i != delegates_.end()) {
118 delegates_.erase(i);
119 }
120 }

## ◆ WakeUp()

void flutter::TaskRunnerWindow::WakeUp | ( |  | ) |

Definition at line 92 of file task_runner_window.cc.

92 {
93 // When waking up from main thread while there are messages in the message
94 // queue use timer to post the WM_NULL message from background thread. This
95 // gives message loop chance to process input events before WM_NULL is
96 // processed - which is necessary because messages scheduled through
97 // PostMessage take precedence over input event messages. Otherwise await
98 // Future.delayed(Duration.zero) deadlocks the main thread. (See
99 // https://github.com/flutter/flutter/issues/173843)
100 if (thread_id_ == GetCurrentThreadId() && GetQueueStatus(QS_ALLEVENTS) != 0) {
101 SetTimer(std::chrono::nanoseconds::zero());
102 return;
103 }
104
105 if (!PostMessage(window_handle_, WM_NULL, 0, 0)) {
106 FML_LOG(ERROR) << "Failed to post message to main thread.";
107 }
108 }

The documentation for this class was generated from the following files:

- shell/platform/windows/task_runner_window.h
- shell/platform/windows/task_runner_window.cc