From 1b274611e74c220f594de777bce5c2c05004dec2 Mon Sep 17 00:00:00 2001 From: MuHong Byun Date: Tue, 29 Jun 2021 16:08:11 +0900 Subject: [PATCH] Add basic shell for test Signed-off-by: MuHong Byun --- shell/platform/tizen/BUILD.gn | 47 ++++++- shell/platform/tizen/flutter_tizen_shell.cc | 121 ++++++++++++++++++ .../platform/tizen/tizen_renderer_evas_gl.cc | 12 +- 3 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 shell/platform/tizen/flutter_tizen_shell.cc diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 05055b9375cca..7393338b33762 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -1,7 +1,6 @@ # Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. - import("//flutter/shell/platform/common/client_wrapper/publish.gni") import("//flutter/shell/platform/config.gni") import("//flutter/shell/platform/tizen/config.gni") @@ -14,6 +13,10 @@ config("tizen_embedder_rpath") { ldflags = [ "-Wl,-rpath,\$ORIGIN" ] } +config("relative_angle_headers") { + include_dirs = [ "//third_party/angle/include" ] +} + source_set("flutter_engine") { visibility = [ ":*" ] @@ -53,8 +56,6 @@ _libs_minimum = [ "ecore_input", "eina", "evas", - "EGL", - "GLESv2", "wayland-client", ] @@ -138,6 +139,8 @@ template("embedder_for_profile") { "feedback", "tbm", "tdm-client", + "EGL", + "GLESv2", ] } @@ -236,6 +239,7 @@ executable("flutter_tizen_unittests") { ] public_configs = [ "//flutter:config" ] + configs += [ ":tizen_rootstrap_include_dirs", "//flutter/shell/platform/common:desktop_library_implementation", @@ -258,6 +262,40 @@ executable("flutter_tizen_unittests") { ] } +executable("flutter_tizen_shell") { + public = _public_headers + sources = _flutter_tizen_source + sources += [ "tizen_renderer_evas_gl.cc" ] + sources += [ "flutter_tizen_shell.cc" ] + libs = _libs_minimum + libs += [ + "ecore_evas", + "elementary", + ] + + defines = [ "TIZEN_RENDERER_EVAS_GL" ] + cflags_cc = [ + "-Wno-newline-eof", + "-Wno-macro-redefined", + ] + + public_configs = [ "//flutter:config" ] + configs += [ + ":tizen_rootstrap_include_dirs", + "//flutter/shell/platform/common:desktop_library_implementation", + ] + public_deps = [ ":flutter_engine" ] + deps = [ + "//flutter/runtime:libdart", + "//flutter/shell/platform/common:common_cpp", + "//flutter/shell/platform/common:common_cpp_input", + "//flutter/shell/platform/common:common_cpp_library_headers", + "//flutter/shell/platform/common/client_wrapper:client_wrapper", + "//flutter/shell/platform/embedder:embedder_headers", + "//third_party/rapidjson", + ] +} + publish_client_wrapper_core("publish_cpp_client_wrapper") { visibility = [ ":*" ] } @@ -293,4 +331,7 @@ group("tizen") { ":publish_cpp_client_wrapper", ":publish_headers_tizen", ] + if (enable_desktop_embeddings) { + deps += [ ":flutter_tizen_shell" ] + } } diff --git a/shell/platform/tizen/flutter_tizen_shell.cc b/shell/platform/tizen/flutter_tizen_shell.cc new file mode 100644 index 0000000000000..a69fe67d624e0 --- /dev/null +++ b/shell/platform/tizen/flutter_tizen_shell.cc @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include + +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" +#include "flutter/shell/platform/tizen/public/flutter_tizen.h" + +extern int gApp_width; +extern int gApp_height; + +std::string TPK_ROOT_PATH = "/tpkroot"; +std::string LIB_PATH = "/lib"; +std::string RES_PATH = "/res"; + +class FlutterApp { + public: + explicit FlutterApp() {} + virtual ~FlutterApp() {} + + bool OnCreate() { + printf("Launching a Flutter application...\n"); + + std::string assets_path; + std::string icu_data_path; + std::string aot_lib_path; + FlutterDesktopEngineProperties engine_prop = {}; + std::vector switches; + + std::string tpk_root; + if (app_path_.empty()) { + char path[256]; + getcwd(path, sizeof(path)); + tpk_root = path + TPK_ROOT_PATH; + } else { + tpk_root = app_path_; + } + + assets_path = tpk_root + RES_PATH + "/flutter_assets"; + icu_data_path = tpk_root + RES_PATH + "/icudtl.dat"; + aot_lib_path = tpk_root + LIB_PATH + "/libapp.so"; + + switches.push_back("--disable-observatory"); + switches.push_back("--verbose-logging"); + switches.push_back("--enable-dart-profiling"); + switches.push_back("--enable-checked-mode"); + + engine_prop.assets_path = assets_path.c_str(); + engine_prop.icu_data_path = icu_data_path.c_str(); + engine_prop.aot_library_path = aot_lib_path.c_str(); + engine_prop.switches = switches.data(); + engine_prop.switches_count = switches.size(); + engine_ = reinterpret_cast( + FlutterDesktopRunEngine(engine_prop, true)); + + if (!engine_) { + printf("Could not launch a Flutter application.\n"); + return false; + } + // RegisterPlugins(this); + return true; + } + void OnResume() {} + void OnPause() {} + void OnTerminate() { + printf("Shutting down the application..."); + + FlutterDesktopShutdownEngine( + reinterpret_cast(engine_)); + delete engine_; + engine_ = nullptr; + + ecore_shutdown(); + } + int Run(int argc, char** argv) { + ecore_init(); + elm_init(0, 0); + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); + elm_config_accel_preference_set("opengl"); + + for (int i = 1; i < argc; i++) { + if (strstr(argv[i], "--width=") == argv[i]) { + gApp_width = std::atoi(argv[i] + strlen("--width=")); + } else if (strstr(argv[i], "--height=") == argv[i]) { + gApp_height = std::atoi(argv[i] + strlen("--height=")); + } else if (strstr(argv[i], "--tpkroot=") == argv[i]) { + app_path_ = argv[i] + strlen("--tpkroot="); + } + } + + ecore_idler_add( + [](void* data) -> Eina_Bool { + FlutterApp* app = (FlutterApp*)data; + app->OnCreate(); + return ECORE_CALLBACK_CANCEL; + }, + this); + ecore_main_loop_begin(); + return 0; + } + + FlutterDesktopPluginRegistrarRef GetRegistrarForPlugin( + const std::string& plugin_name) { + if (engine_) { + return FlutterDesktopGetPluginRegistrar( + reinterpret_cast(engine_), + plugin_name.c_str()); + } + return nullptr; + } + + private: + std::string app_path_ = {}; + flutter::FlutterTizenEngine* engine_ = nullptr; +}; + +int main(int argc, char* argv[]) { + auto app = new FlutterApp(); + return app->Run(argc, argv); +} diff --git a/shell/platform/tizen/tizen_renderer_evas_gl.cc b/shell/platform/tizen/tizen_renderer_evas_gl.cc index 5dfa505a8a4cc..28509c318f2ae 100644 --- a/shell/platform/tizen/tizen_renderer_evas_gl.cc +++ b/shell/platform/tizen/tizen_renderer_evas_gl.cc @@ -8,6 +8,11 @@ Evas_GL* g_evas_gl = nullptr; EVAS_GL_GLOBAL_GLES3_DEFINE(); +#ifdef __X64_SHELL__ +int gApp_width = 800; +int gApp_height = 600; +#endif + #include "flutter/shell/platform/tizen/tizen_log.h" namespace flutter { @@ -601,11 +606,12 @@ bool TizenRendererEvasGL::SetupEvasGL() { gl_config_->depth_bits = EVAS_GL_DEPTH_NONE; gl_config_->stencil_bits = EVAS_GL_STENCIL_NONE; +#ifndef __X64_SHELL__ gl_context_ = evas_gl_context_version_create(evas_gl_, NULL, EVAS_GL_GLES_3_X); gl_resource_context_ = evas_gl_context_version_create(evas_gl_, gl_context_, EVAS_GL_GLES_3_X); - +#endif if (gl_context_ == nullptr) { FT_LOGW( "Failed to create evas gl context with EVAS_GL_GLES_3_X, try to use " @@ -647,6 +653,10 @@ Evas_Object* TizenRendererEvasGL::SetupEvasWindow(int32_t& width, return nullptr; } +#ifdef __X64_SHELL__ + width = gApp_width; + height = gApp_height; +#endif elm_win_alpha_set(evas_window_, EINA_FALSE); evas_object_move(evas_window_, 0, 0); evas_object_resize(evas_window_, width, height);