Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
flutter::FlutterEngine Class Reference

#include <flutter_engine.h>

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

Public Member Functions

 FlutterEngine ()
 
virtual ~FlutterEngine ()
 
 FlutterEngine (FlutterEngine const &)=delete
 
FlutterEngineoperator= (FlutterEngine const &)=delete
 
bool Start (const std::string &icu_data_path, const std::string &assets_path, const std::vector< std::string > &arguments, const std::string &aot_library_path="")
 
void ShutDown ()
 
void RunEventLoopWithTimeout (std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
 
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name) override
 
 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< LRESULTProcessExternalWindowMessage (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
 
virtual FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name)=0
 

Friends

class FlutterViewController
 

Detailed Description

Definition at line 21 of file flutter_engine.h.

Constructor & Destructor Documentation

◆ FlutterEngine() [1/4]

FlutterEngine::FlutterEngine ( )
explicit

Definition at line 12 of file flutter_engine.cc.

12{}

◆ ~FlutterEngine() [1/2]

FlutterEngine::~FlutterEngine ( )
virtual

Definition at line 14 of file flutter_engine.cc.

14{}

◆ FlutterEngine() [2/4]

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

◆ FlutterEngine() [3/4]

FlutterEngine::FlutterEngine ( const DartProject project)
explicit

Definition at line 14 of file flutter_engine.cc.

14 {
15 FlutterDesktopEngineProperties c_engine_properties = {};
16 c_engine_properties.assets_path = project.assets_path().c_str();
17 c_engine_properties.icu_data_path = project.icu_data_path().c_str();
18 c_engine_properties.aot_library_path = project.aot_library_path().c_str();
19 c_engine_properties.dart_entrypoint = project.dart_entrypoint().c_str();
20
21 const std::vector<std::string>& entrypoint_args =
22 project.dart_entrypoint_arguments();
23 std::vector<const char*> entrypoint_argv;
25 entrypoint_args.begin(), entrypoint_args.end(),
26 std::back_inserter(entrypoint_argv),
27 [](const std::string& arg) -> const char* { return arg.c_str(); });
28
29 c_engine_properties.dart_entrypoint_argc =
30 static_cast<int>(entrypoint_argv.size());
31 c_engine_properties.dart_entrypoint_argv =
32 entrypoint_argv.empty() ? nullptr : entrypoint_argv.data();
33
34 engine_ = FlutterDesktopEngineCreate(&c_engine_properties);
35
36 auto core_messenger = FlutterDesktopEngineGetMessenger(engine_);
37 messenger_ = std::make_unique<BinaryMessengerImpl>(core_messenger);
38}
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
FlutterDesktopEngineRef FlutterDesktopEngineCreate(const FlutterDesktopEngineProperties *engine_properties)
FlutterDesktopMessengerRef FlutterDesktopEngineGetMessenger(FlutterDesktopEngineRef engine)

◆ ~FlutterEngine() [2/2]

virtual flutter::FlutterEngine::~FlutterEngine ( )
virtual

◆ FlutterEngine() [4/4]

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

Member Function Documentation

◆ GetRegistrarForPlugin() [1/2]

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

Implements flutter::PluginRegistry.

Definition at line 53 of file flutter_engine.cc.

54 {
55 if (!engine_) {
56 std::cerr << "Cannot get plugin registrar on an engine that isn't running; "
57 "call Run first."
58 << std::endl;
59 return nullptr;
60 }
61 return FlutterDesktopGetPluginRegistrar(engine_.get(), plugin_name.c_str());
62}
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)

◆ GetRegistrarForPlugin() [2/2]

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

◆ messenger()

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

Definition at line 80 of file flutter_engine.h.

80{ return messenger_.get(); }

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ ProcessExternalWindowMessage()

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

Definition at line 103 of file flutter_engine.cc.

107 {
110 engine_, hwnd, message, wparam, lparam, &result)) {
111 return result;
112 }
113 return std::nullopt;
114}
GAsyncResult * result
Win32Message message
bool FlutterDesktopEngineProcessExternalWindowMessage(FlutterDesktopEngineRef engine, HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam, LRESULT *result)
LONG_PTR LRESULT
Definition: windows_types.h:61

◆ ProcessMessages()

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

Definition at line 72 of file flutter_engine.cc.

72 {
73 return std::chrono::nanoseconds(FlutterDesktopEngineProcessMessages(engine_));
74}
uint64_t FlutterDesktopEngineProcessMessages(FlutterDesktopEngineRef engine)

◆ ReloadPlatformBrightness()

void flutter::FlutterEngine::ReloadPlatformBrightness ( )

