Unverified Commit ee4fa1b3 authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Update Windows app template (#65511)

parent 0ea0e9d0
...@@ -17,22 +17,23 @@ bool FlutterWindow::OnCreate() { ...@@ -17,22 +17,23 @@ bool FlutterWindow::OnCreate() {
RECT frame = GetClientArea(); RECT frame = GetClientArea();
// The size here must match the window dimensions to avoid unnecessary surface creation / destruction in the startup path. // The size here must match the window dimensions to avoid unnecessary surface
flutter_controller_ = // creation / destruction in the startup path.
std::make_unique<flutter::FlutterViewController>(frame.right - frame.left, frame.bottom - frame.top, project_); flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
frame.right - frame.left, frame.bottom - frame.top, project_);
// Ensure that basic setup of the controller was successful. // Ensure that basic setup of the controller was successful.
if (!flutter_controller_->engine() || !flutter_controller_->view()) { if (!flutter_controller_->engine() || !flutter_controller_->view()) {
return false; return false;
} }
RegisterPlugins(flutter_controller_.get()); RegisterPlugins(flutter_controller_->engine());
run_loop_->RegisterFlutterInstance(flutter_controller_.get()); run_loop_->RegisterFlutterInstance(flutter_controller_->engine());
SetChildContent(flutter_controller_->view()->GetNativeWindow()); SetChildContent(flutter_controller_->view()->GetNativeWindow());
return true; return true;
} }
void FlutterWindow::OnDestroy() { void FlutterWindow::OnDestroy() {
if (flutter_controller_) { if (flutter_controller_) {
run_loop_->UnregisterFlutterInstance(flutter_controller_.get()); run_loop_->UnregisterFlutterInstance(flutter_controller_->engine());
flutter_controller_ = nullptr; flutter_controller_ = nullptr;
} }
......
...@@ -47,20 +47,19 @@ void RunLoop::Run() { ...@@ -47,20 +47,19 @@ void RunLoop::Run() {
} }
void RunLoop::RegisterFlutterInstance( void RunLoop::RegisterFlutterInstance(
flutter::FlutterViewController* flutter_instance) { flutter::FlutterEngine* flutter_instance) {
flutter_instances_.insert(flutter_instance); flutter_instances_.insert(flutter_instance);
} }
void RunLoop::UnregisterFlutterInstance( void RunLoop::UnregisterFlutterInstance(
flutter::FlutterViewController* flutter_instance) { flutter::FlutterEngine* flutter_instance) {
flutter_instances_.erase(flutter_instance); flutter_instances_.erase(flutter_instance);
} }
RunLoop::TimePoint RunLoop::ProcessFlutterMessages() { RunLoop::TimePoint RunLoop::ProcessFlutterMessages() {
TimePoint next_event_time = TimePoint::max(); TimePoint next_event_time = TimePoint::max();
for (auto flutter_controller : flutter_instances_) { for (auto instance : flutter_instances_) {
std::chrono::nanoseconds wait_duration = std::chrono::nanoseconds wait_duration = instance->ProcessMessages();
flutter_controller->ProcessMessages();
if (wait_duration != std::chrono::nanoseconds::max()) { if (wait_duration != std::chrono::nanoseconds::max()) {
next_event_time = next_event_time =
std::min(next_event_time, TimePoint::clock::now() + wait_duration); std::min(next_event_time, TimePoint::clock::now() + wait_duration);
......
#ifndef RUN_LOOP_H_ #ifndef RUN_LOOP_H_
#define RUN_LOOP_H_ #define RUN_LOOP_H_
#include <flutter/flutter_view_controller.h> #include <flutter/flutter_engine.h>
#include <chrono> #include <chrono>
#include <set> #include <set>
...@@ -22,11 +22,11 @@ class RunLoop { ...@@ -22,11 +22,11 @@ class RunLoop {
// Registers the given Flutter instance for event servicing. // Registers the given Flutter instance for event servicing.
void RegisterFlutterInstance( void RegisterFlutterInstance(
flutter::FlutterViewController* flutter_instance); flutter::FlutterEngine* flutter_instance);
// Unregisters the given Flutter instance from event servicing. // Unregisters the given Flutter instance from event servicing.
void UnregisterFlutterInstance( void UnregisterFlutterInstance(
flutter::FlutterViewController* flutter_instance); flutter::FlutterEngine* flutter_instance);
private: private:
using TimePoint = std::chrono::steady_clock::time_point; using TimePoint = std::chrono::steady_clock::time_point;
...@@ -34,7 +34,7 @@ class RunLoop { ...@@ -34,7 +34,7 @@ class RunLoop {
// Processes all currently pending messages for registered Flutter instances. // Processes all currently pending messages for registered Flutter instances.
TimePoint ProcessFlutterMessages(); TimePoint ProcessFlutterMessages();
std::set<flutter::FlutterViewController*> flutter_instances_; std::set<flutter::FlutterEngine*> flutter_instances_;
}; };
#endif // RUN_LOOP_H_ #endif // RUN_LOOP_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment