Flutter Windows Embedder
flutter::FlutterEngine Class Reference

#include <flutter_engine.h>

Inheritance diagram for flutter::FlutterEngine:
flutter::PluginRegistry

Public Member Functions

 FlutterEngine (const DartProject &project)
 
virtual ~FlutterEngine ()
 
 FlutterEngine (FlutterEngine const &)=delete
 
FlutterEngineoperator= (FlutterEngine const &)=delete
 
bool Run ()
 
bool Run (const char *entry_point)
 
void ShutDown ()
 
std::chrono::nanoseconds ProcessMessages ()
 
void ReloadSystemFonts ()
 
void ReloadPlatformBrightness ()
 
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name) override
 
BinaryMessengermessenger ()
 
void SetNextFrameCallback (std::function< void()> callback)
 
std::optional< LRESULT > ProcessExternalWindowMessage (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
 
- Public Member Functions inherited from flutter::PluginRegistry
 PluginRegistry ()=default
 
virtual ~PluginRegistry ()=default
 
 PluginRegistry (PluginRegistry const &)=delete
 
PluginRegistryoperator= (PluginRegistry const &)=delete
 

Friends

class FlutterViewController
 

Detailed Description

Definition at line 28 of file flutter_engine.h.

Constructor & Destructor Documentation

◆ FlutterEngine() [1/2]

flutter::FlutterEngine::FlutterEngine ( const DartProject project)
explicit

Definition at line 15 of file flutter_engine.cc.

15  {
16  FlutterDesktopEngineProperties c_engine_properties = {};
17  c_engine_properties.assets_path = project.assets_path().c_str();
18  c_engine_properties.icu_data_path = project.icu_data_path().c_str();
19  c_engine_properties.aot_library_path = project.aot_library_path().c_str();
20  c_engine_properties.dart_entrypoint = project.dart_entrypoint().c_str();
21  c_engine_properties.gpu_preference =
22  static_cast<FlutterDesktopGpuPreference>(project.gpu_preference());
23  c_engine_properties.ui_thread_policy =
24  static_cast<FlutterDesktopUIThreadPolicy>(project.ui_thread_policy());
25 
26  const std::vector<std::string>& entrypoint_args =
27  project.dart_entrypoint_arguments();
28  std::vector<const char*> entrypoint_argv;
29  std::transform(
30  entrypoint_args.begin(), entrypoint_args.end(),
31  std::back_inserter(entrypoint_argv),
32  [](const std::string& arg) -> const char* { return arg.c_str(); });
33 
34  c_engine_properties.dart_entrypoint_argc =
35  static_cast<int>(entrypoint_argv.size());
36  c_engine_properties.dart_entrypoint_argv =
37  entrypoint_argv.empty() ? nullptr : entrypoint_argv.data();
38 
39  engine_ = FlutterDesktopEngineCreate(&c_engine_properties);
40 
41  auto core_messenger = FlutterDesktopEngineGetMessenger(engine_);
42  messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
43 }

References FlutterDesktopEngineProperties::aot_library_path, FlutterDesktopEngineProperties::assets_path, flutter::DartProject::dart_entrypoint(), FlutterDesktopEngineProperties::dart_entrypoint, FlutterDesktopEngineProperties::dart_entrypoint_argc, flutter::DartProject::dart_entrypoint_arguments(), FlutterDesktopEngineProperties::dart_entrypoint_argv, FlutterDesktopEngineCreate(), FlutterDesktopEngineGetMessenger(), FlutterDesktopEngineProperties::gpu_preference, flutter::DartProject::gpu_preference(), FlutterDesktopEngineProperties::icu_data_path, FlutterDesktopEngineProperties::ui_thread_policy, and flutter::DartProject::ui_thread_policy().

◆ ~FlutterEngine()

flutter::FlutterEngine::~FlutterEngine ( )
virtual

Definition at line 45 of file flutter_engine.cc.

45  {
46  ShutDown();
47 }

References ShutDown().

◆ FlutterEngine() [2/2]

flutter::FlutterEngine::FlutterEngine ( FlutterEngine const &  )
delete

Member Function Documentation

◆ GetRegistrarForPlugin()

FlutterDesktopPluginRegistrarRef flutter::FlutterEngine::GetRegistrarForPlugin ( const std::string &  plugin_name)
overridevirtual

Implements flutter::PluginRegistry.

Definition at line 85 of file flutter_engine.cc.

86  {
87  if (!engine_) {
88  std::cerr << "Cannot get plugin registrar on an engine that isn't running; "
89  "call Run first."
90  << std::endl;
91  return nullptr;
92  }
93  return FlutterDesktopEngineGetPluginRegistrar(engine_, plugin_name.c_str());
94 }

References FlutterDesktopEngineGetPluginRegistrar().

◆ messenger()

BinaryMessenger* flutter::FlutterEngine::messenger ( )
inline

Definition at line 80 of file flutter_engine.h.

80 { return messenger_.get(); }

Referenced by flutter::TEST().

◆ operator=()

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

◆ ProcessExternalWindowMessage()

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

Definition at line 108 of file flutter_engine.cc.

112  {
113  LRESULT result;
115  engine_, hwnd, message, wparam, lparam, &result)) {
116  return result;
117  }
118  return std::nullopt;
119 }

References FlutterDesktopEngineProcessExternalWindowMessage(), and message.

Referenced by flutter::TEST().

◆ ProcessMessages()

std::chrono::nanoseconds flutter::FlutterEngine::ProcessMessages ( )

