Flutter Engine
flutter::FlutterWindowsEngine Class Reference

#include <flutter_windows_engine.h>

Public Member Functions

 FlutterWindowsEngine (const FlutterProjectBundle &project)
 
virtual ~FlutterWindowsEngine ()
 
 FlutterWindowsEngine (FlutterWindowsEngine const &)=delete
 
FlutterWindowsEngineoperator= (FlutterWindowsEngine const &)=delete
 
bool RunWithEntrypoint (const char *entrypoint)
 
bool running ()
 
bool Stop ()
 
void SetView (FlutterWindowsView *view)
 
FlutterWindowsViewview ()
 
FlutterDesktopPluginRegistrarRef GetRegistrar ()
 
void SetPluginRegistrarDestructionCallback (FlutterDesktopOnPluginRegistrarDestroyed callback)
 
void SetSwitches (const std::vector< std::string > &switches)
 
FlutterDesktopMessengerRef messenger ()
 
IncomingMessageDispatchermessage_dispatcher ()
 
TaskRunnertask_runner ()
 
FlutterWindowsTextureRegistrartexture_registrar ()
 
AngleSurfaceManagersurface_manager ()
 
WindowProcDelegateManagerWin32window_proc_delegate_manager ()
 
void SendWindowMetricsEvent (const FlutterWindowMetricsEvent &event)
 
void SendPointerEvent (const FlutterPointerEvent &event)
 
void SendKeyEvent (const FlutterKeyEvent &event, FlutterKeyEventCallback callback, void *user_data)
 
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 ReloadPlatformBrightness ()
 
bool RegisterExternalTexture (int64_t texture_id)
 
bool UnregisterExternalTexture (int64_t texture_id)
 
bool MarkExternalTextureFrameAvailable (int64_t texture_id)
 

Friends

class EngineModifier
 

Detailed Description

Definition at line 38 of file flutter_windows_engine.h.

Constructor & Destructor Documentation

◆ FlutterWindowsEngine() [1/2]

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

Definition at line 139 of file flutter_windows_engine.cc.

References flutter::AngleSurfaceManager::Create(), flutter::TaskRunner::Create(), FlutterEngineGetProcAddresses(), FlutterEngineProcTable::GetCurrentTime, flutter::JsonMessageCodec::GetInstance(), if(), flutter::kSuccess, flutter::FlutterWindowsTextureRegistrar::ResolveGlFunctions(), FlutterEngineProcTable::RunTask, and FlutterEngineProcTable::struct_size.

