Skip to content

Commit

Permalink
Minor update to Misc (flutter-tizen#19)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bbrto21 authored Jan 4, 2021
1 parent 022b7c3 commit 7c4743e
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 48 deletions.
8 changes: 5 additions & 3 deletions shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include "flutter/shell/platform/tizen/tizen_embedder_engine.h"
#include "flutter/shell/platform/tizen/tizen_log.h"
#include "flutter/shell/platform/tizen/tizen_surface.h"
#include "stdlib.h"
#include "string.h"

Expand Down Expand Up @@ -113,7 +112,9 @@ void TextInputChannel::InputPanelStateChangedCallback(
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);

self->engine_->tizen_native_window->GetTizenNativeEGLWindow()
->ResizeWithRotation(0, 0, surface_w, surface_h, 0);
if (self->rotation == 90 || self->rotation == 270) {
self->engine_->SendWindowMetrics(surface_h, surface_w, 0);
} else {
Expand Down Expand Up @@ -618,7 +619,8 @@ void TextInputChannel::HideSoftwareKeyboard() {
} else {
engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0);
}
engine_->tizen_surface->SetSize(window_geometry.w, window_geometry.h);
engine_->tizen_native_window->GetTizenNativeEGLWindow()
->ResizeWithRotation(0, 0, window_geometry.w, window_geometry.h, 0);
ecore_timer_add(
0.05,
[](void* data) -> Eina_Bool {
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/tizen/external_texture_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier(
opengl_texture->target = GL_TEXTURE_EXTERNAL_OES;
opengl_texture->name = state_->gl_texture;
opengl_texture->format = GL_RGBA8;
opengl_texture->destruction_callback = (VoidCallback)destructionCallback;
opengl_texture->destruction_callback = (VoidCallback)DestructionCallback;
opengl_texture->user_data = static_cast<void*>(this);
opengl_texture->width = width;
opengl_texture->height = height;
Expand All @@ -135,7 +135,7 @@ void ExternalTextureGL::DestructionTbmSurface() {
texture_tbm_surface_ = NULL;
}

void ExternalTextureGL::destructionCallback(void* user_data) {
void ExternalTextureGL::DestructionCallback(void* user_data) {
ExternalTextureGL* externalTextureGL =
reinterpret_cast<ExternalTextureGL*>(user_data);
externalTextureGL->DestructionTbmSurfaceWithLock();
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/tizen/external_texture_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ExternalTextureGL {
/**
* Returns the unique id for the ExternalTextureGL instance.
*/
int64_t texture_id() { return (int64_t)texture_id_; }
int64_t TextureId() { return (int64_t)texture_id_; }

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

Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/flutter_tizen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ int64_t FlutterRegisterExternalTexture(
FlutterTextureRegistrarRef texture_registrar) {
FT_LOGD("FlutterDesktopRegisterExternalTexture");
auto texture_gl = std::make_unique<ExternalTextureGL>();
int64_t texture_id = texture_gl->texture_id();
int64_t texture_id = texture_gl->TextureId();
texture_registrar->textures[texture_id] = std::move(texture_gl);
if (FlutterEngineRegisterExternalTexture(texture_registrar->flutter_engine,
texture_id) == kSuccess) {
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/tizen/tizen_embedder_engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool TizenEmbedderEngine::RunEngine(
auto result = FlutterEngineRun(FLUTTER_ENGINE_VERSION, &config, &args, this,
&flutter_engine);
if (result == kSuccess && flutter_engine != nullptr) {
FT_LOGI("FlutterEngineRun Success!");
FT_LOGD("FlutterEngineRun Success!");
} else {
FT_LOGE("FlutterEngineRun Failure! result: %d", result);
return false;
Expand Down
69 changes: 65 additions & 4 deletions shell/platform/tizen/tizen_native_window.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// 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.
Expand All @@ -6,6 +9,49 @@

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

void LogLastEGLError() {
struct EGLNameErrorPair {
const char* name;
EGLint code;
};

#define _EGL_ERROR_DESC(a) \
{ #a, a }

const EGLNameErrorPair pairs[] = {
_EGL_ERROR_DESC(EGL_SUCCESS),
_EGL_ERROR_DESC(EGL_NOT_INITIALIZED),
_EGL_ERROR_DESC(EGL_BAD_ACCESS),
_EGL_ERROR_DESC(EGL_BAD_ALLOC),
_EGL_ERROR_DESC(EGL_BAD_ATTRIBUTE),
_EGL_ERROR_DESC(EGL_BAD_CONTEXT),
_EGL_ERROR_DESC(EGL_BAD_CONFIG),
_EGL_ERROR_DESC(EGL_BAD_CURRENT_SURFACE),
_EGL_ERROR_DESC(EGL_BAD_DISPLAY),
_EGL_ERROR_DESC(EGL_BAD_SURFACE),
_EGL_ERROR_DESC(EGL_BAD_MATCH),
_EGL_ERROR_DESC(EGL_BAD_PARAMETER),
_EGL_ERROR_DESC(EGL_BAD_NATIVE_PIXMAP),
_EGL_ERROR_DESC(EGL_BAD_NATIVE_WINDOW),
_EGL_ERROR_DESC(EGL_CONTEXT_LOST),
};

#undef _EGL_ERROR_DESC

const auto count = sizeof(pairs) / sizeof(EGLNameErrorPair);

EGLint last_error = eglGetError();

for (size_t i = 0; i < count; i++) {
if (last_error == pairs[i].code) {
FT_LOGE("EGL Error: %s (%d)", pairs[i].name, pairs[i].code);
return;
}
}

FT_LOGE("Unknown EGL Error");
}

class TizenWl2Display {
public:
TizenWl2Display() {
Expand Down Expand Up @@ -45,32 +91,47 @@ TizenNativeEGLWindow::TizenNativeEGLWindow(
g_tizen_wl2_display.GetHandle()));
if (egl_display_ == EGL_NO_DISPLAY) {
FT_LOGE("Could not access EGL display");
LogLastEGLError();
return;
}

EGLint major_version;
EGLint minor_version;
if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) {
FT_LOGE("Could not initialize EGL display");
LogLastEGLError();
return;
}

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

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

TizenNativeEGLWindow::~TizenNativeEGLWindow() {
if (egl_window_) {
if (egl_display_ != EGL_NO_DISPLAY) {
if (eglTerminate(egl_display_) != EGL_TRUE) {
FT_LOGE("Failed to terminate egl display");
LogLastEGLError();
}
egl_display_ = EGL_NO_DISPLAY;
}

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

void TizenNativeEGLWindow::ResizeWithRotation(int32_t dx, int32_t dy,
int32_t width, int32_t height,
int32_t degree) {
ecore_wl2_egl_window_resize_with_rotation(egl_window_, dx, dy, width, height,
degree);
}

TizenNativeWindow::TizenNativeWindow(int32_t x, int32_t y, int32_t w,
Expand Down
6 changes: 5 additions & 1 deletion shell/platform/tizen/tizen_native_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
#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>

void LogLastEGLError();

class TizenNativeWindow;

class TizenNativeEGLWindow {
Expand All @@ -23,6 +25,8 @@ class TizenNativeEGLWindow {

Ecore_Wl2_Egl_Window* GetEglWindowHandle() { return egl_window_; };
EGLDisplay GetEGLDisplayHandle() { return egl_display_; }
void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height,
int32_t degree);

private:
Ecore_Wl2_Egl_Window* egl_window_ = nullptr;
Expand Down
1 change: 0 additions & 1 deletion shell/platform/tizen/tizen_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TizenSurface {
virtual uint32_t OnGetFBO() = 0;
virtual void* OnProcResolver(const char* name) = 0;
virtual bool IsValid() = 0;
virtual void SetSize(int32_t width, int32_t height) = 0;
};

#endif // EMBEDDER_TIZEN_SURFACE_H_
68 changes: 38 additions & 30 deletions shell/platform/tizen/tizen_surface_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ static EGLResult<EGLContext> CreateContext(EGLDisplay display, EGLConfig config,
EGLint attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};

EGLContext context = eglCreateContext(display, config, share, attributes);

if (context == EGL_NO_CONTEXT) {
LogLastEGLError();
}
return {context != EGL_NO_CONTEXT, context};
}

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

if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) !=
EGL_TRUE) {
LogLastEGLError();
return {false, nullptr};
}

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

TizenEGLSurface::~TizenEGLSurface() {
eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(),
egl_surface_);
if (eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(),
egl_surface_) != EGL_TRUE) {
LogLastEGLError();
}
tizen_native_egl_window_ = nullptr;
}

Expand Down Expand Up @@ -81,45 +86,51 @@ TizenEGLContext::TizenEGLContext(
egl_resource_context_ = resource_ctx.second;
}

std::unique_ptr<TizenEGLSurface>
TizenEGLContext::CreateTizenEGLWindowSurface() {
const EGLint attribs[] = {EGL_NONE};
EGLSurface surface = eglCreateWindowSurface(
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_,
ecore_wl2_egl_window_native_get(
tizen_native_egl_window_->GetEglWindowHandle()),
attribs);

return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
}

TizenEGLContext::~TizenEGLContext() {
if (eglDestroyContext(tizen_native_egl_window_->GetEGLDisplayHandle(),
egl_context_) != EGL_TRUE) {
FT_LOGE("Failed to destroy egl context");
LogLastEGLError();
}
if (eglDestroyContext(tizen_native_egl_window_->GetEGLDisplayHandle(),
egl_resource_context_) != EGL_TRUE) {
FT_LOGE("Failed to destroy egl resource context");
LogLastEGLError();
}
tizen_native_egl_window_ = nullptr;
}

bool TizenEGLContext::IsValid() {
return tizen_native_egl_window_ && tizen_native_egl_window_->IsValid() &&
egl_config_ != nullptr && egl_context_ != EGL_NO_CONTEXT &&
egl_resource_context_ != EGL_NO_CONTEXT;
}

std::unique_ptr<TizenEGLSurface>
TizenEGLContext::CreateTizenEGLWindowSurface() {
const EGLint attribs[] = {EGL_NONE};
EGLSurface surface = eglCreateWindowSurface(
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_,
ecore_wl2_egl_window_native_get(
tizen_native_egl_window_->GetEglWindowHandle()),
attribs);
if (surface == EGL_NO_SURFACE) {
LogLastEGLError();
}
return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
}

std::unique_ptr<TizenEGLSurface>
TizenEGLContext::CreateTizenEGLPbufferSurface() {
const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE};
EGLSurface surface = eglCreatePbufferSurface(
tizen_native_egl_window_->GetEGLDisplayHandle(), egl_config_, attribs);

if (surface == EGL_NO_SURFACE) {
LogLastEGLError();
}
return std::make_unique<TizenEGLSurface>(tizen_native_egl_window_, surface);
}

bool TizenEGLContext::IsValid() {
return tizen_native_egl_window_ && tizen_native_egl_window_->IsValid() &&
egl_config_ != nullptr && egl_context_ != EGL_NO_CONTEXT &&
egl_resource_context_ != EGL_NO_CONTEXT;
}

TizenSurfaceGL::TizenSurfaceGL(
std::shared_ptr<TizenNativeWindow> tizen_native_window)
: tizen_native_window_(tizen_native_window) {
Expand Down Expand Up @@ -162,6 +173,7 @@ bool TizenSurfaceGL::OnMakeCurrent() {
tizen_egl_window_surface_->GetEGLSurfaceHandle(),
tizen_context_gl_->GetEGLContextHandle()) != EGL_TRUE) {
FT_LOGE("Could not make the onscreen context current");
LogLastEGLError();
return false;
}
return true;
Expand All @@ -179,6 +191,7 @@ bool TizenSurfaceGL::OnMakeResourceCurrent() {
tizen_context_gl_->GetEGLResourceContextHandle()) !=
EGL_TRUE) {
FT_LOGE("Could not make the offscreen context current");
LogLastEGLError();
return false;
}
return true;
Expand All @@ -195,6 +208,7 @@ bool TizenSurfaceGL::OnClearCurrent() {
EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT) != EGL_TRUE) {
FT_LOGE("Could not clear context");
LogLastEGLError();
return false;
}
return true;
Expand All @@ -211,6 +225,7 @@ bool TizenSurfaceGL::OnPresent() {
tizen_egl_window_surface_->GetEGLSurfaceHandle()) !=
EGL_TRUE) {
FT_LOGE("Could not swap EGl buffer");
LogLastEGLError();
return false;
}
return true;
Expand Down Expand Up @@ -348,16 +363,9 @@ void* TizenSurfaceGL::OnProcResolver(const char* name) {
#undef GL_FUNC

TizenSurfaceGL::~TizenSurfaceGL() {
OnClearCurrent();
tizen_egl_window_surface_ = nullptr;
tizen_egl_pbuffer_surface_ = nullptr;
tizen_context_gl_ = nullptr;
tizen_native_window_ = nullptr;
}

void TizenSurfaceGL::SetSize(int32_t width, int32_t height) {
// FIXME : I think we have to find another way.
FT_LOGD("Resize egl window %d %d", width, height);
ecore_wl2_egl_window_resize_with_rotation(
tizen_native_window_->GetTizenNativeEGLWindow()->GetEglWindowHandle(), 0,
0, width, height, 0);
}
3 changes: 0 additions & 3 deletions shell/platform/tizen/tizen_surface_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef EMBEDDER_TIZEN_SURFACE_GL_H_
#define EMBEDDER_TIZEN_SURFACE_GL_H_

#include <EGL/egl.h>
#include <GLES2/gl2.h>
#include <wayland-client.h>
#include <wayland-egl.h>

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

private:
bool is_valid_{false};
Expand Down

0 comments on commit 7c4743e

Please sign in to comment.