Definition at line 77 of file flutter_engine.cc.

77  {
78  return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_));
79 }

References FlutterDesktopEngineProcessMessages().

Referenced by flutter::TEST().

◆ ReloadPlatformBrightness()

void flutter::FlutterEngine::ReloadPlatformBrightness ( )

◆ ReloadSystemFonts()

void flutter::FlutterEngine::ReloadSystemFonts ( )

Definition at line 81 of file flutter_engine.cc.

81  {
83 }

References FlutterDesktopEngineReloadSystemFonts().

Referenced by flutter::TEST().

◆ Run() [1/2]

bool flutter::FlutterEngine::Run ( )

Definition at line 49 of file flutter_engine.cc.

49  {
50  return Run(nullptr);
51 }

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

◆ Run() [2/2]

bool flutter::FlutterEngine::Run ( const char *  entry_point)

Definition at line 53 of file flutter_engine.cc.

53  {
54  if (!engine_) {
55  std::cerr << "Cannot run an engine that failed creation." << std::endl;
56  return false;
57  }
58  if (run_succeeded_) {
59  std::cerr << "Cannot run an engine more than once." << std::endl;
60  return false;
61  }
62  bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
63  if (!run_succeeded) {
64  std::cerr << "Failed to start engine." << std::endl;
65  }
66  run_succeeded_ = true;
67  return run_succeeded;
68 }

References FlutterDesktopEngineRun().

◆ SetNextFrameCallback()

void flutter::FlutterEngine::SetNextFrameCallback ( std::function< void()>  callback)

Definition at line 96 of file flutter_engine.cc.

96  {
97  next_frame_callback_ = std::move(callback);
99  engine_,
100  [](void* user_data) {
101  FlutterEngine* self = static_cast<FlutterEngine*>(user_data);
102  self->next_frame_callback_();
103  self->next_frame_callback_ = nullptr;
104  },
105  this);
106 }

References callback, FlutterDesktopEngineSetNextFrameCallback(), and user_data.

Referenced by flutter::TEST().

◆ ShutDown()

void flutter::FlutterEngine::ShutDown ( )

Definition at line 70 of file flutter_engine.cc.

70  {
71  if (engine_ && owns_engine_) {
73  }
74  engine_ = nullptr;
75 }

References FlutterDesktopEngineDestroy().

Referenced by flutter::TEST(), and ~FlutterEngine().

Friends And Related Function Documentation

◆ FlutterViewController

friend class FlutterViewController
friend

Definition at line 99 of file flutter_engine.h.


The documentation for this class was generated from the following files:
FlutterDesktopEngineProperties::aot_library_path
const wchar_t * aot_library_path
Definition: flutter_windows.h:75
FlutterDesktopEngineGetMessenger
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:234
FlutterDesktopEngineProperties
Definition: flutter_windows.h:60
FlutterDesktopGpuPreference
FlutterDesktopGpuPreference
Definition: flutter_windows.h:39
user_data
void * user_data
Definition: flutter_windows_view_unittests.cc:53
FlutterDesktopEngineProperties::dart_entrypoint_argv
const char ** dart_entrypoint_argv
Definition: flutter_windows.h:90
FlutterDesktopEngineProperties::icu_data_path
const wchar_t * icu_data_path
Definition: flutter_windows.h:69
FlutterDesktopEngineProcessExternalWindowMessage
bool FlutterDesktopEngineProcessExternalWindowMessage(FlutterDesktopEngineRef engine, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
Definition: flutter_windows.cc:272
FlutterDesktopEngineGetPluginRegistrar
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)
Definition: flutter_windows.cc:224
FlutterDesktopEngineProperties::dart_entrypoint
const char * dart_entrypoint
Definition: flutter_windows.h:83
FlutterDesktopEngineProperties::gpu_preference
FlutterDesktopGpuPreference gpu_preference
Definition: flutter_windows.h:93
flutter::FlutterEngine::Run
bool Run()
Definition: flutter_engine.cc:49
flutter::FlutterEngine::ShutDown
void ShutDown()
Definition: flutter_engine.cc:70
FlutterDesktopEngineProcessMessages
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:216
FlutterDesktopEngineDestroy
bool FlutterDesktopEngineDestroy(FlutterDesktopEngineRef engine_ref)
Definition: flutter_windows.cc:190
FlutterDesktopEngineCreate
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
Definition: flutter_windows.cc:183
FlutterDesktopEngineProperties::dart_entrypoint_argc
int dart_entrypoint_argc
Definition: flutter_windows.h:86
FlutterDesktopEngineProperties::ui_thread_policy
FlutterDesktopUIThreadPolicy ui_thread_policy
Definition: flutter_windows.h:96
message
Win32Message message
Definition: keyboard_unittests.cc:137
FlutterDesktopEngineSetNextFrameCallback
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
Definition: flutter_windows.cc:245
FlutterDesktopUIThreadPolicy
FlutterDesktopUIThreadPolicy
Definition: flutter_windows.h:49
FlutterDesktopEngineProperties::assets_path
const wchar_t * assets_path
Definition: flutter_windows.h:64
FlutterDesktopEngineRun
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)
Definition: flutter_windows.cc:206
flutter::FlutterEngine::FlutterEngine
FlutterEngine(const DartProject &project)
Definition: flutter_engine.cc:15
FlutterDesktopEngineReloadSystemFonts
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)
Definition: flutter_windows.cc:220
callback
FlutterDesktopBinaryReply callback
Definition: flutter_windows_view_unittests.cc:52