140  : project_(std::make_unique<FlutterProjectBundle>(project)),
141  aot_data_(nullptr, nullptr) {
142  embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
143  FlutterEngineGetProcAddresses(&embedder_api_);
144 
145  task_runner_ = TaskRunner::Create(
146  GetCurrentThreadId(), embedder_api_.GetCurrentTime,
147  [this](const auto* task) {
148  if (!engine_) {
149  std::cerr << "Cannot post an engine task when engine is not running."
150  << std::endl;
151  return;
152  }
153  if (embedder_api_.RunTask(engine_, task) != kSuccess) {
154  std::cerr << "Failed to post an engine task." << std::endl;
155  }
156  });
157 
158  // Set up the legacy structs backing the API handles.
159  messenger_ = std::make_unique<FlutterDesktopMessenger>();
160  messenger_->engine = this;
161  plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
162  plugin_registrar_->engine = this;
163 
164  messenger_wrapper_ = std::make_unique<BinaryMessengerImpl>(messenger_.get());
165  message_dispatcher_ =
166  std::make_unique<IncomingMessageDispatcher>(messenger_.get());
167 
169  texture_registrar_ =
170  std::make_unique<FlutterWindowsTextureRegistrar>(this, gl_procs_);
171  surface_manager_ = AngleSurfaceManager::Create();
172 #ifndef WINUWP
173  window_proc_delegate_manager_ =
174  std::make_unique<WindowProcDelegateManagerWin32>();
175 #endif
176 
177  // Set up internal channels.
178  // TODO: Replace this with an embedder.h API. See
179  // https://github.com/flutter/flutter/issues/71099
180  settings_channel_ =
181  std::make_unique<BasicMessageChannel<rapidjson::Document>>(
182  messenger_wrapper_.get(), "flutter/settings",
184 }
if(match !=nullptr)
Definition: fl_engine.cc:79
static std::unique_ptr< AngleSurfaceManager > Create()
FlutterEngineGetCurrentTimeFnPtr GetCurrentTime
Definition: embedder.h:2405
FlutterEngineRunTaskFnPtr RunTask
Definition: embedder.h:2406
Function-pointer-based versions of the APIs above.
Definition: embedder.h:2372
size_t struct_size
The size of this struct. Must be sizeof(FlutterEngineProcs).
Definition: embedder.h:2374
static std::unique_ptr< TaskRunner > Create(DWORD main_thread_id, CurrentTimeProc get_current_time, const TaskExpiredCallback &on_task_expired)
FlutterEngineResult FlutterEngineGetProcAddresses(FlutterEngineProcTable *table)
Gets the table of engine function pointers.
Definition: embedder.cc:2291
static const JsonMessageCodec & GetInstance()

◆ ~FlutterWindowsEngine()

flutter::FlutterWindowsEngine::~FlutterWindowsEngine ( )
virtual

Definition at line 186 of file flutter_windows_engine.cc.

References Stop().

186  {
187  Stop();
188 }

◆ FlutterWindowsEngine() [2/2]

flutter::FlutterWindowsEngine::FlutterWindowsEngine ( FlutterWindowsEngine const &  )
delete

Member Function Documentation

◆ GetRegistrar()

FlutterDesktopPluginRegistrarRef flutter::FlutterWindowsEngine::GetRegistrar ( )

Definition at line 308 of file flutter_windows_engine.cc.

Referenced by FlutterDesktopEngineGetPluginRegistrar(), and view().

308  {
309  return plugin_registrar_.get();
310 }

◆ HandlePlatformMessage()

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

Definition at line 379 of file flutter_windows_engine.cc.

References ConvertToDesktopMessage(), and FlutterPlatformMessage::struct_size.

Referenced by RunWithEntrypoint(), and window_proc_delegate_manager().

380  {
381  if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
382  std::cerr << "Invalid message size received. Expected: "
383  << sizeof(FlutterPlatformMessage) << " but received "
384  << engine_message->struct_size << std::endl;
385  return;
386  }
387 
388  auto message = ConvertToDesktopMessage(*engine_message);
389 
390  message_dispatcher_->HandleMessage(
391  message, [this] {}, [this] {});
392 }
static FlutterDesktopMessage ConvertToDesktopMessage(const FlutterPlatformMessage &engine_message)
size_t struct_size
The size of this struct. Must be sizeof(FlutterPlatformMessage).
Definition: embedder.h:757

◆ MarkExternalTextureFrameAvailable()

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

Definition at line 441 of file flutter_windows_engine.cc.

References flutter::kSuccess, and FlutterEngineProcTable::MarkExternalTextureFrameAvailable.

Referenced by window_proc_delegate_manager().

442  {
443  return (embedder_api_.MarkExternalTextureFrameAvailable(
444  engine_, texture_id) == kSuccess);
445 }
int64_t texture_id
FlutterEngineMarkExternalTextureFrameAvailableFnPtr MarkExternalTextureFrameAvailable
Definition: embedder.h:2395

◆ message_dispatcher()

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

Definition at line 82 of file flutter_windows_engine.h.

82  {
83  return message_dispatcher_.get();
84  }

◆ messenger()

FlutterDesktopMessengerRef flutter::FlutterWindowsEngine::messenger ( )
inline

Definition at line 80 of file flutter_windows_engine.h.

Referenced by FlutterDesktopEngineGetMessenger().

80 { return messenger_.get(); }

◆ operator=()

FlutterWindowsEngine& flutter::FlutterWindowsEngine::operator= ( FlutterWindowsEngine const &  )
delete

◆ RegisterExternalTexture()

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

Definition at line 431 of file flutter_windows_engine.cc.

References flutter::kSuccess, and FlutterEngineProcTable::RegisterExternalTexture.

Referenced by window_proc_delegate_manager().

431  {
432  return (embedder_api_.RegisterExternalTexture(engine_, texture_id) ==
433  kSuccess);
434 }
FlutterEngineRegisterExternalTextureFnPtr RegisterExternalTexture
Definition: embedder.h:2392
int64_t texture_id

◆ ReloadPlatformBrightness()

void flutter::FlutterWindowsEngine::ReloadPlatformBrightness ( )

◆ ReloadSystemFonts()

void flutter::FlutterWindowsEngine::ReloadSystemFonts ( )

Definition at line 394 of file flutter_windows_engine.cc.

References FlutterEngineProcTable::ReloadSystemFonts.

Referenced by FlutterDesktopEngineReloadSystemFonts(), and window_proc_delegate_manager().

