| Flutter Windows Embedder |

Public Member Functions | Protected Member Functions | Friends | List of all members
flutter::FlutterWindowsEngine Class Reference

`#include <flutter_windows_engine.h>`

## Public Member Functions
| FlutterWindowsEngine (const FlutterProjectBundle &project)
virtual | ~FlutterWindowsEngine ()
bool | Run ()
bool | Run (std::string_view entrypoint)
bool | running ()
virtual bool | Stop ()
void | SetView (FlutterWindowsView *view)
FlutterWindowsView * | view ()
FlutterDesktopPluginRegistrarRef | GetRegistrar ()
void | AddPluginRegistrarDestructionCallback (FlutterDesktopOnPluginRegistrarDestroyed callback, FlutterDesktopPluginRegistrarRef registrar)
void | SetSwitches (const std::vector< std::string > &switches)
FlutterDesktopMessengerRef | messenger ()
IncomingMessageDispatcher * | message_dispatcher ()
TaskRunner * | task_runner ()
FlutterWindowsTextureRegistrar * | texture_registrar ()
AngleSurfaceManager * | surface_manager ()
WindowProcDelegateManager * | window_proc_delegate_manager ()
void | SendWindowMetricsEvent (const FlutterWindowMetricsEvent &event)
void | SendPointerEvent (const FlutterPointerEvent &event)
void | SendKeyEvent (const FlutterKeyEvent &event, FlutterKeyEventCallback callback, void *user_data)
KeyboardHandlerBase * | keyboard_key_handler ()
TextInputPlugin * | text_input_plugin ()
bool | SendPlatformMessage (const char *channel, const uint8_t *message, const size_t message_size, const FlutterDesktopBinaryReply reply, void *user_data)
void | SendPlatformMessageResponse (const FlutterDesktopMessageResponseHandle *handle, const uint8_t *data, size_t data_length)
void | HandlePlatformMessage (const FlutterPlatformMessage *)
void | ReloadSystemFonts ()
void | ScheduleFrame ()
void | SetNextFrameCallback (fml::closure callback)
bool | RegisterExternalTexture (int64_t texture_id)
bool | UnregisterExternalTexture (int64_t texture_id)
bool | MarkExternalTextureFrameAvailable (int64_t texture_id)
virtual bool | PostRasterThreadTask (fml::closure callback)
void | OnVsync (intptr_t baton)
bool | DispatchSemanticsAction (uint64_t id, FlutterSemanticsAction action, fml::MallocMapping data)
void | UpdateSemanticsEnabled (bool enabled)
bool | semantics_enabled () const
void | UpdateHighContrastEnabled (bool enabled)
int | EnabledAccessibilityFeatures () const
bool | high_contrast_enabled () const
void | SetRootIsolateCreateCallback (const fml::closure &callback)
std::string | GetExecutableName () const
void | UpdateAccessibilityFeatures (FlutterAccessibilityFeature flags)
void | OnQuit (std::optional< HWND > hwnd, std::optional< WPARAM > wparam, std::optional< LPARAM > lparam, UINT exit_code)
void | RequestApplicationQuit (HWND hwnd, WPARAM wparam, LPARAM lparam, AppExitType exit_type)
void | OnDwmCompositionChanged ()
void | OnWindowStateEvent (HWND hwnd, WindowStateEvent event)
std::optional< LRESULT > | ProcessExternalWindowMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
WindowsLifecycleManager * | lifecycle_manager ()

## Protected Member Functions
virtual std::unique_ptr< KeyboardHandlerBase > | CreateKeyboardKeyHandler (BinaryMessenger *messenger, KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state, KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan)
virtual std::unique_ptr< TextInputPlugin > | CreateTextInputPlugin (BinaryMessenger *messenger)
void | OnPreEngineRestart ()
virtual void | OnChannelUpdate (std::string name, bool listening)

## Friends
class | EngineModifier

## Detailed Description

Definition at line 78 of file flutter_windows_engine.h.

## Constructor & Destructor Documentation

## ◆ FlutterWindowsEngine()

flutter::FlutterWindowsEngine::FlutterWindowsEngine | ( | const FlutterProjectBundle & | project | ) |
| explicit

Definition at line 160 of file flutter_windows_engine.cc.

