Skip to content

Commit e5a1f66

Browse files
committed
Update based on review
Signed-off-by: Boram Bae <boram21.bae@samsung.com>
1 parent fb84e01 commit e5a1f66

File tree

2 files changed

+52
-44
lines changed

2 files changed

+52
-44
lines changed

shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ FlutterTizenEngine::FlutterTizenEngine(bool headed)
4949
event_loop_ = std::make_unique<TizenPlatformEventLoop>(
5050
std::this_thread::get_id(), // main thread
5151
[this](const auto* task) {
52-
if (embedder_api_.RunTask(this->flutter_engine, task) != kSuccess) {
52+
if (embedder_api_.RunTask(this->engine_, task) != kSuccess) {
5353
FT_LOGE("Could not post an engine task.");
5454
}
5555
});
@@ -78,7 +78,7 @@ void FlutterTizenEngine::InitializeRenderer() {
7878
render_loop_ = std::make_unique<TizenRenderEventLoop>(
7979
std::this_thread::get_id(), // main thread
8080
[this](const auto* task) {
81-
if (embedder_api_.RunTask(this->flutter_engine, task) != kSuccess) {
81+
if (embedder_api_.RunTask(this->engine_, task) != kSuccess) {
8282
FT_LOGE("Could not post an engine task.");
8383
}
8484
},
@@ -91,7 +91,7 @@ void FlutterTizenEngine::InitializeRenderer() {
9191
}
9292

9393
void FlutterTizenEngine::NotifyLowMemoryWarning() {
94-
embedder_api_.NotifyLowMemoryWarning(flutter_engine);
94+
embedder_api_.NotifyLowMemoryWarning(engine_);
9595
}
9696

9797
// Attempts to load AOT data from the given path, which must be absolute and
@@ -176,7 +176,18 @@ bool FlutterTizenEngine::RunEngine(
176176
args.icu_data_path = engine_properties.icu_data_path;
177177
args.command_line_argc = static_cast<int>(argv.size());
178178
args.command_line_argv = &argv[0];
179-
args.platform_message_callback = OnFlutterPlatformMessage;
179+
args.platform_message_callback =
180+
[](const FlutterPlatformMessage* engine_message, void* user_data) {
181+
if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
182+
FT_LOGE(
183+
"Invalid message size received. Expected: %zu, but received %zu",
184+
sizeof(FlutterPlatformMessage), engine_message->struct_size);
185+
return;
186+
}
187+
auto engine = reinterpret_cast<FlutterTizenEngine*>(user_data);
188+
auto message = engine->ConvertToDesktopMessage(*engine_message);
189+
engine->message_dispatcher->HandleMessage(message);
190+
};
180191
args.custom_task_runners = &custom_task_runners;
181192
#ifndef TIZEN_RENDERER_EVAS_GL
182193
if (IsHeaded()) {
@@ -199,8 +210,8 @@ bool FlutterTizenEngine::RunEngine(
199210
FlutterRendererConfig renderer_config = GetRendererConfig();
200211

201212
auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
202-
&args, this, &flutter_engine);
203-
if (result == kSuccess && flutter_engine != nullptr) {
213+
&args, this, &engine_);
214+
if (result == kSuccess && engine_ != nullptr) {
204215
FT_LOGD("FlutterEngineRun Success!");
205216
} else {
206217
FT_LOGE("FlutterEngineRun Failure! result: %d", result);
@@ -238,15 +249,15 @@ bool FlutterTizenEngine::RunEngine(
238249
}
239250

240251
bool FlutterTizenEngine::StopEngine() {
241-
if (flutter_engine) {
252+
if (engine_) {
242253
if (platform_view_channel) {
243254
platform_view_channel->Dispose();
244255
}
245256
if (plugin_registrar_destruction_callback_) {
246257
plugin_registrar_destruction_callback_(plugin_registrar_.get());
247258
}
248-
FlutterEngineResult result = embedder_api_.Shutdown(flutter_engine);
249-
flutter_engine = nullptr;
259+
FlutterEngineResult result = embedder_api_.Shutdown(engine_);
260+
engine_ = nullptr;
250261
return (result == kSuccess);
251262
}
252263
return false;
@@ -275,9 +286,9 @@ bool FlutterTizenEngine::SendPlatformMessage(
275286
if (reply != nullptr && user_data != nullptr) {
276287
FlutterEngineResult result =
277288
embedder_api_.PlatformMessageCreateResponseHandle(
278-
flutter_engine, reply, user_data, &response_handle);
289+
engine_, reply, user_data, &response_handle);
279290
if (result != kSuccess) {
280-
std::cout << "Failed to create response handle\n";
291+
FT_LOGE("Failed to create response handle");
281292
return false;
282293
}
283294
}
@@ -291,9 +302,9 @@ bool FlutterTizenEngine::SendPlatformMessage(
291302
};
292303

293304
FlutterEngineResult message_result =
294-
embedder_api_.SendPlatformMessage(flutter_engine, &platform_message);
305+
embedder_api_.SendPlatformMessage(engine_, &platform_message);
295306
if (response_handle != nullptr) {
296-
embedder_api_.PlatformMessageReleaseResponseHandle(flutter_engine,
307+
embedder_api_.PlatformMessageReleaseResponseHandle(engine_,
297308
response_handle);
298309
}
299310
return message_result == kSuccess;
@@ -303,12 +314,11 @@ void FlutterTizenEngine::SendPlatformMessageResponse(
303314
const FlutterDesktopMessageResponseHandle* handle,
304315
const uint8_t* data,
305316
size_t data_length) {
306-
embedder_api_.SendPlatformMessageResponse(flutter_engine, handle, data,
307-
data_length);
317+
embedder_api_.SendPlatformMessageResponse(engine_, handle, data, data_length);
308318
}
309319

310320
void FlutterTizenEngine::SendPointerEvent(const FlutterPointerEvent& event) {
311-
embedder_api_.SendPointerEvent(flutter_engine, &event, 1);
321+
embedder_api_.SendPointerEvent(engine_, &event, 1);
312322
}
313323

314324
void FlutterTizenEngine::SendWindowMetrics(int32_t width,
@@ -339,7 +349,7 @@ void FlutterTizenEngine::SendWindowMetrics(int32_t width,
339349
} else {
340350
event.pixel_ratio = pixel_ratio;
341351
}
342-
embedder_api_.SendWindowMetricsEvent(flutter_engine, &event);
352+
embedder_api_.SendWindowMetricsEvent(engine_, &event);
343353
}
344354

345355
// This must be called at least once in order to initialize the value of
@@ -388,44 +398,32 @@ void FlutterTizenEngine::OnOrientationChange(int32_t degree) {
388398
void FlutterTizenEngine::OnVsync(intptr_t baton,
389399
uint64_t frame_start_time_nanos,
390400
uint64_t frame_target_time_nanos) {
391-
embedder_api_.OnVsync(flutter_engine, baton, frame_start_time_nanos,
401+
embedder_api_.OnVsync(engine_, baton, frame_start_time_nanos,
392402
frame_target_time_nanos);
393403
}
394404

395405
void FlutterTizenEngine::UpdateLocales(const FlutterLocale** locales,
396406
size_t locales_count) {
397-
embedder_api_.UpdateLocales(flutter_engine, locales, locales_count);
407+
embedder_api_.UpdateLocales(engine_, locales, locales_count);
398408
}
399409

400410
bool FlutterTizenEngine::RegisterExternalTexture(int64_t texture_id) {
401-
return (embedder_api_.RegisterExternalTexture(flutter_engine, texture_id) ==
411+
return (embedder_api_.RegisterExternalTexture(engine_, texture_id) ==
402412
kSuccess);
403413
}
404414

405415
bool FlutterTizenEngine::UnregisterExternalTexture(int64_t texture_id) {
406-
return (embedder_api_.UnregisterExternalTexture(flutter_engine, texture_id) ==
416+
return (embedder_api_.UnregisterExternalTexture(engine_, texture_id) ==
407417
kSuccess);
408418
}
409419

410420
bool FlutterTizenEngine::MarkExternalTextureFrameAvailable(int64_t texture_id) {
411421
return (embedder_api_.MarkExternalTextureFrameAvailable(
412-
flutter_engine, texture_id) == kSuccess);
422+
engine_, texture_id) == kSuccess);
413423
}
414424

415425
// The Flutter Engine calls out to this function when new platform messages are
416426
// available.
417-
void FlutterTizenEngine::OnFlutterPlatformMessage(
418-
const FlutterPlatformMessage* engine_message,
419-
void* user_data) {
420-
if (engine_message->struct_size != sizeof(FlutterPlatformMessage)) {
421-
FT_LOGE("Invalid message size received. Expected: %zu, but received %zu",
422-
sizeof(FlutterPlatformMessage), engine_message->struct_size);
423-
return;
424-
}
425-
auto engine = reinterpret_cast<FlutterTizenEngine*>(user_data);
426-
auto message = engine->ConvertToDesktopMessage(*engine_message);
427-
engine->message_dispatcher->HandleMessage(message);
428-
}
429427

430428
// Converts a FlutterPlatformMessage to an equivalent FlutterDesktopMessage.
431429
FlutterDesktopMessage FlutterTizenEngine::ConvertToDesktopMessage(

shell/platform/tizen/flutter_tizen_engine.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,55 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
6767
FlutterTizenEngine& operator=(FlutterTizenEngine const&) = delete;
6868

6969
void InitializeRenderer();
70-
71-
void NotifyLowMemoryWarning();
72-
7370
bool RunEngine(const FlutterDesktopEngineProperties& engine_properties);
7471
bool StopEngine();
7572

7673
// Returns the currently configured Plugin Registrar.
7774
FlutterDesktopPluginRegistrarRef GetPluginRegistrar();
78-
7975
FlutterTizenTextureRegistrar* GetTextureRegistrar();
8076

8177
// Sets |callback| to be called when the plugin registrar is destroyed.
8278
void SetPluginRegistrarDestructionCallback(
8379
FlutterDesktopOnPluginRegistrarDestroyed callback);
8480

81+
// Sends the given message to the engine, calling |reply| with |user_data|
82+
// when a reponse is received from the engine if they are non-null.
8583
bool SendPlatformMessage(const char* channel,
8684
const uint8_t* message,
8785
const size_t message_size,
8886
const FlutterDesktopBinaryReply reply,
8987
void* user_data);
88+
89+
// Sends the given data as the response to an earlier platform message.
9090
void SendPlatformMessageResponse(
9191
const FlutterDesktopMessageResponseHandle* handle,
9292
const uint8_t* data,
9393
size_t data_length);
94+
95+
// Informs the engine of an incoming pointer event.
9496
void SendPointerEvent(const FlutterPointerEvent& event);
97+
98+
// Sends a window metrics update to the Flutter engine using current window
99+
// dimensions in physical
95100
void SendWindowMetrics(int32_t width, int32_t height, double pixel_ratio);
101+
96102
void SetWindowOrientation(int32_t degree);
97103
void OnOrientationChange(int32_t degree) override;
98104
void OnVsync(intptr_t baton,
99105
uint64_t frame_start_time_nanos,
100106
uint64_t frame_target_time_nanos);
107+
108+
void NotifyLowMemoryWarning();
101109
void UpdateLocales(const FlutterLocale** locales, size_t locales_count);
102110

111+
// Attempts to register the texture with the given |texture_id|.
103112
bool RegisterExternalTexture(int64_t texture_id);
113+
114+
// Attempts to unregister the texture with the given |texture_id|.
104115
bool UnregisterExternalTexture(int64_t texture_id);
116+
117+
// Notifies the engine about a new frame being available for the
118+
// given |texture_id|.
105119
bool MarkExternalTextureFrameAvailable(int64_t texture_id);
106120

107121
// The plugin messenger handle given to API clients.
@@ -127,19 +141,15 @@ class FlutterTizenEngine : public TizenRenderer::Delegate {
127141

128142
private:
129143
bool IsHeaded() { return renderer != nullptr; }
130-
131-
static void OnFlutterPlatformMessage(
132-
const FlutterPlatformMessage* engine_message,
133-
void* user_data);
144+
UniqueAotDataPtr LoadAotData(std::string aot_data_path);
134145
FlutterDesktopMessage ConvertToDesktopMessage(
135146
const FlutterPlatformMessage& engine_message);
136147
FlutterRendererConfig GetRendererConfig();
137-
UniqueAotDataPtr LoadAotData(std::string aot_data_path);
138148

139149
FlutterEngineProcTable embedder_api_ = {};
140150

141151
// The Flutter engine instance.
142-
FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine;
152+
FLUTTER_API_SYMBOL(FlutterEngine) engine_;
143153

144154
// The handlers listening to platform events.
145155
std::unique_ptr<KeyEventHandler> key_event_handler_;

0 commit comments

Comments
 (0)