Skip to content

Commit fb84e01

Browse files
committed
Use proc table for embedder APIs
* Use the proc table like other platform implementations * Use FlutterEngine as private memeber of FlutterTizenEngine * Only FlutterTizenEngine is dependent on FlutterEngine Signed-off-by: Boram Bae <[email protected]>
1 parent 9f08d18 commit fb84e01

10 files changed

+152
-85
lines changed

shell/platform/tizen/channels/lifecycle_channel.cc

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "lifecycle_channel.h"
66

7+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
78
#include "flutter/shell/platform/tizen/tizen_log.h"
89

910
static constexpr char kChannelName[] = "flutter/lifecycle";
@@ -12,20 +13,15 @@ static constexpr char kResumed[] = "AppLifecycleState.resumed";
1213
static constexpr char kPaused[] = "AppLifecycleState.paused";
1314
static constexpr char kDetached[] = "AppLifecycleState.detached";
1415

15-
LifecycleChannel::LifecycleChannel(FLUTTER_API_SYMBOL(FlutterEngine)
16-
flutter_engine)
17-
: flutter_engine_(flutter_engine) {}
16+
LifecycleChannel::LifecycleChannel(FlutterTizenEngine* engine)
17+
: engine_(engine) {}
1818

1919
LifecycleChannel::~LifecycleChannel() {}
2020

2121
void LifecycleChannel::SendLifecycleMessage(const char message[]) {
22-
FlutterPlatformMessage platformMessage = {};
23-
platformMessage.struct_size = sizeof(FlutterPlatformMessage);
24-
platformMessage.channel = kChannelName;
25-
platformMessage.message = reinterpret_cast<const uint8_t*>(message);
26-
platformMessage.message_size = strlen(message);
27-
platformMessage.response_handle = nullptr;
28-
FlutterEngineSendPlatformMessage(flutter_engine_, &platformMessage);
22+
engine_->SendPlatformMessage(kChannelName,
23+
reinterpret_cast<const uint8_t*>(message),
24+
strlen(message), nullptr, nullptr);
2925
}
3026