161 : project_(std::make_unique<FlutterProjectBundle>(project)),
162 aot_data_(nullptr, nullptr),
163 lifecycle_manager_(std::make_unique<WindowsLifecycleManager>(this)) {
164 embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
165 FlutterEngineGetProcAddresses(&embedder_api_);
166
167 task_runner_ =
168 std::make_unique<TaskRunner>(
169 embedder_api_.GetCurrentTime, [this](const auto* task) {
170 if (!engine_) {
171 FML_LOG(ERROR)
172 << "Cannot post an engine task when engine is not running.";
173 return;
174 }
175 if (embedder_api_.RunTask(engine_, task) != kSuccess) {
176 FML_LOG(ERROR) << "Failed to post an engine task.";
177 }
178 });
179
180 // Set up the legacy structs backing the API handles.
181 messenger_ =
182 fml::RefPtr<FlutterDesktopMessenger>(new FlutterDesktopMessenger());
183 messenger_->SetEngine(this);
184 plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
185 plugin_registrar_->engine = this;
186
187 messenger_wrapper_ =
188 std::make_unique<BinaryMessengerImpl>(messenger_->ToRef());
189 message_dispatcher_ =
190 std::make_unique<IncomingMessageDispatcher>(messenger_->ToRef());
191 message_dispatcher_->SetMessageCallback(
192 kAccessibilityChannelName,
193 [](FlutterDesktopMessengerRef messenger,
194 const FlutterDesktopMessage* message, void* data) {
195 FlutterWindowsEngine* engine = static_cast<FlutterWindowsEngine*>(data);
196 engine->HandleAccessibilityMessage(messenger, message);
197 },
198 static_cast<void*>(this));
199
200 FlutterWindowsTextureRegistrar::ResolveGlFunctions(gl_procs_);
201 texture_registrar_ =
202 std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
203
204 // Check for impeller support.
205 auto& switches = project_->GetSwitches();
206 enable_impeller_ = std::find(switches.begin(), switches.end(),
207 "--enable-impeller=true") != switches.end();
208
209 surface_manager_ = AngleSurfaceManager::Create(enable_impeller_);
210 window_proc_delegate_manager_ = std::make_unique<WindowProcDelegateManager>();
211 window_proc_delegate_manager_->RegisterTopLevelWindowProcDelegate(
212 [](HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar, void* user_data,
213 LRESULT* result) {
214 BASE_DCHECK(user_data);
215 FlutterWindowsEngine* that =
216 static_cast<FlutterWindowsEngine*>(user_data);
217 BASE_DCHECK(that->lifecycle_manager_);
218 return that->lifecycle_manager_->WindowProc(hwnd, msg, wpar, lpar,
219 result);
220 },
221 static_cast<void*>(this));
222
223 // Set up internal channels.
224 // TODO: Replace this with an embedder.h API. See
225 // https://github.com/flutter/flutter/issues/71099
226 internal_plugin_registrar_ =
227 std::make_unique<PluginRegistrar>(plugin_registrar_.get());
228 cursor_handler_ =
229 std::make_unique<CursorHandler>(messenger_wrapper_.get(), this);
230 platform_handler_ =
231 std::make_unique<PlatformHandler>(messenger_wrapper_.get(), this);
232 settings_plugin_ = std::make_unique<SettingsPlugin>(messenger_wrapper_.get(),
233 task_runner_.get());
234 }

## ◆ ~FlutterWindowsEngine()

flutter::FlutterWindowsEngine::~FlutterWindowsEngine | ( |  | ) |
| virtual

Definition at line 236 of file flutter_windows_engine.cc.

236 {
237 messenger_->SetEngine(nullptr);
238 Stop();
239 }

## Member Function Documentation

## ◆ AddPluginRegistrarDestructionCallback()

void flutter::FlutterWindowsEngine::AddPluginRegistrarDestructionCallback | ( | FlutterDesktopOnPluginRegistrarDestroyed | callback,
|  | FlutterDesktopPluginRegistrarRef | registrar
| ) |  |

Definition at line 493 of file flutter_windows_engine.cc.

495 {
496 plugin_registrar_destruction_callbacks_[callback] = registrar;
497 }

References callback.

Referenced by FlutterDesktopPluginRegistrarSetDestructionHandler().

## ◆ CreateKeyboardKeyHandler()

std::unique_ptr< KeyboardHandlerBase > flutter::FlutterWindowsEngine::CreateKeyboardKeyHandler | ( | BinaryMessenger * | messenger,
|  | KeyboardKeyEmbedderHandler::GetKeyStateHandler | get_key_state,
|  | KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode | map_vk_to_scan
| ) |  |
| protected virtual

Definition at line 643 of file flutter_windows_engine.cc.

646 {
647 auto keyboard_key_handler = std::make_unique<KeyboardKeyHandler>(messenger);
648 keyboard_key_handler->AddDelegate(
649 std::make_unique<KeyboardKeyEmbedderHandler>(
650 [this](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
651 void* user_data) {
652 return SendKeyEvent(event, callback, user_data);
653 },
654 get_key_state, map_vk_to_scan));
655 keyboard_key_handler->AddDelegate(
656 std::make_unique<KeyboardKeyChannelHandler>(messenger));
657 keyboard_key_handler->InitKeyboardChannel();
658 return keyboard_key_handler;
659 }

References callback, and user_data.

## ◆ CreateTextInputPlugin()

std::unique_ptr< TextInputPlugin > flutter::FlutterWindowsEngine::CreateTextInputPlugin | ( | BinaryMessenger * | messenger | ) |
| protected virtual

Definition at line 661 of file flutter_windows_engine.cc.

662 {
663 return std::make_unique<TextInputPlugin>(messenger, view_);
664 }

## ◆ DispatchSemanticsAction()

bool flutter::FlutterWindowsEngine::DispatchSemanticsAction | ( | uint64_t | id,
|  | FlutterSemanticsAction | action,
|  | fml::MallocMapping | data
| ) |  |

Definition at line 702 of file flutter_windows_engine.cc.

705 {
706 return (embedder_api_.DispatchSemanticsAction(engine_, target, action,
707 data.GetMapping(),
708 data.GetSize()) == kSuccess);
709 }

Referenced by flutter::AccessibilityBridgeWindows::DispatchAccessibilityAction().