394  {
395  embedder_api_.ReloadSystemFonts(engine_);
396 }
FlutterEngineReloadSystemFontsFnPtr ReloadSystemFonts
Definition: embedder.h:2400

◆ running()

bool flutter::FlutterWindowsEngine::running ( )
inline

Definition at line 56 of file flutter_windows_engine.h.

References SetView(), Stop(), and view().

Referenced by FlutterDesktopEngineDestroy().

56 { return engine_ != nullptr; }

◆ RunWithEntrypoint()

bool flutter::FlutterWindowsEngine::RunWithEntrypoint ( const char *  entrypoint)

Definition at line 195 of file flutter_windows_engine.cc.

References FlutterProjectArgs::aot_data, args, FlutterProjectArgs::assets_path, FlutterProjectArgs::command_line_argc, FlutterProjectArgs::command_line_argv, FlutterProjectArgs::custom_dart_entrypoint, FlutterProjectArgs::custom_task_runners, FlutterProjectArgs::dart_entrypoint_argc, FlutterProjectArgs::dart_entrypoint_argv, FLUTTER_ENGINE_VERSION, HandlePlatformMessage(), FlutterProjectArgs::icu_data_path, flutter::kSuccess, FlutterProjectArgs::on_pre_engine_restart_callback, flutter::FlutterWindowsView::OnPreEngineRestart(), FlutterProjectArgs::platform_message_callback, FlutterCustomTaskRunners::platform_task_runner, result, FlutterEngineProcTable::Run, FlutterEngineProcTable::RunsAOTCompiledDartCode, FlutterTaskRunnerDescription::struct_size, FlutterCustomTaskRunners::struct_size, FlutterProjectArgs::struct_size, flutter::transform, user_data, and view().

Referenced by FlutterDesktopEngineRun().

195  {
196  if (!project_->HasValidPaths()) {
197  std::cerr << "Missing or unresolvable paths to assets." << std::endl;
198  return false;
199  }
200  std::string assets_path_string = project_->assets_path().u8string();
201  std::string icu_path_string = project_->icu_path().u8string();
202  if (embedder_api_.RunsAOTCompiledDartCode()) {
203  aot_data_ = project_->LoadAotData(embedder_api_);
204  if (!aot_data_) {
205  std::cerr << "Unable to start engine without AOT data." << std::endl;
206  return false;
207  }
208  }
209 
210  // FlutterProjectArgs is expecting a full argv, so when processing it for
211  // flags the first item is treated as the executable and ignored. Add a dummy
212  // value so that all provided arguments are used.
213  std::vector<std::string> switches = project_->GetSwitches();
214  std::vector<const char*> argv = {"placeholder"};
216  switches.begin(), switches.end(), std::back_inserter(argv),
217  [](const std::string& arg) -> const char* { return arg.c_str(); });
218 
219  const std::vector<std::string>& entrypoint_args =
220  project_->dart_entrypoint_arguments();
221  std::vector<const char*> entrypoint_argv;
223  entrypoint_args.begin(), entrypoint_args.end(),
224  std::back_inserter(entrypoint_argv),
225  [](const std::string& arg) -> const char* { return arg.c_str(); });
226 
227  // Configure task runners.
228  FlutterTaskRunnerDescription platform_task_runner = {};
229  platform_task_runner.struct_size = sizeof(FlutterTaskRunnerDescription);
230  platform_task_runner.user_data = task_runner_.get();
231  platform_task_runner.runs_task_on_current_thread_callback =
232  [](void* user_data) -> bool {
233  return static_cast<TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
234  };
235  platform_task_runner.post_task_callback = [](FlutterTask task,
236  uint64_t target_time_nanos,
237  void* user_data) -> void {
238  static_cast<TaskRunner*>(user_data)->PostFlutterTask(task,
239  target_time_nanos);
240  };
241  FlutterCustomTaskRunners custom_task_runners = {};
242  custom_task_runners.struct_size = sizeof(FlutterCustomTaskRunners);
243  custom_task_runners.platform_task_runner = &platform_task_runner;
244 
246  args.struct_size = sizeof(FlutterProjectArgs);
247  args.assets_path = assets_path_string.c_str();
248  args.icu_data_path = icu_path_string.c_str();
249  args.command_line_argc = static_cast<int>(argv.size());
250  args.command_line_argv = argv.size() > 0 ? argv.data() : nullptr;
251  args.dart_entrypoint_argc = static_cast<int>(entrypoint_argv.size());
252  args.dart_entrypoint_argv =
253  entrypoint_argv.size() > 0 ? entrypoint_argv.data() : nullptr;
255  [](const FlutterPlatformMessage* engine_message,
256  void* user_data) -> void {
257  auto host = static_cast<FlutterWindowsEngine*>(user_data);
258  return host->HandlePlatformMessage(engine_message);
259  };
260  args.on_pre_engine_restart_callback = [](void* user_data) {
261  auto host = static_cast<FlutterWindowsEngine*>(user_data);
262  host->view()->OnPreEngineRestart();
263  };
264 
265  args.custom_task_runners = &custom_task_runners;
266 
267  if (aot_data_) {
268  args.aot_data = aot_data_.get();
269  }
270  if (entrypoint) {
271  args.custom_dart_entrypoint = entrypoint;
272  }
273 
274  FlutterRendererConfig renderer_config = surface_manager_
275  ? GetOpenGLRendererConfig()
276  : GetSoftwareRendererConfig();
277 
278  auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
279  &args, this, &engine_);
280  if (result != kSuccess || engine_ == nullptr) {
281  std::cerr << "Failed to start Flutter engine: error " << result
282  << std::endl;
283  return false;
284  }
285 
286  SendSystemSettings();
287 
288  return true;
289 }
G_BEGIN_DECLS FlValue * args
FlutterEngineRunsAOTCompiledDartCodeFnPtr RunsAOTCompiledDartCode
Definition: embedder.h:2408
const char * icu_data_path
Definition: embedder.h:1378
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:913
const FlutterCustomTaskRunners * custom_task_runners
Definition: embedder.h:1493
OnPreEngineRestartCallback on_pre_engine_restart_callback
Definition: embedder.h:1591
void * user_data
GAsyncResult * result
FlutterWindowsEngine(const FlutterProjectBundle &project)
FlutterPlatformMessageCallback platform_message_callback
Definition: embedder.h:1402
const char *const * command_line_argv
Definition: embedder.h:1396
FlutterEngineRunFnPtr Run
Definition: embedder.h:2378
const char *const * dart_entrypoint_argv
Definition: embedder.h:1566
#define FLUTTER_ENGINE_VERSION
Definition: embedder.h:63
const char * custom_dart_entrypoint
Definition: embedder.h:1488
const char * assets_path
Definition: embedder.h:1354
size_t struct_size
The size of this struct. Must be sizeof(FlutterProjectArgs).
Definition: embedder.h:1350
const FlutterTaskRunnerDescription * platform_task_runner
Definition: embedder.h:943
FlutterEngineAOTData aot_data
Definition: embedder.h:1543
size_t struct_size
The size of this struct. Must be sizeof(FlutterCustomTaskRunners).
Definition: embedder.h:938
int command_line_argc
The command line argument count used to initialize the project.
Definition: embedder.h:1380

