Skip to content

Commit

Permalink
Introduce TizenViewNui (#328)
Browse files Browse the repository at this point in the history
This is a View Class that supports NUI UIFW that inherits TizenView.
NUI is a UIFW based on the C# language that wrapping Dali UIFW.
The mouse and the keyboard event callback handling for NUI is handled in embedding(C#).
The embedder handles events related to event delivery and rendering.
Basically draw a flutter on a NativeImageQueue created from embedding.
This corresponds to tbm_surface_queue_h and is rendered flutter view using egl.
(When taking tbm_surface_queue_h from NativeImageQueue, typeid() is used inside dali,
so -rtti flag is absolutely necessary.)

Co-authored-by: Swift Kim <[email protected]>
  • Loading branch information
JSUYA and swift-kim authored Aug 31, 2022
1 parent 0690785 commit e75d0ec
Show file tree
Hide file tree
Showing 12 changed files with 395 additions and 35 deletions.
2 changes: 2 additions & 0 deletions shell/platform/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ source_set("common_cpp_accessibility") {
public_configs =
[ "//flutter/third_party/accessibility:accessibility_config" ]

configs -= [ "//build/config/compiler:no_rtti" ]

public_deps = [
"//flutter/fml:fml",
"//flutter/shell/platform/embedder:embedder_headers",
Expand Down
83 changes: 59 additions & 24 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ config("rootstrap_include_dirs") {
"$custom_sysroot/usr/include",
"$custom_sysroot/usr/include/appfw",
"$custom_sysroot/usr/include/base",
"$custom_sysroot/usr/include/dali",
"$custom_sysroot/usr/include/dali-adaptor",
"$custom_sysroot/usr/include/dali-toolkit",
"$custom_sysroot/usr/include/dlog",
"$custom_sysroot/usr/include/ecore-1",
"$custom_sysroot/usr/include/ecore-imf-1",
Expand Down Expand Up @@ -94,9 +97,14 @@ template("embedder") {
forward_variables_from(invoker,
[
"target_type",
"enable_nui_support",
"defines",
])

if (!defined(enable_nui_support)) {
enable_nui_support = false
}

target(target_type, target_name) {
public = _public_headers

Expand Down Expand Up @@ -133,13 +141,6 @@ template("embedder") {
"tizen_window_elementary.cc",
]

if (target_name != "flutter_tizen_wearable") {
sources += [
"accessibility_bridge_delegate_tizen.cc",
"flutter_platform_node_delegate_tizen.cc",
]
}

libs = [
"base-utils-i18n",
"capi-appfw-application",
Expand All @@ -164,6 +165,26 @@ template("embedder") {
"wayland-client",
]

if (target_name != "flutter_tizen_wearable") {
sources += [
"accessibility_bridge_delegate_tizen.cc",
"external_texture_pixel_egl.cc",
"external_texture_surface_egl.cc",
"flutter_platform_node_delegate_tizen.cc",
"tizen_renderer_egl.cc",
"tizen_vsync_waiter.cc",
"tizen_window_ecore_wl2.cc",
]

libs += [
"ecore_wl2",
"tdm-client",
"tizen-extension-client",
"EGL",
"GLESv2",
]
}

if (target_name == "flutter_tizen_common") {
sources += [ "channels/tizen_shell.cc" ]

Expand All @@ -179,30 +200,28 @@ template("embedder") {
configs +=
[ "//flutter/shell/platform/common:desktop_library_implementation" ]

public_configs = [
":relative_client_wrapper_headers",
":rootstrap_include_dirs",
"//flutter:config",
]

if (target_name != "flutter_tizen_wearable") {
if (enable_nui_support) {
sources += [
"external_texture_pixel_egl.cc",
"external_texture_surface_egl.cc",
"tizen_renderer_egl.cc",
"tizen_vsync_waiter.cc",
"tizen_window_ecore_wl2.cc",
"flutter_tizen_nui.cc",
"tizen_view_nui.cc",
]

libs += [
"ecore_wl2",
"tdm-client",
"tizen-extension-client",
"EGL",
"GLESv2",
"dali2-adaptor",
"dali2-core",
]

defines += [ "NUI_SUPPORT" ]

configs -= [ "//build/config/compiler:no_rtti" ]
}

public_configs = [
":relative_client_wrapper_headers",
":rootstrap_include_dirs",
"//flutter:config",
]

public_deps = [ ":flutter_engine" ]

deps = [
Expand All @@ -226,6 +245,13 @@ embedder("flutter_tizen_mobile") {
defines = [ "MOBILE_PROFILE" ]
}

embedder("flutter_tizen_mobile_nui") {
target_type = "shared_library"
enable_nui_support = true

defines = [ "MOBILE_PROFILE" ]
}

embedder("flutter_tizen_wearable") {
target_type = "shared_library"

Expand All @@ -238,6 +264,13 @@ embedder("flutter_tizen_tv") {
defines = [ "TV_PROFILE" ]
}

embedder("flutter_tizen_tv_nui") {
target_type = "shared_library"
enable_nui_support = true

defines = [ "TV_PROFILE" ]
}

embedder("flutter_tizen_common") {
target_type = "shared_library"

Expand Down Expand Up @@ -316,7 +349,9 @@ group("tizen") {
deps += [
":flutter_tizen_common",
":flutter_tizen_mobile",
":flutter_tizen_mobile_nui",
":flutter_tizen_tv",
":flutter_tizen_tv_nui",
":flutter_tizen_wearable",
]
}
Expand Down
33 changes: 33 additions & 0 deletions shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,39 @@ void FlutterDesktopViewResize(FlutterDesktopViewRef view,
ViewFromHandle(view)->Resize(width, height);
}

void FlutterDesktopViewOnPointerEvent(FlutterDesktopViewRef view,
FlutterDesktopPointerEventType type,
double x,
double y,
size_t timestamp,
int32_t device_id) {
switch (type) {
case FlutterDesktopPointerEventType::kMouseDown:
default:
ViewFromHandle(view)->OnPointerDown(
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
break;
case FlutterDesktopPointerEventType::kMouseUp:
ViewFromHandle(view)->OnPointerUp(
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
break;
case FlutterDesktopPointerEventType::kMouseMove:
ViewFromHandle(view)->OnPointerMove(
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
break;
}
}

void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
const char* key,
const char* string,
uint32_t modifiers,
uint32_t scan_code,
bool is_down) {
ViewFromHandle(view)->OnKey(key, string, nullptr, modifiers, scan_code,
is_down);
}

void FlutterDesktopRegisterViewFactory(
FlutterDesktopPluginRegistrarRef registrar,
const char* view_type,
Expand Down
58 changes: 58 additions & 0 deletions shell/platform/tizen/flutter_tizen_nui.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2022 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.

#include "public/flutter_tizen.h"

#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>

#include <memory>

#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
#include "flutter/shell/platform/tizen/tizen_view_nui.h"

namespace {

// Returns the engine corresponding to the given opaque API handle.
flutter::FlutterTizenEngine* EngineFromHandle(FlutterDesktopEngineRef ref) {
return reinterpret_cast<flutter::FlutterTizenEngine*>(ref);
}

FlutterDesktopViewRef HandleForView(flutter::FlutterTizenView* view) {
return reinterpret_cast<FlutterDesktopViewRef>(view);
}

} // namespace

FlutterDesktopViewRef FlutterDesktopViewCreateFromImageView(
const FlutterDesktopViewProperties& view_properties,
FlutterDesktopEngineRef engine,
void* image_view,
void* native_image_queue,
int32_t default_window_id) {
std::unique_ptr<flutter::TizenViewBase> tizen_view =
std::make_unique<flutter::TizenViewNui>(
view_properties.width, view_properties.height,
reinterpret_cast<Dali::Toolkit::ImageView*>(image_view),
reinterpret_cast<Dali::NativeImageSourceQueue*>(native_image_queue),
default_window_id);

auto view =
std::make_unique<flutter::FlutterTizenView>(std::move(tizen_view));

// Take ownership of the engine, starting it if necessary.
view->SetEngine(
std::unique_ptr<flutter::FlutterTizenEngine>(EngineFromHandle(engine)));
view->CreateRenderSurface(FlutterDesktopRendererType::kEGL);
if (!view->engine()->IsRunning()) {
if (!view->engine()->RunEngine()) {
return nullptr;
}
}

view->SendInitialGeometry();

return HandleForView(view.release());
}
13 changes: 12 additions & 1 deletion shell/platform/tizen/flutter_tizen_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/tizen_view.h"
#ifdef NUI_SUPPORT
#include "flutter/shell/platform/tizen/tizen_view_nui.h"
#endif
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace {
Expand Down Expand Up @@ -131,7 +134,15 @@ bool FlutterTizenView::OnMakeResourceCurrent() {
}

bool FlutterTizenView::OnPresent() {
return engine_->renderer()->OnPresent();
bool result = engine_->renderer()->OnPresent();
#ifdef NUI_SUPPORT
if (tizen_view_->GetType() == flutter::TizenViewType::kView &&
engine_->renderer()->type() == FlutterDesktopRendererType::kEGL) {
auto* view = reinterpret_cast<TizenViewNui*>(tizen_view_.get());
view->RequestRendering();
}
#endif
return result;
}

uint32_t FlutterTizenView::OnGetFBO() {
Expand Down
35 changes: 34 additions & 1 deletion shell/platform/tizen/public/flutter_tizen.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ typedef enum {
kEGL,
} FlutterDesktopRendererType;

typedef enum {
kMouseDown,
kMouseUp,
kMouseMove,
} FlutterDesktopPointerEventType;

// Properties for configuring the initial settings of a Flutter window.
typedef struct {
// The x-coordinate of the top left corner of the window.
Expand Down Expand Up @@ -154,13 +160,25 @@ FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(

// Creates a view that hosts and displays the given engine instance.
//
// The type of parent should be Evas_Object*, Cast Evas_Object* to void*.
// The type of |parent| must be Evas_Object*.
// @warning This API is a work-in-progress and may change.
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewCreateFromElmParent(
const FlutterDesktopViewProperties& view_properties,
FlutterDesktopEngineRef engine,
void* parent);

// Creates a view that hosts and displays the given engine instance.
//
// The type of |image_view| must be Dali::Toolkit::ImageView*.
// The type of |native_image_queue| must be Dali::NativeImageSourceQueue*.
// @warning This API is a work-in-progress and may change.
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewCreateFromImageView(
const FlutterDesktopViewProperties& view_properties,
FlutterDesktopEngineRef engine,
void* image_view,
void* native_image_queue,
int32_t default_window_id);

// Destroys the view.
//
// The engine owned by the view will also be shut down implicitly.
Expand All @@ -183,6 +201,21 @@ FLUTTER_EXPORT void FlutterDesktopViewResize(FlutterDesktopViewRef view,
int32_t width,
int32_t height);

FLUTTER_EXPORT void FlutterDesktopViewOnPointerEvent(
FlutterDesktopViewRef view,
FlutterDesktopPointerEventType type,
double x,
double y,
size_t timestamp,
int32_t device_id);

FLUTTER_EXPORT void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
const char* key,
const char* string,
uint32_t modifiers,
uint32_t scan_code,
bool is_down);

// ========== Plugin Registrar (extensions) ==========

// Returns the view associated with this registrar's engine instance.
Expand Down
Loading

0 comments on commit e75d0ec

Please sign in to comment.