## ◆ EnabledAccessibilityFeatures()

int flutter::FlutterWindowsEngine::EnabledAccessibilityFeatures | ( |  | ) | const

Definition at line 759 of file flutter_windows_engine.cc.

759 {
760 int flags = 0;
761 if (high_contrast_enabled()) {
762 flags |=
763 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
764 }
765 // As more accessibility features are enabled for Windows,
766 // the corresponding checks and flags should be added here.
767 return flags;
768 }

## ◆ GetExecutableName()

std::string flutter::FlutterWindowsEngine::GetExecutableName | ( |  | ) | const

Definition at line 726 of file flutter_windows_engine.cc.

726 {
727 std::pair<bool, std::string> result = fml::paths::GetExecutablePath();
728 if (result.first) {
729 const std::string& executable_path = result.second;
730 size_t last_separator = executable_path.find_last_of("/\\");
731 if (last_separator == std::string::npos ||
732 last_separator == executable_path.size() - 1) {
733 return executable_path;
734 }
735 return executable_path.substr(last_separator + 1);
736 }
737 return "Flutter";
738 }

## ◆ GetRegistrar()

FlutterDesktopPluginRegistrarRef flutter::FlutterWindowsEngine::GetRegistrar | ( |  | ) |

Definition at line 489 of file flutter_windows_engine.cc.

489 {
490 return plugin_registrar_.get();
491 }

Referenced by FlutterDesktopEngineGetPluginRegistrar().

## ◆ HandlePlatformMessage()

void flutter::FlutterWindowsEngine::HandlePlatformMessage | ( | const FlutterPlatformMessage * | engine_message | ) |

Definition at line 561 of file flutter_windows_engine.cc.

562 {
563 if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
564 FML_LOG(ERROR) << "Invalid message size received. Expected: "
565 << sizeof(FlutterPlatformMessage) << " but received "
566 << engine_message->struct_size;
567 return;
568 }
569
570 auto message = ConvertToDesktopMessage(*engine_message);
571
572 message_dispatcher_->HandleMessage(
573 message, [this] {}, [this] {});
574 }

References message.

Referenced by Run().

## ◆ high_contrast_enabled()

bool flutter::FlutterWindowsEngine::high_contrast_enabled | ( |  | ) | const
| inline

Definition at line 225 of file flutter_windows_engine.h.

225 { return high_contrast_enabled_; }

## ◆ keyboard_key_handler()

KeyboardHandlerBase* flutter::FlutterWindowsEngine::keyboard_key_handler | ( |  | ) |
| inline

Definition at line 159 of file flutter_windows_engine.h.

159 {
160 return keyboard_key_handler_.get();
161 }

## ◆ lifecycle_manager()

WindowsLifecycleManager* flutter::FlutterWindowsEngine::lifecycle_manager | ( |  | ) |
| inline

Definition at line 273 of file flutter_windows_engine.h.

273 {
274 return lifecycle_manager_.get();
275 }

Referenced by flutter::testing::TEST_F().

## ◆ MarkExternalTextureFrameAvailable()

bool flutter::FlutterWindowsEngine::MarkExternalTextureFrameAvailable | ( | int64_t | texture_id | ) |

Definition at line 676 of file flutter_windows_engine.cc.

677 {
678 return (embedder_api_.MarkExternalTextureFrameAvailable(
679 engine_, texture_id) == kSuccess);
680 }

## ◆ message_dispatcher()

IncomingMessageDispatcher* flutter::FlutterWindowsEngine::message_dispatcher | ( |  | ) |
| inline

Definition at line 130 of file flutter_windows_engine.h.

130 {
131 return message_dispatcher_.get();
132 }

Referenced by FlutterDesktopMessengerSetCallback().

## ◆ messenger()

FlutterDesktopMessengerRef flutter::FlutterWindowsEngine::messenger | ( |  | ) |
| inline

Definition at line 128 of file flutter_windows_engine.h.

128 { return messenger_->ToRef(); }

Referenced by FlutterDesktopEngineGetMessenger(), FlutterDesktopPluginRegistrarGetMessenger(), and flutter::testing::TEST_F().

## ◆ OnChannelUpdate()

void flutter::FlutterWindowsEngine::OnChannelUpdate | ( | std::string | name,
|  | bool | listening
| ) |  |
| protected virtual

Definition at line 826 of file flutter_windows_engine.cc.

826 {
827 if (name == "flutter/platform" && listening) {
828 lifecycle_manager_->BeginProcessingExit();
829 } else if (name == "flutter/lifecycle" && listening) {
830 lifecycle_manager_->BeginProcessingLifecycle();
831 }
832 }

## ◆ OnDwmCompositionChanged()

void flutter::FlutterWindowsEngine::OnDwmCompositionChanged | ( |  | ) |

Definition at line 805 of file flutter_windows_engine.cc.

805 {
806 view_->OnDwmCompositionChanged();
807 }

Referenced by flutter::testing::TEST(), and flutter::WindowsLifecycleManager::WindowProc().

## ◆ OnPreEngineRestart()

void flutter::FlutterWindowsEngine::OnPreEngineRestart | ( |  | ) |
| protected

Definition at line 719 of file flutter_windows_engine.cc.

719 {
720 // Reset the keyboard's state on hot restart.
721 if (view_) {
722 InitializeKeyboard();
723 }
724 }

