Skip to content

Commit

Permalink
Refactor tizen surface
Browse files Browse the repository at this point in the history
* Add TizenNativeWindow, TizenNativeEGLWindow, TizenWl2Display
* Add TizenEGLContext, TizenEGLSurface, TizenEGLSurface
* TizenEmbedderEngine has TizenNativeWindow as a public member
* Release EGLSurface, EGLDisplay, EGLContext

Signed-off-by: Boram Bae <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 committed Dec 15, 2020
1 parent 602a947 commit bf74173
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 350 deletions.
1 change: 1 addition & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ source_set("flutter_tizen") {
"tizen_surface.cc",
"tizen_surface_gl.cc",
"tizen_vsync_waiter.cc",
"tizen_native_window.cc",
"touch_event_handler.cc",
]

Expand Down
19 changes: 10 additions & 9 deletions shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ void TextInputChannel::InputPanelStateChangedCallback(
0.25,
[](void* data) -> Eina_Bool {
TextInputChannel* self = (TextInputChannel*)data;
int32_t surface_w = self->engine_->tizen_surface->GetWidth();
int32_t surface_h = self->engine_->tizen_surface->GetHeight() -
self->current_keyboard_geometry_.h;
auto window_geometry =
self->engine_->tizen_native_window->GetGeometry();
int32_t surface_w = window_geometry.w;
int32_t surface_h =
window_geometry.h - self->current_keyboard_geometry_.h;
self->engine_->tizen_surface->SetSize(surface_w, surface_h);
if (self->rotation == 90 || self->rotation == 270) {
self->engine_->SendWindowMetrics(surface_h, surface_w, 0);
Expand Down Expand Up @@ -293,7 +295,7 @@ TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger,
}
if (imfContext_) {
Ecore_Wl2_Window* ecoreWindow =
((TizenSurfaceGL*)engine_->tizen_surface.get())->wl2_window();
engine_->tizen_native_window->GetWindowHandle();
ecore_imf_context_client_window_set(
imfContext_, (void*)ecore_wl2_window_id_get(ecoreWindow));
RegisterIMFCallback(ecoreWindow);
Expand Down Expand Up @@ -604,15 +606,14 @@ void TextInputChannel::HideSoftwareKeyboard() {

if (engine_->device_profile ==
"mobile") { // FIXME : Needs improvement on other devices.
auto w = engine_->tizen_surface->GetWidth();
auto h = engine_->tizen_surface->GetHeight();
auto window_geometry = engine_->tizen_native_window->GetGeometry();

if (rotation == 90 || rotation == 270) {
engine_->SendWindowMetrics(h, w, 0);
engine_->SendWindowMetrics(window_geometry.h, window_geometry.w, 0);
} else {
engine_->SendWindowMetrics(w, h, 0);
engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0);
}
engine_->tizen_surface->SetSize(w, h);
engine_->tizen_surface->SetSize(window_geometry.w, window_geometry.h);
ecore_timer_add(
0.05,
[](void* data) -> Eina_Bool {
Expand Down
118 changes: 118 additions & 0 deletions shell/platform/tizen/proc_resolver_macro.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@

// Copyright 2020 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.

#define GL_FUNC(FunctionName) \
else if (strcmp(name, #FunctionName) == 0) { \
return reinterpret_cast<void*>(FunctionName); \
}

GL_FUNC(eglGetCurrentDisplay)
GL_FUNC(eglQueryString)
GL_FUNC(glActiveTexture)
GL_FUNC(glAttachShader)
GL_FUNC(glBindAttribLocation)
GL_FUNC(glBindBuffer)
GL_FUNC(glBindFramebuffer)
GL_FUNC(glBindRenderbuffer)
GL_FUNC(glBindTexture)
GL_FUNC(glBlendColor)
GL_FUNC(glBlendEquation)
GL_FUNC(glBlendFunc)
GL_FUNC(glBufferData)
GL_FUNC(glBufferSubData)
GL_FUNC(glCheckFramebufferStatus)
GL_FUNC(glClear)
GL_FUNC(glClearColor)
GL_FUNC(glClearStencil)
GL_FUNC(glColorMask)
GL_FUNC(glCompileShader)
GL_FUNC(glCompressedTexImage2D)
GL_FUNC(glCompressedTexSubImage2D)
GL_FUNC(glCopyTexSubImage2D)
GL_FUNC(glCreateProgram)
GL_FUNC(glCreateShader)
GL_FUNC(glCullFace)
GL_FUNC(glDeleteBuffers)
GL_FUNC(glDeleteFramebuffers)
GL_FUNC(glDeleteProgram)
GL_FUNC(glDeleteRenderbuffers)
GL_FUNC(glDeleteShader)
GL_FUNC(glDeleteTextures)
GL_FUNC(glDepthMask)
GL_FUNC(glDisable)
GL_FUNC(glDisableVertexAttribArray)
GL_FUNC(glDrawArrays)
GL_FUNC(glDrawElements)
GL_FUNC(glEnable)
GL_FUNC(glEnableVertexAttribArray)
GL_FUNC(glFinish)
GL_FUNC(glFlush)
GL_FUNC(glFramebufferRenderbuffer)
GL_FUNC(glFramebufferTexture2D)
GL_FUNC(glFrontFace)
GL_FUNC(glGenBuffers)
GL_FUNC(glGenerateMipmap)
GL_FUNC(glGenFramebuffers)
GL_FUNC(glGenRenderbuffers)
GL_FUNC(glGenTextures)
GL_FUNC(glGetBufferParameteriv)
GL_FUNC(glGetError)
GL_FUNC(glGetFramebufferAttachmentParameteriv)
GL_FUNC(glGetIntegerv)
GL_FUNC(glGetProgramInfoLog)
GL_FUNC(glGetProgramiv)
GL_FUNC(glGetRenderbufferParameteriv)
GL_FUNC(glGetShaderInfoLog)
GL_FUNC(glGetShaderiv)
GL_FUNC(glGetShaderPrecisionFormat)
GL_FUNC(glGetString)
GL_FUNC(glGetUniformLocation)
GL_FUNC(glIsTexture)
GL_FUNC(glLineWidth)
GL_FUNC(glLinkProgram)
GL_FUNC(glPixelStorei)
GL_FUNC(glReadPixels)
GL_FUNC(glRenderbufferStorage)
GL_FUNC(glScissor)
GL_FUNC(glShaderSource)
GL_FUNC(glStencilFunc)
GL_FUNC(glStencilFuncSeparate)
GL_FUNC(glStencilMask)
GL_FUNC(glStencilMaskSeparate)
GL_FUNC(glStencilOp)
GL_FUNC(glStencilOpSeparate)
GL_FUNC(glTexImage2D)
GL_FUNC(glTexParameterf)
GL_FUNC(glTexParameterfv)
GL_FUNC(glTexParameteri)
GL_FUNC(glTexParameteriv)
GL_FUNC(glTexSubImage2D)
GL_FUNC(glUniform1f)
GL_FUNC(glUniform1fv)
GL_FUNC(glUniform1i)
GL_FUNC(glUniform1iv)
GL_FUNC(glUniform2f)
GL_FUNC(glUniform2fv)
GL_FUNC(glUniform2i)
GL_FUNC(glUniform2iv)
GL_FUNC(glUniform3f)
GL_FUNC(glUniform3fv)
GL_FUNC(glUniform3i)
GL_FUNC(glUniform3iv)
GL_FUNC(glUniform4f)
GL_FUNC(glUniform4fv)
GL_FUNC(glUniform4i)
GL_FUNC(glUniform4iv)
GL_FUNC(glUniformMatrix2fv)
GL_FUNC(glUniformMatrix3fv)
GL_FUNC(glUniformMatrix4fv)
GL_FUNC(glUseProgram)
GL_FUNC(glVertexAttrib1f)
GL_FUNC(glVertexAttrib2fv)
GL_FUNC(glVertexAttrib3fv)
GL_FUNC(glVertexAttrib4fv)
GL_FUNC(glVertexAttribPointer)
GL_FUNC(glViewport)
#undef GL_FUNC
10 changes: 6 additions & 4 deletions shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ static double GetDeviceDpi() {
TizenEmbedderEngine::TizenEmbedderEngine(
const FlutterWindowProperties& window_properties)
: device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) {
tizen_surface = std::make_unique<TizenSurfaceGL>(
tizen_native_window = std::make_unique<TizenNativeWindow>(
window_properties.x, window_properties.y, window_properties.width,
window_properties.height);
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window.get());

// Run flutter task on Tizen main loop.
// Tizen engine has four threads (GPU thread, UI thread, IO thread, platform
Expand All @@ -58,7 +59,7 @@ TizenEmbedderEngine::TizenEmbedderEngine(
tizen_vsync_waiter_ = std::make_unique<TizenVsyncWaiter>();
}

TizenEmbedderEngine::~TizenEmbedderEngine() {}
TizenEmbedderEngine::~TizenEmbedderEngine() { LoggerE("Destroy"); }

// Attempts to load AOT data from the given path, which must be absolute and
// non-empty. Logs and returns nullptr on failure.
Expand Down Expand Up @@ -262,8 +263,9 @@ void TizenEmbedderEngine::SetWindowOrientation(int32_t degree) {

// Compute renderer transformation based on the angle of rotation.
double rad = (360 - degree) * M_PI / 180;
double width = tizen_surface->GetWidth();
double height = tizen_surface->GetHeight();
auto geometry = tizen_native_window->GetGeometry();
double width = geometry.w;
double height = geometry.h;

if (text_input_channel->isSoftwareKeyboardShowing()) {
height -= text_input_channel->GetCurrentKeyboardGeometry().h;
Expand Down
1 change: 1 addition & 0 deletions shell/platform/tizen/tizen_embedder_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class TizenEmbedderEngine {

// The interface between the Flutter rasterizer and the platform.
std::unique_ptr<TizenSurface> tizen_surface;
std::unique_ptr<TizenNativeWindow> tizen_native_window;

// The system channels for communicating between Flutter and the platform.
std::unique_ptr<KeyEventChannel> key_event_channel;
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/tizen/tizen_event_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <atomic>
#include <utility>

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

TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id,
TaskExpiredCallback on_task_expired)
: main_thread_id_(main_thread_id),
Expand All @@ -16,6 +18,7 @@ TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id,
}

TizenEventLoop::~TizenEventLoop() {
LoggerE("enter");
if (ecore_pipe_) {
ecore_pipe_del(ecore_pipe_);
}
Expand Down
113 changes: 113 additions & 0 deletions shell/platform/tizen/tizen_native_window.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Copyright 2020 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 "tizen_native_window.h"

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

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

~TizenWl2Display() {
if (wl2_display_) {
ecore_wl2_display_destroy(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) {
LoggerE("Could not access EGL display");
return;
}

EGLint majorVersion;
EGLint minorVersion;
if (eglInitialize(egl_display_, &majorVersion, &minorVersion) != EGL_TRUE) {
LoggerE("Could not initialize EGL display");
return;
}

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

TizenNativeEGLWindow::~TizenNativeEGLWindow() {
if (egl_window_) {
ecore_wl2_egl_window_destroy(egl_window_);
egl_window_ = nullptr;
}
if (egl_display_ != EGL_NO_CONTEXT) {
eglTerminate(egl_display_);
}
}

TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,
int32_t h) {
if (g_tizen_wl2_display.GetHandle() == nullptr) {
LoggerE("Faild to get display handle");
return;
}
if (w == 0 || h == 0) {
LoggerE("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_unique<TizenNativeEGLWindow>(this, w, h);
isValid_ = true;
}

TizenNativeWindow::~TizenNativeWindow() {
LoggerE("enter");
if (wl2_window_) {
ecore_wl2_window_free(wl2_window_);
wl2_window_ = nullptr;
}
}

TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() {
TizenNativeWindowGeometry result;
ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w,
&result.h);
return result;
}
53 changes: 53 additions & 0 deletions shell/platform/tizen/tizen_native_window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2020 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.

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

#include <memory>
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_; }

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

class TizenNativeWindow {
public:
struct TizenNativeWindowGeometry {
int32_t x{0}, y{0}, w{0}, h{0};
};

TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h);
~TizenNativeWindow();
bool IsValid() { return isValid_; }
Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; }
TizenNativeEGLWindow* GetTizenNativeEGLWindow() {
return tizen_native_egl_window_.get();
};
TizenNativeWindowGeometry GetGeometry();

private:
std::unique_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
Ecore_Wl2_Window* wl2_window_{nullptr};
bool isValid_{false};
};

#endif
Loading

0 comments on commit bf74173

Please sign in to comment.