3127
void LifecycleChannel::AppIsInactive() {

shell/platform/tizen/channels/lifecycle_channel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#ifndef EMBEDDER_LIFECYCLE_CHANNEL_H_
66
#define EMBEDDER_LIFECYCLE_CHANNEL_H_
77

8-
#include "flutter/shell/platform/embedder/embedder.h"
8+
class FlutterTizenEngine;
99

1010
class LifecycleChannel {
1111
public:
12-
explicit LifecycleChannel(FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine);
12+
explicit LifecycleChannel(FlutterTizenEngine* engine);
1313
virtual ~LifecycleChannel();
1414

1515
void AppIsInactive();
@@ -19,7 +19,7 @@ class LifecycleChannel {
1919
void SendLifecycleMessage(const char message[]);
2020

2121
private:
22-
FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_;
22+
FlutterTizenEngine* engine_{nullptr};
2323
};
2424

2525
#endif // EMBEDDER_LIFECYCLE_CHANNEL_H_

shell/platform/tizen/channels/localization_channel.cc

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
#include "localization_channel.h"
66

77
#include <utils_i18n.h>
8-
98
#include <vector>
109

10+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
1111
#include "flutter/shell/platform/tizen/tizen_log.h"
1212
#include "rapidjson/document.h"
1313
#include "rapidjson/writer.h"
1414

1515
static constexpr char kChannelName[] = "flutter/localization";
1616

17-
LocalizationChannel::LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
18-
flutter_engine)
19-
: flutter_engine_(flutter_engine) {}
17+
LocalizationChannel::LocalizationChannel(FlutterTizenEngine* engine)
18+
: engine_(engine) {}
2019

2120
LocalizationChannel::~LocalizationChannel() {}
2221

@@ -54,9 +53,8 @@ void LocalizationChannel::SendLocales() {
5453
}
5554

5655
FT_LOGD("Send %zu available locales", flutter_locales.size());
57-
// send locales to engine
58-
FlutterEngineUpdateLocales(
59-
flutter_engine_,
56+
// Send locales to engine
57+
engine_->UpdateLocales(
6058
const_cast<const FlutterLocale**>(flutter_locales.data()),
6159
flutter_locales.size());
6260

@@ -111,13 +109,9 @@ void LocalizationChannel::SendPlatformResolvedLocale() {
111109
return;
112110
}
113111

114-
FlutterPlatformMessage message = {};
115-
message.struct_size = sizeof(FlutterPlatformMessage);
116-
message.channel = kChannelName;
117-
message.message = reinterpret_cast<const uint8_t*>(buffer.GetString());
118-
message.message_size = buffer.GetSize();
119-
message.response_handle = nullptr;
120-
FlutterEngineSendPlatformMessage(flutter_engine_, &message);
112+
engine_->SendPlatformMessage(
113+
kChannelName, reinterpret_cast<const uint8_t*>(buffer.GetString()),
114+
buffer.GetSize(), nullptr, nullptr);
121115

122116
DestroyFlutterLocale(flutter_locale);
123117
}

shell/platform/tizen/channels/localization_channel.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77

88
#include "flutter/shell/platform/embedder/embedder.h"
99

10+
class FlutterTizenEngine;
11+
1012
class LocalizationChannel {
1113
public:
12-
explicit LocalizationChannel(FLUTTER_API_SYMBOL(FlutterEngine)
13-
flutter_engine);
14+
explicit LocalizationChannel(FlutterTizenEngine* engine);
1415
virtual ~LocalizationChannel();
1516

1617
void SendLocales();
@@ -20,7 +21,7 @@ class LocalizationChannel {
2021
FlutterLocale* GetFlutterLocale(const char* locale);
2122
void DestroyFlutterLocale(FlutterLocale* flutter_locale);
2223

23-
FLUTTER_API_SYMBOL(FlutterEngine) flutter_engine_;
24+
FlutterTizenEngine* engine_;
2425
};
2526

2627
#endif // EMBEDDER_LOCALIZATION_CHANNEL_H_

shell/platform/tizen/flutter_tizen.cc

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,16 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,
8888
const size_t message_size,
8989
const FlutterDesktopBinaryReply reply,
9090
void* user_data) {
91-
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
92-
if (reply != nullptr && user_data != nullptr) {
93-
FlutterEngineResult result = FlutterPlatformMessageCreateResponseHandle(
94-
messenger->engine->flutter_engine, reply, user_data, &response_handle);
95-
if (result != kSuccess) {
96-
FT_LOGE("Failed to create response handle");
97-
return false;
98-
}
99-
}
100-
FlutterPlatformMessage platform_message = {
101-
sizeof(FlutterPlatformMessage),
102-
channel,
103-
message,
104-
message_size,
105-
response_handle,
106-
};
107-
FlutterEngineResult message_result = FlutterEngineSendPlatformMessage(
108-
messenger->engine->flutter_engine, &platform_message);
109-
if (response_handle != nullptr) {
110-
FlutterPlatformMessageReleaseResponseHandle(
111-
messenger->engine->flutter_engine, response_handle);
112-
}
113-
return message_result == kSuccess;
91+
return messenger->engine->SendPlatformMessage(channel, message, message_size,
92+
reply, user_data);
11493
}
11594

11695
void FlutterDesktopMessengerSendResponse(
11796
FlutterDesktopMessengerRef messenger,
11897
const FlutterDesktopMessageResponseHandle* handle,
11998
const uint8_t* data,
12099
size_t data_length) {
121-
FlutterEngineSendPlatformMessageResponse(messenger->engine->flutter_engine,
122-
handle, data, data_length);
100+
messenger->engine->SendPlatformMessageResponse(handle, data, data_length);
123101
}
124102

125103
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
@@ -151,8 +129,7 @@ void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
151129
}
152130

153131
void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) {
154-
auto flutter_engine = EngineFromHandle(engine)->flutter_engine;
155-
FlutterEngineNotifyLowMemoryWarning(flutter_engine);
132+
EngineFromHandle(engine)->NotifyLowMemoryWarning();
156133
}
157134