Referenced by Run().

## ◆ OnQuit()

void flutter::FlutterWindowsEngine::OnQuit | ( | std::optional< HWND > | hwnd,
|  | std::optional< WPARAM > | wparam,
|  | std::optional< LPARAM > | lparam,
|  | UINT | exit_code
| ) |  |

Definition at line 798 of file flutter_windows_engine.cc.

801 {
802 lifecycle_manager_->Quit(hwnd, wparam, lparam, exit_code);
803 }

Referenced by flutter::PlatformHandler::QuitApplication().

## ◆ OnVsync()

void flutter::FlutterWindowsEngine::OnVsync | ( | intptr_t | baton | ) |

Definition at line 460 of file flutter_windows_engine.cc.

460 {
461 std::chrono::nanoseconds current_time =
462 std::chrono::nanoseconds(embedder_api_.GetCurrentTime());
463 std::chrono::nanoseconds frame_interval = FrameInterval();
464 auto next = SnapToNextTick(current_time, start_time_, frame_interval);
465 embedder_api_.OnVsync(engine_, baton, next.count(),
466 (next + frame_interval).count());
467 }

Referenced by Run().

## ◆ OnWindowStateEvent()

void flutter::FlutterWindowsEngine::OnWindowStateEvent | ( | HWND | hwnd,
|  | WindowStateEvent | event
| ) |  |

Definition at line 809 of file flutter_windows_engine.cc.

810 {
811 lifecycle_manager_->OnWindowStateEvent(hwnd, event);
812 }

## ◆ PostRasterThreadTask()

bool flutter::FlutterWindowsEngine::PostRasterThreadTask | ( | fml::closure | callback | ) |
| virtual

Definition at line 682 of file flutter_windows_engine.cc.

682 {
683 struct Captures {
684 fml::closure callback;
685 };
686 auto captures = new Captures();
687 captures->callback = std::move(callback);
688 if (embedder_api_.PostRenderThreadTask(
689 engine_,
690 [](void* opaque) {
691 auto captures = reinterpret_cast<Captures*>(opaque);
692 captures->callback();
693 delete captures;
694 },
695 captures) == kSuccess) {
696 return true;
697 }
698 delete captures;
699 return false;
700 }

References callback.

Referenced by flutter::FlutterWindowsTextureRegistrar::UnregisterTexture().

## ◆ ProcessExternalWindowMessage()

std::optional< LRESULT > flutter::FlutterWindowsEngine::ProcessExternalWindowMessage | ( | HWND | hwnd,
|  | UINT | message,
|  | WPARAM | wparam,
|  | LPARAM | lparam
| ) |  |

Definition at line 814 of file flutter_windows_engine.cc.

818 {
819 if (lifecycle_manager_) {
820 return lifecycle_manager_->ExternalWindowMessage(hwnd, message, wparam,
821 lparam);
822 }
823 return std::nullopt;
824 }

References message.

Referenced by FlutterDesktopEngineProcessExternalWindowMessage(), and flutter::testing::TEST_F().

## ◆ RegisterExternalTexture()

bool flutter::FlutterWindowsEngine::RegisterExternalTexture | ( | int64_t | texture_id | ) |

Definition at line 666 of file flutter_windows_engine.cc.

666 {
667 return (embedder_api_.RegisterExternalTexture(engine_, texture_id) ==
668 kSuccess);
669 }

## ◆ ReloadSystemFonts()

void flutter::FlutterWindowsEngine::ReloadSystemFonts | ( |  | ) |

Definition at line 576 of file flutter_windows_engine.cc.

576 {
577 embedder_api_.ReloadSystemFonts(engine_);
578 }

Referenced by FlutterDesktopEngineReloadSystemFonts().

## ◆ RequestApplicationQuit()

void flutter::FlutterWindowsEngine::RequestApplicationQuit | ( | HWND | hwnd,
|  | WPARAM | wparam,
|  | LPARAM | lparam,
|  | AppExitType | exit_type
| ) |  |

Definition at line 791 of file flutter_windows_engine.cc.

794 {
795 platform_handler_->RequestAppExit(hwnd, wparam, lparam, exit_type, 0);
796 }

## ◆ Run() [1/2]

bool flutter::FlutterWindowsEngine::Run | ( |  | ) |

Definition at line 246 of file flutter_windows_engine.cc.

246 {
247 return Run("");
248 }

Referenced by FlutterDesktopEngineRun(), and flutter::testing::TEST_F().

## ◆ Run() [2/2]

bool flutter::FlutterWindowsEngine::Run | ( | std::string_view | entrypoint | ) |

Definition at line 250 of file flutter_windows_engine.cc.

