2020-09-27 11:18:38 +02:00
|
|
|
#include "run_loop.h"
|
|
|
|
|
2020-10-04 16:06:34 +02:00
|
|
|
#include <windows.h>
|
2020-09-27 11:18:38 +02:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
RunLoop::RunLoop() {}
|
|
|
|
|
|
|
|
RunLoop::~RunLoop() {}
|
|
|
|
|
|
|
|
void RunLoop::Run() {
|
2021-08-09 09:28:52 +02:00
|
|
|
MSG msg;
|
|
|
|
while (GetMessage(&msg, nullptr, 0, 0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
2020-09-27 11:18:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunLoop::RegisterFlutterInstance(
|
2020-10-04 16:06:34 +02:00
|
|
|
flutter::FlutterEngine* flutter_instance) {
|
2020-09-27 11:18:38 +02:00
|
|
|
flutter_instances_.insert(flutter_instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RunLoop::UnregisterFlutterInstance(
|
2020-10-04 16:06:34 +02:00
|
|
|
flutter::FlutterEngine* flutter_instance) {
|
2020-09-27 11:18:38 +02:00
|
|
|
flutter_instances_.erase(flutter_instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
|
|
|
|
TimePoint next_event_time = TimePoint::max();
|
2020-10-04 16:06:34 +02:00
|
|
|
for (auto instance : flutter_instances_) {
|
|
|
|
std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
|
2020-09-27 11:18:38 +02:00
|
|
|
if (wait_duration != std::chrono::nanoseconds::max()) {
|
|
|
|
next_event_time =
|
|
|
|
std::min(next_event_time, TimePoint::clock::now() + wait_duration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return next_event_time;
|
|
|
|
}
|