| 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, std::shared_ptr< WindowsProcTable > windows_proc_table=nullptr)
virtual | ~FlutterWindowsEngine ()
bool | Run ()
bool | Run (std::string_view entrypoint)
virtual bool | running () const
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 () const
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) const
void | OnVsync (intptr_t baton)
bool | DispatchSemanticsAction (uint64_t id, FlutterSemanticsAction action, fml::MallocMapping data)
void | UpdateSemanticsEnabled (bool enabled)
bool | semantics_enabled () const
void | UpdateAccessibilityFeatures ()
void | UpdateHighContrastMode ()
bool | high_contrast_enabled () const
void | SetRootIsolateCreateCallback (const fml::closure &callback)
std::string | GetExecutableName () const
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 ()
std::shared_ptr< WindowsProcTable > | windows_proc_table ()

## 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,
|  | std::shared_ptr< WindowsProcTable > | windows_proc_table = `nullptr`
| ) |  |

Definition at line 160 of file flutter_windows_engine.cc.

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

References flutter::GlProcTable::Create().

## ◆ ~FlutterWindowsEngine()

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

Definition at line 244 of file flutter_windows_engine.cc.

244 {
245 messenger_->SetEngine(nullptr);
246 Stop();
247 }

## Member Function Documentation

## ◆ AddPluginRegistrarDestructionCallback()

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

Definition at line 501 of file flutter_windows_engine.cc.

503 {
504 plugin_registrar_destruction_callbacks_[callback] = registrar;
505 }

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 650 of file flutter_windows_engine.cc.

653 {
654 auto keyboard_key_handler = std::make_unique<KeyboardKeyHandler>(messenger);
655 keyboard_key_handler->AddDelegate(
656 std::make_unique<KeyboardKeyEmbedderHandler>(
657 [this](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
658 void* user_data) {
659 return SendKeyEvent(event, callback, user_data);
660 },
661 get_key_state, map_vk_to_scan));
662 keyboard_key_handler->AddDelegate(
663 std::make_unique<KeyboardKeyChannelHandler>(messenger));
664 keyboard_key_handler->InitKeyboardChannel();
665 return keyboard_key_handler;
666 }

References callback, and user_data.

## ◆ CreateTextInputPlugin()

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

Definition at line 668 of file flutter_windows_engine.cc.

669 {
670 return std::make_unique<TextInputPlugin>(messenger, this);
671 }

## ◆ DispatchSemanticsAction()

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

Definition at line 709 of file flutter_windows_engine.cc.

712 {
713 return (embedder_api_.DispatchSemanticsAction(engine_, target, action,
714 data.GetMapping(),
715 data.GetSize()) == kSuccess);
716 }

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

## ◆ GetExecutableName()

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

Definition at line 733 of file flutter_windows_engine.cc.

733 {
734 std::pair<bool, std::string> result = fml::paths::GetExecutablePath();
735 if (result.first) {
736 const std::string& executable_path = result.second;
737 size_t last_separator = executable_path.find_last_of("/\\");
738 if (last_separator == std::string::npos ||
739 last_separator == executable_path.size() - 1) {
740 return executable_path;
741 }
742 return executable_path.substr(last_separator + 1);
743 }
744 return "Flutter";
745 }

## ◆ GetRegistrar()

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

Definition at line 497 of file flutter_windows_engine.cc.

497 {
498 return plugin_registrar_.get();
499 }

Referenced by FlutterDesktopEngineGetPluginRegistrar().

## ◆ HandlePlatformMessage()

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

Definition at line 569 of file flutter_windows_engine.cc.

570 {
571 if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
572 FML_LOG(ERROR) << "Invalid message size received. Expected: "
573 << sizeof(FlutterPlatformMessage) << " but received "
574 << engine_message->struct_size;
575 return;
576 }
577
578 auto message = ConvertToDesktopMessage(*engine_message);
579
580 message_dispatcher_->HandleMessage(message, [this] {}, [this] {});
581 }

References message.

Referenced by Run().

## ◆ high_contrast_enabled()

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

Definition at line 229 of file flutter_windows_engine.h.

229 { return high_contrast_enabled_; }

## ◆ keyboard_key_handler()

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

Definition at line 163 of file flutter_windows_engine.h.

