Skip to content

Add external output support #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flutter/shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ config("flutter_tizen_config") {
"${sysroot_path}/usr/include/elementary-1",
"${sysroot_path}/usr/include/emile-1",
"${sysroot_path}/usr/include/eo-1",
"${sysroot_path}/usr/include/eom",
"${sysroot_path}/usr/include/ethumb-1",
"${sysroot_path}/usr/include/ethumb-client-1",
"${sysroot_path}/usr/include/evas-1",
Expand Down Expand Up @@ -158,6 +159,7 @@ template("embedder") {
sources += [ "channels/tizen_shell.cc" ]

libs += [
"eom",
"tzsh_common",
"tzsh_softkey",
]
Expand Down
3 changes: 2 additions & 1 deletion flutter/shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ FlutterDesktopViewRef FlutterDesktopViewCreateFromNewWindow(
if (window_properties.renderer_type == FlutterDesktopRendererType::kEvasGL) {
window = std::make_unique<flutter::TizenWindowElementary>(
window_geometry, window_properties.transparent,
window_properties.focusable, window_properties.top_level);
window_properties.focusable, window_properties.top_level,
window_properties.external_output_type);
} else {
#ifndef WEARABLE_PROFILE
window = std::make_unique<flutter::TizenWindowEcoreWl2>(
Expand Down
9 changes: 9 additions & 0 deletions flutter/shell/platform/tizen/public/flutter_tizen.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ typedef enum {
kMouseMove,
} FlutterDesktopPointerEventType;

typedef enum {
// No external output.
kNone,
// Display to the HDMI external output.
kHDMI,
} FlutterDesktopExternalOutputType;

// Properties for configuring the initial settings of a Flutter window.
typedef struct {
// The x-coordinate of the top left corner of the window.
Expand All @@ -56,6 +63,8 @@ typedef struct {
bool top_level;
// The renderer type of the engine.
FlutterDesktopRendererType renderer_type;
// The external output type of the window.
FlutterDesktopExternalOutputType external_output_type;
} FlutterDesktopWindowProperties;

// Properties for configuring the initial settings of a Flutter view.
Expand Down
131 changes: 121 additions & 10 deletions flutter/shell/platform/tizen/tizen_window_elementary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "tizen_window_elementary.h"

#include <efl_extension.h>
#ifdef COMMON_PROFILE
#include <eom.h>
#endif
#include <ui/efl_util.h>

#include "flutter/shell/platform/tizen/logger.h"
Expand Down Expand Up @@ -34,11 +37,27 @@ uint32_t EvasModifierToEcoreEventModifiers(const Evas_Modifier* evas_modifier) {

} // namespace

TizenWindowElementary::TizenWindowElementary(TizenGeometry geometry,
bool transparent,
bool focusable,
bool top_level)
TizenWindowElementary::TizenWindowElementary(
TizenGeometry geometry,
bool transparent,
bool focusable,
bool top_level,
FlutterDesktopExternalOutputType external_output_type)
: TizenWindow(geometry, transparent, focusable, top_level) {
#ifdef COMMON_PROFILE
external_output_type_ = external_output_type;

if (external_output_type_ != FlutterDesktopExternalOutputType::kNone &&
!InitializeEom()) {
FT_LOG(Error) << "Failed to initialize eom.";
return;
}
#else
if (external_output_type != FlutterDesktopExternalOutputType::kNone) {
FT_LOG(Error) << "External output is not supported by this profile.";
}
#endif

if (!CreateWindow()) {
FT_LOG(Error) << "Failed to create a platform window.";
return;
Expand All @@ -51,6 +70,11 @@ TizenWindowElementary::TizenWindowElementary(TizenGeometry geometry,
}

TizenWindowElementary::~TizenWindowElementary() {
#ifdef COMMON_PROFILE
if (external_output_type_ != FlutterDesktopExternalOutputType::kNone) {
DestroyEom();
}
#endif
UnregisterEventHandlers();
DestroyWindow();
}
Expand All @@ -69,11 +93,28 @@ bool TizenWindowElementary::CreateWindow() {
elm_win_aux_hint_add(elm_win_, "wm.policy.win.user.geometry", "1");
#endif

Ecore_Evas* ecore_evas =
ecore_evas_ecore_evas_get(evas_object_evas_get(elm_win_));

int32_t width, height;
ecore_evas_screen_geometry_get(ecore_evas, nullptr, nullptr, &width, &height);
#ifdef COMMON_PROFILE
if (external_output_type_ != FlutterDesktopExternalOutputType::kNone) {
eom_get_output_resolution(ext_output_id_, &width, &height);

if (width == 0 || height == 0) {
FT_LOG(Error) << "Invalid screen size: " << width << " x " << height;
return false;
}

if (eom_set_output_window(ext_output_id_, elm_win_) != EOM_ERROR_NONE) {
FT_LOG(Error) << "eom_set_output_window() failed.";
}
} else
#endif
{
Ecore_Evas* ecore_evas =
ecore_evas_ecore_evas_get(evas_object_evas_get(elm_win_));

ecore_evas_screen_geometry_get(ecore_evas, nullptr, nullptr, &width,
&height);
}
if (width == 0 || height == 0) {
FT_LOG(Error) << "Invalid screen size: " << width << " x " << height;
return false;
Expand Down Expand Up @@ -323,8 +364,8 @@ void TizenWindowElementary::UnregisterEventHandlers() {
}

TizenGeometry TizenWindowElementary::GetGeometry() {
// FIXME : evas_object_geometry_get() and ecore_wl2_window_geometry_get() are
// not equivalent.
// FIXME : evas_object_geometry_get() and ecore_wl2_window_geometry_get()
// are not equivalent.
TizenGeometry result;
evas_object_geometry_get(elm_win_, &result.left, &result.top, &result.width,
&result.height);
Expand Down Expand Up @@ -403,4 +444,74 @@ void TizenWindowElementary::PrepareInputMethod() {
[this](std::string str) { view_delegate_->OnCommit(str); });
}

#ifdef COMMON_PROFILE

int32_t TizenWindowElementary::GetExternalOutputId() {
eom_output_id* output_ids = NULL;
eom_output_id output_id = 0;
eom_output_type_e output_type = EOM_OUTPUT_TYPE_UNKNOWN;
int32_t id_cnt = 0;

output_ids = eom_get_eom_output_ids(&id_cnt);
if (id_cnt == 0) {
FT_LOG(Error) << "No external outputs supported";
return 0;
}

for (int32_t i = 0; i < id_cnt; i++) {
eom_get_output_type(output_ids[i], &output_type);

if (external_output_type_ == FlutterDesktopExternalOutputType::kHDMI &&
(output_type == EOM_OUTPUT_TYPE_HDMIA ||
output_type == EOM_OUTPUT_TYPE_HDMIB)) {
output_id = output_ids[i];
break;
}
}

if (output_ids)
free(output_ids);

return output_id;
}

bool TizenWindowElementary::InitializeEom() {
if (eom_init()) {
FT_LOG(Error) << "Eom init fail.";
return false;
}

int eom_ret;
ext_output_id_ = GetExternalOutputId();
eom_output_mode_e output_mode = EOM_OUTPUT_MODE_NONE;
if (ext_output_id_ == 0) {
FT_LOG(Error) << "External output id is NULL.";
eom_deinit();
return false;
}

eom_ret =
eom_set_output_attribute(ext_output_id_, EOM_OUTPUT_ATTRIBUTE_EXCLUSIVE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what this attribute is meant for? The guide says that EOM_OUTPUT_ATTRIBUTE_NORMAL is the best option for most applications.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right. I modified it to NORMAL

if (eom_ret != EOM_ERROR_NONE) {
FT_LOG(Error)
<< "eom_set_output_attribute() failed. Cannot use external output.";
eom_deinit();
return false;
}

eom_ret = eom_get_output_mode(ext_output_id_, &output_mode);
if (eom_ret != EOM_ERROR_NONE) {
FT_LOG(Error)
<< "eom_get_output_mode() failed. Cannot use external output.";
eom_deinit();
return false;
}
return true;
}

void TizenWindowElementary::DestroyEom() {
eom_deinit();
}
#endif

} // namespace flutter
18 changes: 17 additions & 1 deletion flutter/shell/platform/tizen/tizen_window_elementary.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <unordered_map>
#include <vector>

#include "flutter/shell/platform/tizen/public/flutter_tizen.h"
#include "flutter/shell/platform/tizen/tizen_window.h"

namespace flutter {
Expand All @@ -21,7 +22,8 @@ class TizenWindowElementary : public TizenWindow {
TizenWindowElementary(TizenGeometry geometry,
bool transparent,
bool focusable,
bool top_level);
bool top_level,
FlutterDesktopExternalOutputType external_output_type);

~TizenWindowElementary();

Expand Down Expand Up @@ -50,6 +52,14 @@ class TizenWindowElementary : public TizenWindow {
void Show() override;

private:
#ifdef COMMON_PROFILE
bool InitializeEom();

void DestroyEom();

int GetExternalOutputId();
#endif

bool CreateWindow();

void DestroyWindow();
Expand All @@ -68,6 +78,12 @@ class TizenWindowElementary : public TizenWindow {
Evas_Smart_Cb rotation_changed_callback_ = nullptr;
std::unordered_map<Evas_Callback_Type, Evas_Object_Event_Cb>
evas_object_callbacks_;

#ifdef COMMON_PROFILE
int ext_output_id_;
FlutterDesktopExternalOutputType external_output_type_ =
FlutterDesktopExternalOutputType::kNone;
#endif
};

} // namespace flutter
Expand Down
2 changes: 2 additions & 0 deletions tools/generate_sysroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
'vulkan-loader-devel',
'wayland-extension-client-devel',
'wayland-devel',
'libeom',
'libeom-devel',
]

# Only available for Tizen 6.5 and above.
Expand Down