◆ ReloadSystemFonts()

void FlutterEngine::ReloadSystemFonts ( )

Definition at line 76 of file flutter_engine.cc.

76 {
78}
void FlutterDesktopEngineReloadSystemFonts(FlutterDesktopEngineRef engine)

◆ Run() [1/2]

bool FlutterEngine::Run ( )

Definition at line 44 of file flutter_engine.cc.

44 {
45 return Run(nullptr);
46}

◆ Run() [2/2]

bool FlutterEngine::Run ( const char *  entry_point)

Definition at line 48 of file flutter_engine.cc.

48 {
49 if (!engine_) {
50 std::cerr << "Cannot run an engine that failed creation." << std::endl;
51 return false;
52 }
53 if (run_succeeded_) {
54 std::cerr << "Cannot run an engine more than once." << std::endl;
55 return false;
56 }
57 bool run_succeeded = FlutterDesktopEngineRun(engine_, entry_point);
58 if (!run_succeeded) {
59 std::cerr << "Failed to start engine." << std::endl;
60 }
61 run_succeeded_ = true;
62 return run_succeeded;
63}
bool FlutterDesktopEngineRun(FlutterDesktopEngineRef engine, const char *entry_point)

◆ RunEventLoopWithTimeout()

void FlutterEngine::RunEventLoopWithTimeout ( std::chrono::milliseconds  timeout = std::chrono::milliseconds::max())

Definition at line 64 of file flutter_engine.cc.

64 {
65 if (!engine_) {
66 std::cerr << "Cannot run event loop without a running engine; call "
67 "Run first."
68 << std::endl;
69 return;
70 }
71 uint32_t timeout_milliseconds;
73 // The C API uses 0 to represent no timeout, so convert |max| to 0.
74 timeout_milliseconds = 0;
75 } else if (timeout.count() > UINT32_MAX) {
76 timeout_milliseconds = UINT32_MAX;
77 } else {
78 timeout_milliseconds = static_cast<uint32_t>(timeout.count());
79 }
81 timeout_milliseconds);
82}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
def timeout(deadline, cmd)
void FlutterDesktopRunEngineEventLoopWithTimeout(FlutterDesktopEngineRef engine, uint32_t timeout_milliseconds)

◆ SetNextFrameCallback()

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

Definition at line 91 of file flutter_engine.cc.

91 {
92 next_frame_callback_ = std::move(callback);
94 engine_,
95 [](void* user_data) {
96 FlutterEngine* self = static_cast<FlutterEngine*>(user_data);
97 self->next_frame_callback_();
98 self->next_frame_callback_ = nullptr;
99 },
100 this);
101}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void FlutterDesktopEngineSetNextFrameCallback(FlutterDesktopEngineRef engine, VoidCallback callback, void *user_data)
void * user_data

◆ ShutDown() [1/2]

void FlutterEngine::ShutDown ( )

Definition at line 49 of file flutter_engine.cc.

49 {
50 engine_ = nullptr;
51}

◆ ShutDown() [2/2]

void flutter::FlutterEngine::ShutDown ( )

◆ Start()

bool FlutterEngine::Start ( const std::string &  icu_data_path,
const std::string &  assets_path,
const std::vector< std::string > &  arguments,
const std::string &  aot_library_path = "" 
)

Definition at line 16 of file flutter_engine.cc.

19 {
20 if (engine_) {
21 std::cerr << "Cannot run an already running engine. Create a new instance "
22 "or call ShutDown first."
23 << std::endl;
24 return false;
25 }
26
27 FlutterDesktopEngineProperties c_engine_properties = {};
28 c_engine_properties.assets_path = assets_path.c_str();
29 c_engine_properties.icu_data_path = icu_data_path.c_str();
30 c_engine_properties.aot_library_path = aot_library_path.c_str();
31 std::vector<const char*> engine_switches;
33 arguments.begin(), arguments.end(), std::back_inserter(engine_switches),
34 [](const std::string& arg) -> const char* { return arg.c_str(); });
35 if (!engine_switches.empty()) {
36 c_engine_properties.switches = &engine_switches[0];
37 c_engine_properties.switches_count = engine_switches.size();
38 }
39
40 engine_ = UniqueEnginePtr(FlutterDesktopRunEngine(c_engine_properties),
42 if (!engine_) {
43 std::cerr << "Failed to start engine." << std::endl;
44 return false;
45 }
46 return true;
47}
bool FlutterDesktopShutDownEngine(FlutterDesktopEngineRef engine_ref)
FlutterDesktopEngineRef FlutterDesktopRunEngine(const FlutterDesktopEngineProperties &properties)

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: