diff --git a/shell/platform/tizen/channels/text_input_channel.cc b/shell/platform/tizen/channels/text_input_channel.cc index d2a926e8ff8c7..8ffeeb9a2fd02 100644 --- a/shell/platform/tizen/channels/text_input_channel.cc +++ b/shell/platform/tizen/channels/text_input_channel.cc @@ -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" @@ -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 { @@ -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 { diff --git a/shell/platform/tizen/external_texture_gl.cc b/shell/platform/tizen/external_texture_gl.cc index fc136d6daf2f6..d7078978f5685 100644 --- a/shell/platform/tizen/external_texture_gl.cc +++ b/shell/platform/tizen/external_texture_gl.cc @@ -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(this); opengl_texture->width = width; opengl_texture->height = height; @@ -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(user_data); externalTextureGL->DestructionTbmSurfaceWithLock(); diff --git a/shell/platform/tizen/external_texture_gl.h b/shell/platform/tizen/external_texture_gl.h index 515002c1aa2fb..e0bf689758ecd 100644 --- a/shell/platform/tizen/external_texture_gl.h +++ b/shell/platform/tizen/external_texture_gl.h @@ -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. @@ -48,7 +48,7 @@ class ExternalTextureGL { std::unique_ptr 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_; }; diff --git a/shell/platform/tizen/flutter_tizen.cc b/shell/platform/tizen/flutter_tizen.cc index 35855528c3c0a..01dfe9713423b 100644 --- a/shell/platform/tizen/flutter_tizen.cc +++ b/shell/platform/tizen/flutter_tizen.cc @@ -229,7 +229,7 @@ int64_t FlutterRegisterExternalTexture( FlutterTextureRegistrarRef texture_registrar) { FT_LOGD("FlutterDesktopRegisterExternalTexture"); auto texture_gl = std::make_unique(); - 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) { diff --git a/shell/platform/tizen/tizen_embedder_engine.cc b/shell/platform/tizen/tizen_embedder_engine.cc index 23bedbea78f49..3a517246b03ce 100644 --- a/shell/platform/tizen/tizen_embedder_engine.cc +++ b/shell/platform/tizen/tizen_embedder_engine.cc @@ -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; diff --git a/shell/platform/tizen/tizen_native_window.cc b/shell/platform/tizen/tizen_native_window.cc index a226148a49166..86b3efee5397d 100644 --- a/shell/platform/tizen/tizen_native_window.cc +++ b/shell/platform/tizen/tizen_native_window.cc @@ -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. @@ -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() { @@ -45,6 +91,7 @@ TizenNativeEGLWindow::TizenNativeEGLWindow( g_tizen_wl2_display.GetHandle())); if (egl_display_ == EGL_NO_DISPLAY) { FT_LOGE("Could not access EGL display"); + LogLastEGLError(); return; } @@ -52,6 +99,7 @@ TizenNativeEGLWindow::TizenNativeEGLWindow( EGLint minor_version; if (eglInitialize(egl_display_, &major_version, &minor_version) != EGL_TRUE) { FT_LOGE("Could not initialize EGL display"); + LogLastEGLError(); return; } @@ -59,18 +107,31 @@ TizenNativeEGLWindow::TizenNativeEGLWindow( 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, diff --git a/shell/platform/tizen/tizen_native_window.h b/shell/platform/tizen/tizen_native_window.h index 8c8e7826609e7..8ae0f2fb12ecf 100644 --- a/shell/platform/tizen/tizen_native_window.h +++ b/shell/platform/tizen/tizen_native_window.h @@ -5,11 +5,13 @@ #ifndef EMBEDDER_TIZEN_WINDOW_H_ #define EMBEDDER_TIZEN_WINDOW_H_ #include -#include #define EFL_BETA_API_SUPPORT #include #include + +void LogLastEGLError(); + class TizenNativeWindow; class TizenNativeEGLWindow { @@ -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; diff --git a/shell/platform/tizen/tizen_surface.h b/shell/platform/tizen/tizen_surface.h index 267300dbc3ba6..d8b954ce47a2d 100644 --- a/shell/platform/tizen/tizen_surface.h +++ b/shell/platform/tizen/tizen_surface.h @@ -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_ diff --git a/shell/platform/tizen/tizen_surface_gl.cc b/shell/platform/tizen/tizen_surface_gl.cc index 3dc7422620a32..b02cecdc95023 100644 --- a/shell/platform/tizen/tizen_surface_gl.cc +++ b/shell/platform/tizen/tizen_surface_gl.cc @@ -17,7 +17,9 @@ static EGLResult 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}; } @@ -41,6 +43,7 @@ static EGLResult ChooseEGLConfiguration(EGLDisplay display) { if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) != EGL_TRUE) { + LogLastEGLError(); return {false, nullptr}; } @@ -50,8 +53,10 @@ static EGLResult 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; } @@ -81,45 +86,51 @@ TizenEGLContext::TizenEGLContext( egl_resource_context_ = resource_ctx.second; } -std::unique_ptr -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(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 +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(tizen_native_egl_window_, surface); +} + std::unique_ptr 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(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 tizen_native_window) : tizen_native_window_(tizen_native_window) { @@ -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; @@ -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; @@ -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; @@ -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; @@ -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); -} diff --git a/shell/platform/tizen/tizen_surface_gl.h b/shell/platform/tizen/tizen_surface_gl.h index 5f0a56bf44edc..8a83c82d4f85d 100644 --- a/shell/platform/tizen/tizen_surface_gl.h +++ b/shell/platform/tizen/tizen_surface_gl.h @@ -5,8 +5,6 @@ #ifndef EMBEDDER_TIZEN_SURFACE_GL_H_ #define EMBEDDER_TIZEN_SURFACE_GL_H_ -#include -#include #include #include @@ -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};