Skip to content

Commit e75d0ec

Browse files
JSUYAswift-kim
andauthored
Introduce TizenViewNui (#328)
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]>
1 parent 0690785 commit e75d0ec

File tree

12 files changed

+395
-35
lines changed

12 files changed

+395
-35
lines changed

shell/platform/common/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ source_set("common_cpp_accessibility") {
9191
public_configs =
9292
[ "//flutter/third_party/accessibility:accessibility_config" ]
9393

94+
configs -= [ "//build/config/compiler:no_rtti" ]
95+
9496
public_deps = [
9597
"//flutter/fml:fml",
9698
"//flutter/shell/platform/embedder:embedder_headers",

shell/platform/tizen/BUILD.gn

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ config("rootstrap_include_dirs") {
4242
"$custom_sysroot/usr/include",
4343
"$custom_sysroot/usr/include/appfw",
4444
"$custom_sysroot/usr/include/base",
45+
"$custom_sysroot/usr/include/dali",
46+
"$custom_sysroot/usr/include/dali-adaptor",
47+
"$custom_sysroot/usr/include/dali-toolkit",
4548
"$custom_sysroot/usr/include/dlog",
4649
"$custom_sysroot/usr/include/ecore-1",
4750
"$custom_sysroot/usr/include/ecore-imf-1",
@@ -94,9 +97,14 @@ template("embedder") {
9497
forward_variables_from(invoker,
9598
[
9699
"target_type",
100+
"enable_nui_support",
97101
"defines",
98102
])
99103

104+
if (!defined(enable_nui_support)) {
105+
enable_nui_support = false
106+
}
107+
100108
target(target_type, target_name) {
101109
public = _public_headers
102110

@@ -133,13 +141,6 @@ template("embedder") {
133141
"tizen_window_elementary.cc",
134142
]
135143

136-
if (target_name != "flutter_tizen_wearable") {
137-
sources += [
138-
"accessibility_bridge_delegate_tizen.cc",
139-
"flutter_platform_node_delegate_tizen.cc",
140-
]
141-
}
142-
143144
libs = [
144145
"base-utils-i18n",
145146
"capi-appfw-application",
@@ -164,6 +165,26 @@ template("embedder") {
164165
"wayland-client",
165166
]
166167

168+
if (target_name != "flutter_tizen_wearable") {
169+
sources += [
170+
"accessibility_bridge_delegate_tizen.cc",
171+
"external_texture_pixel_egl.cc",
172+
"external_texture_surface_egl.cc",
173+
"flutter_platform_node_delegate_tizen.cc",
174+
"tizen_renderer_egl.cc",
175+
"tizen_vsync_waiter.cc",
176+
"tizen_window_ecore_wl2.cc",
177+
]
178+
179+
libs += [
180+
"ecore_wl2",
181+
"tdm-client",
182+
"tizen-extension-client",
183+
"EGL",
184+
"GLESv2",
185+
]
186+
}
187+
167188
if (target_name == "flutter_tizen_common") {
168189
sources += [ "channels/tizen_shell.cc" ]
169190

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

182-
public_configs = [
183-
":relative_client_wrapper_headers",
184-
":rootstrap_include_dirs",
185-
"//flutter:config",
186-
]
187-
188-
if (target_name != "flutter_tizen_wearable") {
203+
if (enable_nui_support) {
189204
sources += [
190-
"external_texture_pixel_egl.cc",
191-
"external_texture_surface_egl.cc",
192-
"tizen_renderer_egl.cc",
193-
"tizen_vsync_waiter.cc",
194-
"tizen_window_ecore_wl2.cc",
205+
"flutter_tizen_nui.cc",
206+
"tizen_view_nui.cc",
195207
]
196208

197209
libs += [
198-
"ecore_wl2",
199-
"tdm-client",
200-
"tizen-extension-client",
201-
"EGL",
202-
"GLESv2",
210+
"dali2-adaptor",
211+
"dali2-core",
203212
]
213+
214+
defines += [ "NUI_SUPPORT" ]
215+
216+
configs -= [ "//build/config/compiler:no_rtti" ]
204217
}
205218

219+
public_configs = [
220+
":relative_client_wrapper_headers",
221+
":rootstrap_include_dirs",
222+
"//flutter:config",
223+
]
224+
206225
public_deps = [ ":flutter_engine" ]
207226

208227
deps = [
@@ -226,6 +245,13 @@ embedder("flutter_tizen_mobile") {
226245
defines = [ "MOBILE_PROFILE" ]
227246
}
228247

248+
embedder("flutter_tizen_mobile_nui") {
249+
target_type = "shared_library"
250+
enable_nui_support = true
251+
252+
defines = [ "MOBILE_PROFILE" ]
253+
}
254+
229255
embedder("flutter_tizen_wearable") {
230256
target_type = "shared_library"
231257

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

267+
embedder("flutter_tizen_tv_nui") {
268+
target_type = "shared_library"
269+
enable_nui_support = true
270+
271+
defines = [ "TV_PROFILE" ]
272+
}
273+
241274
embedder("flutter_tizen_common") {
242275
target_type = "shared_library"
243276

@@ -316,7 +349,9 @@ group("tizen") {
316349
deps += [
317350
":flutter_tizen_common",
318351
":flutter_tizen_mobile",
352+
":flutter_tizen_mobile_nui",
319353
":flutter_tizen_tv",
354+
":flutter_tizen_tv_nui",
320355
":flutter_tizen_wearable",
321356
]
322357
}

shell/platform/tizen/flutter_tizen.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,39 @@ void FlutterDesktopViewResize(FlutterDesktopViewRef view,
241241
ViewFromHandle(view)->Resize(width, height);
242242
}
243243

244+
void FlutterDesktopViewOnPointerEvent(FlutterDesktopViewRef view,
245+
FlutterDesktopPointerEventType type,
246+
double x,
247+
double y,
248+
size_t timestamp,
249+
int32_t device_id) {
250+
switch (type) {
251+
case FlutterDesktopPointerEventType::kMouseDown:
252+
default:
253+
ViewFromHandle(view)->OnPointerDown(
254+
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
255+
break;
256+
case FlutterDesktopPointerEventType::kMouseUp:
257+
ViewFromHandle(view)->OnPointerUp(
258+
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
259+
break;
260+
case FlutterDesktopPointerEventType::kMouseMove:
261+
ViewFromHandle(view)->OnPointerMove(
262+
x, y, timestamp, kFlutterPointerDeviceKindTouch, device_id);
263+
break;
264+
}
265+
}
266+
267+
void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
268+
const char* key,
269+
const char* string,
270+
uint32_t modifiers,
271+
uint32_t scan_code,
272+
bool is_down) {
273+
ViewFromHandle(view)->OnKey(key, string, nullptr, modifiers, scan_code,
274+
is_down);
275+
}
276+
244277
void FlutterDesktopRegisterViewFactory(
245278
FlutterDesktopPluginRegistrarRef registrar,
246279
const char* view_type,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2022 Samsung Electronics Co., Ltd. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#include "public/flutter_tizen.h"
6+
7+
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
8+
#include <dali/devel-api/adaptor-framework/native-image-source-queue.h>
9+
10+
#include <memory>
11+
12+
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
13+
#include "flutter/shell/platform/tizen/flutter_tizen_view.h"
14+
#include "flutter/shell/platform/tizen/tizen_view_nui.h"
15+
16+
namespace {
17+
18+
// Returns the engine corresponding to the given opaque API handle.
19+
flutter::FlutterTizenEngine* EngineFromHandle(FlutterDesktopEngineRef ref) {
20+
return reinterpret_cast<flutter::FlutterTizenEngine*>(ref);
21+
}
22+
23+
FlutterDesktopViewRef HandleForView(flutter::FlutterTizenView* view) {
24+
return reinterpret_cast<FlutterDesktopViewRef>(view);
25+
}
26+
27+
} // namespace
28+
29+
FlutterDesktopViewRef FlutterDesktopViewCreateFromImageView(
30+
const FlutterDesktopViewProperties& view_properties,
31+
FlutterDesktopEngineRef engine,
32+
void* image_view,
33+
void* native_image_queue,
34+
int32_t default_window_id) {
35+
std::unique_ptr<flutter::TizenViewBase> tizen_view =
36+
std::make_unique<flutter::TizenViewNui>(
37+
view_properties.width, view_properties.height,
38+
reinterpret_cast<Dali::Toolkit::ImageView*>(image_view),
39+
reinterpret_cast<Dali::NativeImageSourceQueue*>(native_image_queue),
40+
default_window_id);
41+
42+
auto view =
43+
std::make_unique<flutter::FlutterTizenView>(std::move(tizen_view));
44+
45+
// Take ownership of the engine, starting it if necessary.
46+
view->SetEngine(
47+
std::unique_ptr<flutter::FlutterTizenEngine>(EngineFromHandle(engine)));
48+
view->CreateRenderSurface(FlutterDesktopRendererType::kEGL);
49+
if (!view->engine()->IsRunning()) {
50+
if (!view->engine()->RunEngine()) {
51+
return nullptr;
52+
}
53+
}
54+
55+
view->SendInitialGeometry();
56+
57+
return HandleForView(view.release());
58+
}

shell/platform/tizen/flutter_tizen_view.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
#include "flutter/shell/platform/tizen/logger.h"
99
#include "flutter/shell/platform/tizen/tizen_view.h"
10+
#ifdef NUI_SUPPORT
11+
#include "flutter/shell/platform/tizen/tizen_view_nui.h"
12+
#endif
1013
#include "flutter/shell/platform/tizen/tizen_window.h"
1114

1215
namespace {
@@ -131,7 +134,15 @@ bool FlutterTizenView::OnMakeResourceCurrent() {
131134
}
132135

133136
bool FlutterTizenView::OnPresent() {
134-
return engine_->renderer()->OnPresent();
137+
bool result = engine_->renderer()->OnPresent();
138+
#ifdef NUI_SUPPORT
139+
if (tizen_view_->GetType() == flutter::TizenViewType::kView &&
140+
engine_->renderer()->type() == FlutterDesktopRendererType::kEGL) {
141+
auto* view = reinterpret_cast<TizenViewNui*>(tizen_view_.get());
142+
view->RequestRendering();
143+
}
144+
#endif
145+
return result;
135146
}
136147

137148
uint32_t FlutterTizenView::OnGetFBO() {

shell/platform/tizen/public/flutter_tizen.h

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ typedef enum {
3232
kEGL,
3333
} FlutterDesktopRendererType;
3434

35+
typedef enum {
36+
kMouseDown,
37+
kMouseUp,
38+
kMouseMove,
39+
} FlutterDesktopPointerEventType;
40+
3541
// Properties for configuring the initial settings of a Flutter window.
3642
typedef struct {
3743
// The x-coordinate of the top left corner of the window.
@@ -154,13 +160,25 @@ FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(
154160

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

170+
// Creates a view that hosts and displays the given engine instance.
171+
//
172+
// The type of |image_view| must be Dali::Toolkit::ImageView*.
173+
// The type of |native_image_queue| must be Dali::NativeImageSourceQueue*.
174+
// @warning This API is a work-in-progress and may change.
175+
FLUTTER_EXPORT FlutterDesktopViewRef FlutterDesktopViewCreateFromImageView(
176+
const FlutterDesktopViewProperties& view_properties,
177+
FlutterDesktopEngineRef engine,
178+
void* image_view,
179+
void* native_image_queue,
180+
int32_t default_window_id);
181+
164182
// Destroys the view.
165183
//
166184
// The engine owned by the view will also be shut down implicitly.
@@ -183,6 +201,21 @@ FLUTTER_EXPORT void FlutterDesktopViewResize(FlutterDesktopViewRef view,
183201
int32_t width,
184202
int32_t height);
185203

204+
FLUTTER_EXPORT void FlutterDesktopViewOnPointerEvent(
205+
FlutterDesktopViewRef view,
206+
FlutterDesktopPointerEventType type,
207+
double x,
208+
double y,
209+
size_t timestamp,
210+
int32_t device_id);
211+
212+
FLUTTER_EXPORT void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
213+
const char* key,
214+
const char* string,
215+
uint32_t modifiers,
216+
uint32_t scan_code,
217+
bool is_down);
218+
186219
// ========== Plugin Registrar (extensions) ==========
187220

188221
// Returns the view associated with this registrar's engine instance.

0 commit comments

Comments
 (0)