Skip to content

Commit 712c376

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 9f408ef commit 712c376

9 files changed

+130
-80
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
@@ -94,38 +94,16 @@ bool FlutterDesktopMessengerSendWithReply(FlutterDesktopMessengerRef messenger,
9494
const size_t message_size,
9595
const FlutterDesktopBinaryReply reply,
9696
void* user_data) {
97-
FlutterPlatformMessageResponseHandle* response_handle = nullptr;
98-
if (reply != nullptr && user_data != nullptr) {
99-
FlutterEngineResult result = FlutterPlatformMessageCreateResponseHandle(
100-
messenger->engine->flutter_engine, reply, user_data, &response_handle);
101-
if (result != kSuccess) {
102-
FT_LOGE("Failed to create response handle");
103-
return false;
104-
}
105-
}
106-
FlutterPlatformMessage platform_message = {
107-
sizeof(FlutterPlatformMessage),
108-
channel,
109-
message,
110-
message_size,
111-
response_handle,
112-
};
113-
FlutterEngineResult message_result = FlutterEngineSendPlatformMessage(
114-
messenger->engine->flutter_engine, &platform_message);
115-
if (response_handle != nullptr) {
116-
FlutterPlatformMessageReleaseResponseHandle(
117-
messenger->engine->flutter_engine, response_handle);
118-
}
119-
return message_result == kSuccess;
97+
return messenger->engine->SendPlatformMessage(channel, message, message_size,
98+
reply, user_data);
12099
}
121100

122101
void FlutterDesktopMessengerSendResponse(
123102
FlutterDesktopMessengerRef messenger,
124103
const FlutterDesktopMessageResponseHandle* handle,
125104
const uint8_t* data,
126105
size_t data_length) {
127-
FlutterEngineSendPlatformMessageResponse(messenger->engine->flutter_engine,
128-
handle, data, data_length);
106+
messenger->engine->SendPlatformMessageResponse(handle, data, data_length);
129107
}
130108

131109
void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
@@ -157,8 +135,7 @@ void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
157135
}
158136

159137
void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) {
160-
auto flutter_engine = EngineFromHandle(engine)->flutter_engine;
161-
FlutterEngineNotifyLowMemoryWarning(flutter_engine);
138+
EngineFromHandle(engine)->NotifyLowMemoryWarning();
162139
}
163140

164141
int64_t FlutterRegisterExternalTexture(

shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 76 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,9 @@ 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);
213220

214221
if (IsHeaded()) {
215222
auto texture_registrar = std::make_unique<FlutterTextureRegistrar>();
@@ -241,7 +248,7 @@ bool FlutterTizenEngine::StopEngine() {
241248
if (plugin_registrar_destruction_callback_) {
242249
plugin_registrar_destruction_callback_(plugin_registrar_.get());
243250
}
244-
FlutterEngineResult result = FlutterEngineShutdown(flutter_engine);
251+
FlutterEngineResult result = embedder_api_.Shutdown(flutter_engine);
245252
flutter_engine = nullptr;
246253
return (result == kSuccess);
247254
}
@@ -257,6 +264,52 @@ void FlutterTizenEngine::SetPluginRegistrarDestructionCallback(
257264
plugin_registrar_destruction_callback_ = callback;
258265
}
259266

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

291344
// This must be called at least once in order to initialize the value of
@@ -331,6 +384,18 @@ void FlutterTizenEngine::OnOrientationChange(int32_t degree) {
331384
SetWindowOrientation(degree);
332385
}
333386

387+
void FlutterTizenEngine::OnVsync(intptr_t baton,
388+
uint64_t frame_start_time_nanos,
389+
uint64_t frame_target_time_nanos) {
390+
embedder_api_.OnVsync(flutter_engine, baton, frame_start_time_nanos,
391+
frame_target_time_nanos);
392+
}
393+
394+
void FlutterTizenEngine::UpdateLocales(const FlutterLocale** locales,
395+
size_t locales_count) {
396+
embedder_api_.UpdateLocales(flutter_engine, locales, locales_count);
397+
}
398+
334399
// The Flutter Engine calls out to this function when new platform messages are
335400
// available.
336401
void FlutterTizenEngine::OnFlutterPlatformMessage(

0 commit comments

Comments
 (0)