158135
void FlutterRegisterViewFactory(

shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ static DeviceProfile GetDeviceProfile() {
4040

4141
FlutterTizenEngine::FlutterTizenEngine(bool headed)
4242
: device_profile(GetDeviceProfile()) {
43+
embedder_api_.struct_size = sizeof(FlutterEngineProcTable);
44+
FlutterEngineGetProcAddresses(&embedder_api_);
45+
4346
// Run flutter task on Tizen main loop.
4447
// Tizen engine has four threads (GPU thread, UI thread, IO thread, platform
4548
// thread). UI threads need to send flutter task to platform thread.
4649
event_loop_ = std::make_unique<TizenPlatformEventLoop>(
4750
std::this_thread::get_id(), // main thread
4851
[this](const auto* task) {
49-
if (FlutterEngineRunTask(this->flutter_engine, task) != kSuccess) {
52+
if (embedder_api_.RunTask(this->flutter_engine, task) != kSuccess) {
5053
FT_LOGE("Could not post an engine task.");
5154
}
5255
});
@@ -75,7 +78,7 @@ void FlutterTizenEngine::InitializeRenderer() {
7578
render_loop_ = std::make_unique<TizenRenderEventLoop>(
7679
std::this_thread::get_id(), // main thread
7780
[this](const auto* task) {
78-
if (FlutterEngineRunTask(this->flutter_engine, task) != kSuccess) {
81+
if (embedder_api_.RunTask(this->flutter_engine, task) != kSuccess) {
7982
FT_LOGE("Could not post an engine task.");
8083
}
8184
},
@@ -87,9 +90,13 @@ void FlutterTizenEngine::InitializeRenderer() {
8790
#endif
8891
}
8992

93+
void FlutterTizenEngine::NotifyLowMemoryWarning() {
94+
embedder_api_.NotifyLowMemoryWarning(flutter_engine);
95+
}
96+
9097
// Attempts to load AOT data from the given path, which must be absolute and
9198
// non-empty. Logs and returns nullptr on failure.
92-
UniqueAotDataPtr LoadAotData(std::string aot_data_path) {
99+
UniqueAotDataPtr FlutterTizenEngine::LoadAotData(std::string aot_data_path) {
93100
if (aot_data_path.empty()) {
94101
FT_LOGE(
95102
"Attempted to load AOT data, but no aot_library_path was provided.");
@@ -104,7 +111,7 @@ UniqueAotDataPtr LoadAotData(std::string aot_data_path) {
104111
source.type = kFlutterEngineAOTDataSourceTypeElfPath;
105112
source.elf_path = aot_data_path.c_str();
106113
FlutterEngineAOTData data = nullptr;
107-
auto result = FlutterEngineCreateAOTData(&source, &data);
114+
auto result = embedder_api_.CreateAOTData(&source, &data);
108115
if (result != kSuccess) {
109116
FT_LOGE("Failed to load AOT data from: %s", aot_data_path.c_str());
110117
return nullptr;
@@ -180,7 +187,7 @@ bool FlutterTizenEngine::RunEngine(
180187
}
181188
#endif
182189

183-
if (FlutterEngineRunsAOTCompiledDartCode()) {
190+
if (embedder_api_.RunsAOTCompiledDartCode()) {
184191
aot_data_ = LoadAotData(engine_properties.aot_library_path);
185192
if (!aot_data_) {
186193
FT_LOGE("Unable to start engine without AOT data.");
@@ -191,8 +198,8 @@ bool FlutterTizenEngine::RunEngine(
191198

192199
FlutterRendererConfig renderer_config = GetRendererConfig();
193200

194-
auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &renderer_config,
195-
&args, this, &flutter_engine);
201+
auto result = embedder_api_.Run(FLUTTER_ENGINE_VERSION, &renderer_config,
202+
&args, this, &flutter_engine);
196203
if (result == kSuccess && flutter_engine != nullptr) {
197204
FT_LOGD("FlutterEngineRun Success!");
198205
} else {
@@ -207,9 +214,10 @@ bool FlutterTizenEngine::RunEngine(
207214
internal_plugin_registrar_->messenger(), renderer.get());
208215
settings_channel = std::make_unique<SettingsChannel>(
209216
internal_plugin_registrar_->messenger());
210-
localization_channel = std::make_unique<LocalizationChannel>(flutter_engine);
217+
localization_channel = std::make_unique<LocalizationChannel>(this);
211218
localization_channel->SendLocales();
212-
lifecycle_channel = std::make_unique<LifecycleChannel>(flutter_engine);
219+
lifecycle_channel = std::make_unique<LifecycleChannel>(this);
220+
213221
if (IsHeaded()) {
214222
texture_registrar_ = std::make_unique<FlutterTizenTextureRegistrar>(this);
215223
key_event_channel = std::make_unique<KeyEventChannel>(
@@ -237,7 +245,7 @@ bool FlutterTizenEngine::StopEngine() {
237245
if (plugin_registrar_destruction_callback_) {
238246
plugin_registrar_destruction_callback_(plugin_registrar_.get());
239247
}
240-
FlutterEngineResult result = FlutterEngineShutdown(flutter_engine);
248+
FlutterEngineResult result = embedder_api_.Shutdown(flutter_engine);
241249
flutter_engine = nullptr;
242250
return (result == kSuccess);
243251
}
@@ -257,6 +265,52 @@ void FlutterTizenEngine::SetPluginRegistrarDestructionCallback(
257265
plugin_registrar_destruction_callback_ = callback;
258266
}
259267

268+
bool FlutterTizenEngine::SendPlatformMessage(
269+
const char* channel,
270+
const uint8_t* message,
271+
const size_t message_size,
272+
const FlutterDesktopBinaryReply reply,
273+
void* user_data) {
274+
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
275+
if (reply != nullptr && user_data != nullptr) {
276+
FlutterEngineResult result =
277+
embedder_api_.PlatformMessageCreateResponseHandle(
278+
flutter_engine, reply, user_data, &response_handle);
279+
if (result != kSuccess) {
280+
std::cout << "Failed to create response handle\n";
281+
return false;
282+
}
283+
}
284+
285+
FlutterPlatformMessage platform_message = {
286+
sizeof(FlutterPlatformMessage),
287+
channel,
288+
message,
289+
message_size,
290+
response_handle,
291+
};
292+
293+
FlutterEngineResult message_result =
294+
embedder_api_.SendPlatformMessage(flutter_engine, &platform_message);
295+
if (response_handle != nullptr) {
296+
embedder_api_.PlatformMessageReleaseResponseHandle(flutter_engine,
297+
response_handle);
298+
}
299+
return message_result == kSuccess;
300+
}
301+
302+
void FlutterTizenEngine::SendPlatformMessageResponse(
303+
const FlutterDesktopMessageResponseHandle* handle,
304+
const uint8_t* data,
305+
size_t data_length) {
306+
embedder_api_.SendPlatformMessageResponse(flutter_engine, handle, data,
307+
data_length);
308+
}
309+
310+
void FlutterTizenEngine::SendPointerEvent(const FlutterPointerEvent& event) {
311+
embedder_api_.SendPointerEvent(flutter_engine, &event, 1);
312+
}
313+
260314
void FlutterTizenEngine::SendWindowMetrics(int32_t width,
261315
int32_t height,
262316
double pixel_ratio) {
@@ -285,7 +339,7 @@ void FlutterTizenEngine::SendWindowMetrics(int32_t width,
285339
} else {
286340
event.pixel_ratio = pixel_ratio;
287341
}
288-
FlutterEngineSendWindowMetricsEvent(flutter_engine, &event);
342+
embedder_api_.SendWindowMetricsEvent(flutter_engine, &event);
289343
}
290344

291345
// This must be called at least once in order to initialize the value of
@@ -331,6 +385,33 @@ void FlutterTizenEngine::OnOrientationChange(int32_t degree) {
331385
SetWindowOrientation(degree);
332386
}
333387

388+
void FlutterTizenEngine::OnVsync(intptr_t baton,
389+
uint64_t frame_start_time_nanos,
390+
uint64_t frame_target_time_nanos) {
391+
embedder_api_.OnVsync(flutter_engine, baton, frame_start_time_nanos,
392+
frame_target_time_nanos);
393+
}
394+
395+
void FlutterTizenEngine::UpdateLocales(const FlutterLocale** locales,
396+
size_t locales_count) {
397+
embedder_api_.UpdateLocales(flutter_engine, locales, locales_count);
398+
}
399+
400+
bool FlutterTizenEngine::RegisterExternalTexture(int64_t texture_id) {
401+
return (embedder_api_.RegisterExternalTexture(flutter_engine, texture_id) ==
402+
kSuccess);
403+
}
404+
405+
bool FlutterTizenEngine::UnregisterExternalTexture(int64_t texture_id) {
406+
return (embedder_api_.UnregisterExternalTexture(flutter_engine, texture_id) ==
407+
kSuccess);
408+
}
409+
410+
bool FlutterTizenEngine::MarkExternalTextureFrameAvailable(int64_t texture_id) {
411+
return (embedder_api_.MarkExternalTextureFrameAvailable(
412+
flutter_engine, texture_id) == kSuccess);
413+
}
414+
334415
// The Flutter Engine calls out to this function when new platform messages are
335416
// available.
336417
void FlutterTizenEngine::OnFlutterPlatformMessage(

0 commit comments

Comments
 (0)