5
5
6
6
#include " flutter_tizen_engine.h"
7
7
8
- #include < filesystem >
8
+ #include < algorithm >
9
9
#include < string>
10
10
#include < vector>
11
11
@@ -33,7 +33,9 @@ constexpr double kProfileFactor = 1.0;
33
33
34
34
} // namespace
35
35
36
- FlutterTizenEngine::FlutterTizenEngine (bool headed) {
36
+ FlutterTizenEngine::FlutterTizenEngine (const FlutterProjectBundle& project)
37
+ : project_(std::make_unique<FlutterProjectBundle>(project)),
38
+ aot_data_ (nullptr , nullptr ) {
37
39
embedder_api_.struct_size = sizeof (FlutterEngineProcTable);
38
40
FlutterEngineGetProcAddresses (&embedder_api_);
39
41
@@ -55,19 +57,20 @@ FlutterTizenEngine::FlutterTizenEngine(bool headed) {
55
57
56
58
plugin_registrar_ = std::make_unique<FlutterDesktopPluginRegistrar>();
57
59
plugin_registrar_->engine = this ;
58
-
59
- if (headed) {
60
- InitializeRenderer ();
61
- }
62
60
}
63
61
64
62
FlutterTizenEngine::~FlutterTizenEngine () {
65
63
renderer = nullptr ;
66
64
}
67
65
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
+
69
72
#ifdef TIZEN_RENDERER_EVAS_GL
70
- renderer = std::make_unique<TizenRendererEvasGL>(*this );
73
+ renderer = std::make_unique<TizenRendererEvasGL>(geometry, *this );
71
74
72
75
render_loop_ = std::make_unique<TizenRenderEventLoop>(
73
76
std::this_thread::get_id (), // main thread
@@ -78,7 +81,7 @@ void FlutterTizenEngine::InitializeRenderer() {
78
81
},
79
82
renderer.get ());
80
83
#else
81
- renderer = std::make_unique<TizenRendererEcoreWl2>(*this );
84
+ renderer = std::make_unique<TizenRendererEcoreWl2>(geometry, *this );
82
85
83
86
tizen_vsync_waiter_ = std::make_unique<TizenVsyncWaiter>(this );
84
87
#endif
@@ -88,52 +91,42 @@ void FlutterTizenEngine::NotifyLowMemoryWarning() {
88
91
embedder_api_.NotifyLowMemoryWarning (engine_);
89
92
}
90
93
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 ;
112
98
}
113
- return UniqueAotDataPtr (data);
114
- }
115
-
116
- bool FlutterTizenEngine::RunEngine (
117
- const FlutterDesktopEngineProperties& engine_properties) {
118
99
if (IsHeaded () && !renderer->IsValid ()) {
119
100
FT_LOGE (" The display was not valid." );
120
101
return false ;
121
102
}
122
103
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
+
123
118
// FlutterProjectArgs is expecting a full argv, so when processing it for
124
119
// flags the first item is treated as the executable and ignored. Add a dummy
125
120
// value so that all provided arguments are used.
121
+ std::vector<std::string> switches = project_->switches ();
126
122
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 (); });
131
126
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);
137
130
}
138
131
139
132
// Configure task runners.
@@ -173,10 +166,10 @@ bool FlutterTizenEngine::RunEngine(
173
166
174
167
FlutterProjectArgs args = {};
175
168
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 () ;
178
171
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 ;
180
173
args.platform_message_callback =
181
174
[](const FlutterPlatformMessage* engine_message, void * user_data) {
182
175
if (engine_message->struct_size != sizeof (FlutterPlatformMessage)) {
@@ -198,13 +191,7 @@ bool FlutterTizenEngine::RunEngine(
198
191
};
199
192
}
200
193
#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_) {
208
195
args.aot_data = aot_data_.get ();
209
196
}
210
197
@@ -357,7 +344,7 @@ void FlutterTizenEngine::SetWindowOrientation(int32_t degree) {
357
344
renderer->SetRotate (degree);
358
345
// Compute renderer transformation based on the angle of rotation.
359
346
double rad = (360 - degree) * M_PI / 180 ;
360
- auto geometry = renderer->GetGeometry ();
347
+ auto geometry = renderer->GetCurrentGeometry ();
361
348
double width = geometry.w ;
362
349
double height = geometry.h ;
363
350
0 commit comments