Skip to content

Commit

Permalink
Add basic shell for test
Browse files Browse the repository at this point in the history
Signed-off-by: MuHong Byun <mh.byun@samsung.com>
  • Loading branch information
bwikbs committed Jun 29, 2021
1 parent 803d7d5 commit 1b27461
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 4 deletions.
47 changes: 44 additions & 3 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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 = [ ":*" ]

Expand Down Expand Up @@ -53,8 +56,6 @@ _libs_minimum = [
"ecore_input",
"eina",
"evas",
"EGL",
"GLESv2",
"wayland-client",
]

Expand Down Expand Up @@ -138,6 +139,8 @@ template("embedder_for_profile") {
"feedback",
"tbm",
"tdm-client",
"EGL",
"GLESv2",
]
}

Expand Down Expand Up @@ -236,6 +239,7 @@ executable("flutter_tizen_unittests") {
]

public_configs = [ "//flutter:config" ]

configs += [
":tizen_rootstrap_include_dirs",
"//flutter/shell/platform/common:desktop_library_implementation",
Expand All @@ -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 = [ ":*" ]
}
Expand Down Expand Up @@ -293,4 +331,7 @@ group("tizen") {
":publish_cpp_client_wrapper",
":publish_headers_tizen",
]
if (enable_desktop_embeddings) {
deps += [ ":flutter_tizen_shell" ]
}
}
121 changes: 121 additions & 0 deletions shell/platform/tizen/flutter_tizen_shell.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#include <assert.h>
#include <unistd.h>
#include <chrono>
#include <iostream>
#include <thread>

#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<const char*> 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<flutter::FlutterTizenEngine*>(
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<FlutterDesktopEngineRef>(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<FlutterDesktopEngineRef>(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);
}
12 changes: 11 additions & 1 deletion shell/platform/tizen/tizen_renderer_evas_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b27461

Please sign in to comment.