Skip to content

Commit a2d8464

Browse files
authored
Refactor tizen surface (flutter-tizen#10)
* 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 50e1265 commit a2d8464

11 files changed

+405
-239
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 {

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() { LoggerD("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;
+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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+
return;
15+
}
16+
// ecore_wl2 DISPLAY
17+
wl2_display_ = ecore_wl2_display_connect(nullptr);
18+
if (wl2_display_ == nullptr) {
19+
LoggerE("Display not found");
20+
return;
21+
}
22+
ecore_wl2_sync();
23+
}
24+
25+
~TizenWl2Display() {
26+
if (wl2_display_) {
27+
ecore_wl2_display_destroy(wl2_display_);
28+
wl2_display_ = nullptr;
29+
}
30+
ecore_wl2_shutdown();
31+
}
32+
Ecore_Wl2_Display* GetHandle() { return wl2_display_; }
33+
34+
private:
35+
Ecore_Wl2_Display* wl2_display_{nullptr};
36+
};
37+
TizenWl2Display g_tizen_wl2_display;
38+
39+
TizenNativeEGLWindow::TizenNativeEGLWindow(
40+
TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) {
41+
egl_window_ =
42+
ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h);
43+
44+
egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get(
45+
g_tizen_wl2_display.GetHandle()));
46+
if (egl_display_ == EGL_NO_DISPLAY) {
47+
LoggerE("Could not access EGL display");
48+
return;
49+
}
50+
51+
EGLint major_version;
52+
EGLint minor_version;
53+
if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) {
54+
LoggerE("Could not initialize EGL display");
55+
return;
56+
}
57+
58+
LoggerD("eglInitialized: %d.%d", major_version, minor_version);
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+
is_valid_ = true;
98+
}
99+
100+
TizenNativeWindow::~TizenNativeWindow() {
101+
if (wl2_window_) {
102+
ecore_wl2_window_free(wl2_window_);
103+
wl2_window_ = nullptr;
104+
}
105+
}
106+
107+
TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() {
108+
TizenNativeWindowGeometry result;
109+
ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w,
110+
&result.h);
111+
return result;
112+
}
+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 is_valid_; }
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 is_valid_{false};
51+
};
52+
53+
#endif

shell/platform/tizen/tizen_surface.cc

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44

55
#include "tizen_surface.h"
66

7-
TizenSurface::TizenSurface(int32_t x, int32_t y, int32_t width, int32_t height)
8-
: window_width_(width), window_height_(height), x_(x), y_(y) {}
9-
10-
TizenSurface::~TizenSurface() {}
11-
12-
int32_t TizenSurface::GetWidth() { return window_width_; }
13-
14-
int32_t TizenSurface::GetHeight() { return window_height_; }
7+
TizenSurface::~TizenSurface() = default;

shell/platform/tizen/tizen_surface.h

-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
class TizenSurface {
1111
public:
12-
TizenSurface(int32_t x, int32_t y, int32_t width, int32_t height);
1312
virtual ~TizenSurface();
1413
virtual bool OnMakeCurrent() = 0;
1514
virtual bool OnClearCurrent() = 0;
@@ -19,14 +18,6 @@ class TizenSurface {
1918
virtual void* OnProcResolver(const char* name) = 0;
2019
virtual bool IsValid() = 0;
2120
virtual void SetSize(int32_t width, int32_t height) = 0;
22-
int32_t GetWidth();
23-
int32_t GetHeight();
24-
25-
protected:
26-
const int32_t window_width_;
27-
const int32_t window_height_;
28-
int32_t x_;
29-
int32_t y_;
3021
};
3122

3223
#endif // EMBEDDER_TIZEN_SURFACE_H_

0 commit comments

Comments
 (0)