250 {
251 if (!project_->HasValidPaths()) {
252 FML_LOG(ERROR) << "Missing or unresolvable paths to assets.";
253 return false;
254 }
255 std::string assets_path_string = project_->assets_path().u8string();
256 std::string icu_path_string = project_->icu_path().u8string();
257 if (embedder_api_.RunsAOTCompiledDartCode()) {
258 aot_data_ = project_->LoadAotData(embedder_api_);
259 if (!aot_data_) {
260 FML_LOG(ERROR) << "Unable to start engine without AOT data.";
261 return false;
262 }
263 }
264
265 // FlutterProjectArgs is expecting a full argv, so when processing it for
266 // flags the first item is treated as the executable and ignored. Add a dummy
267 // value so that all provided arguments are used.
268 std::string executable_name = GetExecutableName();
269 std::vector<const char*> argv = {executable_name.c_str()};
270 std::vector<std::string> switches = project_->GetSwitches();
271 std::transform(
272 switches.begin(), switches.end(), std::back_inserter(argv),
273 [](const std::string& arg) -> const char* { return arg.c_str(); });
274
275 const std::vector<std::string>& entrypoint_args =
276 project_->dart_entrypoint_arguments();
277 std::vector<const char*> entrypoint_argv;
278 std::transform(
279 entrypoint_args.begin(), entrypoint_args.end(),
280 std::back_inserter(entrypoint_argv),
281 [](const std::string& arg) -> const char* { return arg.c_str(); });
282
283 // Configure task runners.
284 FlutterTaskRunnerDescription platform_task_runner = {};
285 platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
286 platform_task_runner.user_data = task_runner_.get();
287 platform_task_runner.runs_task_on_current_thread_callback =
288 [](void* user_data) -> bool {
289 return static_cast<TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
290 };
291 platform_task_runner.post_task_callback = [](FlutterTask task,
292 uint64_t target_time_nanos,
293 void* user_data) -> void {
294 static_cast<TaskRunner*>(user_data)->PostFlutterTask(task,
295 target_time_nanos);
296 };
297 FlutterCustomTaskRunners custom_task_runners = {};
298 custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
299 custom_task_runners.platform_task_runner = &platform_task_runner;
300 custom_task_runners.thread_priority_setter =
301 &WindowsPlatformThreadPrioritySetter;
302
303 FlutterProjectArgs args = {};
304 args.struct_size = sizeof(FlutterProjectArgs);
305 args.shutdown_dart_vm_when_done = true;
306 args.assets_path = assets_path_string.c_str();
307 args.icu_data_path = icu_path_string.c_str();
308 args.command_line_argc = static_cast<int>(argv.size());
309 args.command_line_argv = argv.empty() ? nullptr : argv.data();
310
311 // Fail if conflicting non-default entrypoints are specified in the method
312 // argument and the project.
313 //
314 // TODO(cbracken): https://github.com/flutter/flutter/issues/109285
315 // The entrypoint method parameter should eventually be removed from this
316 // method and only the entrypoint specified in project_ should be used.
317 if (!project_->dart_entrypoint().empty() && !entrypoint.empty() &&
318 project_->dart_entrypoint() != entrypoint) {
319 FML_LOG(ERROR) << "Conflicting entrypoints were specified in "
320 "FlutterDesktopEngineProperties.dart_entrypoint and "
321 "FlutterDesktopEngineRun(engine, entry_point). ";
322 return false;
323 }
324 if (!entrypoint.empty()) {
325 args.custom_dart_entrypoint = entrypoint.data();
326 } else if (!project_->dart_entrypoint().empty()) {
327 args.custom_dart_entrypoint = project_->dart_entrypoint().c_str();
328 }
329 args.dart_entrypoint_argc = static_cast<int>(entrypoint_argv.size());
330 args.dart_entrypoint_argv =
331 entrypoint_argv.empty() ? nullptr : entrypoint_argv.data();
332 args.platform_message_callback =
333 [](const FlutterPlatformMessage* engine_message,
334 void* user_data) -> void {
335 auto host = static_cast<FlutterWindowsEngine*>(user_data);
336 return host->HandlePlatformMessage(engine_message);
337 };
338 args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
339 auto host = static_cast<FlutterWindowsEngine*>(user_data);
340 host->OnVsync(baton);
341 };
342 args.on_pre_engine_restart_callback = [](void* user_data) {
343 auto host = static_cast<FlutterWindowsEngine*>(user_data);
344 host->OnPreEngineRestart();
345 };
346 args.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update,
347 void* user_data) {
348 auto host = static_cast<FlutterWindowsEngine*>(user_data);
349 auto view = host->view();
350 if (!view) {
351 return;
352 }
353
354 auto accessibility_bridge = view->accessibility_bridge().lock();
355 if (!accessibility_bridge) {
356 return;
357 }
358
359 for (size_t i = 0; i < update->node_count; i++) {
360 const FlutterSemanticsNode2* node = update->nodes[i];
361 accessibility_bridge->AddFlutterSemanticsNodeUpdate(*node);
362 }
363
364 for (size_t i = 0; i < update->custom_action_count; i++) {
365 const FlutterSemanticsCustomAction2* action = update->custom_actions[i];
366 accessibility_bridge->AddFlutterSemanticsCustomActionUpdate(*action);
367 }
368
369 accessibility_bridge->CommitUpdates();
370 };
371 args.root_isolate_create_callback = [](void* user_data) {
372 auto host = static_cast<FlutterWindowsEngine*>(user_data);
373 if (host->root_isolate_create_callback_) {
374 host->root_isolate_create_callback_();
375 }
376 };
377 args.channel_update_callback = [](const FlutterChannelUpdate* update,
378 void* user_data) {
379 auto host = static_cast<FlutterWindowsEngine*>(user_data);
380 if (SAFE_ACCESS(update, channel, nullptr) != nullptr) {
381 std::string channel_name(update->channel);
382 host->OnChannelUpdate(std::move(channel_name),
383 SAFE_ACCESS(update, listening, false));
384 }
385 };
386
387 args.custom_task_runners = &custom_task_runners;
388
389 if (aot_data_) {
390 args.aot_data = aot_data_.get();
391 }
392
393 // The platform thread creates OpenGL contexts. These
394 // must be released to be used by the engine's threads.
395 FML_DCHECK(!surface_manager_ || !surface_manager_->HasContextCurrent());
396
397 FlutterRendererConfig renderer_config;
398
399 if (enable_impeller_) {
400 // Impeller does not support a Software backend. Avoid falling back and
401 // confusing the engine on which renderer is selected.
402 if (!surface_manager_) {
403 FML_LOG(ERROR) << "Could not create surface manager. Impeller backend "
404 "does not support software rendering.";
405 return false;
406 }
407 renderer_config = GetOpenGLRendererConfig();
408 } else {
409 renderer_config = surface_manager_ ? GetOpenGLRendererConfig()
410 : GetSoftwareRendererConfig();
411 }
412
413 auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
414 &args, this, &engine_);
415 if (result != kSuccess || engine_ == nullptr) {
416 FML_LOG(ERROR) << "Failed to start Flutter engine: error " << result;
417 return false;
418 }
419
420 // Configure device frame rate displayed via devtools.
421 FlutterEngineDisplay display = {};
422 display.struct_size = sizeof(FlutterEngineDisplay);
423 display.display_id = 0;
424 display.single_display = true;
425 display.refresh_rate =
426 1.0 / (static_cast<double>(FrameInterval().count()) / 1000000000.0);
427
428 std::vector<FlutterEngineDisplay> displays = {display};
429 embedder_api_.NotifyDisplayUpdate(engine_,
430 kFlutterEngineDisplaysUpdateTypeStartup,
431 displays.data(), displays.size());
432
433 SendSystemLocales();
434 SetLifecycleState(flutter::AppLifecycleState::kResumed);
435
436 settings_plugin_->StartWatching();
437 settings_plugin_->SendSettings();
438
439 return true;
440 }