◆ SendKeyEvent()

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

Definition at line 330 of file flutter_windows_engine.cc.

References FlutterEngineProcTable::SendKeyEvent.

Referenced by window_proc_delegate_manager().

332  {
333  if (engine_) {
334  embedder_api_.SendKeyEvent(engine_, &event, callback, user_data);
335  }
336 }
void * user_data
FlutterEngineSendKeyEventFnPtr SendKeyEvent
Definition: embedder.h:2385
FlKeyEvent FlKeyResponderAsyncCallback callback

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

References flutter::kSuccess, FlutterEngineProcTable::PlatformMessageCreateResponseHandle, FlutterEngineProcTable::PlatformMessageReleaseResponseHandle, result, and FlutterEngineProcTable::SendPlatformMessage.

Referenced by window_proc_delegate_manager().

343  {
344  FlutterPlatformMessageResponseHandle* response_handle = nullptr;
345  if (reply != nullptr && user_data != nullptr) {
348  engine_, reply, user_data, &response_handle);
349  if (result != kSuccess) {
350  std::cout << "Failed to create response handle\n";
351  return false;
352  }
353  }
354 
355  FlutterPlatformMessage platform_message = {
356  sizeof(FlutterPlatformMessage),
357  channel,
358  message,
359  message_size,
360  response_handle,
361  };
362 
363  FlutterEngineResult message_result =
364  embedder_api_.SendPlatformMessage(engine_, &platform_message);
365  if (response_handle != nullptr) {
366  embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
367  response_handle);
368  }
369  return message_result == kSuccess;
370 }
void * user_data
FlutterEngineSendPlatformMessageFnPtr SendPlatformMessage
Definition: embedder.h:2386
GAsyncResult * result
FlutterEnginePlatformMessageCreateResponseHandleFnPtr PlatformMessageCreateResponseHandle
Definition: embedder.h:2388
FlutterEnginePlatformMessageReleaseResponseHandleFnPtr PlatformMessageReleaseResponseHandle
Definition: embedder.h:2390
FlutterEngineResult
Definition: embedder.h:65

