Skip to content

Commit 6ac2e23

Browse files
authored
Refactor embedder and introduce FlutterTizenView (#278)
* Introduce FlutterTizenView. It is a delegate for the flutter rendering host. and it provides interfaces. * Introduce TizenView. it abstracts the platform window and it provides interfaces. Responsibilities of TizenRenderer is reduced, and those responsibilities are transferred to TizenWindow and FlutterTizenView. * Rename the Flutter-tizen C-APIs. this change requires an update of flutter-tizen and plugin too. * The engine runs as headless mode by default now. Signed-off-by: Boram Bae <[email protected]>
1 parent 45e7e13 commit 6ac2e23

36 files changed

+2158
-1482
lines changed

shell/platform/tizen/BUILD.gn

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,12 @@ template("embedder") {
123123
"flutter_tizen.cc",
124124
"flutter_tizen_engine.cc",
125125
"flutter_tizen_texture_registrar.cc",
126-
"key_event_handler.cc",
126+
"flutter_tizen_view.cc",
127127
"logger.cc",
128128
"system_utils.cc",
129129
"tizen_event_loop.cc",
130130
"tizen_input_method_context.cc",
131131
"tizen_renderer.cc",
132-
"touch_event_handler.cc",
133132
]
134133

135134
if (target_name != "flutter_tizen_wearable") {
@@ -185,7 +184,11 @@ template("embedder") {
185184
]
186185

187186
if (use_evas_gl_renderer) {
188-
sources += [ "tizen_renderer_evas_gl.cc" ]
187+
sources += [
188+
"flutter_tizen_elementary.cc",
189+
"tizen_renderer_evas_gl.cc",
190+
"tizen_window_elementary.cc",
191+
]
189192

190193
libs += [
191194
"ecore_evas",
@@ -196,8 +199,10 @@ template("embedder") {
196199
public_configs += [ ":evas_gl_renderer" ]
197200
} else {
198201
sources += [
199-
"tizen_renderer_ecore_wl2.cc",
202+
"flutter_tizen_ecore.cc",
203+
"tizen_renderer_egl.cc",
200204
"tizen_vsync_waiter.cc",
205+
"tizen_window_ecore_wl2.cc",
201206
]
202207

203208
libs += [

shell/platform/tizen/channels/platform_channel.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ std::string text_clipboard = "";
5858
} // namespace
5959

6060
PlatformChannel::PlatformChannel(BinaryMessenger* messenger,
61-
TizenRenderer* renderer)
61+
TizenWindow* window)
6262
: channel_(std::make_unique<MethodChannel<rapidjson::Document>>(
6363
messenger,
6464
kChannelName,
6565
&JsonMethodCodec::GetInstance())),
66-
renderer_(renderer) {
66+
window_(window) {
6767
channel_->SetMethodCallHandler(
6868
[this](const MethodCall<rapidjson::Document>& call,
6969
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
@@ -164,13 +164,13 @@ void PlatformChannel::HapticFeedbackVibrate(const std::string& feedback_type) {
164164
}
165165

166166
void PlatformChannel::RestoreSystemUiOverlays() {
167-
if (!renderer_) {
167+
if (!window_) {
168168
return;
169169
}
170170

171171
#ifdef COMMON_PROFILE
172172
auto& shell = TizenShell::GetInstance();
173-
shell.InitializeSoftkey(renderer_->GetWindowId());
173+
shell.InitializeSoftkey(window_->GetWindowId());
174174

175175
if (shell.IsSoftkeyShown()) {
176176
shell.ShowSoftkey();
@@ -182,13 +182,13 @@ void PlatformChannel::RestoreSystemUiOverlays() {
182182

183183
void PlatformChannel::SetEnabledSystemUiOverlays(
184184
const std::vector<std::string>& overlays) {
185-
if (!renderer_) {
185+
if (!window_) {
186186
return;
187187
}
188188

189189
#ifdef COMMON_PROFILE
190190
auto& shell = TizenShell::GetInstance();
191-
shell.InitializeSoftkey(renderer_->GetWindowId());
191+
shell.InitializeSoftkey(window_->GetWindowId());
192192

193193
if (std::find(overlays.begin(), overlays.end(), kSystemUiOverlayBottom) !=
194194
overlays.end()) {
@@ -201,7 +201,7 @@ void PlatformChannel::SetEnabledSystemUiOverlays(
201201

202202
void PlatformChannel::SetPreferredOrientations(
203203
const std::vector<std::string>& orientations) {
204-
if (!renderer_) {
204+
if (!window_) {
205205
return;
206206
}
207207

@@ -220,7 +220,7 @@ void PlatformChannel::SetPreferredOrientations(
220220
// default.
221221
rotations = {0, 90, 180, 270};
222222
}
223-
renderer_->SetPreferredOrientations(rotations);
223+
window_->SetPreferredOrientations(rotations);
224224
}
225225

226226
} // namespace flutter

shell/platform/tizen/channels/platform_channel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
1313
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
14-
#include "flutter/shell/platform/tizen/tizen_renderer.h"
14+
#include "flutter/shell/platform/tizen/tizen_window.h"
1515
#include "rapidjson/document.h"
1616

1717
namespace flutter {
1818

1919
class PlatformChannel {
2020
public:
21-
explicit PlatformChannel(BinaryMessenger* messenger, TizenRenderer* renderer);
21+
explicit PlatformChannel(BinaryMessenger* messenger, TizenWindow* window);
2222
virtual ~PlatformChannel();
2323

2424
private:
@@ -35,9 +35,9 @@ class PlatformChannel {
3535

3636
std::unique_ptr<MethodChannel<rapidjson::Document>> channel_;
3737

38-
// A reference to the renderer object managed by FlutterTizenEngine.
38+
// A reference to the window object managed by FlutterTizenView.
3939
// This can be nullptr if the engine is running in headless mode.
40-
TizenRenderer* renderer_;
40+
TizenWindow* window_;
4141
};
4242

4343
} // namespace flutter

shell/platform/tizen/channels/window_channel.cc

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ constexpr char kChannelName[] = "tizen/internal/window";
1616

1717
} // namespace
1818

19-
WindowChannel::WindowChannel(BinaryMessenger* messenger,
20-
TizenRenderer* renderer,
21-
TizenRenderer::Delegate* delegate)
22-
: renderer_(renderer), delegate_(delegate) {
19+
WindowChannel::WindowChannel(BinaryMessenger* messenger, TizenWindow* window)
20+
: window_(window) {
2321
channel_ = std::make_unique<MethodChannel<EncodableValue>>(
2422
messenger, kChannelName, &StandardMethodCodec::GetInstance());
2523
channel_->SetMethodCallHandler(
@@ -37,12 +35,12 @@ void WindowChannel::HandleMethodCall(
3735
const std::string& method_name = method_call.method_name();
3836

3937
if (method_name == "getWindowGeometry") {
40-
TizenRenderer::Geometry geometry = renderer_->GetWindowGeometry();
38+
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
4139
EncodableMap map;
42-
map[EncodableValue("x")] = EncodableValue(geometry.x);
43-
map[EncodableValue("y")] = EncodableValue(geometry.y);
44-
map[EncodableValue("width")] = EncodableValue(geometry.w);
45-
map[EncodableValue("height")] = EncodableValue(geometry.h);
40+
map[EncodableValue("x")] = EncodableValue(geometry.left);
41+
map[EncodableValue("y")] = EncodableValue(geometry.top);
42+
map[EncodableValue("width")] = EncodableValue(geometry.width);
43+
map[EncodableValue("height")] = EncodableValue(geometry.height);
4644
result->Success(EncodableValue(map));
4745
} else if (method_name == "setWindowGeometry") {
4846
#ifdef TIZEN_RENDERER_EVAS_GL
@@ -59,18 +57,23 @@ void WindowChannel::HandleMethodCall(
5957
EncodableValueHolder<int32_t> width(arguments, "width");
6058
EncodableValueHolder<int32_t> height(arguments, "height");
6159

62-
TizenRenderer::Geometry geometry = renderer_->GetWindowGeometry();
63-
64-
delegate_->OnGeometryChange(x ? *x : geometry.x, y ? *y : geometry.y,
65-
width ? *width : geometry.w,
66-
height ? *height : geometry.h);
60+
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
61+
// FIXME: Use SetWindowGeometry() instead of OnGeometryChanged()
62+
// After the SetWindowGeometry was successfully executed, I expected a
63+
// handler of ECORE_WL2_EVENT_WINDOW_CONFIGURE to be called, but it didn't.
64+
window_->OnGeometryChanged({
65+
x ? *x : geometry.left,
66+
y ? *y : geometry.top,
67+
width ? *width : geometry.width,
68+
height ? *height : geometry.height,
69+
});
6770
result->Success();
6871
#endif
6972
} else if (method_name == "getScreenGeometry") {
70-
TizenRenderer::Geometry geometry = renderer_->GetScreenGeometry();
73+
TizenWindow::Geometry geometry = window_->GetScreenGeometry();
7174
EncodableMap map;
72-
map[EncodableValue("width")] = EncodableValue(geometry.w);
73-
map[EncodableValue("height")] = EncodableValue(geometry.h);
75+
map[EncodableValue("width")] = EncodableValue(geometry.width);
76+
map[EncodableValue("height")] = EncodableValue(geometry.height);
7477
result->Success(EncodableValue(map));
7578
} else {
7679
result->NotImplemented();

shell/platform/tizen/channels/window_channel.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,14 @@
1010
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
1111
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
1212
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
13-
#include "flutter/shell/platform/tizen/tizen_renderer.h"
13+
#include "flutter/shell/platform/tizen/tizen_window.h"
1414

1515
namespace flutter {
1616

1717
// Channel to get/set application's window size and device's screen size.
1818
class WindowChannel {
1919
public:
20-
explicit WindowChannel(BinaryMessenger* messenger,
21-
TizenRenderer* renderer,
22-
TizenRenderer::Delegate* delegate);
20+
explicit WindowChannel(BinaryMessenger* messenger, TizenWindow* window);
2321
virtual ~WindowChannel();
2422

2523
private:
@@ -28,11 +26,8 @@ class WindowChannel {
2826

2927
std::unique_ptr<MethodChannel<EncodableValue>> channel_;
3028

31-
// A reference to the renderer object managed by FlutterTizenEngine.
32-
// This can be nullptr if the engine is running in headless mode.
33-
TizenRenderer* renderer_;
34-
35-
[[maybe_unused]] TizenRenderer::Delegate* delegate_;
29+
// A reference to the renderer object managed by FlutterTizenView.
30+
TizenWindow* window_;
3631
};
3732

3833
} // namespace flutter

shell/platform/tizen/flutter_project_bundle.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ FlutterProjectBundle::FlutterProjectBundle(
4040
aot_library_path_ = std::filesystem::path(properties.aot_library_path);
4141
}
4242

43+
if (properties.entrypoint != nullptr) {
44+
custom_dart_entrypoint_ = std::string(properties.entrypoint);
45+
}
46+
4347
for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
4448
dart_entrypoint_arguments_.push_back(
4549
std::string(properties.dart_entrypoint_argv[i]));

shell/platform/tizen/flutter_project_bundle.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class FlutterProjectBundle {
5656
// Logs and returns nullptr on failure.
5757
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs);
5858

59+
// Returns custom entrypoint in the Dart project.
60+
const std::string& custom_dart_entrypoint() {
61+
return custom_dart_entrypoint_;
62+
}
63+
5964
// Returns the command line arguments to be passed through to the Dart
6065
// entrypoint.
6166
const std::vector<std::string>& dart_entrypoint_arguments() const {
@@ -70,6 +75,9 @@ class FlutterProjectBundle {
7075
// Path to the AOT library file, if any.
7176
std::filesystem::path aot_library_path_;
7277

78+
// Custom entrypoint in the Dart project
79+
std::string custom_dart_entrypoint_;
80+
7381
// Dart entrypoint arguments.
7482
std::vector<std::string> dart_entrypoint_arguments_;
7583
};

shell/platform/tizen/flutter_tizen.cc

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
1111
#include "flutter/shell/platform/tizen/flutter_project_bundle.h"
1212
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
13+
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
1314
#include "flutter/shell/platform/tizen/logger.h"
1415
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
16+
#include "flutter/shell/platform/tizen/tizen_window.h"
1517

1618
namespace {
1719

@@ -39,8 +41,7 @@ FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(
3941

4042
} // namespace
4143

42-
FlutterDesktopEngineRef FlutterDesktopRunEngine(
43-
const FlutterDesktopWindowProperties& window_properties,
44+
FlutterDesktopEngineRef FlutterDesktopEngineCreate(
4445
const FlutterDesktopEngineProperties& engine_properties) {
4546
flutter::FlutterProjectBundle project(engine_properties);
4647
if (project.HasArgument("--verbose-logging")) {
@@ -53,29 +54,24 @@ FlutterDesktopEngineRef FlutterDesktopRunEngine(
5354
flutter::Logger::Start();
5455

5556
auto engine = std::make_unique<flutter::FlutterTizenEngine>(project);
56-
if (window_properties.headed) {
57-
engine->InitializeRenderer(
58-
window_properties.x, window_properties.y, window_properties.width,
59-
window_properties.height, window_properties.transparent,
60-
window_properties.focusable, window_properties.top_level);
61-
}
62-
if (!engine->RunEngine(engine_properties.entrypoint)) {
63-
FT_LOG(Error) << "Failed to start the Flutter engine.";
64-
return nullptr;
65-
}
6657
return HandleForEngine(engine.release());
6758
}
6859

69-
void FlutterDesktopShutdownEngine(FlutterDesktopEngineRef engine_ref) {
60+
bool FlutterDesktopEngineRun(const FlutterDesktopEngineRef engine) {
61+
return EngineFromHandle(engine)->RunEngine();
62+
}
63+
64+
void FlutterDesktopEngineShutdown(FlutterDesktopEngineRef engine_ref) {
7065
flutter::Logger::Stop();
7166

7267
flutter::FlutterTizenEngine* engine = EngineFromHandle(engine_ref);
7368
engine->StopEngine();
7469
delete engine;
7570
}
7671

77-
void* FlutterDesktopGetWindow(FlutterDesktopPluginRegistrarRef registrar) {
78-
return registrar->engine->renderer()->GetWindowHandle();
72+
void* FlutterDesktopPluginRegistrarGetNativeWindow(
73+
FlutterDesktopPluginRegistrarRef registrar) {
74+
return registrar->engine->view()->window()->GetWindowHandle();
7975
}
8076

8177
void FlutterDesktopPluginRegistrarEnableInputBlocking(
@@ -85,7 +81,7 @@ void FlutterDesktopPluginRegistrarEnableInputBlocking(
8581
channel);
8682
}
8783

88-
FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(
84+
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(
8985
FlutterDesktopEngineRef engine,
9086
const char* plugin_name) {
9187
// Currently, one registrar acts as the registrar for all plugins, so the
@@ -144,33 +140,34 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
144140
user_data);
145141
}
146142

147-
void FlutterDesktopNotifyAppControl(FlutterDesktopEngineRef engine,
148-
void* app_control) {
143+
void FlutterDesktopEngineNotifyAppControl(FlutterDesktopEngineRef engine,
144+
void* app_control) {
149145
EngineFromHandle(engine)->app_control_channel()->NotifyAppControl(
150146
app_control);
151147
}
152148

153-
void FlutterDesktopNotifyLocaleChange(FlutterDesktopEngineRef engine) {
149+
void FlutterDesktopEngineNotifyLocaleChange(FlutterDesktopEngineRef engine) {
154150
EngineFromHandle(engine)->SetupLocales();
155151
}
156152

157-
void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) {
153+
void FlutterDesktopEngineNotifyLowMemoryWarning(
154+
FlutterDesktopEngineRef engine) {
158155
EngineFromHandle(engine)->NotifyLowMemoryWarning();
159156
}
160157

161-
void FlutterDesktopNotifyAppIsInactive(FlutterDesktopEngineRef engine) {
158+
void FlutterDesktopEngineNotifyAppIsInactive(FlutterDesktopEngineRef engine) {
162159
EngineFromHandle(engine)->lifecycle_channel()->AppIsInactive();
163160
}
164161

165-
void FlutterDesktopNotifyAppIsResumed(FlutterDesktopEngineRef engine) {
162+
void FlutterDesktopEngineNotifyAppIsResumed(FlutterDesktopEngineRef engine) {
166163
EngineFromHandle(engine)->lifecycle_channel()->AppIsResumed();
167164
}
168165

169-
void FlutterDesktopNotifyAppIsPaused(FlutterDesktopEngineRef engine) {
166+
void FlutterDesktopEngineNotifyAppIsPaused(FlutterDesktopEngineRef engine) {
170167
EngineFromHandle(engine)->lifecycle_channel()->AppIsPaused();
171168
}
172169

173-
void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
170+
void FlutterDesktopEngineNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
174171
EngineFromHandle(engine)->lifecycle_channel()->AppIsDetached();
175172
}
176173

0 commit comments

Comments
 (0)