Skip to content

Commit bede03f

Browse files
committed
Refactor tizen surface
* Add TizenNativeWindow, TizenNativeEGLWindow, TizenWl2Display * Add TizenEGLContext, TizenEGLSurface, TizenEGLSurface * TizenEmbedderEngine has TizenNativeWindow as a public member * Release EGLSurface, EGLDisplay, EGLContext Signed-off-by: Boram Bae <[email protected]>
1 parent 602a947 commit bede03f

14 files changed

+528
-350
lines changed

shell/platform/tizen/BUILD.gn

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ source_set("flutter_tizen") {
4646
"tizen_surface.cc",
4747
"tizen_surface_gl.cc",
4848
"tizen_vsync_waiter.cc",
49+
"tizen_native_window.cc",
4950
"touch_event_handler.cc",
5051
]
5152

shell/platform/tizen/channels/text_input_channel.cc

+10-9
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,11 @@ void TextInputChannel::InputPanelStateChangedCallback(
105105
0.25,
106106
[](void* data) -> Eina_Bool {
107107
TextInputChannel* self = (TextInputChannel*)data;
108-
int32_t surface_w = self->engine_->tizen_surface->GetWidth();
109-
int32_t surface_h = self->engine_->tizen_surface->GetHeight() -
110-
self->current_keyboard_geometry_.h;
108+
auto window_geometry =
109+
self->engine_->tizen_native_window->GetGeometry();
110+
int32_t surface_w = window_geometry.w;
111+
int32_t surface_h =
112+
window_geometry.h - self->current_keyboard_geometry_.h;
111113
self->engine_->tizen_surface->SetSize(surface_w, surface_h);
112114
if (self->rotation == 90 || self->rotation == 270) {
113115
self->engine_->SendWindowMetrics(surface_h, surface_w, 0);
@@ -293,7 +295,7 @@ TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger,
293295
}
294296
if (imfContext_) {
295297
Ecore_Wl2_Window* ecoreWindow =
296-
((TizenSurfaceGL*)engine_->tizen_surface.get())->wl2_window();
298+
engine_->tizen_native_window->GetWindowHandle();
297299
ecore_imf_context_client_window_set(
298300
imfContext_, (void*)ecore_wl2_window_id_get(ecoreWindow));
299301
RegisterIMFCallback(ecoreWindow);
@@ -604,15 +606,14 @@ void TextInputChannel::HideSoftwareKeyboard() {
604606

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

610611
if (rotation == 90 || rotation == 270) {
611-
engine_->SendWindowMetrics(h, w, 0);
612+
engine_->SendWindowMetrics(window_geometry.h, window_geometry.w, 0);
612613
} else {
613-
engine_->SendWindowMetrics(w, h, 0);
614+
engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0);
614615
}
615-
engine_->tizen_surface->SetSize(w, h);
616+
engine_->tizen_surface->SetSize(window_geometry.w, window_geometry.h);
616617
ecore_timer_add(
617618
0.05,
618619
[](void* data) -> Eina_Bool {
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Copyright 2020 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+
#define GL_FUNC(FunctionName) \
6+
else if (strcmp(name, #FunctionName) == 0) { \
7+
return reinterpret_cast<void*>(FunctionName); \
8+
}
9+
10+
GL_FUNC(eglGetCurrentDisplay)
11+
GL_FUNC(eglQueryString)
12+
GL_FUNC(glActiveTexture)
13+
GL_FUNC(glAttachShader)
14+
GL_FUNC(glBindAttribLocation)
15+
GL_FUNC(glBindBuffer)
16+
GL_FUNC(glBindFramebuffer)
17+
GL_FUNC(glBindRenderbuffer)
18+
GL_FUNC(glBindTexture)
19+
GL_FUNC(glBlendColor)
20+
GL_FUNC(glBlendEquation)
21+
GL_FUNC(glBlendFunc)
22+
GL_FUNC(glBufferData)
23+
GL_FUNC(glBufferSubData)
24+
GL_FUNC(glCheckFramebufferStatus)
25+
GL_FUNC(glClear)
26+
GL_FUNC(glClearColor)
27+
GL_FUNC(glClearStencil)
28+
GL_FUNC(glColorMask)
29+
GL_FUNC(glCompileShader)
30+
GL_FUNC(glCompressedTexImage2D)
31+
GL_FUNC(glCompressedTexSubImage2D)
32+
GL_FUNC(glCopyTexSubImage2D)
33+
GL_FUNC(glCreateProgram)
34+
GL_FUNC(glCreateShader)
35+
GL_FUNC(glCullFace)
36+
GL_FUNC(glDeleteBuffers)
37+
GL_FUNC(glDeleteFramebuffers)
38+
GL_FUNC(glDeleteProgram)
39+
GL_FUNC(glDeleteRenderbuffers)
40+
GL_FUNC(glDeleteShader)
41+
GL_FUNC(glDeleteTextures)
42+
GL_FUNC(glDepthMask)
43+
GL_FUNC(glDisable)
44+
GL_FUNC(glDisableVertexAttribArray)
45+
GL_FUNC(glDrawArrays)
46+
GL_FUNC(glDrawElements)
47+
GL_FUNC(glEnable)
48+
GL_FUNC(glEnableVertexAttribArray)
49+
GL_FUNC(glFinish)
50+
GL_FUNC(glFlush)
51+
GL_FUNC(glFramebufferRenderbuffer)
52+
GL_FUNC(glFramebufferTexture2D)
53+
GL_FUNC(glFrontFace)
54+
GL_FUNC(glGenBuffers)
55+
GL_FUNC(glGenerateMipmap)
56+
GL_FUNC(glGenFramebuffers)
57+
GL_FUNC(glGenRenderbuffers)
58+
GL_FUNC(glGenTextures)
59+
GL_FUNC(glGetBufferParameteriv)
60+
GL_FUNC(glGetError)
61+
GL_FUNC(glGetFramebufferAttachmentParameteriv)
62+
GL_FUNC(glGetIntegerv)
63+
GL_FUNC(glGetProgramInfoLog)
64+
GL_FUNC(glGetProgramiv)
65+
GL_FUNC(glGetRenderbufferParameteriv)
66+
GL_FUNC(glGetShaderInfoLog)
67+
GL_FUNC(glGetShaderiv)
68+
GL_FUNC(glGetShaderPrecisionFormat)
69+
GL_FUNC(glGetString)
70+
GL_FUNC(glGetUniformLocation)
71+
GL_FUNC(glIsTexture)
72+
GL_FUNC(glLineWidth)
73+
GL_FUNC(glLinkProgram)
74+
GL_FUNC(glPixelStorei)
75+
GL_FUNC(glReadPixels)
76+
GL_FUNC(glRenderbufferStorage)
77+
GL_FUNC(glScissor)
78+
GL_FUNC(glShaderSource)
79+
GL_FUNC(glStencilFunc)
80+
GL_FUNC(glStencilFuncSeparate)
81+
GL_FUNC(glStencilMask)
82+
GL_FUNC(glStencilMaskSeparate)
83+
GL_FUNC(glStencilOp)
84+
GL_FUNC(glStencilOpSeparate)
85+
GL_FUNC(glTexImage2D)
86+
GL_FUNC(glTexParameterf)
87+
GL_FUNC(glTexParameterfv)
88+
GL_FUNC(glTexParameteri)
89+
GL_FUNC(glTexParameteriv)
90+
GL_FUNC(glTexSubImage2D)
91+
GL_FUNC(glUniform1f)
92+
GL_FUNC(glUniform1fv)
93+
GL_FUNC(glUniform1i)
94+
GL_FUNC(glUniform1iv)
95+
GL_FUNC(glUniform2f)
96+
GL_FUNC(glUniform2fv)
97+
GL_FUNC(glUniform2i)
98+
GL_FUNC(glUniform2iv)
99+
GL_FUNC(glUniform3f)
100+
GL_FUNC(glUniform3fv)
101+
GL_FUNC(glUniform3i)
102+
GL_FUNC(glUniform3iv)
103+
GL_FUNC(glUniform4f)
104+
GL_FUNC(glUniform4fv)
105+
GL_FUNC(glUniform4i)
106+
GL_FUNC(glUniform4iv)
107+
GL_FUNC(glUniformMatrix2fv)
108+
GL_FUNC(glUniformMatrix3fv)
109+
GL_FUNC(glUniformMatrix4fv)
110+
GL_FUNC(glUseProgram)
111+
GL_FUNC(glVertexAttrib1f)
112+
GL_FUNC(glVertexAttrib2fv)
113+
GL_FUNC(glVertexAttrib3fv)
114+
GL_FUNC(glVertexAttrib4fv)
115+
GL_FUNC(glVertexAttribPointer)
116+
GL_FUNC(glViewport)
117+
#undef GL_FUNC

shell/platform/tizen/tizen_embedder_engine.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ static double GetDeviceDpi() {
3535
TizenEmbedderEngine::TizenEmbedderEngine(
3636
const FlutterWindowProperties& window_properties)
3737
: device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) {
38-
tizen_surface = std::make_unique<TizenSurfaceGL>(
38+
tizen_native_window = std::make_unique<TizenNativeWindow>(
3939
window_properties.x, window_properties.y, window_properties.width,
4040
window_properties.height);
41+
tizen_surface = std::make_unique<TizenSurfaceGL>(tizen_native_window.get());
4142

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

61-
TizenEmbedderEngine::~TizenEmbedderEngine() {}
62+
TizenEmbedderEngine::~TizenEmbedderEngine() { LoggerE("Destroy"); }
6263

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

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

268270
if (text_input_channel->isSoftwareKeyboardShowing()) {
269271
height -= text_input_channel->GetCurrentKeyboardGeometry().h;

shell/platform/tizen/tizen_embedder_engine.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class TizenEmbedderEngine {
9595

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

99100
// The system channels for communicating between Flutter and the platform.
100101
std::unique_ptr<KeyEventChannel> key_event_channel;

shell/platform/tizen/tizen_event_loop.cc

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <atomic>
99
#include <utility>
1010

11+
#include "flutter/shell/platform/tizen/logger.h"
12+
1113
TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id,
1214
TaskExpiredCallback on_task_expired)
1315
: main_thread_id_(main_thread_id),
@@ -16,6 +18,7 @@ TizenEventLoop::TizenEventLoop(std::thread::id main_thread_id,
1618
}
1719

1820
TizenEventLoop::~TizenEventLoop() {
21+
LoggerE("enter");
1922
if (ecore_pipe_) {
2023
ecore_pipe_del(ecore_pipe_);
2124
}
+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2020 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 "tizen_native_window.h"
6+
7+
#include "flutter/shell/platform/tizen/logger.h"
8+
9+
class TizenWl2Display {
10+
public:
11+
TizenWl2Display() {
12+
if (!ecore_wl2_init()) {
13+
LoggerE("Could not initialize ecore_wl2");
14+
abort();
15+
return;
16+
}
17+
// ecore_wl2 DISPLAY
18+
wl2_display_ = ecore_wl2_display_connect(nullptr);
19+
if (wl2_display_ == nullptr) {
20+
LoggerE("Display not found");
21+
abort();
22+
return;
23+
}
24+
ecore_wl2_sync();
25+
}
26+
27+
~TizenWl2Display() {
28+
if (wl2_display_) {
29+
ecore_wl2_display_destroy(wl2_display_);
30+
wl2_display_ = nullptr;
31+
}
32+
ecore_wl2_shutdown();
33+
}
34+
Ecore_Wl2_Display* GetHandle() { return wl2_display_; }
35+
36+
private:
37+
Ecore_Wl2_Display* wl2_display_{nullptr};
38+
};
39+
TizenWl2Display g_tizen_wl2_display;
40+
41+
TizenNativeEGLWindow::TizenNativeEGLWindow(
42+
TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) {
43+
egl_window_ =
44+
ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h);
45+
46+
egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(
47+
g_tizen_wl2_display.GetHandle()));
48+
if (egl_display_ == EGL_NO_DISPLAY) {
49+
LoggerE("Could not access EGL display");
50+
return;
51+
}
52+
53+
EGLint majorVersion;
54+
EGLint minorVersion;
55+
if (eglInitialize(egl_display_, &majorVersion, &minorVersion) != EGL_TRUE) {
56+
LoggerE("Could not initialize EGL display");
57+
return;
58+
}
59+
60+
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
61+
LoggerE("Could not bind API");
62+
return;
63+
}
64+
}
65+
66+
TizenNativeEGLWindow::~TizenNativeEGLWindow() {
67+
if (egl_window_) {
68+
ecore_wl2_egl_window_destroy(egl_window_);
69+
egl_window_ = nullptr;
70+
}
71+
if (egl_display_ != EGL_NO_CONTEXT) {
72+
eglTerminate(egl_display_);
73+
}
74+
}
75+
76+
TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,
77+
int32_t h) {
78+
if (g_tizen_wl2_display.GetHandle() == nullptr) {
79+
LoggerE("Faild to get display handle");
80+
return;
81+
}
82+
if (w == 0 || h == 0) {
83+
LoggerE("Failed to create because of the wrong size");
84+
return;
85+
}
86+
87+
wl2_window_ = ecore_wl2_window_new(g_tizen_wl2_display.GetHandle(), nullptr,
88+
x, y, w, h);
89+
90+
ecore_wl2_window_type_set(wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
91+
ecore_wl2_window_alpha_set(wl2_window_, EINA_FALSE);
92+
ecore_wl2_window_aux_hint_add(wl2_window_, 0, "wm.policy.win.user.geometry",
93+
"1");
94+
ecore_wl2_window_show(wl2_window_);
95+
96+
tizen_native_egl_window_ = std::make_unique<TizenNativeEGLWindow>(this, w, h);
97+
isValid_ = true;
98+
}
99+
100+
TizenNativeWindow::~TizenNativeWindow() {
101+
LoggerE("enter");
102+
if (wl2_window_) {
103+
ecore_wl2_window_free(wl2_window_);
104+
wl2_window_ = nullptr;
105+
}
106+
}
107+
108+
TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() {
109+
TizenNativeWindowGeometry result;
110+
ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w,
111+
&result.h);
112+
return result;
113+
}
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2020 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+
#ifndef EMBEDDER_TIZEN_WINDOW_H_
6+
#define EMBEDDER_TIZEN_WINDOW_H_
7+
#include <EGL/egl.h>
8+
#include <GLES2/gl2.h>
9+
#define EFL_BETA_API_SUPPORT
10+
#include <Ecore_Wl2.h>
11+
12+
#include <memory>
13+
class TizenNativeWindow;
14+
15+
class TizenNativeEGLWindow {
16+
public:
17+
TizenNativeEGLWindow(TizenNativeWindow* tizen_native_window, int32_t w,
18+
int32_t h);
19+
~TizenNativeEGLWindow();
20+
bool IsValid() {
21+
return egl_window_ != nullptr && egl_display_ != EGL_NO_DISPLAY;
22+
};
23+
24+
Ecore_Wl2_Egl_Window* GetEglWindowHandle() { return egl_window_; };
25+
EGLDisplay GetEGLDisplayHandle() { return egl_display_; }
26+
27+
private:
28+
Ecore_Wl2_Egl_Window* egl_window_ = nullptr;
29+
EGLDisplay egl_display_ = EGL_NO_DISPLAY;
30+
};
31+
32+
class TizenNativeWindow {
33+
public:
34+
struct TizenNativeWindowGeometry {
35+
int32_t x{0}, y{0}, w{0}, h{0};
36+
};
37+
38+
TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h);
39+
~TizenNativeWindow();
40+
bool IsValid() { return isValid_; }
41+
Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; }
42+
TizenNativeEGLWindow* GetTizenNativeEGLWindow() {
43+
return tizen_native_egl_window_.get();
44+
};
45+
TizenNativeWindowGeometry GetGeometry();
46+
47+
private:
48+
std::unique_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
49+
Ecore_Wl2_Window* wl2_window_{nullptr};
50+
bool isValid_{false};
51+
};
52+
53+
#endif

0 commit comments

Comments
 (0)