163 {
164 return keyboard_key_handler_.get();
165 }

Referenced by flutter::FlutterWindowsView::OnPointerMove().

## ◆ lifecycle_manager()

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

Definition at line 274 of file flutter_windows_engine.h.

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

## ◆ MarkExternalTextureFrameAvailable()

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

Definition at line 683 of file flutter_windows_engine.cc.

684 {
685 return (embedder_api_.MarkExternalTextureFrameAvailable(
686 engine_, texture_id) == kSuccess);
687 }

## ◆ message_dispatcher()

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

Definition at line 132 of file flutter_windows_engine.h.

132 {
133 return message_dispatcher_.get();
134 }

Referenced by FlutterDesktopMessengerSetCallback().

## ◆ messenger()

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

Definition at line 130 of file flutter_windows_engine.h.

130 { return messenger_->ToRef(); }

Referenced by FlutterDesktopEngineGetMessenger(), and FlutterDesktopPluginRegistrarGetMessenger().

## ◆ 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 726 of file flutter_windows_engine.cc.

726 {
727 // Reset the keyboard's state on hot restart.
728 if (view_) {
729 InitializeKeyboard();
730 }
731 }

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 468 of file flutter_windows_engine.cc.

468 {
469 std::chrono::nanoseconds current_time =
470 std::chrono::nanoseconds(embedder_api_.GetCurrentTime());
471 std::chrono::nanoseconds frame_interval = FrameInterval();
472 auto next = SnapToNextTick(current_time, start_time_, frame_interval);
473 embedder_api_.OnVsync(engine_, baton, next.count(),
474 (next + frame_interval).count());
475 }

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 }

Referenced by flutter::FlutterWindowsView::OnWindowStateEvent().

## ◆ PostRasterThreadTask()

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

Definition at line 689 of file flutter_windows_engine.cc.

689 {
690 struct Captures {
691 fml::closure callback;
692 };
693 auto captures = new Captures();
694 captures->callback = std::move(callback);
695 if (embedder_api_.PostRenderThreadTask(
696 engine_,
697 [](void* opaque) {
698 auto captures = reinterpret_cast<Captures*>(opaque);
699 captures->callback();
700 delete captures;
701 },
702 captures) == kSuccess) {
703 return true;
704 }
705 delete captures;
706 return false;
707 }

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().

## ◆ RegisterExternalTexture()

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

Definition at line 673 of file flutter_windows_engine.cc.

673 {
674 return (embedder_api_.RegisterExternalTexture(engine_, texture_id) ==
675 kSuccess);
676 }

## ◆ ReloadSystemFonts()

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

Definition at line 583 of file flutter_windows_engine.cc.

583 {
584 embedder_api_.ReloadSystemFonts(engine_);
585 }

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 254 of file flutter_windows_engine.cc.

254 {
255 return Run("");
256 }

Referenced by FlutterDesktopEngineRun().

## ◆ Run() [2/2]

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

Definition at line 258 of file flutter_windows_engine.cc.

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

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

## ◆ running()

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

Definition at line 105 of file flutter_windows_engine.h.

105 { return engine_ != nullptr; }

Referenced by FlutterDesktopEngineDestroy().

## ◆ ScheduleFrame()

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

Definition at line 587 of file flutter_windows_engine.cc.

587 {
588 embedder_api_.ScheduleFrame(engine_);
589 }

Referenced by flutter::FlutterWindowsView::ForceRedraw().

## ◆ semantics_enabled()

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

Definition at line 220 of file flutter_windows_engine.h.

220 { return semantics_enabled_; }

## ◆ SendKeyEvent()

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

Definition at line 520 of file flutter_windows_engine.cc.

522 {
523 if (engine_) {
524 embedder_api_.SendKeyEvent(engine_, &event, callback, user_data);
525 }
526 }

## ◆ 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 528 of file flutter_windows_engine.cc.

