Skip to content
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

[wip] POC code for using EvasGL #25

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,21 @@ source_set("flutter_tizen") {
"$custom_sysroot/usr/include/ecore-input-1",
"$custom_sysroot/usr/include/ecore-wl2-1",
"$custom_sysroot/usr/include/efl-1",
"$custom_sysroot/usr/include/efl-1/interfaces",
"$custom_sysroot/usr/include/eina-1",
"$custom_sysroot/usr/include/eina-1/eina",
"$custom_sysroot/usr/include/emile-1",
"$custom_sysroot/usr/include/eo-1",
"$custom_sysroot/usr/include/evas-1",
"$custom_sysroot/usr/include/system",
"$custom_sysroot/usr/include/elementary-1",
"$custom_sysroot/usr/include/eet-1",
"$custom_sysroot/usr/include/ecore-file-1",
"$custom_sysroot/usr/include/ecore-con-1",
"$custom_sysroot/usr/include/edje-1",
"$custom_sysroot/usr/include/efreet-1",
"$custom_sysroot/usr/include/ethumb-1",
"$custom_sysroot/usr/include/ethumb-client-1",
]

lib_dirs = [ "$custom_sysroot/usr/lib" ]
Expand All @@ -105,6 +114,7 @@ source_set("flutter_tizen") {
"tbm",
"tdm-client",
"wayland-client",
"elementary",
]
}

Expand Down
13 changes: 6 additions & 7 deletions shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ void TextInputChannel::InputPanelStateChangedCallback(
int32_t surface_h =
window_geometry.h - self->current_keyboard_geometry_.h;

self->engine_->tizen_native_window->GetTizenNativeEGLWindow()
->ResizeWithRotation(0, 0, surface_w, surface_h, 0);
self->engine_->tizen_native_window->ResizeWithRotation(0, 0, surface_w, surface_h, 0);
if (self->rotation == 90 || self->rotation == 270) {
self->engine_->SendWindowMetrics(surface_h, surface_w, 0);
} else {
Expand Down Expand Up @@ -298,10 +297,10 @@ TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger,
imf_context_ = ecore_imf_context_add(GetImfMethod());
}
if (imf_context_) {
Ecore_Wl2_Window* ecoreWindow =
engine_->tizen_native_window->GetWindowHandle();
ecore_imf_context_client_window_set(
imf_context_, (void*)ecore_wl2_window_id_get(ecoreWindow));
// Ecore_Wl2_Window* ecoreWindow =
// engine_->tizen_native_window->GetWindowHandle();
// ecore_imf_context_client_window_set(
// imf_context_, (void*)ecore_wl2_window_id_get(ecoreWindow));
RegisterIMFCallback();
} else {
FT_LOGE("Failed to create imfContext");
Expand Down Expand Up @@ -619,7 +618,7 @@ void TextInputChannel::HideSoftwareKeyboard() {
} else {
engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0);
}
engine_->tizen_native_window->GetTizenNativeEGLWindow()
engine_->tizen_native_window
->ResizeWithRotation(0, 0, window_geometry.w, window_geometry.h, 0);
ecore_timer_add(
0.05,
Expand Down
165 changes: 26 additions & 139 deletions shell/platform/tizen/tizen_native_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,168 +7,55 @@

#include "tizen_native_window.h"

#include <Elementary.h>
#include "flutter/shell/platform/tizen/tizen_log.h"

void LogLastEGLError() {
struct EGLNameErrorPair {
const char* name;
EGLint code;
};

#define _EGL_ERROR_DESC(a) \
{ #a, a }

const EGLNameErrorPair pairs[] = {
_EGL_ERROR_DESC(EGL_SUCCESS),
_EGL_ERROR_DESC(EGL_NOT_INITIALIZED),
_EGL_ERROR_DESC(EGL_BAD_ACCESS),
_EGL_ERROR_DESC(EGL_BAD_ALLOC),
_EGL_ERROR_DESC(EGL_BAD_ATTRIBUTE),
_EGL_ERROR_DESC(EGL_BAD_CONTEXT),
_EGL_ERROR_DESC(EGL_BAD_CONFIG),
_EGL_ERROR_DESC(EGL_BAD_CURRENT_SURFACE),
_EGL_ERROR_DESC(EGL_BAD_DISPLAY),
_EGL_ERROR_DESC(EGL_BAD_SURFACE),
_EGL_ERROR_DESC(EGL_BAD_MATCH),
_EGL_ERROR_DESC(EGL_BAD_PARAMETER),
_EGL_ERROR_DESC(EGL_BAD_NATIVE_PIXMAP),
_EGL_ERROR_DESC(EGL_BAD_NATIVE_WINDOW),
_EGL_ERROR_DESC(EGL_CONTEXT_LOST),
};

#undef _EGL_ERROR_DESC

const auto count = sizeof(pairs) / sizeof(EGLNameErrorPair);

EGLint last_error = eglGetError();

for (size_t i = 0; i < count; i++) {
if (last_error == pairs[i].code) {
FT_LOGE("EGL Error: %s (%d)", pairs[i].name, pairs[i].code);
return;
}
}

FT_LOGE("Unknown EGL Error");
}

class TizenWl2Display {
public:
TizenWl2Display() {
if (!ecore_wl2_init()) {
FT_LOGE("Could not initialize ecore_wl2");
return;
}
// ecore_wl2 DISPLAY
wl2_display_ = ecore_wl2_display_connect(nullptr);
if (wl2_display_ == nullptr) {
FT_LOGE("Display not found");
return;
}
ecore_wl2_sync();
}

~TizenWl2Display() {
if (wl2_display_) {
ecore_wl2_display_disconnect(wl2_display_);
wl2_display_ = nullptr;
}
ecore_wl2_shutdown();
}
Ecore_Wl2_Display* GetHandle() { return wl2_display_; }

private:
Ecore_Wl2_Display* wl2_display_{nullptr};
};
TizenWl2Display g_tizen_wl2_display;

TizenNativeEGLWindow::TizenNativeEGLWindow(
TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) {
egl_window_ =
ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h);

egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(
g_tizen_wl2_display.GetHandle()));
if (egl_display_ == EGL_NO_DISPLAY) {
FT_LOGE("Could not access EGL display");
LogLastEGLError();
return;
}

EGLint major_version;
EGLint minor_version;
if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) {
FT_LOGE("Could not initialize EGL display");
LogLastEGLError();
return;
}

FT_LOGD("eglInitialized: %d.%d", major_version, minor_version);

if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
FT_LOGE("Could not bind API");
LogLastEGLError();
return;
}
}