References flutter::FlutterWindowsView::accessibility_bridge(), action, HandlePlatformMessage(), OnPreEngineRestart(), OnVsync(), user_data, view(), and flutter::WindowsPlatformThreadPrioritySetter().

## ◆ running()

bool flutter::FlutterWindowsEngine::running | ( |  | ) |
| inline

Definition at line 103 of file flutter_windows_engine.h.

103 { return engine_ != nullptr; }

Referenced by FlutterDesktopEngineDestroy().

## ◆ ScheduleFrame()

void flutter::FlutterWindowsEngine::ScheduleFrame | ( |  | ) |

Definition at line 580 of file flutter_windows_engine.cc.

580 {
581 embedder_api_.ScheduleFrame(engine_);
582 }

## ◆ semantics_enabled()

bool flutter::FlutterWindowsEngine::semantics_enabled | ( |  | ) | const
| inline

Definition at line 216 of file flutter_windows_engine.h.

216 { return semantics_enabled_; }

## ◆ SendKeyEvent()

void flutter::FlutterWindowsEngine::SendKeyEvent | ( | const FlutterKeyEvent & | event,
|  | FlutterKeyEventCallback | callback,
|  | void * | user_data
| ) |  |

Definition at line 512 of file flutter_windows_engine.cc.

514 {
515 if (engine_) {
516 embedder_api_.SendKeyEvent(engine_, &event, callback, user_data);
517 }
518 }

## ◆ SendPlatformMessage()

bool flutter::FlutterWindowsEngine::SendPlatformMessage | ( | const char * | channel,
|  | const uint8_t * | message,
|  | const size_t | message_size,
|  | const FlutterDesktopBinaryReply | reply,
|  | void * | user_data
| ) |  |

Definition at line 520 of file flutter_windows_engine.cc.

525 {
526 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
527 if (reply != nullptr && user_data != nullptr) {
528 FlutterEngineResult result =
529 embedder_api_.PlatformMessageCreateResponseHandle(
530 engine_, reply, user_data, &response_handle);
531 if (result != kSuccess) {
532 FML_LOG(ERROR) << "Failed to create response handle";
533 return false;
534 }
535 }
536
537 FlutterPlatformMessage platform_message = {
538 sizeof(FlutterPlatformMessage),
539 channel,
540 message,
541 message_size,
542 response_handle,
543 };
544
545 FlutterEngineResult message_result =
546 embedder_api_.SendPlatformMessage(engine_, &platform_message);
547 if (response_handle != nullptr) {
548 embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
549 response_handle);
550 }
551 return message_result == kSuccess;
552 }

References user_data.

Referenced by FlutterDesktopMessengerSendWithReply().

## ◆ SendPlatformMessageResponse()

void flutter::FlutterWindowsEngine::SendPlatformMessageResponse | ( | const FlutterDesktopMessageResponseHandle * | handle,
|  | const uint8_t * | data,
|  | size_t | data_length
| ) |  |

Definition at line 554 of file flutter_windows_engine.cc.

557 {
558 embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
559 }

Referenced by FlutterDesktopMessengerSendResponse().