533 {
534 FlutterPlatformMessageResponseHandle* response_handle = nullptr;
535 if (reply != nullptr && user_data != nullptr) {
536 FlutterEngineResult result =
537 embedder_api_.PlatformMessageCreateResponseHandle(
538 engine_, reply, user_data, &response_handle);
539 if (result != kSuccess) {
540 FML_LOG(ERROR) << "Failed to create response handle";
541 return false;
542 }
543 }
544
545 FlutterPlatformMessage platform_message = {
546 sizeof(FlutterPlatformMessage),
547 channel,
548 message,
549 message_size,
550 response_handle,
551 };
552
553 FlutterEngineResult message_result =
554 embedder_api_.SendPlatformMessage(engine_, &platform_message);
555 if (response_handle != nullptr) {
556 embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
557 response_handle);
558 }
559 return message_result == kSuccess;
560 }

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 562 of file flutter_windows_engine.cc.

565 {
566 embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
567 }

Referenced by FlutterDesktopMessengerSendResponse().

## ◆ SendPointerEvent()

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

Definition at line 514 of file flutter_windows_engine.cc.

514 {
515 if (engine_) {
516 embedder_api_.SendPointerEvent(engine_, &event, 1);
517 }
518 }

## ◆ SendWindowMetricsEvent()

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

Definition at line 507 of file flutter_windows_engine.cc.

508 {
509 if (engine_) {
510 embedder_api_.SendWindowMetricsEvent(engine_, &event);
511 }
512 }

## ◆ SetNextFrameCallback()

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

Definition at line 591 of file flutter_windows_engine.cc.

591 {
592 next_frame_callback_ = std::move(callback);
593
594 embedder_api_.SetNextFrameCallback(
595 engine_,
596 [](void* user_data) {
597 // Embedder callback runs on raster thread. Switch back to platform
598 // thread.
599 FlutterWindowsEngine* self =
600 static_cast<FlutterWindowsEngine*>(user_data);
601
602 self->task_runner_->PostTask(std::move(self->next_frame_callback_));
603 },
604 this);
605 }

Referenced by FlutterDesktopEngineSetNextFrameCallback().

## ◆ SetRootIsolateCreateCallback()

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

Definition at line 240 of file flutter_windows_engine.h.

240 {
241 root_isolate_create_callback_ = callback;
242 }

References callback.

## ◆ SetSwitches()

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

Definition at line 249 of file flutter_windows_engine.cc.

250 {
251 project_->SetSwitches(switches);
252 }

## ◆ SetView()

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

Definition at line 463 of file flutter_windows_engine.cc.

463 {
464 view_ = view;
465 InitializeKeyboard();
466 }

Referenced by flutter::FlutterWindowsView::SetEngine().

## ◆ Stop()

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

Definition at line 450 of file flutter_windows_engine.cc.

450 {
451 if (engine_) {
452 for (const auto& [callback, registrar] :
453 plugin_registrar_destruction_callbacks_) {
454 callback(registrar);
455 }
456 FlutterEngineResult result = embedder_api_.Shutdown(engine_);
457 engine_ = nullptr;
458 return (result == kSuccess);
459 }
460 return false;
461 }

Referenced by FlutterDesktopEngineDestroy(), and flutter::FlutterWindowsView::~FlutterWindowsView().

## ◆ surface_manager()

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

Definition at line 144 of file flutter_windows_engine.h.

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

Referenced by flutter::FlutterWindowsView::CreateRenderSurface(), flutter::FlutterWindowsView::DestroyRenderSurface(), FlutterDesktopViewGetGraphicsAdapter(), flutter::FlutterWindowsView::GetFrameBufferId(), flutter::FlutterWindowsView::OnWindowSizeChanged(), flutter::FlutterWindowsTextureRegistrar::RegisterTexture(), and flutter::FlutterWindowsView::SwapBuffers().

## ◆ task_runner()

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

Definition at line 136 of file flutter_windows_engine.h.

136 { return task_runner_.get(); }

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

## ◆ text_input_plugin()

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

Definition at line 166 of file flutter_windows_engine.h.

166 { return text_input_plugin_.get(); }

## ◆ texture_registrar()

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

Definition at line 138 of file flutter_windows_engine.h.

138 {
139 return texture_registrar_.get();
140 }

Referenced by FlutterDesktopRegistrarGetTextureRegistrar().

## ◆ UnregisterExternalTexture()

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

Definition at line 678 of file flutter_windows_engine.cc.

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

## ◆ UpdateAccessibilityFeatures()

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

Definition at line 747 of file flutter_windows_engine.cc.

