Flutter Windows Embedder
flutter_windows_engine.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <dwmapi.h>
8 
9 #include <filesystem>
10 #include <shared_mutex>
11 #include <sstream>
12 
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"
30 #include "flutter/third_party/accessibility/ax/ax_node.h"
32 
33 // winbase.h defines GetCurrentTime as a macro.
34 #undef GetCurrentTime
35 
36 static constexpr char kAccessibilityChannelName[] = "flutter/accessibility";
37 
38 namespace flutter {
39 
40 namespace {
41 
42 // Lifted from vsync_waiter_fallback.cc
43 static std::chrono::nanoseconds SnapToNextTick(
44  std::chrono::nanoseconds value,
45  std::chrono::nanoseconds tick_phase,
46  std::chrono::nanoseconds tick_interval) {
47  std::chrono::nanoseconds offset = (tick_phase - value) % tick_interval;
48  if (offset != std::chrono::nanoseconds::zero())
49  offset = offset + tick_interval;
50  return value + offset;
51 }
52 
53 // Creates and returns a FlutterRendererConfig that renders to the view (if any)
54 // of a FlutterWindowsEngine, using OpenGL (via ANGLE).
55 // The user_data received by the render callbacks refers to the
56 // FlutterWindowsEngine.
57 FlutterRendererConfig GetOpenGLRendererConfig() {
58  FlutterRendererConfig config = {};
59  config.type = kOpenGL;
60  config.open_gl.struct_size = sizeof(config.open_gl);
61  config.open_gl.make_current = [](void* user_data) -> bool {
62  auto host = static_cast<FlutterWindowsEngine*>(user_data);
63  if (!host->egl_manager()) {
64  return false;
65  }
66  return host->egl_manager()->render_context()->MakeCurrent();
67  };
68  config.open_gl.clear_current = [](void* user_data) -> bool {
69  auto host = static_cast<FlutterWindowsEngine*>(user_data);
70  if (!host->egl_manager()) {
71  return false;
72  }
73  return host->egl_manager()->render_context()->ClearCurrent();
74  };
75  config.open_gl.present = [](void* user_data) -> bool { FML_UNREACHABLE(); };
76  config.open_gl.fbo_reset_after_present = true;
77  config.open_gl.fbo_with_frame_info_callback =
78  [](void* user_data, const FlutterFrameInfo* info) -> uint32_t {
79  FML_UNREACHABLE();
80  };
81  config.open_gl.gl_proc_resolver = [](void* user_data,
82  const char* what) -> void* {
83  return reinterpret_cast<void*>(eglGetProcAddress(what));
84  };
85  config.open_gl.make_resource_current = [](void* user_data) -> bool {
86  auto host = static_cast<FlutterWindowsEngine*>(user_data);
87  if (!host->egl_manager()) {
88  return false;
89  }
90  return host->egl_manager()->resource_context()->MakeCurrent();
91  };
92  config.open_gl.gl_external_texture_frame_callback =
93  [](void* user_data, int64_t texture_id, size_t width, size_t height,
94  FlutterOpenGLTexture* texture) -> bool {
95  auto host = static_cast<FlutterWindowsEngine*>(user_data);
96  if (!host->texture_registrar()) {
97  return false;
98  }
99  return host->texture_registrar()->PopulateTexture(texture_id, width, height,
100  texture);
101  };
102  return config;
103 }
104 
105 // Creates and returns a FlutterRendererConfig that renders to the view (if any)
106 // of a FlutterWindowsEngine, using software rasterization.
107 // The user_data received by the render callbacks refers to the
108 // FlutterWindowsEngine.
109 FlutterRendererConfig GetSoftwareRendererConfig() {
110  FlutterRendererConfig config = {};
111  config.type = kSoftware;
112  config.software.struct_size = sizeof(config.software);
113  config.software.surface_present_callback =
114  [](void* user_data, const void* allocation, size_t row_bytes,
115  size_t height) {
116  FML_UNREACHABLE();
117  return false;
118  };
119  return config;
120 }
121 
122 // Converts a FlutterPlatformMessage to an equivalent FlutterDesktopMessage.
123 static FlutterDesktopMessage ConvertToDesktopMessage(
124  const FlutterPlatformMessage& engine_message) {
126  message.struct_size = sizeof(message);
127  message.channel = engine_message.channel;
128  message.message = engine_message.message;
129  message.message_size = engine_message.message_size;
130  message.response_handle = engine_message.response_handle;
131  return message;
132 }
133 
134 // Converts a LanguageInfo struct to a FlutterLocale struct. |info| must outlive
135 // the returned value, since the returned FlutterLocale has pointers into it.
136 FlutterLocale CovertToFlutterLocale(const LanguageInfo& info) {
137  FlutterLocale locale = {};
138  locale.struct_size = sizeof(FlutterLocale);
139  locale.language_code = info.language.c_str();
140  if (!info.region.empty()) {
141  locale.country_code = info.region.c_str();
142  }
143  if (!info.script.empty()) {
144  locale.script_code = info.script.c_str();
145  }
146  return locale;
147 }
148 
149 } // namespace
150 
152  const FlutterProjectBundle& project,
153  std::shared_ptr<WindowsProcTable> windows_proc_table)
154  : project_(std::make_unique<FlutterProjectBundle>(project)),
155  windows_proc_table_(std::move(windows_proc_table)),
156  aot_data_(nullptr, nullptr),
157  lifecycle_manager_(std::make_unique<WindowsLifecycleManager>(this)) {
158  if (windows_proc_table_ == nullptr) {
159  windows_proc_table_ = std::make_shared<WindowsProcTable>();
160  }
161 
162  gl_ = egl::ProcTable::Create();
163 
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 
192  texture_registrar_ =
193  std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_);
194 
195  // Check for impeller support.
196  auto& switches = project_->GetSwitches();
197  bool enable_impeller = true;
198  if (project_->impeller_switch() == FlutterImpellerSwitch::Enabled) {
199  enable_impeller = true;
200  } else if (project_->impeller_switch() == FlutterImpellerSwitch::Disabled) {
201  enable_impeller = false;
202  }
203  for (const auto& env_switch : switches) {
204  if (env_switch == "--enable-impeller" ||
205  env_switch == "--enable-impeller=true") {
206  enable_impeller = true;
207  } else if (env_switch == "--enable-impeller=false") {
208  enable_impeller = false;
209  }
210  }
211  enable_impeller_ = enable_impeller;
212 
213  // Only Impeller knows how to render into a top-left origin default
214  // framebuffer. The Skia path still expects OpenGL's bottom-left origin.
215  egl_manager_ = egl::Manager::Create(
216  static_cast<egl::GpuPreference>(project_->gpu_preference()),
217  /*allow_inverted_surface=*/enable_impeller_);
218  window_proc_delegate_manager_ = std::make_unique<WindowProcDelegateManager>();
219 
220  display_manager_ = std::make_shared<DisplayManagerWin32>(this);
221 
222  window_proc_delegate_manager_->RegisterTopLevelWindowProcDelegate(
223  [](HWND hwnd, UINT msg, WPARAM wpar, LPARAM lpar, void* user_data,
224  LRESULT* result) {
225  BASE_DCHECK(user_data);
226  FlutterWindowsEngine* that =
227  static_cast<FlutterWindowsEngine*>(user_data);
228 
229  BASE_DCHECK(that->display_manager_);
230  if (that->display_manager_->HandleWindowMessage(hwnd, msg, wpar, lpar,
231  result)) {
232  return true;
233  }
234 
235  BASE_DCHECK(that->lifecycle_manager_);
236  bool handled =
237  that->lifecycle_manager_->WindowProc(hwnd, msg, wpar, lpar, result);
238  if (handled) {
239  return true;
240  }
241  auto message_result =
242  that->window_manager_->HandleMessage(hwnd, msg, wpar, lpar);
243  if (message_result) {
244  *result = *message_result;
245  return true;
246  }
247  return false;
248  },
249  static_cast<void*>(this));
250 
251  // Set up internal channels.
252  // TODO: Replace this with an embedder.h API. See
253  // https://github.com/flutter/flutter/issues/71099
254  internal_plugin_registrar_ =
255  std::make_unique<PluginRegistrar>(plugin_registrar_.get());
256 
257  accessibility_plugin_ = std::make_unique<AccessibilityPlugin>(this);
258  AccessibilityPlugin::SetUp(messenger_wrapper_.get(),
259  accessibility_plugin_.get());
260 
261  cursor_handler_ =
262  std::make_unique<CursorHandler>(messenger_wrapper_.get(), this);
263  platform_handler_ =
264  std::make_unique<PlatformHandler>(messenger_wrapper_.get(), this);
265  window_manager_ = std::make_unique<WindowManager>(this);
266  settings_plugin_ = std::make_unique<SettingsPlugin>(messenger_wrapper_.get(),
267  task_runner_.get());
268 }
269 
270 FlutterWindowsEngine::~FlutterWindowsEngine() {
271  messenger_->SetEngine(nullptr);
272  Stop();
273 }
274 
275 FlutterWindowsEngine* FlutterWindowsEngine::GetEngineForId(int64_t engine_id) {
276  return reinterpret_cast<FlutterWindowsEngine*>(engine_id);
277 }
278 
279 void FlutterWindowsEngine::SetSwitches(
280  const std::vector<std::string>& switches) {
281  project_->SetSwitches(switches);
282 }
283 
284 bool FlutterWindowsEngine::Run() {
285  return Run("");
286 }
287 
288 bool FlutterWindowsEngine::Run(std::string_view entrypoint) {
289  if (!project_->HasValidPaths()) {
290  FML_LOG(ERROR) << "Missing or unresolvable paths to assets.";
291  return false;
292  }
293  std::string assets_path_string = fml::PathToUtf8(project_->assets_path());
294  std::string icu_path_string = fml::PathToUtf8(project_->icu_path());
295  if (embedder_api_.RunsAOTCompiledDartCode()) {
296  aot_data_ = project_->LoadAotData(embedder_api_);
297  if (!aot_data_) {
298  FML_LOG(ERROR) << "Unable to start engine without AOT data.";
299  return false;
300  }
301  }
302 
303  // FlutterProjectArgs is expecting a full argv, so when processing it for
304  // flags the first item is treated as the executable and ignored. Add a dummy
305  // value so that all provided arguments are used.
306  std::string executable_name = GetExecutableName();
307  std::vector<const char*> argv = {executable_name.c_str()};
308  std::vector<std::string> switches = project_->GetSwitches();
309  if (enable_impeller_) {
310  if (std::find(switches.begin(), switches.end(),
311  "--impeller-use-sdfs=true") == switches.end() &&
312  std::find(switches.begin(), switches.end(),
313  "--impeller-use-sdfs=false") == switches.end()) {
314  switches.push_back("--impeller-use-sdfs=true");
315  }
316  if (std::find(switches.begin(), switches.end(), "--enable-impeller") ==
317  switches.end() &&
318  std::find(switches.begin(), switches.end(), "--enable-impeller=true") ==
319  switches.end()) {
320  // Impeller was enabled programmatically, so forward the switch to the
321  // engine.
322  switches.push_back("--enable-impeller");
323  }
324  if (egl_manager_ && egl_manager_->surface_origin_is_top_left()) {
325  // ANGLE gave us a window surface with an inverted Y axis, so the default
326  // framebuffer is top-down. Tell Impeller so that it stores backing store
327  // contents in the same orientation and the presenting blit stays a
328  // straight copy.
329  switches.push_back("--impeller-top-left-default-framebuffer-origin");
330  }
331  } else if (project_->impeller_switch() == FlutterImpellerSwitch::Disabled) {
332  if (std::find(switches.begin(), switches.end(),
333  "--enable-impeller=false") == switches.end()) {
334  // Impeller was disabled programmatically, so forward the switch to the
335  // engine.
336  switches.push_back("--enable-impeller=false");
337  }
338  }
339  if (project_->enable_flutter_gpu()) {
340  if (std::find(switches.begin(), switches.end(), "--enable-flutter-gpu") ==
341  switches.end() &&
342  std::find(switches.begin(), switches.end(),
343  "--enable-flutter-gpu=true") == switches.end()) {
344  // Flutter GPU was enabled programmatically, so forward the switch to
345  // the engine.
346  switches.push_back("--enable-flutter-gpu");
347  }
348  }
349  std::transform(
350  switches.begin(), switches.end(), std::back_inserter(argv),
351  [](const std::string& arg) -> const char* { return arg.c_str(); });
352 
353  const std::vector<std::string>& entrypoint_args =
354  project_->dart_entrypoint_arguments();
355  std::vector<const char*> entrypoint_argv;
356  std::transform(
357  entrypoint_args.begin(), entrypoint_args.end(),
358  std::back_inserter(entrypoint_argv),
359  [](const std::string& arg) -> const char* { return arg.c_str(); });
360 
361  // Configure task runners.
362  FlutterTaskRunnerDescription platform_task_runner = {};
363  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
364  platform_task_runner.user_data = task_runner_.get();
365  platform_task_runner.runs_task_on_current_thread_callback =
366  [](void* user_data) -> bool {
367  return static_cast<TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
368  };
369  platform_task_runner.post_task_callback = [](FlutterTask task,
370  uint64_t target_time_nanos,
371  void* user_data) -> void {
372  static_cast<TaskRunner*>(user_data)->PostFlutterTask(task,
373  target_time_nanos);
374  };
375  FlutterCustomTaskRunners custom_task_runners = {};
376  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
377  custom_task_runners.platform_task_runner = &platform_task_runner;
378  custom_task_runners.thread_priority_setter =
380 
381  if (project_->ui_thread_policy() !=
383  custom_task_runners.ui_task_runner = &platform_task_runner;
384  } else {
385  FML_LOG(WARNING) << "Running with unmerged platform and UI threads. This "
386  "will be removed in future.";
387  }
388 
389  FlutterProjectArgs args = {};
390  args.struct_size = sizeof(FlutterProjectArgs);
391  args.shutdown_dart_vm_when_done = true;
392  args.assets_path = assets_path_string.c_str();
393  args.icu_data_path = icu_path_string.c_str();
394  args.command_line_argc = static_cast<int>(argv.size());
395  args.command_line_argv = argv.empty() ? nullptr : argv.data();
396  args.engine_id = reinterpret_cast<int64_t>(this);
397 
398  // Fail if conflicting non-default entrypoints are specified in the method
399  // argument and the project.
400  //
401  // TODO(cbracken): https://github.com/flutter/flutter/issues/109285
402  // The entrypoint method parameter should eventually be removed from this
403  // method and only the entrypoint specified in project_ should be used.
404  if (!project_->dart_entrypoint().empty() && !entrypoint.empty() &&
405  project_->dart_entrypoint() != entrypoint) {
406  FML_LOG(ERROR) << "Conflicting entrypoints were specified in "
407  "FlutterDesktopEngineProperties.dart_entrypoint and "
408  "FlutterDesktopEngineRun(engine, entry_point). ";
409  return false;
410  }
411  if (!entrypoint.empty()) {
412  args.custom_dart_entrypoint = entrypoint.data();
413  } else if (!project_->dart_entrypoint().empty()) {
414  args.custom_dart_entrypoint = project_->dart_entrypoint().c_str();
415  }
416  args.dart_entrypoint_argc = static_cast<int>(entrypoint_argv.size());
417  args.dart_entrypoint_argv =
418  entrypoint_argv.empty() ? nullptr : entrypoint_argv.data();
419  args.platform_message_callback =
420  [](const FlutterPlatformMessage* engine_message,
421  void* user_data) -> void {
422  auto host = static_cast<FlutterWindowsEngine*>(user_data);
423  return host->HandlePlatformMessage(engine_message);
424  };
425  args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
426  auto host = static_cast<FlutterWindowsEngine*>(user_data);
427  host->OnVsync(baton);
428  };
429  args.on_pre_engine_restart_callback = [](void* user_data) {
430  auto host = static_cast<FlutterWindowsEngine*>(user_data);
431  host->OnPreEngineRestart();
432  };
433  args.update_semantics_callback2 = [](const FlutterSemanticsUpdate2* update,
434  void* user_data) {
435  auto host = static_cast<FlutterWindowsEngine*>(user_data);
436 
437  auto view = host->view(update->view_id);
438  if (!view) {
439  return;
440  }
441 
442  auto accessibility_bridge = view->accessibility_bridge().lock();
443  if (!accessibility_bridge) {
444  return;
445  }
446 
447  for (size_t i = 0; i < update->node_count; i++) {
448  const FlutterSemanticsNode2* node = update->nodes[i];
449  accessibility_bridge->AddFlutterSemanticsNodeUpdate(*node);
450  }
451 
452  for (size_t i = 0; i < update->custom_action_count; i++) {
453  const FlutterSemanticsCustomAction2* action = update->custom_actions[i];
454  accessibility_bridge->AddFlutterSemanticsCustomActionUpdate(*action);
455  }
456 
457  accessibility_bridge->CommitUpdates();
458  };
459  args.root_isolate_create_callback = [](void* user_data) {
460  auto host = static_cast<FlutterWindowsEngine*>(user_data);
461  if (host->root_isolate_create_callback_) {
462  host->root_isolate_create_callback_();
463  }
464  };
465  args.channel_update_callback = [](const FlutterChannelUpdate* update,
466  void* user_data) {
467  auto host = static_cast<FlutterWindowsEngine*>(user_data);
468  if (SAFE_ACCESS(update, channel, nullptr) != nullptr) {
469  std::string channel_name(update->channel);
470  host->OnChannelUpdate(std::move(channel_name),
471  SAFE_ACCESS(update, listening, false));
472  }
473  };
474  args.view_focus_change_request_callback =
475  [](const FlutterViewFocusChangeRequest* request, void* user_data) {
476  auto host = static_cast<FlutterWindowsEngine*>(user_data);
477  host->OnViewFocusChangeRequest(request);
478  };
479 
480  args.custom_task_runners = &custom_task_runners;
481 
482  if (!platform_view_plugin_) {
483  platform_view_plugin_ = std::make_unique<PlatformViewPlugin>(
484  messenger_wrapper_.get(), task_runner_.get());
485  }
486  if (egl_manager_) {
487  auto resolver = [](const char* name) -> void* {
488  return reinterpret_cast<void*>(::eglGetProcAddress(name));
489  };
490 
491  // TODO(schectman) Pass the platform view manager to the compositor
492  // constructors: https://github.com/flutter/flutter/issues/143375
493  compositor_ =
494  std::make_unique<CompositorOpenGL>(this, resolver, enable_impeller_);
495  } else {
496  compositor_ = std::make_unique<CompositorSoftware>();
497  }
498 
499  FlutterCompositor compositor = {};
500  compositor.struct_size = sizeof(FlutterCompositor);
501  compositor.user_data = this;
502  compositor.create_backing_store_callback =
503  [](const FlutterBackingStoreConfig* config,
504  FlutterBackingStore* backing_store_out, void* user_data) -> bool {
505  auto host = static_cast<FlutterWindowsEngine*>(user_data);
506 
507  return host->compositor_->CreateBackingStore(*config, backing_store_out);
508  };
509 
510  compositor.collect_backing_store_callback =
511  [](const FlutterBackingStore* backing_store, void* user_data) -> bool {
512  auto host = static_cast<FlutterWindowsEngine*>(user_data);
513 
514  return host->compositor_->CollectBackingStore(backing_store);
515  };
516 
517  compositor.present_view_callback =
518  [](const FlutterPresentViewInfo* info) -> bool {
519  auto host = static_cast<FlutterWindowsEngine*>(info->user_data);
520 
521  return host->Present(info);
522  };
523  args.compositor = &compositor;
524 
525  if (aot_data_) {
526  args.aot_data = aot_data_.get();
527  }
528 
529  // The platform thread creates OpenGL contexts. These
530  // must be released to be used by the engine's threads.
531  FML_DCHECK(!egl_manager_ || !egl_manager_->HasContextCurrent());
532 
533  FlutterRendererConfig renderer_config;
534 
535  if (enable_impeller_) {
536  // Impeller does not support a Software backend. Avoid falling back and
537  // confusing the engine on which renderer is selected.
538  if (!egl_manager_) {
539  FML_LOG(ERROR) << "Could not create surface manager. Impeller backend "
540  "does not support software rendering.";
541  return false;
542  }
543  renderer_config = GetOpenGLRendererConfig();
544  } else {
545  renderer_config =
546  egl_manager_ ? GetOpenGLRendererConfig() : GetSoftwareRendererConfig();
547  }
548 
549  auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
550  &args, this, &engine_);
551  if (result != kSuccess || engine_ == nullptr) {
552  FML_LOG(ERROR) << "Failed to start Flutter engine: error " << result;
553  return false;
554  }
555 
556  display_manager_->UpdateDisplays();
557 
558  SendSystemLocales();
559 
560  settings_plugin_->StartWatching();
561  settings_plugin_->SendSettings();
562 
563  InitializeKeyboard();
564 
565  return true;
566 }
567 
568 bool FlutterWindowsEngine::Stop() {
569  if (engine_) {
570  window_manager_->OnEngineShutdown();
571  for (const auto& [callback, registrar] :
572  plugin_registrar_destruction_callbacks_) {
573  callback(registrar);
574  }
575  FlutterEngineResult result = embedder_api_.Shutdown(engine_);
576  engine_ = nullptr;
577  return (result == kSuccess);
578  }
579  return false;
580 }
581 
582 std::unique_ptr<FlutterWindowsView> FlutterWindowsEngine::CreateView(
583  std::unique_ptr<WindowBindingHandler> window,
584  bool is_sized_to_content,
585  const BoxConstraints& box_constraints,
586  bool allow_implicit_view,
587  FlutterWindowsViewSizingDelegate* sizing_delegate) {
588  if (!allow_implicit_view && next_view_id_ == kImplicitViewId) {
589  ++next_view_id_;
590  }
591 
592  auto view_id = next_view_id_;
593  auto view = std::make_unique<FlutterWindowsView>(
594  view_id, this, std::move(window), is_sized_to_content, box_constraints,
595  sizing_delegate, windows_proc_table_);
596 
597  view->CreateRenderSurface();
598  view->UpdateSemanticsEnabled(semantics_enabled_);
599 
600  next_view_id_++;
601 
602  {
603  // Add the view to the embedder. This must happen before the engine
604  // is notified the view exists and starts presenting to it.
605  std::unique_lock write_lock(views_mutex_);
606  FML_DCHECK(views_.find(view_id) == views_.end());
607  views_[view_id] = view.get();
608  }
609 
610  if (!view->IsImplicitView()) {
611  FML_DCHECK(running());
612 
613  struct Captures {
614  fml::AutoResetWaitableEvent latch;
615  bool added;
616  };
617  Captures captures = {};
618 
619  FlutterWindowMetricsEvent metrics = view->CreateWindowMetricsEvent();
620 
621  FlutterAddViewInfo info = {};
622  info.struct_size = sizeof(FlutterAddViewInfo);
623  info.view_id = view_id;
624  info.view_metrics = &metrics;
625  info.user_data = &captures;
626  info.add_view_callback = [](const FlutterAddViewResult* result) {
627  Captures* captures = reinterpret_cast<Captures*>(result->user_data);
628  captures->added = result->added;
629  captures->latch.Signal();
630  };
631 
632  FlutterEngineResult result = embedder_api_.AddView(engine_, &info);
633  if (result != kSuccess) {
634  FML_LOG(ERROR)
635  << "Starting the add view operation failed. FlutterEngineAddView "
636  "returned an unexpected result: "
637  << result << ". This indicates a bug in the Windows embedder.";
638  FML_DCHECK(false);
639  return nullptr;
640  }
641 
642  // Block the platform thread until the engine has added the view.
643  // TODO(loicsharma): This blocks the platform thread eagerly and can
644  // cause unnecessary delay in input processing. Instead, this should block
645  // lazily only when the app does an operation which needs the view.
646  // https://github.com/flutter/flutter/issues/146248
647  captures.latch.Wait();
648 
649  if (!captures.added) {
650  // Adding the view failed. Update the embedder's state to match the
651  // engine's state. This is unexpected and indicates a bug in the Windows
652  // embedder.
653  FML_LOG(ERROR) << "FlutterEngineAddView failed to add view";
654  std::unique_lock write_lock(views_mutex_);
655  views_.erase(view_id);
656  return nullptr;
657  }
658  }
659 
660  return std::move(view);
661 }
662 
663 void FlutterWindowsEngine::RemoveView(FlutterViewId view_id) {
664  FML_DCHECK(running());
665 
666  // Notify the engine to stop rendering to the view if it isn't the implicit
667  // view. The engine and framework assume the implicit view always exists and
668  // can continue presenting.
669  if (view_id != kImplicitViewId) {
670  struct Captures {
671  fml::AutoResetWaitableEvent latch;
672  bool removed;
673  };
674  Captures captures = {};
675 
676  FlutterRemoveViewInfo info = {};
677  info.struct_size = sizeof(FlutterRemoveViewInfo);
678  info.view_id = view_id;
679  info.user_data = &captures;
680  info.remove_view_callback = [](const FlutterRemoveViewResult* result) {
681  // This is invoked on an engine thread. If
682  // |FlutterRemoveViewResult.removed| is `true`, the engine guarantees the
683  // view won't be presented.
684  Captures* captures = reinterpret_cast<Captures*>(result->user_data);
685  captures->removed = result->removed;
686  captures->latch.Signal();
687  };
688 
689  FlutterEngineResult result = embedder_api_.RemoveView(engine_, &info);
690  if (result != kSuccess) {
691  FML_LOG(ERROR) << "Starting the remove view operation failed. "
692  "FlutterEngineRemoveView "
693  "returned an unexpected result: "
694  << result
695  << ". This indicates a bug in the Windows embedder.";
696  FML_DCHECK(false);
697  return;
698  }
699 
700  // Block the platform thread until the engine has removed the view.
701  // TODO(loicsharma): This blocks the platform thread eagerly and can
702  // cause unnecessary delay in input processing. Instead, this should block
703  // lazily only when an operation needs the view.
704  // https://github.com/flutter/flutter/issues/146248
705  captures.latch.Wait();
706 
707  if (!captures.removed) {
708  // Removing the view failed. This is unexpected and indicates a bug in the
709  // Windows embedder.
710  FML_LOG(ERROR) << "FlutterEngineRemoveView failed to remove view";
711  return;
712  }
713  }
714 
715  {
716  // The engine no longer presents to the view. Remove the view from the
717  // embedder.
718  std::unique_lock write_lock(views_mutex_);
719 
720  FML_DCHECK(views_.find(view_id) != views_.end());
721 
722  // Reset text input state if the removed view is the active text input
723  // view, to prevent stale view references.
724  if (text_input_plugin_) {
725  text_input_plugin_->OnViewRemoved(view_id);
726  }
727 
728  views_.erase(view_id);
729  }
730 }
731 
732 void FlutterWindowsEngine::OnVsync(intptr_t baton) {
733  std::chrono::nanoseconds current_time =
734  std::chrono::nanoseconds(embedder_api_.GetCurrentTime());
735  std::chrono::nanoseconds frame_interval = FrameInterval();
736  auto next = SnapToNextTick(current_time, start_time_, frame_interval);
737  embedder_api_.OnVsync(engine_, baton, next.count(),
738  (next + frame_interval).count());
739 }
740 
741 std::chrono::nanoseconds FlutterWindowsEngine::FrameInterval() {
742  if (frame_interval_override_.has_value()) {
743  return frame_interval_override_.value();
744  }
745  uint64_t interval = 16600000;
746 
747  DWM_TIMING_INFO timing_info = {};
748  timing_info.cbSize = sizeof(timing_info);
749  HRESULT result = DwmGetCompositionTimingInfo(NULL, &timing_info);
750  if (result == S_OK && timing_info.rateRefresh.uiDenominator > 0 &&
751  timing_info.rateRefresh.uiNumerator > 0) {
752  interval = static_cast<double>(timing_info.rateRefresh.uiDenominator *
753  1000000000.0) /
754  static_cast<double>(timing_info.rateRefresh.uiNumerator);
755  }
756 
757  return std::chrono::nanoseconds(interval);
758 }
759 
760 FlutterWindowsView* FlutterWindowsEngine::view(FlutterViewId view_id) const {
761  std::shared_lock read_lock(views_mutex_);
762 
763  auto iterator = views_.find(view_id);
764  if (iterator == views_.end()) {
765  return nullptr;
766  }
767 
768  return iterator->second;
769 }
770 
771 // Returns the currently configured Plugin Registrar.
772 FlutterDesktopPluginRegistrarRef FlutterWindowsEngine::GetRegistrar() {
773  return plugin_registrar_.get();
774 }
775 
776 void FlutterWindowsEngine::AddPluginRegistrarDestructionCallback(
779  plugin_registrar_destruction_callbacks_[callback] = registrar;
780 }
781 
782 void FlutterWindowsEngine::UpdateDisplay(
783  const std::vector<FlutterEngineDisplay>& displays) {
784  if (engine_) {
785  embedder_api_.NotifyDisplayUpdate(engine_,
786  kFlutterEngineDisplaysUpdateTypeStartup,
787  displays.data(), displays.size());
788  }
789 }
790 
791 void FlutterWindowsEngine::SendWindowMetricsEvent(
792  const FlutterWindowMetricsEvent& event) {
793  if (engine_) {
794  embedder_api_.SendWindowMetricsEvent(engine_, &event);
795  }
796 }
797 
798 void FlutterWindowsEngine::SendPointerEvent(const FlutterPointerEvent& event) {
799  if (engine_) {
800  embedder_api_.SendPointerEvent(engine_, &event, 1);
801  }
802 }
803 
804 void FlutterWindowsEngine::SendKeyEvent(const FlutterKeyEvent& event,
805  FlutterKeyEventCallback callback,
806  void* user_data) {
807  if (engine_) {
808  embedder_api_.SendKeyEvent(engine_, &event, callback, user_data);
809  }
810 }
811 
812 void FlutterWindowsEngine::SendViewFocusEvent(
813  const FlutterViewFocusEvent& event) {
814  if (engine_) {
815  embedder_api_.SendViewFocusEvent(engine_, &event);
816  }
817 }
818 
819 bool FlutterWindowsEngine::SendPlatformMessage(
820  const char* channel,
821  const uint8_t* message,
822  const size_t message_size,
823  const FlutterDesktopBinaryReply reply,
824  void* user_data) {
825  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
826  if (reply != nullptr && user_data != nullptr) {
827  FlutterEngineResult result =
828  embedder_api_.PlatformMessageCreateResponseHandle(
829  engine_, reply, user_data, &response_handle);
830  if (result != kSuccess) {
831  FML_LOG(ERROR) << "Failed to create response handle";
832  return false;
833  }
834  }
835 
836  FlutterPlatformMessage platform_message = {
837  sizeof(FlutterPlatformMessage),
838  channel,
839  message,
840  message_size,
841  response_handle,
842  };
843 
844  FlutterEngineResult message_result =
845  embedder_api_.SendPlatformMessage(engine_, &platform_message);
846  if (response_handle != nullptr) {
847  embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
848  response_handle);
849  }
850  return message_result == kSuccess;
851 }
852 
853 void FlutterWindowsEngine::SendPlatformMessageResponse(
855  const uint8_t* data,
856  size_t data_length) {
857  embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
858 }
859 
860 void FlutterWindowsEngine::HandlePlatformMessage(
861  const FlutterPlatformMessage* engine_message) {
862  if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
863  FML_LOG(ERROR) << "Invalid message size received. Expected: "
864  << sizeof(FlutterPlatformMessage) << " but received "
865  << engine_message->struct_size;
866  return;
867  }
868 
869  auto message = ConvertToDesktopMessage(*engine_message);
870 
871  message_dispatcher_->HandleMessage(message, [this] {}, [this] {});
872 }
873 
874 void FlutterWindowsEngine::ReloadSystemFonts() {
875  embedder_api_.ReloadSystemFonts(engine_);
876 }
877 
878 void FlutterWindowsEngine::ScheduleFrame() {
879  embedder_api_.ScheduleFrame(engine_);
880 }
881 
882 void FlutterWindowsEngine::SetNextFrameCallback(fml::closure callback) {
883  next_frame_callback_ = std::move(callback);
884 
885  embedder_api_.SetNextFrameCallback(
886  engine_,
887  [](void* user_data) {
888  // Embedder callback runs on raster thread. Switch back to platform
889  // thread.
890  FlutterWindowsEngine* self =
891  static_cast<FlutterWindowsEngine*>(user_data);
892 
893  self->task_runner_->PostTask(std::move(self->next_frame_callback_));
894  },
895  this);
896 }
897 
898 HCURSOR FlutterWindowsEngine::GetCursorByName(
899  const std::string& cursor_name) const {
900  static auto* cursors = new std::map<std::string, const wchar_t*>{
901  {"allScroll", IDC_SIZEALL},
902  {"basic", IDC_ARROW},
903  {"click", IDC_HAND},
904  {"forbidden", IDC_NO},
905  {"help", IDC_HELP},
906  {"move", IDC_SIZEALL},
907  {"none", nullptr},
908  {"noDrop", IDC_NO},
909  {"precise", IDC_CROSS},
910  {"progress", IDC_APPSTARTING},
911  {"text", IDC_IBEAM},
912  {"resizeColumn", IDC_SIZEWE},
913  {"resizeDown", IDC_SIZENS},
914  {"resizeDownLeft", IDC_SIZENESW},
915  {"resizeDownRight", IDC_SIZENWSE},
916  {"resizeLeft", IDC_SIZEWE},
917  {"resizeLeftRight", IDC_SIZEWE},
918  {"resizeRight", IDC_SIZEWE},
919  {"resizeRow", IDC_SIZENS},
920  {"resizeUp", IDC_SIZENS},
921  {"resizeUpDown", IDC_SIZENS},
922  {"resizeUpLeft", IDC_SIZENWSE},
923  {"resizeUpRight", IDC_SIZENESW},
924  {"resizeUpLeftDownRight", IDC_SIZENWSE},
925  {"resizeUpRightDownLeft", IDC_SIZENESW},
926  {"wait", IDC_WAIT},
927  };
928  const wchar_t* idc_name = IDC_ARROW;
929  auto it = cursors->find(cursor_name);
930  if (it != cursors->end()) {
931  idc_name = it->second;
932  }
933  return windows_proc_table_->LoadCursor(nullptr, idc_name);
934 }
935 
936 FlutterWindowsView* FlutterWindowsEngine::GetViewFromTopLevelWindow(
937  HWND hwnd) const {
938  std::shared_lock read_lock(views_mutex_);
939  auto const iterator =
940  std::find_if(views_.begin(), views_.end(), [hwnd](auto const& pair) {
941  FlutterWindowsView* const view = pair.second;
942  return GetAncestor(view->GetWindowHandle(), GA_ROOT) == hwnd;
943  });
944  if (iterator != views_.end()) {
945  return iterator->second;
946  }
947  return nullptr;
948 }
949 
950 void FlutterWindowsEngine::SendSystemLocales() {
951  std::vector<LanguageInfo> languages =
952  GetPreferredLanguageInfo(*windows_proc_table_);
953  std::vector<FlutterLocale> flutter_locales;
954  flutter_locales.reserve(languages.size());
955  for (const auto& info : languages) {
956  flutter_locales.push_back(CovertToFlutterLocale(info));
957  }
958  // Convert the locale list to the locale pointer list that must be provided.
959  std::vector<const FlutterLocale*> flutter_locale_list;
960  flutter_locale_list.reserve(flutter_locales.size());
961  std::transform(flutter_locales.begin(), flutter_locales.end(),
962  std::back_inserter(flutter_locale_list),
963  [](const auto& arg) -> const auto* { return &arg; });
964  embedder_api_.UpdateLocales(engine_, flutter_locale_list.data(),
965  flutter_locale_list.size());
966 }
967 
968 void FlutterWindowsEngine::InitializeKeyboard() {
969  auto internal_plugin_messenger = internal_plugin_registrar_->messenger();
970  KeyboardKeyEmbedderHandler::GetKeyStateHandler get_key_state = GetKeyState;
971  KeyboardKeyEmbedderHandler::MapVirtualKeyToScanCode map_vk_to_scan =
972  [](UINT virtual_key, bool extended) {
973  return MapVirtualKey(virtual_key,
974  extended ? MAPVK_VK_TO_VSC_EX : MAPVK_VK_TO_VSC);
975  };
976  keyboard_key_handler_ = std::move(CreateKeyboardKeyHandler(
977  internal_plugin_messenger, get_key_state, map_vk_to_scan));
978  text_input_plugin_ =
979  std::move(CreateTextInputPlugin(internal_plugin_messenger));
980 }
981 
982 std::unique_ptr<KeyboardHandlerBase>
983 FlutterWindowsEngine::CreateKeyboardKeyHandler(
984  BinaryMessenger* messenger,
987  auto keyboard_key_handler = std::make_unique<KeyboardKeyHandler>(messenger);
988  keyboard_key_handler->AddDelegate(
989  std::make_unique<KeyboardKeyEmbedderHandler>(
990  [this](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
991  void* user_data) {
992  return SendKeyEvent(event, callback, user_data);
993  },
994  get_key_state, map_vk_to_scan));
995  keyboard_key_handler->AddDelegate(
996  std::make_unique<KeyboardKeyChannelHandler>(messenger));
997  keyboard_key_handler->InitKeyboardChannel();
998  return keyboard_key_handler;
999 }
1000 
1001 std::unique_ptr<TextInputPlugin> FlutterWindowsEngine::CreateTextInputPlugin(
1002  BinaryMessenger* messenger) {
1003  return std::make_unique<TextInputPlugin>(messenger, this);
1004 }
1005 
1006 bool FlutterWindowsEngine::RegisterExternalTexture(int64_t texture_id) {
1007  return (embedder_api_.RegisterExternalTexture(engine_, texture_id) ==
1008  kSuccess);
1009 }
1010 
1011 bool FlutterWindowsEngine::UnregisterExternalTexture(int64_t texture_id) {
1012  return (embedder_api_.UnregisterExternalTexture(engine_, texture_id) ==
1013  kSuccess);
1014 }
1015 
1016 bool FlutterWindowsEngine::MarkExternalTextureFrameAvailable(
1017  int64_t texture_id) {
1018  return (embedder_api_.MarkExternalTextureFrameAvailable(
1019  engine_, texture_id) == kSuccess);
1020 }
1021 
1022 bool FlutterWindowsEngine::PostRasterThreadTask(fml::closure callback) const {
1023  struct Captures {
1024  fml::closure callback;
1025  };
1026  auto captures = new Captures();
1027  captures->callback = std::move(callback);
1028  if (embedder_api_.PostRenderThreadTask(
1029  engine_,
1030  [](void* opaque) {
1031  auto captures = reinterpret_cast<Captures*>(opaque);
1032  captures->callback();
1033  delete captures;
1034  },
1035  captures) == kSuccess) {
1036  return true;
1037  }
1038  delete captures;
1039  return false;
1040 }
1041 
1042 bool FlutterWindowsEngine::DispatchSemanticsAction(
1043  FlutterViewId view_id,
1044  uint64_t target,
1045  FlutterSemanticsAction action,
1046  fml::MallocMapping data) {
1047  FlutterSendSemanticsActionInfo info{
1048  .struct_size = sizeof(FlutterSendSemanticsActionInfo),
1049  .view_id = view_id,
1050  .node_id = target,
1051  .action = action,
1052  .data = data.GetMapping(),
1053  .data_length = data.GetSize(),
1054  };
1055  return (embedder_api_.SendSemanticsAction(engine_, &info));
1056 }
1057 
1058 void FlutterWindowsEngine::UpdateSemanticsEnabled(bool enabled) {
1059  if (engine_ && semantics_enabled_ != enabled) {
1060  std::shared_lock read_lock(views_mutex_);
1061 
1062  semantics_enabled_ = enabled;
1063  embedder_api_.UpdateSemanticsEnabled(engine_, enabled);
1064  for (auto iterator = views_.begin(); iterator != views_.end(); iterator++) {
1065  iterator->second->UpdateSemanticsEnabled(enabled);
1066  }
1067  }
1068 }
1069 
1070 void FlutterWindowsEngine::OnPreEngineRestart() {
1071  // Reset the keyboard's state on hot restart.
1072  InitializeKeyboard();
1073  window_manager_->OnPreEngineRestart();
1074 }
1075 
1076 std::string FlutterWindowsEngine::GetExecutableName() const {
1077  std::pair<bool, std::string> result = fml::paths::GetExecutablePath();
1078  if (result.first) {
1079  const std::string& executable_path = result.second;
1080  size_t last_separator = executable_path.find_last_of("/\\");
1081  if (last_separator == std::string::npos ||
1082  last_separator == executable_path.size() - 1) {
1083  return executable_path;
1084  }
1085  return executable_path.substr(last_separator + 1);
1086  }
1087  return "Flutter";
1088 }
1089 
1090 void FlutterWindowsEngine::UpdateAccessibilityFeatures() {
1091  UpdateHighContrastMode();
1092 }
1093 
1094 void FlutterWindowsEngine::UpdateHighContrastMode() {
1095  high_contrast_enabled_ = windows_proc_table_->GetHighContrastEnabled();
1096 
1097  SendAccessibilityFeatures();
1098  settings_plugin_->UpdateHighContrastMode(high_contrast_enabled_);
1099 }
1100 
1101 void FlutterWindowsEngine::SendAccessibilityFeatures() {
1102  int flags = 0;
1103 
1104  if (high_contrast_enabled_) {
1105  flags |=
1106  FlutterAccessibilityFeature::kFlutterAccessibilityFeatureHighContrast;
1107  }
1108 
1109  embedder_api_.UpdateAccessibilityFeatures(
1110  engine_, static_cast<FlutterAccessibilityFeature>(flags));
1111 }
1112 
1113 void FlutterWindowsEngine::RequestApplicationQuit(HWND hwnd,
1114  WPARAM wparam,
1115  LPARAM lparam,
1116  AppExitType exit_type) {
1117  platform_handler_->RequestAppExit(hwnd, wparam, lparam, exit_type, 0);
1118 }
1119 
1120 void FlutterWindowsEngine::OnQuit(std::optional<HWND> hwnd,
1121  std::optional<WPARAM> wparam,
1122  std::optional<LPARAM> lparam,
1123  UINT exit_code) {
1124  lifecycle_manager_->Quit(hwnd, wparam, lparam, exit_code);
1125 }
1126 
1127 void FlutterWindowsEngine::OnDwmCompositionChanged() {
1128  if (display_manager_) {
1129  display_manager_->UpdateDisplays();
1130  }
1131 
1132  std::shared_lock read_lock(views_mutex_);
1133  for (auto iterator = views_.begin(); iterator != views_.end(); iterator++) {
1134  iterator->second->OnDwmCompositionChanged();
1135  }
1136 }
1137 
1138 void FlutterWindowsEngine::OnWindowStateEvent(HWND hwnd,
1139  WindowStateEvent event) {
1140  lifecycle_manager_->OnWindowStateEvent(hwnd, event);
1141 }
1142 
1143 std::optional<LRESULT> FlutterWindowsEngine::ProcessExternalWindowMessage(
1144  HWND hwnd,
1145  UINT message,
1146  WPARAM wparam,
1147  LPARAM lparam) {
1148  if (lifecycle_manager_) {
1149  return lifecycle_manager_->ExternalWindowMessage(hwnd, message, wparam,
1150  lparam);
1151  }
1152  return std::nullopt;
1153 }
1154 
1155 void FlutterWindowsEngine::UpdateFlutterCursor(
1156  const std::string& cursor_name) const {
1157  SetFlutterCursor(GetCursorByName(cursor_name));
1158 }
1159 
1160 void FlutterWindowsEngine::SetFlutterCursor(HCURSOR cursor) const {
1161  windows_proc_table_->SetCursor(cursor);
1162 }
1163 
1164 void FlutterWindowsEngine::OnChannelUpdate(std::string name, bool listening) {
1165  if (name == "flutter/platform" && listening) {
1166  lifecycle_manager_->BeginProcessingExit();
1167  } else if (name == "flutter/lifecycle" && listening) {
1168  lifecycle_manager_->BeginProcessingLifecycle();
1169  }
1170 }
1171 
1172 void FlutterWindowsEngine::OnViewFocusChangeRequest(
1173  const FlutterViewFocusChangeRequest* request) {
1174  std::shared_lock read_lock(views_mutex_);
1175 
1176  auto iterator = views_.find(request->view_id);
1177  if (iterator == views_.end()) {
1178  return;
1179  }
1180 
1181  FlutterWindowsView* view = iterator->second;
1182  view->Focus();
1183 }
1184 
1185 bool FlutterWindowsEngine::Present(const FlutterPresentViewInfo* info) {
1186  // This runs on the raster thread. Lock the views map for the entirety of the
1187  // present operation to block the platform thread from destroying the
1188  // view during the present.
1189  std::shared_lock read_lock(views_mutex_);
1190 
1191  auto iterator = views_.find(info->view_id);
1192  if (iterator == views_.end()) {
1193  return false;
1194  }
1195 
1196  FlutterWindowsView* view = iterator->second;
1197 
1198  return compositor_->Present(view, info->layers, info->layers_count);
1199 }
1200 
1201 bool FlutterWindowsEngine::HandleDisplayMonitorMessage(HWND hwnd,
1202  UINT message,
1203  WPARAM wparam,
1204  LPARAM lparam,
1205  LRESULT* result) {
1206  if (!display_manager_) {
1207  return false;
1208  }
1209 
1210  return display_manager_->HandleWindowMessage(hwnd, message, wparam, lparam,
1211  result);
1212 }
1213 
1214 } // namespace flutter
static void SetUp(BinaryMessenger *binary_messenger, AccessibilityPlugin *plugin)
FlutterWindowsEngine(const FlutterProjectBundle &project, std::shared_ptr< WindowsProcTable > windows_proc_table=nullptr)
FlutterWindowsView * view(FlutterViewId view_id) const
virtual void OnViewFocusChangeRequest(const FlutterViewFocusChangeRequest *request)
void HandlePlatformMessage(const FlutterPlatformMessage *)
void SetSwitches(const std::vector< std::string > &switches)
std::weak_ptr< AccessibilityBridgeWindows > accessibility_bridge()
std::function< SHORT(UINT, bool)> MapVirtualKeyToScanCode
static std::unique_ptr< Manager > Create(GpuPreference gpu_preference, bool allow_inverted_surface, std::optional< D3DFeatureLevel > max_feature_level=std::nullopt)
Definition: manager.cc:61
static std::shared_ptr< ProcTable > Create()
Definition: proc_table.cc:12
uint32_t texture_id
const char * name
std::vector< FlutterEngineDisplay > * displays
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
struct _FlutterPlatformMessageResponseHandle FlutterDesktopMessageResponseHandle
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
@ RunOnSeparateThread
static constexpr char kAccessibilityChannelName[]
FlutterDesktopBinaryReply callback
Win32Message message
std::vector< LanguageInfo > GetPreferredLanguageInfo(const WindowsProcTable &windows_proc_table)
Definition: system_utils.cc:15
WindowStateEvent
An event representing a change in window state that may update the.
int64_t FlutterViewId
static void WindowsPlatformThreadPrioritySetter(FlutterThreadPriority priority)
constexpr FlutterViewId kImplicitViewId