Skip to content

Commit

Permalink
Introduce TizenViewElementary (#292)
Browse files Browse the repository at this point in the history
There are two ways to draw FlutterTizenView in Tizen. (TizenWindowElementary and TizenWindowEcore)
Both ways are drawing on Window component(surface).

We try to draw FlutterTizenView on the appropriate component
provided by Tizen UIFW and support it to be place with other components.
To do that, we created a TizenView class on the same level as TizenWindow
and abstracted common methods to TizenViewBase.
we can add FlutterTizenView to other UIFW of Tizen while adding TizenView{?}(maybe Tizen NUI).

```
 TizenViewBase -> TizenView        -> TizenViewElementary
                                                       -> TizenView{?}
                            -> TizenWindow -> TizenWindowElementary
                                                       -> TizenWindowEcore
```

related PR : flutter-tizen/flutter-tizen#373
  • Loading branch information
JSUYA authored Jun 14, 2022
1 parent 7b0c7a1 commit b98c6b6
Show file tree
Hide file tree
Showing 19 changed files with 761 additions and 151 deletions.
1 change: 1 addition & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ template("embedder") {
sources += [
"flutter_tizen_elementary.cc",
"tizen_renderer_evas_gl.cc",
"tizen_view_elementary.cc",
"tizen_window_elementary.cc",
]

Expand Down
10 changes: 5 additions & 5 deletions shell/platform/tizen/channels/window_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void WindowChannel::HandleMethodCall(
const std::string& method_name = method_call.method_name();

if (method_name == "getWindowGeometry") {
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
TizenGeometry geometry = window_->GetGeometry();
EncodableMap map;
map[EncodableValue("x")] = EncodableValue(geometry.left);
map[EncodableValue("y")] = EncodableValue(geometry.top);
Expand All @@ -57,9 +57,9 @@ void WindowChannel::HandleMethodCall(
EncodableValueHolder<int32_t> width(arguments, "width");
EncodableValueHolder<int32_t> height(arguments, "height");

TizenWindow::Geometry geometry = window_->GetWindowGeometry();
// FIXME: Use SetWindowGeometry() instead of OnGeometryChanged()
// After the SetWindowGeometry was successfully executed, I expected a
TizenGeometry geometry = window_->GetGeometry();
// FIXME: Use SetGeometry() instead of OnGeometryChanged()
// After the SetGeometry 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,
Expand All @@ -70,7 +70,7 @@ void WindowChannel::HandleMethodCall(
result->Success();
#endif
} else if (method_name == "getScreenGeometry") {
TizenWindow::Geometry geometry = window_->GetScreenGeometry();
TizenGeometry geometry = window_->GetScreenGeometry();
EncodableMap map;
map[EncodableValue("width")] = EncodableValue(geometry.width);
map[EncodableValue("height")] = EncodableValue(geometry.height);
Expand Down
7 changes: 6 additions & 1 deletion shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ void FlutterDesktopEngineShutdown(FlutterDesktopEngineRef engine_ref) {

void* FlutterDesktopPluginRegistrarGetNativeWindow(
FlutterDesktopPluginRegistrarRef registrar) {
return registrar->engine->view()->window()->GetWindowHandle();
flutter::TizenViewBase* tizen_view = registrar->engine->view()->tizen_view();
if (tizen_view->GetType() == flutter::TizenViewType::kWindow) {
auto* window = reinterpret_cast<flutter::TizenWindow*>(tizen_view);
return window->GetWindowHandle();
}
return nullptr;
}

void FlutterDesktopPluginRegistrarEnableInputBlocking(
Expand Down
29 changes: 23 additions & 6 deletions shell/platform/tizen/flutter_tizen_ecore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#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/tizen_window_ecore_wl2.h"

namespace {
Expand All @@ -24,12 +25,9 @@ FlutterDesktopViewRef HandleForView(flutter::FlutterTizenView* view) {
FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(
const FlutterDesktopWindowProperties& window_properties,
FlutterDesktopEngineRef engine) {
flutter::TizenWindow::Geometry window_geometry = {
window_properties.x,
window_properties.y,
window_properties.width,
window_properties.height,
};
flutter::TizenGeometry window_geometry = {
window_properties.x, window_properties.y, window_properties.width,
window_properties.height};

std::unique_ptr<flutter::TizenWindow> window =
std::make_unique<flutter::TizenWindowEcoreWl2>(
Expand All @@ -52,3 +50,22 @@ FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(

return HandleForView(view.release());
}

FlutterDesktopViewRef FlutterDesktopViewCreateFromElmParent(
const FlutterDesktopViewProperties& view_properties,
FlutterDesktopEngineRef engine,
void* parent) {
FT_LOG(Warn) << "Not applicable!";
return nullptr;
}

void* FlutterDesktopViewGetEvasObject(FlutterDesktopViewRef view_ref) {
FT_LOG(Warn) << "Not applicable!";
return nullptr;
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view_ref,
int32_t width,
int32_t height) {
FT_LOG(Warn) << "Not applicable!";
}
55 changes: 49 additions & 6 deletions shell/platform/tizen/flutter_tizen_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#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_elementary.h"
#include "flutter/shell/platform/tizen/tizen_window_elementary.h"

namespace {
Expand All @@ -24,12 +25,9 @@ FlutterDesktopViewRef HandleForView(flutter::FlutterTizenView* view) {
FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(
const FlutterDesktopWindowProperties& window_properties,
FlutterDesktopEngineRef engine) {
flutter::TizenWindow::Geometry window_geometry = {
window_properties.x,
window_properties.y,
window_properties.width,
window_properties.height,
};
flutter::TizenGeometry window_geometry = {
window_properties.x, window_properties.y, window_properties.width,
window_properties.height};

std::unique_ptr<flutter::TizenWindow> window =
std::make_unique<flutter::TizenWindowElementary>(
Expand All @@ -52,3 +50,48 @@ FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(

return HandleForView(view.release());
}

FlutterDesktopViewRef FlutterDesktopViewCreateFromElmParent(
const FlutterDesktopViewProperties& view_properties,
FlutterDesktopEngineRef engine,
void* parent) {
std::unique_ptr<flutter::TizenViewBase> tizen_view =
std::make_unique<flutter::TizenViewElementary>(
view_properties.width, view_properties.height,
static_cast<Evas_Object*>(parent));

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();
if (!view->engine()->IsRunning()) {
if (!view->engine()->RunEngine()) {
return nullptr;
}
}

view->SendInitialGeometry();

return HandleForView(view.release());
}

void* FlutterDesktopViewGetEvasObject(FlutterDesktopViewRef view_ref) {
auto* view = reinterpret_cast<flutter::FlutterTizenView*>(view_ref);
if (view->tizen_view()->GetType() == flutter::TizenViewType::kView) {
auto* tizen_view =
reinterpret_cast<flutter::TizenView*>(view->tizen_view());
return tizen_view->GetRenderTargetContainer();
}
return nullptr;
}

void FlutterDesktopViewResize(FlutterDesktopViewRef view_ref,
int32_t width,
int32_t height) {
auto* view = reinterpret_cast<flutter::FlutterTizenView*>(view_ref);
flutter::TizenGeometry view_geometry = {0, 0, width, height};
view->tizen_view()->OnGeometryChanged(view_geometry);
}
3 changes: 1 addition & 2 deletions shell/platform/tizen/flutter_tizen_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,7 @@ void FlutterTizenEngine::OnUpdateSemanticsCustomActions(
bridge->GetFlutterPlatformNodeDelegateFromID(0);
std::shared_ptr<FlutterPlatformWindowDelegateTizen> window =
FlutterPlatformAppDelegateTizen::GetInstance().GetWindow().lock();
TizenWindow::Geometry geometry =
engine->view_->window()->GetWindowGeometry();
TizenGeometry geometry = engine->view_->tizen_view()->GetGeometry();
window->SetGeometry(geometry.left, geometry.top, geometry.width,
geometry.height);
window->SetRootNode(root);
Expand Down
67 changes: 45 additions & 22 deletions shell/platform/tizen/flutter_tizen_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "flutter_tizen_view.h"

#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/tizen_view.h"
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace {

Expand Down Expand Up @@ -40,10 +42,10 @@ const std::vector<std::string> kBindableSystemKeys = {

namespace flutter {

FlutterTizenView::FlutterTizenView(std::unique_ptr<TizenWindow> window)
: window_(std::move(window)) {
window_->SetView(this);
window_->BindKeys(kBindableSystemKeys);
FlutterTizenView::FlutterTizenView(std::unique_ptr<TizenViewBase> tizen_view)
: tizen_view_(std::move(tizen_view)) {
tizen_view_->SetView(this);
tizen_view_->BindKeys(kBindableSystemKeys);
}

FlutterTizenView::~FlutterTizenView() {}
Expand All @@ -57,19 +59,34 @@ void FlutterTizenView::SetEngine(std::unique_ptr<FlutterTizenEngine> engine) {

// Set up window dependent channels.
BinaryMessenger* messenger = internal_plugin_registrar_->messenger();
platform_channel_ =
std::make_unique<PlatformChannel>(messenger, window_.get());
window_channel_ = std::make_unique<WindowChannel>(messenger, window_.get());

if (tizen_view_->GetType() == TizenViewType::kWindow) {
auto* window = reinterpret_cast<TizenWindow*>(tizen_view_.get());
platform_channel_ = std::make_unique<PlatformChannel>(messenger, window);
window_channel_ = std::make_unique<WindowChannel>(messenger, window);
} else {
platform_channel_ = std::make_unique<PlatformChannel>(messenger, nullptr);
window_channel_ = std::make_unique<WindowChannel>(messenger, nullptr);
}

text_input_channel_ = std::make_unique<TextInputChannel>(
internal_plugin_registrar_->messenger(), window_->input_method_context());
internal_plugin_registrar_->messenger(),
tizen_view_->input_method_context());
}

void FlutterTizenView::CreateRenderSurface() {
if (engine_ && engine_->renderer()) {
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
engine_->renderer()->CreateSurface(window_->GetRenderTarget(),
window_->GetRenderTargetDisplay(),
geometry.width, geometry.height);
TizenGeometry geometry = tizen_view_->GetGeometry();
if (tizen_view_->GetType() == TizenViewType::kWindow) {
auto* window = reinterpret_cast<TizenWindow*>(tizen_view_.get());
engine_->renderer()->CreateSurface(window->GetRenderTarget(),
window->GetRenderTargetDisplay(),
geometry.width, geometry.height);
} else {
auto* tizen_view = reinterpret_cast<TizenView*>(tizen_view_.get());
engine_->renderer()->CreateSurface(tizen_view->GetRenderTarget(), nullptr,
geometry.width, geometry.height);
}
}
}

Expand Down Expand Up @@ -111,16 +128,15 @@ void FlutterTizenView::OnResize(int32_t left,
std::swap(width, height);
}

window_->ResizeRenderTargetWithRotation({left, top, width, height},
rotation_degree_);
tizen_view_->ResizeWithRotation({left, top, width, height}, rotation_degree_);
SendWindowMetrics(left, top, width, height, 0.0);
}

void FlutterTizenView::OnRotate(int32_t degree) {
rotation_degree_ = degree;
// Compute renderer transformation based on the angle of rotation.
double rad = (360 - rotation_degree_) * M_PI / 180;
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
TizenGeometry geometry = tizen_view_->GetGeometry();
int32_t width = geometry.width;
int32_t height = geometry.height;

Expand All @@ -144,8 +160,8 @@ void FlutterTizenView::OnRotate(int32_t degree) {
std::swap(width, height);
}

window_->ResizeRenderTargetWithRotation(
{geometry.left, geometry.top, width, height}, rotation_degree_);
tizen_view_->ResizeWithRotation({geometry.left, geometry.top, width, height},
rotation_degree_);

// Window position does not change on rotation regardless of its orientation.
SendWindowMetrics(geometry.left, geometry.top, width, height, 0.0);
Expand Down Expand Up @@ -254,7 +270,14 @@ void FlutterTizenView::OnCommit(const std::string& str) {
}

void FlutterTizenView::SendInitialGeometry() {
OnRotate(window_->GetRotation());
if (tizen_view_->GetType() == TizenViewType::kWindow) {
auto* window = reinterpret_cast<TizenWindow*>(tizen_view_.get());
OnRotate(window->GetRotation());
} else {
TizenGeometry geometry = tizen_view_->GetGeometry();
SendWindowMetrics(geometry.left, geometry.top, geometry.width,
geometry.height, 0.0);
}
}

void FlutterTizenView::SendWindowMetrics(int32_t left,
Expand All @@ -270,7 +293,7 @@ void FlutterTizenView::SendWindowMetrics(int32_t left,
#ifdef TV_PROFILE
double dpi = 72.0;
#else
double dpi = static_cast<double>(window_->GetDpi());
double dpi = static_cast<double>(tizen_view_->GetDpi());
#endif
double scale_factor = dpi / 90.0 * kProfileFactor;
computed_pixel_ratio = std::max(scale_factor, 1.0);
Expand All @@ -290,7 +313,7 @@ void FlutterTizenView::SendFlutterPointerEvent(
size_t timestamp,
FlutterPointerDeviceKind device_kind,
int device_id) {
TizenWindow::Geometry geometry = window_->GetWindowGeometry();
TizenGeometry geometry = tizen_view_->GetGeometry();
double new_x = x, new_y = y;

if (rotation_degree_ == 90) {
Expand All @@ -307,8 +330,8 @@ void FlutterTizenView::SendFlutterPointerEvent(
FlutterPointerEvent event = {};
event.struct_size = sizeof(event);
event.phase = phase;
event.x = new_x;
event.y = new_y;
event.x = new_x - geometry.left;
event.y = new_y - geometry.top;
if (delta_x != 0 || delta_y != 0) {
event.signal_kind = kFlutterPointerSignalKindScroll;
}
Expand Down
9 changes: 4 additions & 5 deletions shell/platform/tizen/flutter_tizen_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
#include "flutter/shell/platform/tizen/channels/text_input_channel.h"
#include "flutter/shell/platform/tizen/channels/window_channel.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace flutter {

class FlutterTizenView {
public:
FlutterTizenView(std::unique_ptr<TizenWindow> window);
FlutterTizenView(std::unique_ptr<TizenViewBase> tizen_view);

~FlutterTizenView();

Expand All @@ -30,7 +29,7 @@ class FlutterTizenView {

FlutterTizenEngine* engine() { return engine_.get(); }

TizenWindow* window() { return window_.get(); }
TizenViewBase* tizen_view() { return tizen_view_.get(); }

// Creates rendering surface for Flutter engine to draw into.
// Should be called before calling FlutterEngineRun using this view.
Expand Down Expand Up @@ -126,8 +125,8 @@ class FlutterTizenView {
// The engine associated with this view.
std::unique_ptr<FlutterTizenEngine> engine_;

// The window associated with this view.
std::unique_ptr<TizenWindow> window_;
// The platform view associated with this Flutter view.
std::unique_ptr<TizenViewBase> tizen_view_;

// The plugin registrar managing internal plugins.
std::unique_ptr<PluginRegistrar> internal_plugin_registrar_;
Expand Down
Loading

0 comments on commit b98c6b6

Please sign in to comment.