55
66#include " flutter_tizen_engine.h"
77
8- #include < filesystem >
8+ #include < algorithm >
99#include < string>
1010#include < vector>
1111
@@ -33,7 +33,9 @@ constexpr double kProfileFactor = 1.0;
3333
3434} // namespace
3535
36- FlutterTizenEngine::FlutterTizenEngine (bool headed) {
36+ FlutterTizenEngine::FlutterTizenEngine (const FlutterProjectBundle& project)
37+ : project_(std::make_unique<FlutterProjectBundle>(project)),
38+ aot_data_ (nullptr , nullptr ) {
3739 embedder_api_.struct_size = sizeof (FlutterEngineProcTable);
3840 FlutterEngineGetProcAddresses (&embedder_api_);
3941
@@ -55,19 +57,20 @@ FlutterTizenEngine::FlutterTizenEngine(bool headed) {
5557
5658 plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
5759 plugin_registrar_->engine = this ;
58-
59- if (headed) {
60- InitializeRenderer ();
61- }
6260}
6361
6462FlutterTizenEngine::~FlutterTizenEngine () {
6563 renderer = nullptr ;
6664}
6765
68- void FlutterTizenEngine::InitializeRenderer () {
66+ void FlutterTizenEngine::InitializeRenderer (int32_t x,
67+ int32_t y,
68+ int32_t width,
69+ int32_t height) {
70+ TizenRenderer::WindowGeometry geometry = {x, y, width, height};
71+
6972#ifdef TIZEN_RENDERER_EVAS_GL
70- renderer = std::make_unique<TizenRendererEvasGL>(*this );
73+ renderer = std::make_unique<TizenRendererEvasGL>(geometry, *this );
7174
7275 render_loop_ = std::make_unique<TizenRenderEventLoop>(
7376 std::this_thread::get_id (), // main thread
@@ -78,7 +81,7 @@ void FlutterTizenEngine::InitializeRenderer() {
7881 },
7982 renderer.get ());
8083#else
81- renderer = std::make_unique<TizenRendererEcoreWl2>(*this );
84+ renderer = std::make_unique<TizenRendererEcoreWl2>(geometry, *this );
8285
8386 tizen_vsync_waiter_ = std::make_unique<TizenVsyncWaiter>(this );
8487#endif
@@ -88,52 +91,42 @@ void FlutterTizenEngine::NotifyLowMemoryWarning() {
8891 embedder_api_.NotifyLowMemoryWarning (engine_);
8992}
9093
91- // Attempts to load AOT data from the given path, which must be absolute and
92- // non-empty. Logs and returns nullptr on failure.
93- UniqueAotDataPtr FlutterTizenEngine::LoadAotData (std::string aot_data_path) {
94- if (aot_data_path.empty ()) {
95- FT_LOGE (
96- " Attempted to load AOT data, but no aot_library_path was provided." );
97- return nullptr ;
98- }
99- if (!std::filesystem::exists (aot_data_path)) {
100- FT_LOGE (" Can't load AOT data from %s; no such file." ,
101- aot_data_path.c_str ());
102- return nullptr ;
103- }
104- FlutterEngineAOTDataSource source = {};
105- source.type = kFlutterEngineAOTDataSourceTypeElfPath ;
106- source.elf_path = aot_data_path.c_str ();
107- FlutterEngineAOTData data = nullptr ;
108- auto result = embedder_api_.CreateAOTData (&source, &data);
109- if (result != kSuccess ) {
110- FT_LOGE (" Failed to load AOT data from: %s" , aot_data_path.c_str ());
111- return nullptr ;
94+ bool FlutterTizenEngine::RunEngine () {
95+ if (engine_ != nullptr ) {
96+ FT_LOGE (" The engine has already started." );
97+ return false ;
11298 }
113- return UniqueAotDataPtr (data);
114- }
115-
116- bool FlutterTizenEngine::RunEngine (
117- const FlutterDesktopEngineProperties& engine_properties) {
11899 if (IsHeaded () && !renderer->IsValid ()) {
119100 FT_LOGE (" The display was not valid." );
120101 return false ;
121102 }
122103
104+ if (!project_->HasValidPaths ()) {
105+ FT_LOGE (" Missing or unresolvable paths to assets." );
106+ return false ;
107+ }
108+ std::string assets_path_string = project_->assets_path ().u8string ();
109+ std::string icu_path_string = project_->icu_path ().u8string ();
110+ if (embedder_api_.RunsAOTCompiledDartCode ()) {
111+ aot_data_ = project_->LoadAotData (embedder_api_);
112+ if (!aot_data_) {
113+ FT_LOGE (" Unable to start engine without AOT data." );
114+ return false ;
115+ }
116+ }
117+
123118 // FlutterProjectArgs is expecting a full argv, so when processing it for
124119 // flags the first item is treated as the executable and ignored. Add a dummy
125120 // value so that all provided arguments are used.
121+ std::vector<std::string> switches = project_->switches ();
126122 std::vector<const char *> argv = {" placeholder" };
127- if (engine_properties.switches_count > 0 ) {
128- argv.insert (argv.end (), &engine_properties.switches [0 ],
129- &engine_properties.switches [engine_properties.switches_count ]);
130- }
123+ std::transform (
124+ switches.begin (), switches.end (), std::back_inserter (argv),
125+ [](const std::string& arg) -> const char * { return arg.c_str (); });
131126
132- for (size_t i = 0 ; i < engine_properties.switches_count ; ++i) {
133- auto str = std::string{engine_properties.switches [i]};
134- if (str.find (" verbose-logging" ) != std::string::npos) {
135- SetMinLoggingLevel (DLOG_INFO);
136- }
127+ if (std::find (switches.begin (), switches.end (), " verbose-logging" ) !=
128+ switches.end ()) {
129+ SetMinLoggingLevel (DLOG_INFO);
137130 }
138131
139132 // Configure task runners.
@@ -173,10 +166,10 @@ bool FlutterTizenEngine::RunEngine(
173166
174167 FlutterProjectArgs args = {};
175168 args.struct_size = sizeof (FlutterProjectArgs);
176- args.assets_path = engine_properties. assets_path ;
177- args.icu_data_path = engine_properties. icu_data_path ;
169+ args.assets_path = assets_path_string. c_str () ;
170+ args.icu_data_path = icu_path_string. c_str () ;
178171 args.command_line_argc = static_cast <int >(argv.size ());
179- args.command_line_argv = & argv[ 0 ] ;
172+ args.command_line_argv = argv. size () > 0 ? argv. data () : nullptr ;
180173 args.platform_message_callback =
181174 [](const FlutterPlatformMessage* engine_message, void * user_data) {
182175 if (engine_message->struct_size != sizeof (FlutterPlatformMessage)) {
@@ -198,13 +191,7 @@ bool FlutterTizenEngine::RunEngine(
198191 };
199192 }
200193#endif
201-
202- if (embedder_api_.RunsAOTCompiledDartCode ()) {
203- aot_data_ = LoadAotData (engine_properties.aot_library_path );
204- if (!aot_data_) {
205- FT_LOGE (" Unable to start engine without AOT data." );
206- return false ;
207- }
194+ if (aot_data_) {
208195 args.aot_data = aot_data_.get ();
209196 }
210197
@@ -357,7 +344,7 @@ void FlutterTizenEngine::SetWindowOrientation(int32_t degree) {
357344 renderer->SetRotate (degree);
358345 // Compute renderer transformation based on the angle of rotation.
359346 double rad = (360 - degree) * M_PI / 180 ;
360- auto geometry = renderer->GetGeometry ();
347+ auto geometry = renderer->GetCurrentGeometry ();
361348 double width = geometry.w ;
362349 double height = geometry.h ;
363350
0 commit comments