Skip to content

Commit 2aa474e

Browse files
committed
Minor update to Misc
* Call first OnClearCurrent when destroying TizenSurfaceGL * Add LogLastEGLError from the Android Shell * Move a method for resizing egl window to TizenNativeEGLWindow * Tidy up Signed-off-by: Boram Bae <[email protected]>
1 parent 022b7c3 commit 2aa474e

10 files changed

+119
-48
lines changed

shell/platform/tizen/channels/text_input_channel.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "flutter/shell/platform/tizen/tizen_embedder_engine.h"
1111
#include "flutter/shell/platform/tizen/tizen_log.h"
12-
#include "flutter/shell/platform/tizen/tizen_surface.h"
1312
#include "stdlib.h"
1413
#include "string.h"
1514

@@ -113,7 +112,9 @@ void TextInputChannel::InputPanelStateChangedCallback(
113112
int32_t surface_w = window_geometry.w;
114113
int32_t surface_h =
115114
window_geometry.h - self->current_keyboard_geometry_.h;
116-
self->engine_->tizen_surface->SetSize(surface_w, surface_h);
115+
116+
self->engine_->tizen_native_window->GetTizenNativeEGLWindow()
117+
->ResizeWithRotation(0, 0, surface_w, surface_h, 0);
117118
if (self->rotation == 90 || self->rotation == 270) {
118119
self->engine_->SendWindowMetrics(surface_h, surface_w, 0);
119120
} else {
@@ -618,7 +619,8 @@ void TextInputChannel::HideSoftwareKeyboard() {
618619
} else {
619620
engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0);
620621
}
621-
engine_->tizen_surface->SetSize(window_geometry.w, window_geometry.h);
622+
engine_->tizen_native_window->GetTizenNativeEGLWindow()
623+
->ResizeWithRotation(0, 0, window_geometry.w, window_geometry.h, 0);
622624
ecore_timer_add(
623625
0.05,
624626
[](void* data) -> Eina_Bool {

shell/platform/tizen/external_texture_gl.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
112112
opengl_texture->target = GL_TEXTURE_EXTERNAL_OES;
113113
opengl_texture->name = state_->gl_texture;
114114
opengl_texture->format = GL_RGBA8;
115-
opengl_texture->destruction_callback = (VoidCallback)destructionCallback;
115+
opengl_texture->destruction_callback = (VoidCallback)DestructionCallback;
116116
opengl_texture->user_data = static_cast<void*>(this);
117117
opengl_texture->width = width;
118118
opengl_texture->height = height;
@@ -135,7 +135,7 @@ void ExternalTextureGL::DestructionTbmSurface() {
135135
texture_tbm_surface_ = NULL;
136136
}
137137

138-
void ExternalTextureGL::destructionCallback(void* user_data) {
138+
void ExternalTextureGL::DestructionCallback(void* user_data) {
139139
ExternalTextureGL* externalTextureGL =
140140
reinterpret_cast<ExternalTextureGL*>(user_data);
141141
externalTextureGL->DestructionTbmSurfaceWithLock();

shell/platform/tizen/external_texture_gl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ExternalTextureGL {
2828
/**
2929
* Returns the unique id for the ExternalTextureGL instance.
3030
*/
31-
int64_t texture_id() { return (int64_t)texture_id_; }
31+
int64_t TextureId() { return (int64_t)texture_id_; }
3232

3333
/**
3434
* Accepts texture buffer copy request from the Flutter engine.
@@ -48,7 +48,7 @@ class ExternalTextureGL {
4848
std::unique_ptr<ExternalTextureGLState> state_;
4949
std::mutex mutex_;
5050
tbm_surface_h texture_tbm_surface_;
51-
static void destructionCallback(void* user_data);
51+
static void DestructionCallback(void* user_data);
5252
const long texture_id_;
5353
};
5454

shell/platform/tizen/flutter_tizen.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ int64_t FlutterRegisterExternalTexture(
229229
FlutterTextureRegistrarRef texture_registrar) {
230230
FT_LOGD("FlutterDesktopRegisterExternalTexture");
231231
auto texture_gl = std::make_unique<ExternalTextureGL>();
232-
int64_t texture_id = texture_gl->texture_id();
232+
int64_t texture_id = texture_gl->TextureId();
233233
texture_registrar->textures[texture_id] = std::move(texture_gl);
234234
if (FlutterEngineRegisterExternalTexture(texture_registrar->flutter_engine,
235235
texture_id) == kSuccess) {

shell/platform/tizen/tizen_embedder_engine.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ bool TizenEmbedderEngine::RunEngine(
158158
auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, this,
159159
&flutter_engine);
160160
if (result == kSuccess && flutter_engine != nullptr) {
161-
FT_LOGI("FlutterEngineRun Success!");
161+
FT_LOGD("FlutterEngineRun Success!");
162162
} else {
163163
FT_LOGE("FlutterEngineRun Failure! result: %d", result);
164164
return false;

shell/platform/tizen/tizen_native_window.cc

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright 2013 The Flutter Authors. 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.
14
// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved.
25
// Use of this source code is governed by a BSD-style license that can be
36
// found in the LICENSE file.
@@ -6,6 +9,49 @@
69

710
#include "flutter/shell/platform/tizen/tizen_log.h"
811

12+
void LogLastEGLError() {
13+
struct EGLNameErrorPair {
14+
const char* name;
15+
EGLint code;
16+
};
17+
18+
#define _EGL_ERROR_DESC(a) \
19+
{ #a, a }
20+
21+
const EGLNameErrorPair pairs[] = {
22+
_EGL_ERROR_DESC(EGL_SUCCESS),
23+
_EGL_ERROR_DESC(EGL_NOT_INITIALIZED),
24+
_EGL_ERROR_DESC(EGL_BAD_ACCESS),
25+
_EGL_ERROR_DESC(EGL_BAD_ALLOC),
26+
_EGL_ERROR_DESC(EGL_BAD_ATTRIBUTE),
27+
_EGL_ERROR_DESC(EGL_BAD_CONTEXT),
28+
_EGL_ERROR_DESC(EGL_BAD_CONFIG),
29+
_EGL_ERROR_DESC(EGL_BAD_CURRENT_SURFACE),
30+
_EGL_ERROR_DESC(EGL_BAD_DISPLAY),
31+
_EGL_ERROR_DESC(EGL_BAD_SURFACE),
32+
_EGL_ERROR_DESC(EGL_BAD_MATCH),
33+
_EGL_ERROR_DESC(EGL_BAD_PARAMETER),
34+
_EGL_ERROR_DESC(EGL_BAD_NATIVE_PIXMAP),
35+
_EGL_ERROR_DESC(EGL_BAD_NATIVE_WINDOW),
36+
_EGL_ERROR_DESC(EGL_CONTEXT_LOST),
37+
};
38+
39+
#undef _EGL_ERROR_DESC
40+
41+
const auto count = sizeof(pairs) / sizeof(EGLNameErrorPair);
42+
43+
EGLint last_error = eglGetError();
44+
45+
for (size_t i = 0; i < count; i++) {
46+
if (last_error == pairs[i].code) {
47+
FT_LOGE("EGL Error: %s (%d)", pairs[i].name, pairs[i].code);
48+
return;
49+
}
50+
}
51+
52+
FT_LOGE("Unknown EGL Error");
53+
}
54+
955
class TizenWl2Display {
1056
public:
1157
TizenWl2Display() {
@@ -45,32 +91,47 @@ TizenNativeEGLWindow::TizenNativeEGLWindow(
4591
g_tizen_wl2_display.GetHandle()));
4692
if (egl_display_ == EGL_NO_DISPLAY) {
4793
FT_LOGE("Could not access EGL display");
94+
LogLastEGLError();
4895
return;
4996
}
5097

5198
EGLint major_version;
5299
EGLint minor_version;
53100
if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) {
54101
FT_LOGE("Could not initialize EGL display");
102+
LogLastEGLError();
55103
return;
56104
}
57105

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

60108
if (eglBindAPI(EGL_OPENGL_ES_API) != EGL_TRUE) {
61109
FT_LOGE("Could not bind API");
110+
LogLastEGLError();
62111
return;
63112
}
64113
}
65114

66115
TizenNativeEGLWindow::~TizenNativeEGLWindow() {
67-
if (egl_window_) {
116+
if (egl_display_ != EGL_NO_DISPLAY) {
117+
if (eglTerminate(egl_display_) != EGL_TRUE) {
118+
FT_LOGE("Failed to terminate egl display");
119+
LogLastEGLError();
120+
}
121+
egl_display_ = EGL_NO_DISPLAY;
122+
}
123+
124+
if (egl_window_ != nullptr) {
68125
ecore_wl2_egl_window_destroy(egl_window_);
69126
egl_window_ = nullptr;
70127
}
71-
if (egl_display_ != EGL_NO_CONTEXT) {
72-
eglTerminate(egl_display_);
73-
}
128+
}
129+
130+
void TizenNativeEGLWindow::ResizeWithRotation(int32_t dx, int32_t dy,
131+
int32_t width, int32_t height,
132+
int32_t degree) {
133+
ecore_wl2_egl_window_resize_with_rotation(egl_window_, dx, dy, width, height,
134+
degree);
74135
}
75136

76137
TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,

shell/platform/tizen/tizen_native_window.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#ifndef EMBEDDER_TIZEN_WINDOW_H_
66
#define EMBEDDER_TIZEN_WINDOW_H_
77
#include <EGL/egl.h>
8-
#include <GLES2/gl2.h>
98
#define EFL_BETA_API_SUPPORT
109
#include <Ecore_Wl2.h>
1110

1211
#include <memory>
12+
13+
void LogLastEGLError();
14+
1315
class TizenNativeWindow;
1416

1517
class TizenNativeEGLWindow {
@@ -23,6 +25,8 @@ class TizenNativeEGLWindow {
2325

2426
Ecore_Wl2_Egl_Window* GetEglWindowHandle() { return egl_window_; };
2527
EGLDisplay GetEGLDisplayHandle() { return egl_display_; }
28+
void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height,
29+
int32_t degree);
2630

2731
private:
2832
Ecore_Wl2_Egl_Window* egl_window_ = nullptr;

shell/platform/tizen/tizen_surface.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class TizenSurface {
1717
virtual uint32_t OnGetFBO() = 0;
1818
virtual void* OnProcResolver(const char* name) = 0;
1919
virtual bool IsValid() = 0;
20-
virtual void SetSize(int32_t width, int32_t height) = 0;
2120
};
2221

2322
#endif // EMBEDDER_TIZEN_SURFACE_H_

shell/platform/tizen/tizen_surface_gl.cc

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ static EGLResult<EGLContext> CreateContext(EGLDisplay display, EGLConfig config,
1717
EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
1818

1919
EGLContext context = eglCreateContext(display, config, share, attributes);
20-
20+
if (context == EGL_NO_CONTEXT) {
21+
LogLastEGLError();
22+
}
2123
return {context != EGL_NO_CONTEXT, context};
2224
}
2325

@@ -41,6 +43,7 @@ static EGLResult<EGLConfig> ChooseEGLConfiguration(EGLDisplay display) {
4143

4244
if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) !=
4345
EGL_TRUE) {
46+
LogLastEGLError();
4447
return {false, nullptr};
4548
}
4649

@@ -50,8 +53,10 @@ static EGLResult<EGLConfig> ChooseEGLConfiguration(EGLDisplay display) {
5053
}
5154

5255
TizenEGLSurface::~TizenEGLSurface() {
53-
eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(),
54-
egl_surface_);
56+
if (eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(),
57+
egl_surface_) != EGL_TRUE) {
58+
LogLastEGLError();
59+
}
5560
tizen_native_egl_window_ = nullptr;
5661
}
5762

@@ -81,45 +86,51 @@ TizenEGLContext::TizenEGLContext(
8186
egl_resource_context_ = resource_ctx.second;
8287
}
8388

84-
std::unique_ptr<TizenEGLSurface>
85-
TizenEGLContext::CreateTizenEGLWindowSurface() {
86-
const EGLint attribs[] = {EGL_NONE};
87-
EGLSurface surface = eglCreateWindowSurface(
88-
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_,
89-
ecore_wl2_egl_window_native_get(
90-
tizen_native_egl_window_->GetEglWindowHandle()),
91-
attribs);
92-
93-
return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
94-
}
95-
9689
TizenEGLContext::~TizenEGLContext() {
9790
if (eglDestroyContext(tizen_native_egl_window_->GetEGLDisplayHandle(),
9891
egl_context_) != EGL_TRUE) {
9992
FT_LOGE("Failed to destroy egl context");
93+
LogLastEGLError();
10094
}
10195
if (eglDestroyContext(tizen_native_egl_window_->GetEGLDisplayHandle(),
10296
egl_resource_context_) != EGL_TRUE) {
10397
FT_LOGE("Failed to destroy egl resource context");
98+
LogLastEGLError();
10499
}
105100
tizen_native_egl_window_ = nullptr;
106101
}
107102

103+
bool TizenEGLContext::IsValid() {
104+
return tizen_native_egl_window_ && tizen_native_egl_window_->IsValid() &&
105+
egl_config_ != nullptr && egl_context_ != EGL_NO_CONTEXT &&
106+
egl_resource_context_ != EGL_NO_CONTEXT;
107+
}
108+
109+
std::unique_ptr<TizenEGLSurface>
110+
TizenEGLContext::CreateTizenEGLWindowSurface() {
111+
const EGLint attribs[] = {EGL_NONE};
112+
EGLSurface surface = eglCreateWindowSurface(
113+
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_,
114+
ecore_wl2_egl_window_native_get(
115+
tizen_native_egl_window_->GetEglWindowHandle()),
116+
attribs);
117+
if (surface == EGL_NO_SURFACE) {
118+
LogLastEGLError();
119+
}
120+
return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
121+
}
122+
108123
std::unique_ptr<TizenEGLSurface>
109124
TizenEGLContext::CreateTizenEGLPbufferSurface() {
110125
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
111126
EGLSurface surface = eglCreatePbufferSurface(
112127
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_, attribs);
113-
128+
if (surface == EGL_NO_SURFACE) {
129+
LogLastEGLError();
130+
}
114131
return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
115132
}
116133

117-
bool TizenEGLContext::IsValid() {
118-
return tizen_native_egl_window_ && tizen_native_egl_window_->IsValid() &&
119-
egl_config_ != nullptr && egl_context_ != EGL_NO_CONTEXT &&
120-
egl_resource_context_ != EGL_NO_CONTEXT;
121-
}
122-
123134
TizenSurfaceGL::TizenSurfaceGL(
124135
std::shared_ptr<TizenNativeWindow> tizen_native_window)
125136
: tizen_native_window_(tizen_native_window) {
@@ -162,6 +173,7 @@ bool TizenSurfaceGL::OnMakeCurrent() {
162173
tizen_egl_window_surface_->GetEGLSurfaceHandle(),
163174
tizen_context_gl_->GetEGLContextHandle()) != EGL_TRUE) {
164175
FT_LOGE("Could not make the onscreen context current");
176+
LogLastEGLError();
165177
return false;
166178
}
167179
return true;
@@ -179,6 +191,7 @@ bool TizenSurfaceGL::OnMakeResourceCurrent() {
179191
tizen_context_gl_->GetEGLResourceContextHandle()) !=
180192
EGL_TRUE) {
181193
FT_LOGE("Could not make the offscreen context current");
194+
LogLastEGLError();
182195
return false;
183196
}
184197
return true;
@@ -195,6 +208,7 @@ bool TizenSurfaceGL::OnClearCurrent() {
195208
EGL_NO_SURFACE, EGL_NO_SURFACE,
196209
EGL_NO_CONTEXT) != EGL_TRUE) {
197210
FT_LOGE("Could not clear context");
211+
LogLastEGLError();
198212
return false;
199213
}
200214
return true;
@@ -211,6 +225,7 @@ bool TizenSurfaceGL::OnPresent() {
211225
tizen_egl_window_surface_->GetEGLSurfaceHandle()) !=
212226
EGL_TRUE) {
213227
FT_LOGE("Could not swap EGl buffer");
228+
LogLastEGLError();
214229
return false;
215230
}
216231
return true;
@@ -348,16 +363,9 @@ void* TizenSurfaceGL::OnProcResolver(const char* name) {
348363
#undef GL_FUNC
349364

350365
TizenSurfaceGL::~TizenSurfaceGL() {
366+
OnClearCurrent();
351367
tizen_egl_window_surface_ = nullptr;
352368
tizen_egl_pbuffer_surface_ = nullptr;
353369
tizen_context_gl_ = nullptr;
354370
tizen_native_window_ = nullptr;
355371
}
356-
357-
void TizenSurfaceGL::SetSize(int32_t width, int32_t height) {
358-
// FIXME : I think we have to find another way.
359-
FT_LOGD("Resize egl window %d %d", width, height);
360-
ecore_wl2_egl_window_resize_with_rotation(
361-
tizen_native_window_->GetTizenNativeEGLWindow()->GetEglWindowHandle(), 0,
362-
0, width, height, 0);
363-
}

shell/platform/tizen/tizen_surface_gl.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#ifndef EMBEDDER_TIZEN_SURFACE_GL_H_
66
#define EMBEDDER_TIZEN_SURFACE_GL_H_
77

8-
#include <EGL/egl.h>
9-
#include <GLES2/gl2.h>
108
#include <wayland-client.h>
119
#include <wayland-egl.h>
1210

@@ -65,7 +63,6 @@ class TizenSurfaceGL : public TizenSurface {
6563
uint32_t OnGetFBO() override;
6664
void* OnProcResolver(const char* name) override;
6765
bool IsValid() override { return is_valid_; };
68-
void SetSize(int32_t width, int32_t height) override;
6966

7067
private:
7168
bool is_valid_{false};

0 commit comments

Comments
 (0)