TizenNativeEGLWindow::~TizenNativeEGLWindow() {
if (egl_display_ != EGL_NO_DISPLAY) {
if (eglTerminate(egl_display_) != EGL_TRUE) {
FT_LOGE("Failed to terminate egl display");
LogLastEGLError();
}
egl_display_ = EGL_NO_DISPLAY;
}

if (egl_window_ != nullptr) {
ecore_wl2_egl_window_destroy(egl_window_);
egl_window_ = nullptr;
}
}

void TizenNativeEGLWindow::ResizeWithRotation(int32_t dx, int32_t dy,
void TizenNativeWindow::ResizeWithRotation(int32_t dx, int32_t dy,
int32_t width, int32_t height,
int32_t degree) {
ecore_wl2_egl_window_resize_with_rotation(egl_window_, dx, dy, width, height,
degree);
// ecore_wl2_egl_window_resize_with_rotation(egl_window_, dx, dy, width, height,
// degree);
}

TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (g_tizen_wl2_display.GetHandle() == nullptr) {
FT_LOGE("Faild to get display handle");
return;
}
if (w == 0 || h == 0) {
FT_LOGE("Failed to create because of the wrong size");
return;
}

wl2_window_ = ecore_wl2_window_new(g_tizen_wl2_display.GetHandle(), nullptr,
x, y, w, h);

ecore_wl2_window_type_set(wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
ecore_wl2_window_alpha_set(wl2_window_, EINA_FALSE);
ecore_wl2_window_aux_hint_add(wl2_window_, 0, "wm.policy.win.user.geometry",
"1");
ecore_wl2_window_show(wl2_window_);

tizen_native_egl_window_ = std::make_shared<TizenNativeEGLWindow>(this, w, h);
elm_config_accel_preference_set("opengl");

evas_window_ = elm_win_util_standard_add("", "");
evas_object_move(evas_window_,x,y);
evas_object_resize(evas_window_,w,h);
evas_object_show(evas_window_);
// ecore_wl2_window_type_set(evas_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
// ecore_wl2_window_alpha_set(evas_window_, EINA_FALSE);
// ecore_wl2_window_aux_hint_add(evas_window_, 0, "wm.policy.win.user.geometry",
// "1");
// ecore_wl2_window_show(evas_window_);
evas_gl_ = evas_gl_new(evas_object_evas_get(evas_window_));
evas_glGlapi = evas_gl_api_get(evas_gl_);
is_valid_ = true;
}

TizenNativeWindow::~TizenNativeWindow() {
tizen_native_egl_window_ = nullptr;
if (wl2_window_) {
ecore_wl2_window_free(wl2_window_);
wl2_window_ = nullptr;
if (evas_window_) {
evas_object_del(evas_window_);
evas_gl_free(evas_gl_);
evas_window_ = nullptr;
evas_gl_ = nullptr;
}
}

TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() {
TizenNativeWindowGeometry result;
ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w,
&result.h);
result.w=100;
result.h=100;
// ecore_wl2_window_geometry_get(evas_window_, &result.x, &result.y, &result.w,
// &result.h);
return result;
}
44 changes: 14 additions & 30 deletions shell/platform/tizen/tizen_native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,17 @@

#ifndef EMBEDDER_TIZEN_WINDOW_H_
#define EMBEDDER_TIZEN_WINDOW_H_
#include <EGL/egl.h>
#define EFL_BETA_API_SUPPORT
#include <Ecore_Wl2.h>

#undef EFL_BETA_API_SUPPORT
// #ifndef EFL_BETA_API_SUPPORT
// #define EFL_BETA_API_SUPPORT
// #endif
#include <Elementary.h>
#include <Evas_GL.h>
#include <memory>

void LogLastEGLError();

class TizenNativeWindow;

class TizenNativeEGLWindow {
public:
TizenNativeEGLWindow(TizenNativeWindow* tizen_native_window, int32_t w,
int32_t h);
~TizenNativeEGLWindow();
bool IsValid() {
return egl_window_ != nullptr && egl_display_ != EGL_NO_DISPLAY;
};

Ecore_Wl2_Egl_Window* GetEglWindowHandle() { return egl_window_; };
EGLDisplay GetEGLDisplayHandle() { return egl_display_; }
void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height,
int32_t degree);

private:
Ecore_Wl2_Egl_Window* egl_window_ = nullptr;
EGLDisplay egl_display_ = EGL_NO_DISPLAY;
};

class TizenNativeWindow {
public:
struct TizenNativeWindowGeometry {
Expand All @@ -42,15 +24,17 @@ class TizenNativeWindow {
TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h);
~TizenNativeWindow();
bool IsValid() { return is_valid_; }
Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; }
std::shared_ptr<TizenNativeEGLWindow> GetTizenNativeEGLWindow() {
return tizen_native_egl_window_;
};
Evas_Object* GetWindowHandle() { return evas_window_; }
Evas_GL* GetEvasGLHandle() { return evas_gl_; }
Evas_GL_API* GetEvasGLApiHandle() { return evas_glGlapi; }
TizenNativeWindowGeometry GetGeometry();
void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height,
int32_t degree);

private:
std::shared_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
Ecore_Wl2_Window* wl2_window_{nullptr};
Evas_Object* evas_window_{nullptr};
Evas_GL* evas_gl_{nullptr};
Evas_GL_API* evas_glGlapi{nullptr};;
bool is_valid_{false};
};

Expand Down
Loading