10 #include <shared_mutex>
13 #include "flutter/fml/logging.h"
14 #include "flutter/fml/paths.h"
15 #include "flutter/fml/platform/win/wstring_conversion.h"
16 #include "flutter/fml/synchronization/waitable_event.h"
20 #include "flutter/shell/platform/embedder/embedder_struct_macros.h"
28 #include "flutter/third_party/accessibility/ax/ax_node.h"
40 static std::chrono::nanoseconds SnapToNextTick(
41 std::chrono::nanoseconds value,
42 std::chrono::nanoseconds tick_phase,
43 std::chrono::nanoseconds tick_interval) {
44 std::chrono::nanoseconds offset = (tick_phase - value) % tick_interval;
45 if (offset != std::chrono::nanoseconds::zero())
46 offset = offset + tick_interval;
47 return value + offset;
54 FlutterRendererConfig GetOpenGLRendererConfig() {
55 FlutterRendererConfig config = {};
56 config.type = kOpenGL;
57 config.open_gl.struct_size =
sizeof(config.open_gl);
58 config.open_gl.make_current = [](
void*
user_data) ->
bool {
59 auto host =
static_cast<FlutterWindowsEngine*
>(
user_data);
60 if (!host->egl_manager()) {
63 return host->egl_manager()->render_context()->MakeCurrent();
65 config.open_gl.clear_current = [](
void*
user_data) ->
bool {
66 auto host =
static_cast<FlutterWindowsEngine*
>(
user_data);
67 if (!host->egl_manager()) {
70 return host->egl_manager()->render_context()->ClearCurrent();
72 config.open_gl.present = [](
void*
user_data) ->
bool { FML_UNREACHABLE(); };
73 config.open_gl.fbo_reset_after_present =
true;
74 config.open_gl.fbo_with_frame_info_callback =
75 [](
void*
user_data,
const FlutterFrameInfo* info) -> uint32_t {
78 config.open_gl.gl_proc_resolver = [](
void*
user_data,
79 const char* what) ->
void* {
80 return reinterpret_cast<void*
>(eglGetProcAddress(what));
82 config.open_gl.make_resource_current = [](
void*
user_data) ->
bool {
83 auto host =
static_cast<FlutterWindowsEngine*
>(
user_data);
84 if (!host->egl_manager()) {
87 return host->egl_manager()->resource_context()->MakeCurrent();
89 config.open_gl.gl_external_texture_frame_callback =
91 FlutterOpenGLTexture* texture) ->
bool {
92 auto host =
static_cast<FlutterWindowsEngine*
>(
user_data);
93 if (!host->texture_registrar()) {
96 return host->texture_registrar()->PopulateTexture(
texture_id, width, height,
106 FlutterRendererConfig GetSoftwareRendererConfig() {
107 FlutterRendererConfig config = {};
108 config.type = kSoftware;
109 config.software.struct_size =
sizeof(config.software);
110 config.software.surface_present_callback =
111 [](
void*
user_data,
const void* allocation,
size_t row_bytes,
121 const FlutterPlatformMessage& engine_message) {
124 message.channel = engine_message.channel;
125 message.message = engine_message.message;
126 message.message_size = engine_message.message_size;
127 message.response_handle = engine_message.response_handle;
133 FlutterLocale CovertToFlutterLocale(
const LanguageInfo& info) {
134 FlutterLocale locale = {};
135 locale.struct_size =
sizeof(FlutterLocale);
136 locale.language_code = info.language.c_str();
137 if (!info.region.empty()) {
138 locale.country_code = info.region.c_str();
140 if (!info.script.empty()) {
141 locale.script_code = info.script.c_str();
150 std::shared_ptr<WindowsProcTable> windows_proc_table)
152 windows_proc_table_(std::move(windows_proc_table)),
153 aot_data_(nullptr, nullptr),
155 if (windows_proc_table_ ==
nullptr) {
156 windows_proc_table_ = std::make_shared<WindowsProcTable>();
161 embedder_api_.struct_size =
sizeof(FlutterEngineProcTable);
162 FlutterEngineGetProcAddresses(&embedder_api_);
165 std::make_unique<TaskRunner>(
166 embedder_api_.GetCurrentTime, [
this](
const auto* task) {
169 <<
"Cannot post an engine task when engine is not running.";
172 if (embedder_api_.RunTask(engine_, task) != kSuccess) {
173 FML_LOG(ERROR) <<
"Failed to post an engine task.";
180 messenger_->SetEngine(
this);
181 plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
182 plugin_registrar_->engine =
this;
185 std::make_unique<BinaryMessengerImpl>(messenger_->ToRef());
186 message_dispatcher_ =
187 std::make_unique<IncomingMessageDispatcher>(messenger_->ToRef());
190 std::make_unique<FlutterWindowsTextureRegistrar>(
this, gl_);
193 auto& switches = project_->GetSwitches();
194 enable_impeller_ = std::find(switches.begin(), switches.end(),
195 "--enable-impeller=true") != switches.end();
198 window_proc_delegate_manager_ = std::make_unique<WindowProcDelegateManager>();
199 window_proc_delegate_manager_->RegisterTopLevelWindowProcDelegate(
200 [](HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar,
void*
user_data,
205 BASE_DCHECK(that->lifecycle_manager_);
206 return that->lifecycle_manager_->WindowProc(hwnd, msg, wpar, lpar,
209 static_cast<void*
>(
this));
214 internal_plugin_registrar_ =
215 std::make_unique<PluginRegistrar>(plugin_registrar_.get());
217 accessibility_plugin_ = std::make_unique<AccessibilityPlugin>(
this);
219 accessibility_plugin_.get());
222 std::make_unique<CursorHandler>(messenger_wrapper_.get(),
this);
224 std::make_unique<PlatformHandler>(messenger_wrapper_.get(),
this);
225 settings_plugin_ = std::make_unique<SettingsPlugin>(messenger_wrapper_.get(),
229 FlutterWindowsEngine::~FlutterWindowsEngine() {
230 messenger_->SetEngine(
nullptr);
234 void FlutterWindowsEngine::SetSwitches(
235 const std::vector<std::string>& switches) {
236 project_->SetSwitches(switches);
239 bool FlutterWindowsEngine::Run() {
243 bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
244 if (!project_->HasValidPaths()) {
245 FML_LOG(ERROR) <<
"Missing or unresolvable paths to assets.";
248 std::string assets_path_string = project_->assets_path().u8string();
249 std::string icu_path_string = project_->icu_path().u8string();
250 if (embedder_api_.RunsAOTCompiledDartCode()) {
251 aot_data_ = project_->LoadAotData(embedder_api_);
253 FML_LOG(ERROR) <<
"Unable to start engine without AOT data.";
261 std::string executable_name = GetExecutableName();
262 std::vector<const char*> argv = {executable_name.c_str()};
263 std::vector<std::string> switches = project_->GetSwitches();
265 switches.begin(), switches.end(), std::back_inserter(argv),
266 [](
const std::string& arg) ->
const char* { return arg.c_str(); });
268 const std::vector<std::string>& entrypoint_args =
269 project_->dart_entrypoint_arguments();
270 std::vector<const char*> entrypoint_argv;
272 entrypoint_args.begin(), entrypoint_args.end(),
273 std::back_inserter(entrypoint_argv),
274 [](
const std::string& arg) ->
const char* { return arg.c_str(); });
277 FlutterTaskRunnerDescription platform_task_runner = {};
278 platform_task_runner.struct_size =
sizeof(FlutterTaskRunnerDescription);
279 platform_task_runner.user_data = task_runner_.get();
280 platform_task_runner.runs_task_on_current_thread_callback =
284 platform_task_runner.post_task_callback = [](FlutterTask task,
285 uint64_t target_time_nanos,
290 FlutterCustomTaskRunners custom_task_runners = {};
291 custom_task_runners.struct_size =
sizeof(FlutterCustomTaskRunners);
292 custom_task_runners.platform_task_runner = &platform_task_runner;
293 custom_task_runners.thread_priority_setter =
296 FlutterProjectArgs args = {};
297 args.struct_size =
sizeof(FlutterProjectArgs);
298 args.shutdown_dart_vm_when_done =
true;
299 args.assets_path = assets_path_string.c_str();
300 args.icu_data_path = icu_path_string.c_str();
301 args.command_line_argc =
static_cast<int>(argv.size());
302 args.command_line_argv = argv.empty() ? nullptr : argv.data();
310 if (!project_->dart_entrypoint().empty() && !entrypoint.empty() &&
311 project_->dart_entrypoint() != entrypoint) {
312 FML_LOG(ERROR) <<
"Conflicting entrypoints were specified in "
313 "FlutterDesktopEngineProperties.dart_entrypoint and "
314 "FlutterDesktopEngineRun(engine, entry_point). ";
317 if (!entrypoint.empty()) {
318 args.custom_dart_entrypoint = entrypoint.data();
319 }
else if (!project_->dart_entrypoint().empty()) {
320 args.custom_dart_entrypoint = project_->dart_entrypoint().c_str();
322 args.dart_entrypoint_argc =
static_cast<int>(entrypoint_argv.size());
323 args.dart_entrypoint_argv =
324 entrypoint_argv.empty() ? nullptr : entrypoint_argv.data();
325 args.platform_message_callback =
326 [](
const FlutterPlatformMessage* engine_message,
331 args.vsync_callback = [](
void*
user_data, intptr_t baton) ->
void {
335 args.on_pre_engine_restart_callback = [](
void*
user_data) {
339 args.update_semantics_callback2 = [](
const FlutterSemanticsUpdate2* update,
351 if (!accessibility_bridge) {
355 for (
size_t i = 0; i < update->node_count; i++) {
356 const FlutterSemanticsNode2* node = update->nodes[i];
357 accessibility_bridge->AddFlutterSemanticsNodeUpdate(*node);
360 for (
size_t i = 0; i < update->custom_action_count; i++) {
361 const FlutterSemanticsCustomAction2*
action = update->custom_actions[i];
362 accessibility_bridge->AddFlutterSemanticsCustomActionUpdate(*
action);
365 accessibility_bridge->CommitUpdates();
367 args.root_isolate_create_callback = [](
void*
user_data) {
369 if (host->root_isolate_create_callback_) {
370 host->root_isolate_create_callback_();
373 args.channel_update_callback = [](
const FlutterChannelUpdate* update,
376 if (SAFE_ACCESS(update, channel,
nullptr) !=
nullptr) {
377 std::string channel_name(update->channel);
378 host->OnChannelUpdate(std::move(channel_name),
379 SAFE_ACCESS(update, listening,
false));
383 args.custom_task_runners = &custom_task_runners;
385 if (!platform_view_plugin_) {
386 platform_view_plugin_ = std::make_unique<PlatformViewPlugin>(
387 messenger_wrapper_.get(), task_runner_.get());
390 auto resolver = [](
const char* name) ->
void* {
391 return reinterpret_cast<void*
>(::eglGetProcAddress(name));
397 std::make_unique<CompositorOpenGL>(
this, resolver, enable_impeller_);
399 compositor_ = std::make_unique<CompositorSoftware>();
402 FlutterCompositor compositor = {};
403 compositor.struct_size =
sizeof(FlutterCompositor);
404 compositor.user_data =
this;
405 compositor.create_backing_store_callback =
406 [](
const FlutterBackingStoreConfig* config,
407 FlutterBackingStore* backing_store_out,
void*
user_data) ->
bool {
410 return host->compositor_->CreateBackingStore(*config, backing_store_out);
413 compositor.collect_backing_store_callback =
414 [](
const FlutterBackingStore* backing_store,
void*
user_data) ->
bool {
417 return host->compositor_->CollectBackingStore(backing_store);
420 compositor.present_view_callback =
421 [](
const FlutterPresentViewInfo* info) ->
bool {
424 return host->Present(info);
426 args.compositor = &compositor;
429 args.aot_data = aot_data_.get();
434 FML_DCHECK(!egl_manager_ || !egl_manager_->HasContextCurrent());
436 FlutterRendererConfig renderer_config;
438 if (enable_impeller_) {
442 FML_LOG(ERROR) <<
"Could not create surface manager. Impeller backend "
443 "does not support software rendering.";
446 renderer_config = GetOpenGLRendererConfig();
449 egl_manager_ ? GetOpenGLRendererConfig() : GetSoftwareRendererConfig();
452 auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
453 &args,
this, &engine_);
454 if (result != kSuccess || engine_ ==
nullptr) {
455 FML_LOG(ERROR) <<
"Failed to start Flutter engine: error " << result;
460 FlutterEngineDisplay display = {};
461 display.struct_size =
sizeof(FlutterEngineDisplay);
462 display.display_id = 0;
463 display.single_display =
true;
464 display.refresh_rate =
465 1.0 / (
static_cast<double>(FrameInterval().count()) / 1000000000.0);
467 std::vector<FlutterEngineDisplay> displays = {display};
468 embedder_api_.NotifyDisplayUpdate(engine_,
469 kFlutterEngineDisplaysUpdateTypeStartup,
470 displays.data(), displays.size());
475 settings_plugin_->StartWatching();
476 settings_plugin_->SendSettings();
478 InitializeKeyboard();
483 bool FlutterWindowsEngine::Stop() {
485 for (
const auto& [
callback, registrar] :
486 plugin_registrar_destruction_callbacks_) {
489 FlutterEngineResult result = embedder_api_.Shutdown(engine_);
491 return (result == kSuccess);
496 std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
497 std::unique_ptr<WindowBindingHandler> window) {
498 auto view_id = next_view_id_;
499 auto view = std::make_unique<FlutterWindowsView>(
500 view_id,
this, std::move(window), windows_proc_table_);
502 view->CreateRenderSurface();
509 std::unique_lock write_lock(views_mutex_);
510 FML_DCHECK(views_.find(view_id) == views_.end());
511 views_[view_id] = view.get();
514 if (!view->IsImplicitView()) {
515 FML_DCHECK(running());
518 fml::AutoResetWaitableEvent latch;
521 Captures captures = {};
523 FlutterWindowMetricsEvent metrics = view->CreateWindowMetricsEvent();
525 FlutterAddViewInfo info = {};
526 info.struct_size =
sizeof(FlutterAddViewInfo);
527 info.view_id = view_id;
528 info.view_metrics = &metrics;
529 info.user_data = &captures;
530 info.add_view_callback = [](
const FlutterAddViewResult* result) {
531 Captures* captures =
reinterpret_cast<Captures*
>(result->user_data);
532 captures->added = result->added;
533 captures->latch.Signal();
536 FlutterEngineResult result = embedder_api_.AddView(engine_, &info);
537 if (result != kSuccess) {
539 <<
"Starting the add view operation failed. FlutterEngineAddView "
540 "returned an unexpected result: "
541 << result <<
". This indicates a bug in the Windows embedder.";
551 captures.latch.Wait();
553 if (!captures.added) {
557 FML_LOG(ERROR) <<
"FlutterEngineAddView failed to add view";
558 std::unique_lock write_lock(views_mutex_);
559 views_.erase(view_id);
564 return std::move(view);
568 FML_DCHECK(running());
575 fml::AutoResetWaitableEvent latch;
578 Captures captures = {};
580 FlutterRemoveViewInfo info = {};
581 info.struct_size =
sizeof(FlutterRemoveViewInfo);
582 info.view_id = view_id;
583 info.user_data = &captures;
584 info.remove_view_callback = [](
const FlutterRemoveViewResult* result) {
588 Captures* captures =
reinterpret_cast<Captures*
>(result->user_data);
589 captures->removed = result->removed;
590 captures->latch.Signal();
593 FlutterEngineResult result = embedder_api_.RemoveView(engine_, &info);
594 if (result != kSuccess) {
595 FML_LOG(ERROR) <<
"Starting the remove view operation failed. "
596 "FlutterEngineRemoveView "
597 "returned an unexpected result: "
599 <<
". This indicates a bug in the Windows embedder.";
609 captures.latch.Wait();
611 if (!captures.removed) {
614 FML_LOG(ERROR) <<
"FlutterEngineRemoveView failed to remove view";
622 std::unique_lock write_lock(views_mutex_);
624 FML_DCHECK(views_.find(view_id) != views_.end());
625 views_.erase(view_id);
629 void FlutterWindowsEngine::OnVsync(intptr_t baton) {
630 std::chrono::nanoseconds current_time =
631 std::chrono::nanoseconds(embedder_api_.GetCurrentTime());
632 std::chrono::nanoseconds frame_interval = FrameInterval();
633 auto next = SnapToNextTick(current_time, start_time_, frame_interval);
634 embedder_api_.OnVsync(engine_, baton, next.count(),
635 (next + frame_interval).count());
638 std::chrono::nanoseconds FlutterWindowsEngine::FrameInterval() {
639 if (frame_interval_override_.has_value()) {
640 return frame_interval_override_.value();
642 uint64_t interval = 16600000;
644 DWM_TIMING_INFO timing_info = {};
645 timing_info.cbSize =
sizeof(timing_info);
646 HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info);
647 if (result == S_OK && timing_info.rateRefresh.uiDenominator > 0 &&
648 timing_info.rateRefresh.uiNumerator > 0) {
649 interval =
static_cast<double>(timing_info.rateRefresh.uiDenominator *
651 static_cast<double>(timing_info.rateRefresh.uiNumerator);
654 return std::chrono::nanoseconds(interval);
658 std::shared_lock read_lock(views_mutex_);
660 auto iterator = views_.find(view_id);
661 if (iterator == views_.end()) {
665 return iterator->second;
670 return plugin_registrar_.get();
673 void FlutterWindowsEngine::AddPluginRegistrarDestructionCallback(
676 plugin_registrar_destruction_callbacks_[
callback] = registrar;
679 void FlutterWindowsEngine::SendWindowMetricsEvent(
680 const FlutterWindowMetricsEvent& event) {
682 embedder_api_.SendWindowMetricsEvent(engine_, &event);
686 void FlutterWindowsEngine::SendPointerEvent(
const FlutterPointerEvent& event) {
688 embedder_api_.SendPointerEvent(engine_, &event, 1);
692 void FlutterWindowsEngine::SendKeyEvent(
const FlutterKeyEvent& event,
700 bool FlutterWindowsEngine::SendPlatformMessage(
703 const size_t message_size,
706 FlutterPlatformMessageResponseHandle* response_handle =
nullptr;
707 if (reply !=
nullptr &&
user_data !=
nullptr) {
708 FlutterEngineResult result =
709 embedder_api_.PlatformMessageCreateResponseHandle(
710 engine_, reply,
user_data, &response_handle);
711 if (result != kSuccess) {
712 FML_LOG(ERROR) <<
"Failed to create response handle";
717 FlutterPlatformMessage platform_message = {
718 sizeof(FlutterPlatformMessage),
725 FlutterEngineResult message_result =
726 embedder_api_.SendPlatformMessage(engine_, &platform_message);
727 if (response_handle !=
nullptr) {
728 embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
731 return message_result == kSuccess;
734 void FlutterWindowsEngine::SendPlatformMessageResponse(
737 size_t data_length) {
738 embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
741 void FlutterWindowsEngine::HandlePlatformMessage(
742 const FlutterPlatformMessage* engine_message) {
743 if (engine_message->struct_size !=
sizeof(FlutterPlatformMessage)) {
744 FML_LOG(ERROR) <<
"Invalid message size received. Expected: "
745 <<
sizeof(FlutterPlatformMessage) <<
" but received "
746 << engine_message->struct_size;
750 auto message = ConvertToDesktopMessage(*engine_message);
752 message_dispatcher_->HandleMessage(
message, [
this] {}, [
this] {});
755 void FlutterWindowsEngine::ReloadSystemFonts() {
756 embedder_api_.ReloadSystemFonts(engine_);
759 void FlutterWindowsEngine::ScheduleFrame() {
760 embedder_api_.ScheduleFrame(engine_);
763 void FlutterWindowsEngine::SetNextFrameCallback(fml::closure
callback) {
764 next_frame_callback_ = std::move(
callback);
766 embedder_api_.SetNextFrameCallback(
774 self->task_runner_->PostTask(std::move(self->next_frame_callback_));
780 if (lifecycle_manager_) {
781 lifecycle_manager_->SetLifecycleState(state);
785 void FlutterWindowsEngine::SendSystemLocales() {
786 std::vector<LanguageInfo> languages =
788 std::vector<FlutterLocale> flutter_locales;
789 flutter_locales.reserve(languages.size());
790 for (
const auto& info : languages) {
791 flutter_locales.push_back(CovertToFlutterLocale(info));
794 std::vector<const FlutterLocale*> flutter_locale_list;
795 flutter_locale_list.reserve(flutter_locales.size());
796 std::transform(flutter_locales.begin(), flutter_locales.end(),
797 std::back_inserter(flutter_locale_list),
798 [](
const auto& arg) ->
const auto* { return &arg; });
799 embedder_api_.UpdateLocales(engine_, flutter_locale_list.data(),
800 flutter_locale_list.size());
803 void FlutterWindowsEngine::InitializeKeyboard() {
804 auto internal_plugin_messenger = internal_plugin_registrar_->messenger();
805 KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = GetKeyState;
806 KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan =
807 [](UINT virtual_key,
bool extended) {
808 return MapVirtualKey(virtual_key,
809 extended ? MAPVK_VK_TO_VSC_EX : MAPVK_VK_TO_VSC);
811 keyboard_key_handler_ = std::move(CreateKeyboardKeyHandler(
812 internal_plugin_messenger, get_key_state, map_vk_to_scan));
814 std::move(CreateTextInputPlugin(internal_plugin_messenger));
817 std::unique_ptr<KeyboardHandlerBase>
818 FlutterWindowsEngine::CreateKeyboardKeyHandler(
822 auto keyboard_key_handler = std::make_unique<KeyboardKeyHandler>(messenger);
823 keyboard_key_handler->AddDelegate(
824 std::make_unique<KeyboardKeyEmbedderHandler>(
825 [
this](
const FlutterKeyEvent& event, FlutterKeyEventCallback
callback,
829 get_key_state, map_vk_to_scan));
830 keyboard_key_handler->AddDelegate(
831 std::make_unique<KeyboardKeyChannelHandler>(messenger));
832 keyboard_key_handler->InitKeyboardChannel();
833 return keyboard_key_handler;
836 std::unique_ptr<TextInputPlugin> FlutterWindowsEngine::CreateTextInputPlugin(
838 return std::make_unique<TextInputPlugin>(messenger,
this);
841 bool FlutterWindowsEngine::RegisterExternalTexture(int64_t
texture_id) {
842 return (embedder_api_.RegisterExternalTexture(engine_,
texture_id) ==
846 bool FlutterWindowsEngine::UnregisterExternalTexture(int64_t
texture_id) {
847 return (embedder_api_.UnregisterExternalTexture(engine_,
texture_id) ==
851 bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable(
853 return (embedder_api_.MarkExternalTextureFrameAvailable(
857 bool FlutterWindowsEngine::PostRasterThreadTask(fml::closure
callback)
const {
861 auto captures =
new Captures();
862 captures->callback = std::move(
callback);
863 if (embedder_api_.PostRenderThreadTask(
866 auto captures = reinterpret_cast<Captures*>(opaque);
867 captures->callback();
870 captures) == kSuccess) {
877 bool FlutterWindowsEngine::DispatchSemanticsAction(
879 FlutterSemanticsAction
action,
880 fml::MallocMapping data) {
881 return (embedder_api_.DispatchSemanticsAction(engine_, target,
action,
883 data.GetSize()) == kSuccess);
886 void FlutterWindowsEngine::UpdateSemanticsEnabled(
bool enabled) {
887 if (engine_ && semantics_enabled_ != enabled) {
888 std::shared_lock read_lock(views_mutex_);
890 semantics_enabled_ = enabled;
891 embedder_api_.UpdateSemanticsEnabled(engine_, enabled);
892 for (
auto iterator = views_.begin(); iterator != views_.end(); iterator++) {
893 iterator->second->UpdateSemanticsEnabled(enabled);
898 void FlutterWindowsEngine::OnPreEngineRestart() {
900 InitializeKeyboard();
903 std::string FlutterWindowsEngine::GetExecutableName()
const {
904 std::pair<bool, std::string> result = fml::paths::GetExecutablePath();
906 const std::string& executable_path = result.second;
907 size_t last_separator = executable_path.find_last_of(
"/\\");
908 if (last_separator == std::string::npos ||
909 last_separator == executable_path.size() - 1) {
910 return executable_path;
912 return executable_path.substr(last_separator + 1);
917 void FlutterWindowsEngine::UpdateAccessibilityFeatures() {
918 UpdateHighContrastMode();
921 void FlutterWindowsEngine::UpdateHighContrastMode() {
922 high_contrast_enabled_ = windows_proc_table_->GetHighContrastEnabled();
924 SendAccessibilityFeatures();
925 settings_plugin_->UpdateHighContrastMode(high_contrast_enabled_);
928 void FlutterWindowsEngine::SendAccessibilityFeatures() {
931 if (high_contrast_enabled_) {
933 FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
936 embedder_api_.UpdateAccessibilityFeatures(
937 engine_,
static_cast<FlutterAccessibilityFeature
>(flags));
940 void FlutterWindowsEngine::RequestApplicationQuit(HWND hwnd,
944 platform_handler_->RequestAppExit(hwnd, wparam, lparam, exit_type, 0);
947 void FlutterWindowsEngine::OnQuit(std::optional<HWND> hwnd,
948 std::optional<WPARAM> wparam,
949 std::optional<LPARAM> lparam,
951 lifecycle_manager_->Quit(hwnd, wparam, lparam, exit_code);
954 void FlutterWindowsEngine::OnDwmCompositionChanged() {
955 std::shared_lock read_lock(views_mutex_);
957 for (
auto iterator = views_.begin(); iterator != views_.end(); iterator++) {
958 iterator->second->OnDwmCompositionChanged();
962 void FlutterWindowsEngine::OnWindowStateEvent(HWND hwnd,
964 lifecycle_manager_->OnWindowStateEvent(hwnd, event);
967 std::optional<LRESULT> FlutterWindowsEngine::ProcessExternalWindowMessage(
972 if (lifecycle_manager_) {
973 return lifecycle_manager_->ExternalWindowMessage(hwnd,
message, wparam,
979 void FlutterWindowsEngine::OnChannelUpdate(std::string name,
bool listening) {
980 if (name ==
"flutter/platform" && listening) {
981 lifecycle_manager_->BeginProcessingExit();
982 }
else if (name ==
"flutter/lifecycle" && listening) {
983 lifecycle_manager_->BeginProcessingLifecycle();
987 bool FlutterWindowsEngine::Present(
const FlutterPresentViewInfo* info) {
991 std::shared_lock read_lock(views_mutex_);
993 auto iterator = views_.find(info->view_id);
994 if (iterator == views_.end()) {
998 FlutterWindowsView* view = iterator->second;
1000 return compositor_->Present(view, info->layers, info->layers_count);