Skip to content

Commit

Permalink
Refactor embedder and introduce FlutterTizenView (#278)
Browse files Browse the repository at this point in the history
* 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 <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 authored May 3, 2022
1 parent 45e7e13 commit 6ac2e23
Show file tree
Hide file tree
Showing 36 changed files with 2,158 additions and 1,482 deletions.
13 changes: 9 additions & 4 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ template("embedder") {
"flutter_tizen.cc",
"flutter_tizen_engine.cc",
"flutter_tizen_texture_registrar.cc",
"key_event_handler.cc",
"flutter_tizen_view.cc",
"logger.cc",
"system_utils.cc",
"tizen_event_loop.cc",
"tizen_input_method_context.cc",
"tizen_renderer.cc",
"touch_event_handler.cc",
]

if (target_name != "flutter_tizen_wearable") {
Expand Down Expand Up @@ -185,7 +184,11 @@ template("embedder") {
]

if (use_evas_gl_renderer) {
sources += [ "tizen_renderer_evas_gl.cc" ]
sources += [
"flutter_tizen_elementary.cc",
"tizen_renderer_evas_gl.cc",
"tizen_window_elementary.cc",
]

libs += [
"ecore_evas",
Expand All @@ -196,8 +199,10 @@ template("embedder") {
public_configs += [ ":evas_gl_renderer" ]
} else {
sources += [
"tizen_renderer_ecore_wl2.cc",
"flutter_tizen_ecore.cc",
"tizen_renderer_egl.cc",
"tizen_vsync_waiter.cc",
"tizen_window_ecore_wl2.cc",
]

libs += [
Expand Down
16 changes: 8 additions & 8 deletions shell/platform/tizen/channels/platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ std::string text_clipboard = "";
} // namespace

PlatformChannel::PlatformChannel(BinaryMessenger* messenger,
TizenRenderer* renderer)
TizenWindow* window)
: channel_(std::make_unique<MethodChannel<rapidjson::Document>>(
messenger,
kChannelName,
&JsonMethodCodec::GetInstance())),
renderer_(renderer) {
window_(window) {
channel_->SetMethodCallHandler(
[this](const MethodCall<rapidjson::Document>& call,
std::unique_ptr<MethodResult<rapidjson::Document>> result) {
Expand Down Expand Up @@ -164,13 +164,13 @@ void PlatformChannel::HapticFeedbackVibrate(const std::string& feedback_type) {
}

void PlatformChannel::RestoreSystemUiOverlays() {
if (!renderer_) {
if (!window_) {
return;
}

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

if (shell.IsSoftkeyShown()) {
shell.ShowSoftkey();
Expand All @@ -182,13 +182,13 @@ void PlatformChannel::RestoreSystemUiOverlays() {

void PlatformChannel::SetEnabledSystemUiOverlays(
const std::vector<std::string>& overlays) {
if (!renderer_) {
if (!window_) {
return;
}

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

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

void PlatformChannel::SetPreferredOrientations(
const std::vector<std::string>& orientations) {
if (!renderer_) {
if (!window_) {
return;
}

Expand All @@ -220,7 +220,7 @@ void PlatformChannel::SetPreferredOrientations(
// default.
rotations = {0, 90, 180, 270};
}
renderer_->SetPreferredOrientations(rotations);
window_->SetPreferredOrientations(rotations);
}

} // namespace flutter
8 changes: 4 additions & 4 deletions shell/platform/tizen/channels/platform_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "flutter/shell/platform/tizen/tizen_renderer.h"
#include "flutter/shell/platform/tizen/tizen_window.h"
#include "rapidjson/document.h"

namespace flutter {

class PlatformChannel {
public:
explicit PlatformChannel(BinaryMessenger* messenger, TizenRenderer* renderer);
explicit PlatformChannel(BinaryMessenger* messenger, TizenWindow* window);
virtual ~PlatformChannel();

private:
Expand All @@ -35,9 +35,9 @@ class PlatformChannel {

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

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

} // namespace flutter
Expand Down
37 changes: 20 additions & 17 deletions shell/platform/tizen/channels/window_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ constexpr char kChannelName[] = "tizen/internal/window";

} // namespace

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

if (method_name == "getWindowGeometry") {
TizenRenderer::Geometry geometry = renderer_->GetWindowGeometry();
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
EncodableMap map;
map[EncodableValue("x")] = EncodableValue(geometry.x);
map[EncodableValue("y")] = EncodableValue(geometry.y);
map[EncodableValue("width")] = EncodableValue(geometry.w);
map[EncodableValue("height")] = EncodableValue(geometry.h);
map[EncodableValue("x")] = EncodableValue(geometry.left);
map[EncodableValue("y")] = EncodableValue(geometry.top);
map[EncodableValue("width")] = EncodableValue(geometry.width);
map[EncodableValue("height")] = EncodableValue(geometry.height);
result->Success(EncodableValue(map));
} else if (method_name == "setWindowGeometry") {
#ifdef TIZEN_RENDERER_EVAS_GL
Expand All @@ -59,18 +57,23 @@ void WindowChannel::HandleMethodCall(
EncodableValueHolder<int32_t> width(arguments, "width");
EncodableValueHolder<int32_t> height(arguments, "height");

TizenRenderer::Geometry geometry = renderer_->GetWindowGeometry();

delegate_->OnGeometryChange(x ? *x : geometry.x, y ? *y : geometry.y,
width ? *width : geometry.w,
height ? *height : geometry.h);
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
// FIXME: Use SetWindowGeometry() instead of OnGeometryChanged()
// After the SetWindowGeometry was successfully executed, I expected a
// handler of ECORE_WL2_EVENT_WINDOW_CONFIGURE to be called, but it didn't.
window_->OnGeometryChanged({
x ? *x : geometry.left,
y ? *y : geometry.top,
width ? *width : geometry.width,
height ? *height : geometry.height,
});
result->Success();
#endif
} else if (method_name == "getScreenGeometry") {
TizenRenderer::Geometry geometry = renderer_->GetScreenGeometry();
TizenWindow::Geometry geometry = window_->GetScreenGeometry();
EncodableMap map;
map[EncodableValue("width")] = EncodableValue(geometry.w);
map[EncodableValue("height")] = EncodableValue(geometry.h);
map[EncodableValue("width")] = EncodableValue(geometry.width);
map[EncodableValue("height")] = EncodableValue(geometry.height);
result->Success(EncodableValue(map));
} else {
result->NotImplemented();
Expand Down
13 changes: 4 additions & 9 deletions shell/platform/tizen/channels/window_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
#include "flutter/shell/platform/tizen/tizen_renderer.h"
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace flutter {

// Channel to get/set application's window size and device's screen size.
class WindowChannel {
public:
explicit WindowChannel(BinaryMessenger* messenger,
TizenRenderer* renderer,
TizenRenderer::Delegate* delegate);
explicit WindowChannel(BinaryMessenger* messenger, TizenWindow* window);
virtual ~WindowChannel();

private:
Expand All @@ -28,11 +26,8 @@ class WindowChannel {

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

// A reference to the renderer object managed by FlutterTizenEngine.
// This can be nullptr if the engine is running in headless mode.
TizenRenderer* renderer_;

[[maybe_unused]] TizenRenderer::Delegate* delegate_;
// A reference to the renderer object managed by FlutterTizenView.
TizenWindow* window_;
};

} // namespace flutter
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/tizen/flutter_project_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ FlutterProjectBundle::FlutterProjectBundle(
aot_library_path_ = std::filesystem::path(properties.aot_library_path);
}

if (properties.entrypoint != nullptr) {
custom_dart_entrypoint_ = std::string(properties.entrypoint);
}

for (int i = 0; i < properties.dart_entrypoint_argc; i++) {
dart_entrypoint_arguments_.push_back(
std::string(properties.dart_entrypoint_argv[i]));
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/tizen/flutter_project_bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class FlutterProjectBundle {
// Logs and returns nullptr on failure.
UniqueAotDataPtr LoadAotData(const FlutterEngineProcTable& engine_procs);

// Returns custom entrypoint in the Dart project.
const std::string& custom_dart_entrypoint() {
return custom_dart_entrypoint_;
}

// Returns the command line arguments to be passed through to the Dart
// entrypoint.
const std::vector<std::string>& dart_entrypoint_arguments() const {
Expand All @@ -70,6 +75,9 @@ class FlutterProjectBundle {
// Path to the AOT library file, if any.
std::filesystem::path aot_library_path_;

// Custom entrypoint in the Dart project
std::string custom_dart_entrypoint_;

// Dart entrypoint arguments.
std::vector<std::string> dart_entrypoint_arguments_;
};
Expand Down
45 changes: 21 additions & 24 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#include "flutter/shell/platform/common/incoming_message_dispatcher.h"
#include "flutter/shell/platform/tizen/flutter_project_bundle.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace {

Expand Down Expand Up @@ -39,8 +41,7 @@ FlutterDesktopTextureRegistrarRef HandleForTextureRegistrar(

} // namespace

FlutterDesktopEngineRef FlutterDesktopRunEngine(
const FlutterDesktopWindowProperties& window_properties,
FlutterDesktopEngineRef FlutterDesktopEngineCreate(
const FlutterDesktopEngineProperties& engine_properties) {
flutter::FlutterProjectBundle project(engine_properties);
if (project.HasArgument("--verbose-logging")) {
Expand All @@ -53,29 +54,24 @@ FlutterDesktopEngineRef FlutterDesktopRunEngine(
flutter::Logger::Start();

auto engine = std::make_unique<flutter::FlutterTizenEngine>(project);
if (window_properties.headed) {
engine->InitializeRenderer(
window_properties.x, window_properties.y, window_properties.width,
window_properties.height, window_properties.transparent,
window_properties.focusable, window_properties.top_level);
}
if (!engine->RunEngine(engine_properties.entrypoint)) {
FT_LOG(Error) << "Failed to start the Flutter engine.";
return nullptr;
}
return HandleForEngine(engine.release());
}

void FlutterDesktopShutdownEngine(FlutterDesktopEngineRef engine_ref) {
bool FlutterDesktopEngineRun(const FlutterDesktopEngineRef engine) {
return EngineFromHandle(engine)->RunEngine();
}

void FlutterDesktopEngineShutdown(FlutterDesktopEngineRef engine_ref) {
flutter::Logger::Stop();

flutter::FlutterTizenEngine* engine = EngineFromHandle(engine_ref);
engine->StopEngine();
delete engine;
}

void* FlutterDesktopGetWindow(FlutterDesktopPluginRegistrarRef registrar) {
return registrar->engine->renderer()->GetWindowHandle();
void* FlutterDesktopPluginRegistrarGetNativeWindow(
FlutterDesktopPluginRegistrarRef registrar) {
return registrar->engine->view()->window()->GetWindowHandle();
}

void FlutterDesktopPluginRegistrarEnableInputBlocking(
Expand All @@ -85,7 +81,7 @@ void FlutterDesktopPluginRegistrarEnableInputBlocking(
channel);
}

FlutterDesktopPluginRegistrarRef FlutterDesktopGetPluginRegistrar(
FlutterDesktopPluginRegistrarRef FlutterDesktopEngineGetPluginRegistrar(
FlutterDesktopEngineRef engine,
const char* plugin_name) {
// Currently, one registrar acts as the registrar for all plugins, so the
Expand Down Expand Up @@ -144,33 +140,34 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger,
user_data);
}

void FlutterDesktopNotifyAppControl(FlutterDesktopEngineRef engine,
void* app_control) {
void FlutterDesktopEngineNotifyAppControl(FlutterDesktopEngineRef engine,
void* app_control) {
EngineFromHandle(engine)->app_control_channel()->NotifyAppControl(
app_control);
}

void FlutterDesktopNotifyLocaleChange(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyLocaleChange(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->SetupLocales();
}

void FlutterDesktopNotifyLowMemoryWarning(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyLowMemoryWarning(
FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->NotifyLowMemoryWarning();
}

void FlutterDesktopNotifyAppIsInactive(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyAppIsInactive(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->lifecycle_channel()->AppIsInactive();
}

void FlutterDesktopNotifyAppIsResumed(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyAppIsResumed(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->lifecycle_channel()->AppIsResumed();
}

void FlutterDesktopNotifyAppIsPaused(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyAppIsPaused(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->lifecycle_channel()->AppIsPaused();
}

void FlutterDesktopNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
void FlutterDesktopEngineNotifyAppIsDetached(FlutterDesktopEngineRef engine) {
EngineFromHandle(engine)->lifecycle_channel()->AppIsDetached();
}

Expand Down
Loading

0 comments on commit 6ac2e23

Please sign in to comment.