Skip to content

Commit aaa7adc

Browse files
committed
Refactor tizen surface
* Add TizenNativeWindow, TizenNativeEGLWindow, TizenWl2Display * Add TizenEGLContext, TizenEGLSurface, TizenEGLSurface * Release EGLSurface, EGLDisplay, EGLContext Signed-off-by: Boram Bae <[email protected]>
1 parent 48a5982 commit aaa7adc

File tree

6 files changed

+498
-314
lines changed

6 files changed

+498
-314
lines changed

shell/platform/tizen/BUILD.gn

Lines changed: 1 addition & 0 deletions
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

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
3+
// Use of this source code is governed by a BSD-style license that can be
4+
// found in the LICENSE file.
5+
6+
#define GL_FUNC(FunctionName) \
7+
else if (strcmp(name, #FunctionName) == 0) { \
8+
return reinterpret_cast<void*>(FunctionName); \
9+
}
10+
11+
GL_FUNC(eglGetCurrentDisplay)
12+
GL_FUNC(eglQueryString)
13+
GL_FUNC(glActiveTexture)
14+
GL_FUNC(glAttachShader)
15+
GL_FUNC(glBindAttribLocation)
16+
GL_FUNC(glBindBuffer)
17+
GL_FUNC(glBindFramebuffer)
18+
GL_FUNC(glBindRenderbuffer)
19+
GL_FUNC(glBindTexture)
20+
GL_FUNC(glBlendColor)
21+
GL_FUNC(glBlendEquation)
22+
GL_FUNC(glBlendFunc)
23+
GL_FUNC(glBufferData)
24+
GL_FUNC(glBufferSubData)
25+
GL_FUNC(glCheckFramebufferStatus)
26+
GL_FUNC(glClear)
27+
GL_FUNC(glClearColor)
28+
GL_FUNC(glClearStencil)
29+
GL_FUNC(glColorMask)
30+
GL_FUNC(glCompileShader)
31+
GL_FUNC(glCompressedTexImage2D)
32+
GL_FUNC(glCompressedTexSubImage2D)
33+
GL_FUNC(glCopyTexSubImage2D)
34+
GL_FUNC(glCreateProgram)
35+
GL_FUNC(glCreateShader)
36+
GL_FUNC(glCullFace)
37+
GL_FUNC(glDeleteBuffers)
38+
GL_FUNC(glDeleteFramebuffers)
39+
GL_FUNC(glDeleteProgram)
40+
GL_FUNC(glDeleteRenderbuffers)
41+
GL_FUNC(glDeleteShader)
42+
GL_FUNC(glDeleteTextures)
43+
GL_FUNC(glDepthMask)
44+
GL_FUNC(glDisable)
45+
GL_FUNC(glDisableVertexAttribArray)
46+
GL_FUNC(glDrawArrays)
47+
GL_FUNC(glDrawElements)
48+
GL_FUNC(glEnable)
49+
GL_FUNC(glEnableVertexAttribArray)
50+
GL_FUNC(glFinish)
51+
GL_FUNC(glFlush)
52+
GL_FUNC(glFramebufferRenderbuffer)
53+
GL_FUNC(glFramebufferTexture2D)
54+
GL_FUNC(glFrontFace)
55+
GL_FUNC(glGenBuffers)
56+
GL_FUNC(glGenerateMipmap)
57+
GL_FUNC(glGenFramebuffers)
58+
GL_FUNC(glGenRenderbuffers)
59+
GL_FUNC(glGenTextures)
60+
GL_FUNC(glGetBufferParameteriv)
61+
GL_FUNC(glGetError)
62+
GL_FUNC(glGetFramebufferAttachmentParameteriv)
63+
GL_FUNC(glGetIntegerv)
64+
GL_FUNC(glGetProgramInfoLog)
65+
GL_FUNC(glGetProgramiv)
66+
GL_FUNC(glGetRenderbufferParameteriv)
67+
GL_FUNC(glGetShaderInfoLog)
68+
GL_FUNC(glGetShaderiv)
69+
GL_FUNC(glGetShaderPrecisionFormat)
70+
GL_FUNC(glGetString)
71+
GL_FUNC(glGetUniformLocation)
72+
GL_FUNC(glIsTexture)
73+
GL_FUNC(glLineWidth)
74+
GL_FUNC(glLinkProgram)
75+
GL_FUNC(glPixelStorei)
76+
GL_FUNC(glReadPixels)
77+
GL_FUNC(glRenderbufferStorage)
78+
GL_FUNC(glScissor)
79+
GL_FUNC(glShaderSource)
80+
GL_FUNC(glStencilFunc)
81+
GL_FUNC(glStencilFuncSeparate)
82+
GL_FUNC(glStencilMask)
83+
GL_FUNC(glStencilMaskSeparate)
84+
GL_FUNC(glStencilOp)
85+
GL_FUNC(glStencilOpSeparate)
86+
GL_FUNC(glTexImage2D)
87+
GL_FUNC(glTexParameterf)
88+
GL_FUNC(glTexParameterfv)
89+
GL_FUNC(glTexParameteri)
90+
GL_FUNC(glTexParameteriv)
91+
GL_FUNC(glTexSubImage2D)
92+
GL_FUNC(glUniform1f)
93+
GL_FUNC(glUniform1fv)
94+
GL_FUNC(glUniform1i)
95+
GL_FUNC(glUniform1iv)
96+
GL_FUNC(glUniform2f)
97+
GL_FUNC(glUniform2fv)
98+
GL_FUNC(glUniform2i)
99+
GL_FUNC(glUniform2iv)
100+
GL_FUNC(glUniform3f)
101+
GL_FUNC(glUniform3fv)
102+
GL_FUNC(glUniform3i)
103+
GL_FUNC(glUniform3iv)
104+
GL_FUNC(glUniform4f)
105+
GL_FUNC(glUniform4fv)
106+
GL_FUNC(glUniform4i)
107+
GL_FUNC(glUniform4iv)
108+
GL_FUNC(glUniformMatrix2fv)
109+
GL_FUNC(glUniformMatrix3fv)
110+
GL_FUNC(glUniformMatrix4fv)
111+
GL_FUNC(glUseProgram)
112+
GL_FUNC(glVertexAttrib1f)
113+
GL_FUNC(glVertexAttrib2fv)
114+
GL_FUNC(glVertexAttrib3fv)
115+
GL_FUNC(glVertexAttrib4fv)
116+
GL_FUNC(glVertexAttribPointer)
117+
GL_FUNC(glViewport)
118+
#undef GL_FUNC
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
}
15+
// ecore_wl2 DISPLAY
16+
wl2_display_ = ecore_wl2_display_connect(nullptr);
17+
if (wl2_display_ == nullptr) {
18+
LoggerE("Display not found");
19+
}
20+
ecore_wl2_sync();
21+
}
22+
23+
~TizenWl2Display() {
24+
if (wl2_display_) {
25+
ecore_wl2_display_destroy(wl2_display_);
26+
wl2_display_ = nullptr;
27+
}
28+
ecore_wl2_shutdown();
29+
}
30+
Ecore_Wl2_Display* GetHandle() { return wl2_display_; }
31+
32+
private:
33+
Ecore_Wl2_Display* wl2_display_ = nullptr;
34+
};
35+
TizenWl2Display g_tizen_wl2_display;
36+
37+
TizenNativeEGLWindow::TizenNativeEGLWindow(
38+
TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) {
39+
egl_window_ =
40+
ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h);
41+
42+
egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(
43+
g_tizen_wl2_display.GetHandle()));
44+
if (egl_display_ == EGL_NO_DISPLAY) {
45+
LoggerE("Could not access EGL display");
46+
return;
47+
}
48+
49+
EGLint majorVersion;
50+
EGLint minorVersion;
51+
if (eglInitialize(egl_display_, &majorVersion, &minorVersion) != EGL_TRUE) {
52+
LoggerE("Could not initialize EGL display");
53+
return;
54+
}
55+
56+
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
57+
LoggerE("Could not bind API");
58+
return;
59+
}
60+
}
61+
62+
TizenNativeEGLWindow::~TizenNativeEGLWindow() {
63+
if (egl_window_) {
64+
ecore_wl2_egl_window_destroy(egl_window_);
65+
egl_window_ = nullptr;
66+
}
67+
if (egl_display_ != EGL_NO_CONTEXT) {
68+
eglTerminate(egl_display_);
69+
}
70+
}
71+
72+
TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h)
73+
: x_(x), y_(y), w_(w), h_(h) {
74+
if (g_tizen_wl2_display.GetHandle() == nullptr) {
75+
LoggerE("Faild to get display handle");
76+
return;
77+
}
78+
79+
wl2_window_ = ecore_wl2_window_new(g_tizen_wl2_display.GetHandle(), nullptr,
80+
x_, y_, w_, h_);
81+
82+
ecore_wl2_window_type_set(wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL);
83+
ecore_wl2_window_alpha_set(wl2_window_, EINA_FALSE);
84+
ecore_wl2_window_aux_hint_add(wl2_window_, 0, "wm.policy.win.user.geometry",
85+
"1");
86+
ecore_wl2_window_show(wl2_window_);
87+
88+
tizen_native_egl_window_ = std::make_unique<TizenNativeEGLWindow>(this, w, h);
89+
isValid_ = true;
90+
}
91+
92+
TizenNativeWindow::~TizenNativeWindow() {
93+
if (wl2_window_) {
94+
ecore_wl2_window_free(wl2_window_);
95+
wl2_window_ = nullptr;
96+
}
97+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h);
35+
~TizenNativeWindow();
36+
bool IsValid() { return isValid_; }
37+
Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; }
38+
TizenNativeEGLWindow* GetTizenNativeEGLWindow() {
39+
return tizen_native_egl_window_.get();
40+
};
41+
42+
private:
43+
std::unique_ptr<TizenNativeEGLWindow> tizen_native_egl_window_;
44+
int32_t x_{0};
45+
int32_t y_{0};
46+
int32_t w_{0};
47+
int32_t h_{0};
48+
Ecore_Wl2_Window* wl2_window_{nullptr};
49+
bool isValid_{false};
50+
};
51+
52+
#endif

0 commit comments

Comments
 (0)