◆ SendPlatformMessageResponse()

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

Definition at line 372 of file flutter_windows_engine.cc.

References FlutterEngineProcTable::SendPlatformMessageResponse.

Referenced by window_proc_delegate_manager().

375  {
376  embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
377 }
FlutterEngineSendPlatformMessageResponseFnPtr SendPlatformMessageResponse
Definition: embedder.h:2391

◆ SendPointerEvent()

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

Definition at line 324 of file flutter_windows_engine.cc.

References FlutterEngineProcTable::SendPointerEvent.

Referenced by window_proc_delegate_manager().

324  {
325  if (engine_) {
326  embedder_api_.SendPointerEvent(engine_, &event, 1);
327  }
328 }
FlutterEngineSendPointerEventFnPtr SendPointerEvent
Definition: embedder.h:2384

◆ SendWindowMetricsEvent()

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

Definition at line 317 of file flutter_windows_engine.cc.

References FlutterEngineProcTable::SendWindowMetricsEvent.

Referenced by window_proc_delegate_manager().

318  {
319  if (engine_) {
320  embedder_api_.SendWindowMetricsEvent(engine_, &event);
321  }
322 }
FlutterEngineSendWindowMetricsEventFnPtr SendWindowMetricsEvent
Definition: embedder.h:2383

◆ SetPluginRegistrarDestructionCallback()

void flutter::FlutterWindowsEngine::SetPluginRegistrarDestructionCallback ( FlutterDesktopOnPluginRegistrarDestroyed  callback)

Definition at line 312 of file flutter_windows_engine.cc.

References callback.

Referenced by view().

313  {
314  plugin_registrar_destruction_callback_ = callback;
315 }
FlKeyEvent FlKeyResponderAsyncCallback callback

◆ SetSwitches()

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

Definition at line 190 of file flutter_windows_engine.cc.

Referenced by view().

191  {
192  project_->SetSwitches(switches);
193 }

◆ SetView()

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

Definition at line 303 of file flutter_windows_engine.cc.

References view().

Referenced by running().

303  {
304  view_ = view;
305 }

◆ Stop()

bool flutter::FlutterWindowsEngine::Stop ( )

Definition at line 291 of file flutter_windows_engine.cc.

References flutter::kSuccess, result, and FlutterEngineProcTable::Shutdown.

Referenced by FlutterDesktopEngineDestroy(), running(), and ~FlutterWindowsEngine().

291  {
292  if (engine_) {
293  if (plugin_registrar_destruction_callback_) {
294  plugin_registrar_destruction_callback_(plugin_registrar_.get());
295  }
296  FlutterEngineResult result = embedder_api_.Shutdown(engine_);
297  engine_ = nullptr;
298  return (result == kSuccess);
299  }
300  return false;
301 }
GAsyncResult * result
FlutterEngineShutdownFnPtr Shutdown
Definition: embedder.h:2379
FlutterEngineResult
Definition: embedder.h:65

◆ surface_manager()

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

Definition at line 94 of file flutter_windows_engine.h.

94 { return surface_manager_.get(); }

◆ task_runner()

◆ texture_registrar()

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

Definition at line 88 of file flutter_windows_engine.h.

88  {
89  return texture_registrar_.get();
90  }

◆ UnregisterExternalTexture()

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

Definition at line 436 of file flutter_windows_engine.cc.

References flutter::kSuccess, and FlutterEngineProcTable::UnregisterExternalTexture.

Referenced by window_proc_delegate_manager().

436  {
437  return (embedder_api_.UnregisterExternalTexture(engine_, texture_id) ==
438  kSuccess);
439 }
int64_t texture_id
FlutterEngineUnregisterExternalTextureFnPtr UnregisterExternalTexture
Definition: embedder.h:2393

◆ view()

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

Definition at line 68 of file flutter_windows_engine.h.

References callback, GetRegistrar(), SetPluginRegistrarDestructionCallback(), and SetSwitches().

Referenced by running(), RunWithEntrypoint(), and SetView().

68 { return view_; }

◆ window_proc_delegate_manager()

Friends And Related Function Documentation

◆ EngineModifier

friend class EngineModifier
friend

Definition at line 149 of file flutter_windows_engine.h.


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