747 {
748 UpdateHighContrastMode();
749 }

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

## ◆ UpdateHighContrastMode()

void flutter::FlutterWindowsEngine::UpdateHighContrastMode | ( |  | ) |

Definition at line 751 of file flutter_windows_engine.cc.

751 {
752 high_contrast_enabled_ = windows_proc_table_->GetHighContrastEnabled();
753
754 SendAccessibilityFeatures();
755 settings_plugin_->UpdateHighContrastMode(high_contrast_enabled_);
756 }

Referenced by flutter::FlutterWindowsView::OnHighContrastChanged().

## ◆ UpdateSemanticsEnabled()

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

Definition at line 718 of file flutter_windows_engine.cc.

718 {
719 if (engine_ && semantics_enabled_ != enabled) {
720 semantics_enabled_ = enabled;
721 embedder_api_.UpdateSemanticsEnabled(engine_, enabled);
722 view_->UpdateSemanticsEnabled(enabled);
723 }
724 }

Referenced by flutter::FlutterWindowsView::OnUpdateSemanticsEnabled().

## ◆ view()

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

Definition at line 117 of file flutter_windows_engine.h.

117 { 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 148 of file flutter_windows_engine.h.

148 {
149 return window_proc_delegate_manager_.get();
150 }

Referenced by FlutterDesktopPluginRegistrarRegisterTopLevelWindowProcDelegate(), and FlutterDesktopPluginRegistrarUnregisterTopLevelWindowProcDelegate().

## ◆ windows_proc_table()

std::shared_ptr<WindowsProcTable> flutter::FlutterWindowsEngine::windows_proc_table | ( |  | ) |
| inline

Definition at line 278 of file flutter_windows_engine.h.

278 {
279 return windows_proc_table_;
280 }

Referenced by FlutterDesktopViewControllerCreate().

## Friends And Related Function Documentation

## ◆ EngineModifier

friend class EngineModifier
| friend

Definition at line 311 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

user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:49
flutter::FlutterWindowsView::accessibility_bridge
std::weak_ptr< AccessibilityBridgeWindows > accessibility_bridge()
Definition: flutter_windows_view.h:207
flutter::FlutterWindowsEngine::FlutterWindowsEngine
FlutterWindowsEngine(const FlutterProjectBundle &project, std::shared_ptr< WindowsProcTable > windows_proc_table=nullptr)
Definition: flutter_windows_engine.cc:160
kAccessibilityChannelName
static constexpr char kAccessibilityChannelName[]
Definition: flutter_windows_engine.cc:29
flutter::FlutterWindowsEngine::windows_proc_table
std::shared_ptr< WindowsProcTable > windows_proc_table()
Definition: flutter_windows_engine.h:278
flutter::FlutterWindowsEngine::Stop
virtual bool Stop()
Definition: flutter_windows_engine.cc:450
flutter::FlutterWindowsEngine::messenger
FlutterDesktopMessengerRef messenger()
Definition: flutter_windows_engine.h:130
flutter::GlProcTable::Create
static std::shared_ptr< GlProcTable > Create()
Definition: gl_proc_table.cc:11
flutter::FlutterWindowsEngine::keyboard_key_handler
KeyboardHandlerBase * keyboard_key_handler()
Definition: flutter_windows_engine.h:163
flutter::FlutterWindowsEngine::SendKeyEvent
void SendKeyEvent(const FlutterKeyEvent &event, FlutterKeyEventCallback callback, void *user_data)
Definition: flutter_windows_engine.cc:520
flutter::FlutterWindowsView::OnDwmCompositionChanged
void OnDwmCompositionChanged()
Definition: flutter_windows_view.cc:695
flutter::FlutterWindowsEngine::UpdateHighContrastMode
void UpdateHighContrastMode()
Definition: flutter_windows_engine.cc:751
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:117
flutter::AppLifecycleState::kResumed
@ kResumed
flutter::FlutterWindowsView::UpdateSemanticsEnabled
virtual void UpdateSemanticsEnabled(bool enabled)
Definition: flutter_windows_view.cc:683
message
Win32Message message
Definition: keyboard_unittests.cc:137
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
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24
flutter::FlutterWindowsEngine::Run
bool Run()
Definition: flutter_windows_engine.cc:254
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:733
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:48