## ◆ SendPointerEvent()

void flutter::FlutterWindowsEngine::SendPointerEvent | ( | const FlutterPointerEvent & | event | ) |

Definition at line 506 of file flutter_windows_engine.cc.

506 {
507 if (engine_) {
508 embedder_api_.SendPointerEvent(engine_, &event, 1);
509 }
510 }

## ◆ SendWindowMetricsEvent()

void flutter::FlutterWindowsEngine::SendWindowMetricsEvent | ( | const FlutterWindowMetricsEvent & | event | ) |

Definition at line 499 of file flutter_windows_engine.cc.

500 {
501 if (engine_) {
502 embedder_api_.SendWindowMetricsEvent(engine_, &event);
503 }
504 }

## ◆ SetNextFrameCallback()

void flutter::FlutterWindowsEngine::SetNextFrameCallback | ( | fml::closure | callback | ) |

Definition at line 584 of file flutter_windows_engine.cc.

584 {
585 next_frame_callback_ = std::move(callback);
586
587 embedder_api_.SetNextFrameCallback(
588 engine_,
589 [](void* user_data) {
590 // Embedder callback runs on raster thread. Switch back to platform
591 // thread.
592 FlutterWindowsEngine* self =
593 static_cast<FlutterWindowsEngine*>(user_data);
594
595 self->task_runner_->PostTask(std::move(self->next_frame_callback_));
596 },
597 this);
598 }

Referenced by FlutterDesktopEngineSetNextFrameCallback().

## ◆ SetRootIsolateCreateCallback()

void flutter::FlutterWindowsEngine::SetRootIsolateCreateCallback | ( | const fml::closure & | callback | ) |
| inline

Definition at line 236 of file flutter_windows_engine.h.

236 {
237 root_isolate_create_callback_ = callback;
238 }

References callback.

## ◆ SetSwitches()

void flutter::FlutterWindowsEngine::SetSwitches | ( | const std::vector< std::string > & | switches | ) |

Definition at line 241 of file flutter_windows_engine.cc.

242 {
243 project_->SetSwitches(switches);
244 }

## ◆ SetView()

void flutter::FlutterWindowsEngine::SetView | ( | FlutterWindowsView * | view | ) |

Definition at line 455 of file flutter_windows_engine.cc.

455 {
456 view_ = view;
457 InitializeKeyboard();
458 }

## ◆ Stop()

bool flutter::FlutterWindowsEngine::Stop | ( |  | ) |
| virtual

Definition at line 442 of file flutter_windows_engine.cc.

442 {
443 if (engine_) {
444 for (const auto& [callback, registrar] :
445 plugin_registrar_destruction_callbacks_) {
446 callback(registrar);
447 }
448 FlutterEngineResult result = embedder_api_.Shutdown(engine_);
449 engine_ = nullptr;
450 return (result == kSuccess);
451 }
452 return false;
453 }

Referenced by FlutterDesktopEngineDestroy().

## ◆ surface_manager()

AngleSurfaceManager* flutter::FlutterWindowsEngine::surface_manager | ( |  | ) |
| inline

Definition at line 142 of file flutter_windows_engine.h.

142 { return surface_manager_.get(); }

Referenced by FlutterDesktopViewGetGraphicsAdapter(), and flutter::FlutterWindowsTextureRegistrar::RegisterTexture().

## ◆ task_runner()

TaskRunner* flutter::FlutterWindowsEngine::task_runner | ( |  | ) |
| inline

Definition at line 134 of file flutter_windows_engine.h.

134 { return task_runner_.get(); }

Referenced by flutter::FlutterWindowsTextureRegistrar::MarkTextureFrameAvailable(), flutter::testing::TEST_F(), and flutter::FlutterWindowsTextureRegistrar::UnregisterTexture().

## ◆ text_input_plugin()

TextInputPlugin* flutter::FlutterWindowsEngine::text_input_plugin | ( |  | ) |
| inline

Definition at line 162 of file flutter_windows_engine.h.

162 { return text_input_plugin_.get(); }

## ◆ texture_registrar()

FlutterWindowsTextureRegistrar* flutter::FlutterWindowsEngine::texture_registrar | ( |  | ) |
| inline

Definition at line 136 of file flutter_windows_engine.h.

136 {
137 return texture_registrar_.get();
138 }

Referenced by FlutterDesktopRegistrarGetTextureRegistrar().

## ◆ UnregisterExternalTexture()

bool flutter::FlutterWindowsEngine::UnregisterExternalTexture | ( | int64_t | texture_id | ) |

Definition at line 671 of file flutter_windows_engine.cc.

671 {
672 return (embedder_api_.UnregisterExternalTexture(engine_, texture_id) ==
673 kSuccess);
674 }

## ◆ UpdateAccessibilityFeatures()

void flutter::FlutterWindowsEngine::UpdateAccessibilityFeatures | ( | FlutterAccessibilityFeature | flags | ) |

Definition at line 740 of file flutter_windows_engine.cc.

741 {
742 embedder_api_.UpdateAccessibilityFeatures(engine_, flags);
743 }

## ◆ UpdateHighContrastEnabled()

void flutter::FlutterWindowsEngine::UpdateHighContrastEnabled | ( | bool | enabled | ) |

Definition at line 745 of file flutter_windows_engine.cc.

