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

#include <flutter_window_controller.h>

Inheritance diagram for flutter::FlutterWindowController:
flutter::PluginRegistry

Public Member Functions

 FlutterWindowController (const std::string &icu_data_path)
 
virtual ~FlutterWindowController ()
 
 FlutterWindowController (FlutterWindowController const &)=delete
 
FlutterWindowControlleroperator= (FlutterWindowController const &)=delete
 
bool CreateWindow (const WindowProperties &window_properties, const std::string &assets_path, const std::vector< std::string > &arguments, const std::string &aot_library_path="")
 
void DestroyWindow ()
 
FlutterWindowwindow ()
 
bool RunEventLoopWithTimeout (std::chrono::milliseconds timeout=std::chrono::milliseconds::max())
 
void RunEventLoop ()
 
FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin (const std::string &plugin_name) override
 
- 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
 

Detailed Description

Definition at line 44 of file flutter_window_controller.h.

Constructor & Destructor Documentation

◆ FlutterWindowController() [1/2]

flutter::FlutterWindowController::FlutterWindowController ( const std::string &  icu_data_path)
explicit

Definition at line 12 of file flutter_window_controller.cc.

14 : icu_data_path_(icu_data_path) {
15 init_succeeded_ = FlutterDesktopInit();
16}
bool FlutterDesktopInit()

◆ ~FlutterWindowController()

flutter::FlutterWindowController::~FlutterWindowController ( )
virtual

Definition at line 18 of file flutter_window_controller.cc.

18 {
19 if (controller_) {
20 FlutterDesktopDestroyWindow(controller_);
21 }
22 if (init_succeeded_) {
24 }
25}
void FlutterDesktopDestroyWindow(FlutterDesktopWindowControllerRef controller)
void FlutterDesktopTerminate()

◆ FlutterWindowController() [2/2]

flutter::FlutterWindowController::FlutterWindowController ( FlutterWindowController const &  )
delete

Member Function Documentation

◆ CreateWindow()

bool flutter::FlutterWindowController::CreateWindow ( const WindowProperties window_properties,
const std::string &  assets_path,
const std::vector< std::string > &  arguments,
const std::string &  aot_library_path = "" 
)

Definition at line 27 of file flutter_window_controller.cc.

31 {
32 if (!init_succeeded_) {
33 std::cerr << "Could not create window; FlutterDesktopInit failed."
34 << std::endl;
35 return false;
36 }
37
38 if (controller_) {
39 std::cerr << "Only one Flutter window can exist at a time." << std::endl;
40 return false;
41 }
42
43 FlutterDesktopWindowProperties c_window_properties = {};
44 c_window_properties.title = window_properties.title.c_str();
45 c_window_properties.width = window_properties.width;
46 c_window_properties.height = window_properties.height;
47 c_window_properties.prevent_resize = window_properties.prevent_resize;
48
49 FlutterDesktopEngineProperties c_engine_properties = {};
50 c_engine_properties.assets_path = assets_path.c_str();
51 c_engine_properties.aot_library_path = aot_library_path.c_str();
52 c_engine_properties.icu_data_path = icu_data_path_.c_str();
53 std::vector<const char*> engine_switches;
55 arguments.begin(), arguments.end(), std::back_inserter(engine_switches),
56 [](const std::string& arg) -> const char* { return arg.c_str(); });
57 if (!engine_switches.empty()) {
58 c_engine_properties.switches = &engine_switches[0];
59 c_engine_properties.switches_count = engine_switches.size();
60 }
61
62 controller_ =
63 FlutterDesktopCreateWindow(c_window_properties, c_engine_properties);
64 if (!controller_) {
65 std::cerr << "Failed to create window." << std::endl;
66 return false;
67 }
68 window_ =
69 std::make_unique<FlutterWindow>(FlutterDesktopGetWindow(controller_));
70 return true;
71}
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow(const FlutterDesktopWindowProperties &window_properties, const FlutterDesktopEngineProperties &engine_properties)
FlutterDesktopWindowRef FlutterDesktopGetWindow(FlutterDesktopWindowControllerRef controller)

◆ DestroyWindow()

void flutter::FlutterWindowController::DestroyWindow ( )

Definition at line 73 of file flutter_window_controller.cc.

73 {
74 if (controller_) {
75 FlutterDesktopDestroyWindow(controller_);
76 controller_ = nullptr;
77 window_ = nullptr;
78 }
79}

◆ GetRegistrarForPlugin()

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

Implements flutter::PluginRegistry.

Definition at line 81 of file flutter_window_controller.cc.

82 {
83 if (!controller_) {
84 std::cerr << "Cannot get plugin registrar without a window; call "
85 "CreateWindow first."
86 << std::endl;
87 return nullptr;
88 }
90 plugin_name.c_str());
91}
FlutterDesktopEngineRef FlutterDesktopGetEngine(FlutterDesktopWindowControllerRef controller)
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(FlutterDesktopEngineRef engine, const char *plugin_name)

◆ operator=()

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

◆ RunEventLoop()

void flutter::FlutterWindowController::RunEventLoop ( )

Definition at line 118 of file flutter_window_controller.cc.

118 {
119 while (RunEventLoopWithTimeout()) {
120 }
121}
bool RunEventLoopWithTimeout(std::chrono::milliseconds timeout=std::chrono::milliseconds::max())

◆ RunEventLoopWithTimeout()

bool flutter::FlutterWindowController::RunEventLoopWithTimeout ( std::chrono::milliseconds  timeout = std::chrono::milliseconds::max())

Definition at line 93 of file flutter_window_controller.cc.

94 {
95 if (!controller_) {
96 std::cerr << "Cannot run event loop without a window window; call "
97 "CreateWindow first."
98 << std::endl;
99 return false;
100 }
101 uint32_t timeout_milliseconds;
103 // The C API uses 0 to represent no timeout, so convert |max| to 0.
104 timeout_milliseconds = 0;
105 } else if (timeout.count() > UINT32_MAX) {
106 timeout_milliseconds = UINT32_MAX;
107 } else {
108 timeout_milliseconds = static_cast<uint32_t>(timeout.count());
109 }
111 controller_, timeout_milliseconds);
112 if (!still_running) {
114 }
115 return still_running;
116}
static float max(float r, float g, float b)
Definition: hsl.cpp:49
def timeout(deadline, cmd)
bool FlutterDesktopRunWindowEventLoopWithTimeout(FlutterDesktopWindowControllerRef controller, uint32_t millisecond_timeout)

◆ window()

FlutterWindow * flutter::FlutterWindowController::window ( )
inline

Definition at line 88 of file flutter_window_controller.h.

88{ return window_.get(); }

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