745 {
746 high_contrast_enabled_ = enabled;
747 int flags = EnabledAccessibilityFeatures();
748 if (enabled) {
749 flags |=
750 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
751 } else {
752 flags &=
753 ~FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
754 }
755 UpdateAccessibilityFeatures(static_cast<FlutterAccessibilityFeature>(flags));
756 settings_plugin_->UpdateHighContrastMode(enabled);
757 }

## ◆ UpdateSemanticsEnabled()

void flutter::FlutterWindowsEngine::UpdateSemanticsEnabled | ( | bool | enabled | ) |

Definition at line 711 of file flutter_windows_engine.cc.

711 {
712 if (engine_ && semantics_enabled_ != enabled) {
713 semantics_enabled_ = enabled;
714 embedder_api_.UpdateSemanticsEnabled(engine_, enabled);
715 view_->UpdateSemanticsEnabled(enabled);
716 }
717 }

Referenced by flutter::testing::TEST_F().

## ◆ view()

FlutterWindowsView* flutter::FlutterWindowsEngine::view | ( |  | ) |
| inline

Definition at line 115 of file flutter_windows_engine.h.

115 { return view_; }

Referenced by FlutterDesktopPluginRegistrarGetView(), flutter::PlatformHandler::GetHasStrings(), flutter::PlatformHandler::GetPlainText(), Run(), and flutter::PlatformHandler::SetPlainText().

## ◆ window_proc_delegate_manager()

WindowProcDelegateManager* flutter::FlutterWindowsEngine::window_proc_delegate_manager | ( |  | ) |
| inline

Definition at line 144 of file flutter_windows_engine.h.

144 {
145 return window_proc_delegate_manager_.get();
146 }

Referenced by FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(), FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate(), and flutter::testing::TEST_F().

## Friends And Related Function Documentation

## ◆ EngineModifier

friend class EngineModifier
| friend

Definition at line 306 of file flutter_windows_engine.h.

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

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

flutter::FlutterWindowsEngine::high_contrast_enabled
bool high_contrast_enabled() const
Definition: flutter_windows_engine.h:225
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:47
flutter::FlutterWindowsEngine::FlutterWindowsEngine
FlutterWindowsEngine(const FlutterProjectBundle &project)
Definition: flutter_windows_engine.cc:160
flutter::FlutterWindowsView::accessibility_bridge
std::weak_ptr< AccessibilityBridgeWindows > accessibility_bridge()
Definition: flutter_windows_view.h:210
kAccessibilityChannelName
static constexpr char kAccessibilityChannelName[]
Definition: flutter_windows_engine.cc:29
flutter::FlutterWindowsEngine::Stop
virtual bool Stop()
Definition: flutter_windows_engine.cc:442
flutter::FlutterWindowsEngine::messenger
FlutterDesktopMessengerRef messenger()
Definition: flutter_windows_engine.h:128
flutter::FlutterWindowsEngine::keyboard_key_handler
KeyboardHandlerBase * keyboard_key_handler()
Definition: flutter_windows_engine.h:159
flutter::FlutterWindowsEngine::SendKeyEvent
void SendKeyEvent(const FlutterKeyEvent &event, FlutterKeyEventCallback callback, void *user_data)
Definition: flutter_windows_engine.cc:512
flutter::FlutterWindowsView::OnDwmCompositionChanged
void OnDwmCompositionChanged()
Definition: flutter_windows_view.cc:676
FlutterDesktopMessengerRef
struct FlutterDesktopMessenger * FlutterDesktopMessengerRef
Definition: flutter_messenger.h:19
FlutterDesktopMessage
Definition: flutter_messenger.h:31
flutter::FlutterWindowsEngine::view
FlutterWindowsView * view()
Definition: flutter_windows_engine.h:115
flutter::AppLifecycleState::kResumed
@ kResumed
flutter::FlutterWindowsView::UpdateSemanticsEnabled
virtual void UpdateSemanticsEnabled(bool enabled)
Definition: flutter_windows_view.cc:664
message
Win32Message message
Definition: keyboard_unittests.cc:137
flutter::FlutterWindowsEngine::UpdateAccessibilityFeatures
void UpdateAccessibilityFeatures(FlutterAccessibilityFeature flags)
Definition: flutter_windows_engine.cc:740
action
int action
Definition: keyboard_key_handler_unittests.cc:116
flutter::AngleSurfaceManager::Create
static std::unique_ptr< AngleSurfaceManager > Create(bool enable_impeller)
Definition: angle_surface_manager.cc:23
flutter::FlutterWindowsTextureRegistrar::ResolveGlFunctions
static void ResolveGlFunctions(GlProcs &gl_procs)
Definition: flutter_windows_texture_registrar.cc:129
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
flutter::FlutterWindowsEngine::Run
bool Run()
Definition: flutter_windows_engine.cc:246
flutter::WindowsPlatformThreadPrioritySetter
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
Definition: flutter_windows_engine.h:48
flutter::FlutterWindowsEngine::GetExecutableName
std::string GetExecutableName() const
Definition: flutter_windows_engine.cc:726
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:46
flutter::FlutterWindowsEngine::EnabledAccessibilityFeatures
int EnabledAccessibilityFeatures() const
Definition: flutter_windows_engine.cc:759