From e1bbb1092fa66701e55d8d5792ce66d4eb86554b Mon Sep 17 00:00:00 2001 From: xiaowei guan Date: Tue, 12 Jan 2021 02:01:35 +0800 Subject: [PATCH 1/3] Support tizen 4.0 1.Add build arg(tizen-sdk-4) for tizen4.0. 2.Because Tizen4 only support ecore_wl, but tizen5,tizen6 only support ecore_wl2. so implement tizen_render_ecore_wl for tizen4 and tizen_render_ecore_wl2 for tizen5 and tizen6. --- shell/platform/tizen/BUILD.gn | 17 +- .../tizen/channels/text_input_channel.cc | 18 +- .../tizen/channels/text_input_channel.h | 1 - shell/platform/tizen/config.gni | 1 + shell/platform/tizen/flutter_tizen.cc | 1 + shell/platform/tizen/tizen_embedder_engine.cc | 36 +- shell/platform/tizen/tizen_embedder_engine.h | 11 +- shell/platform/tizen/tizen_native_window.cc | 174 ------- shell/platform/tizen/tizen_native_window.h | 57 --- shell/platform/tizen/tizen_renderer.cc | 455 ++++++++++++++++++ shell/platform/tizen/tizen_renderer.h | 56 +++ .../platform/tizen/tizen_renderer_ecore_wl.cc | 101 ++++ .../platform/tizen/tizen_renderer_ecore_wl.h | 39 ++ .../tizen/tizen_renderer_ecore_wl2.cc | 98 ++++ .../platform/tizen/tizen_renderer_ecore_wl2.h | 38 ++ shell/platform/tizen/tizen_surface.cc | 7 - shell/platform/tizen/tizen_surface.h | 22 - shell/platform/tizen/tizen_surface_gl.cc | 371 -------------- shell/platform/tizen/tizen_surface_gl.h | 75 --- shell/platform/tizen/tizen_vsync_waiter.cc | 62 +-- shell/platform/tizen/tizen_vsync_waiter.h | 7 +- shell/platform/tizen/touch_event_handler.cc | 2 +- tools/gn | 2 + 23 files changed, 846 insertions(+), 805 deletions(-) delete mode 100644 shell/platform/tizen/tizen_native_window.cc delete mode 100644 shell/platform/tizen/tizen_native_window.h create mode 100644 shell/platform/tizen/tizen_renderer.cc create mode 100644 shell/platform/tizen/tizen_renderer.h create mode 100644 shell/platform/tizen/tizen_renderer_ecore_wl.cc create mode 100644 shell/platform/tizen/tizen_renderer_ecore_wl.h create mode 100644 shell/platform/tizen/tizen_renderer_ecore_wl2.cc create mode 100644 shell/platform/tizen/tizen_renderer_ecore_wl2.h delete mode 100644 shell/platform/tizen/tizen_surface.cc delete mode 100644 shell/platform/tizen/tizen_surface.h delete mode 100644 shell/platform/tizen/tizen_surface_gl.cc delete mode 100644 shell/platform/tizen/tizen_surface_gl.h diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 2fbafca3d8105..27d38501f5fe2 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -2,6 +2,7 @@ # 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. +import("//flutter/shell/platform/tizen/config.gni") _public_headers = [ "public/flutter_tizen.h" ] @@ -43,10 +44,8 @@ source_set("flutter_tizen") { "key_event_handler.cc", "tizen_embedder_engine.cc", "tizen_event_loop.cc", - "tizen_surface.cc", - "tizen_surface_gl.cc", + "tizen_renderer.cc", "tizen_vsync_waiter.cc", - "tizen_native_window.cc", "touch_event_handler.cc", ] @@ -72,6 +71,7 @@ source_set("flutter_tizen") { "$custom_sysroot/usr/include/ecore-imf-1", "$custom_sysroot/usr/include/ecore-imf-evas-1", "$custom_sysroot/usr/include/ecore-input-1", + "$custom_sysroot/usr/include/ecore-wayland-1", "$custom_sysroot/usr/include/ecore-wl2-1", "$custom_sysroot/usr/include/efl-1", "$custom_sysroot/usr/include/eina-1", @@ -80,6 +80,7 @@ source_set("flutter_tizen") { "$custom_sysroot/usr/include/eo-1", "$custom_sysroot/usr/include/evas-1", "$custom_sysroot/usr/include/system", + "$custom_sysroot/usr/include/wayland-extension" ] lib_dirs = [ "$custom_sysroot/usr/lib" ] @@ -98,7 +99,6 @@ source_set("flutter_tizen") { "ecore", "ecore_imf", "ecore_input", - "ecore_wl2", "EGL", "evas", "GLESv2", @@ -106,6 +106,15 @@ source_set("flutter_tizen") { "tdm-client", "wayland-client", ] + + if(tizen_sdk_4){ + sources += ["tizen_renderer_ecore_wl.cc",] + libs += ["ecore_wayland", "wayland-egl"] + defines = [ "FLUTTER_TIZEN_4" ] + }else { + sources += ["tizen_renderer_ecore_wl2.cc",] + libs += ["ecore_wl2"] + } } copy("publish_headers_tizen") { diff --git a/shell/platform/tizen/channels/text_input_channel.cc b/shell/platform/tizen/channels/text_input_channel.cc index 8ffeeb9a2fd02..a5056e7321927 100644 --- a/shell/platform/tizen/channels/text_input_channel.cc +++ b/shell/platform/tizen/channels/text_input_channel.cc @@ -108,13 +108,13 @@ void TextInputChannel::InputPanelStateChangedCallback( [](void* data) -> Eina_Bool { TextInputChannel* self = (TextInputChannel*)data; auto window_geometry = - self->engine_->tizen_native_window->GetGeometry(); + self->engine_->tizen_renderer->GetGeometry(); int32_t surface_w = window_geometry.w; int32_t surface_h = window_geometry.h - self->current_keyboard_geometry_.h; - self->engine_->tizen_native_window->GetTizenNativeEGLWindow() - ->ResizeWithRotation(0, 0, surface_w, surface_h, 0); + self->engine_->tizen_renderer->ResizeWithRotation(0, 0, surface_w, + surface_h, 0); if (self->rotation == 90 || self->rotation == 270) { self->engine_->SendWindowMetrics(surface_h, surface_w, 0); } else { @@ -298,10 +298,8 @@ TextInputChannel::TextInputChannel(flutter::BinaryMessenger* messenger, imf_context_ = ecore_imf_context_add(GetImfMethod()); } if (imf_context_) { - Ecore_Wl2_Window* ecoreWindow = - engine_->tizen_native_window->GetWindowHandle(); ecore_imf_context_client_window_set( - imf_context_, (void*)ecore_wl2_window_id_get(ecoreWindow)); + imf_context_, (void*)engine_->tizen_renderer->GetEcoreWindowId()); RegisterIMFCallback(); } else { FT_LOGE("Failed to create imfContext"); @@ -456,7 +454,9 @@ bool TextInputChannel::FilterEvent(Ecore_Event_Key* keyDownEvent) { ecore_device_class_get(keyDownEvent->dev)); ecoreKeyDownEvent.dev_subclass = EoreDeviceSubClassToEcoreIMFDeviceSubClass( ecore_device_subclass_get(keyDownEvent->dev)); +#ifndef FLUTTER_TIZEN_4 ecoreKeyDownEvent.keycode = keyDownEvent->keycode; +#endif bool isIME = strcmp(device, "ime") == 0; if (isIME && strcmp(keyDownEvent->key, "Select") == 0) { @@ -612,15 +612,15 @@ void TextInputChannel::HideSoftwareKeyboard() { if (engine_->device_profile == "mobile") { // FIXME : Needs improvement on other devices. - auto window_geometry = engine_->tizen_native_window->GetGeometry(); + auto window_geometry = engine_->tizen_renderer->GetGeometry(); if (rotation == 90 || rotation == 270) { engine_->SendWindowMetrics(window_geometry.h, window_geometry.w, 0); } else { engine_->SendWindowMetrics(window_geometry.w, window_geometry.h, 0); } - engine_->tizen_native_window->GetTizenNativeEGLWindow() - ->ResizeWithRotation(0, 0, window_geometry.w, window_geometry.h, 0); + engine_->tizen_renderer->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/channels/text_input_channel.h b/shell/platform/tizen/channels/text_input_channel.h index 1a1e44404d9bf..345b51216a114 100644 --- a/shell/platform/tizen/channels/text_input_channel.h +++ b/shell/platform/tizen/channels/text_input_channel.h @@ -8,7 +8,6 @@ #define EFL_BETA_API_SUPPORT #include #include -#include #include diff --git a/shell/platform/tizen/config.gni b/shell/platform/tizen/config.gni index 245032c3255cd..ffd4d2b766659 100644 --- a/shell/platform/tizen/config.gni +++ b/shell/platform/tizen/config.gni @@ -10,4 +10,5 @@ declare_args() { # as an extra build artifact with this flag. The native toolkit shell will # still be built as well. build_tizen_shell = false + tizen_sdk_4 = false } diff --git a/shell/platform/tizen/flutter_tizen.cc b/shell/platform/tizen/flutter_tizen.cc index 01dfe9713423b..0f5eb866489e7 100644 --- a/shell/platform/tizen/flutter_tizen.cc +++ b/shell/platform/tizen/flutter_tizen.cc @@ -6,6 +6,7 @@ #include "public/flutter_tizen.h" #include +#include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h" diff --git a/shell/platform/tizen/tizen_embedder_engine.cc b/shell/platform/tizen/tizen_embedder_engine.cc index e97d58711be24..199bead7e0400 100644 --- a/shell/platform/tizen/tizen_embedder_engine.cc +++ b/shell/platform/tizen/tizen_embedder_engine.cc @@ -35,10 +35,15 @@ static double GetDeviceDpi() { TizenEmbedderEngine::TizenEmbedderEngine( const FlutterWindowProperties& window_properties) : device_profile(GetDeviceProfile()), device_dpi(GetDeviceDpi()) { - tizen_native_window = std::make_shared( +#ifdef FLUTTER_TIZEN_4 + tizen_renderer = std::make_unique( window_properties.x, window_properties.y, window_properties.width, window_properties.height); - tizen_surface = std::make_unique(tizen_native_window); +#else + tizen_renderer = std::make_unique( + window_properties.x, window_properties.y, window_properties.width, + window_properties.height); +#endif // Run flutter task on Tizen main loop. // Tizen engine has four threads (GPU thread, UI thread, IO thread, platform @@ -61,8 +66,7 @@ TizenEmbedderEngine::TizenEmbedderEngine( TizenEmbedderEngine::~TizenEmbedderEngine() { FT_LOGD("Destroy"); - tizen_surface = nullptr; - tizen_native_window = nullptr; + tizen_renderer = nullptr; } // Attempts to load AOT data from the given path, which must be absolute and @@ -92,7 +96,7 @@ UniqueAotDataPtr LoadAotData(std::string aot_data_path) { bool TizenEmbedderEngine::RunEngine( const FlutterEngineProperties& engine_properties) { - if (!tizen_surface->IsValid()) { + if (!tizen_renderer->IsValid()) { FT_LOGE("The display was not valid."); return false; } @@ -262,13 +266,13 @@ void TizenEmbedderEngine::SendWindowMetrics(int32_t width, int32_t height, // This must be called at least once in order to initialize the value of // transformation_. void TizenEmbedderEngine::SetWindowOrientation(int32_t degree) { - if (!tizen_surface) { + if (!tizen_renderer) { return; } // Compute renderer transformation based on the angle of rotation. double rad = (360 - degree) * M_PI / 180; - auto geometry = tizen_native_window->GetGeometry(); + auto geometry = tizen_renderer->GetGeometry(); double width = geometry.w; double height = geometry.h; @@ -331,11 +335,7 @@ void TizenEmbedderEngine::OnFlutterPlatformMessage( void TizenEmbedderEngine::OnVsyncCallback(void* user_data, intptr_t baton) { TizenEmbedderEngine* tizen_embedder_engine = reinterpret_cast(user_data); - if (tizen_embedder_engine->tizen_vsync_waiter_->IsValid()) { - tizen_embedder_engine->tizen_vsync_waiter_->AsyncWaitForVsync(baton); - return; - } - FT_ASSERT_NOT_REACHED(); + tizen_embedder_engine->tizen_vsync_waiter_->AsyncWaitForVsync(baton); } // Converts a FlutterPlatformMessage to an equivalent FlutterDesktopMessage. @@ -352,27 +352,27 @@ FlutterDesktopMessage TizenEmbedderEngine::ConvertToDesktopMessage( bool TizenEmbedderEngine::MakeContextCurrent(void* user_data) { return reinterpret_cast(user_data) - ->tizen_surface->OnMakeCurrent(); + ->tizen_renderer->OnMakeCurrent(); } bool TizenEmbedderEngine::ClearContext(void* user_data) { return reinterpret_cast(user_data) - ->tizen_surface->OnClearCurrent(); + ->tizen_renderer->OnClearCurrent(); } bool TizenEmbedderEngine::Present(void* user_data) { return reinterpret_cast(user_data) - ->tizen_surface->OnPresent(); + ->tizen_renderer->OnPresent(); } bool TizenEmbedderEngine::MakeResourceCurrent(void* user_data) { return reinterpret_cast(user_data) - ->tizen_surface->OnMakeResourceCurrent(); + ->tizen_renderer->OnMakeResourceCurrent(); } uint32_t TizenEmbedderEngine::GetActiveFbo(void* user_data) { return reinterpret_cast(user_data) - ->tizen_surface->OnGetFBO(); + ->tizen_renderer->OnGetFBO(); } FlutterTransformation TizenEmbedderEngine::Transformation(void* user_data) { @@ -381,5 +381,5 @@ FlutterTransformation TizenEmbedderEngine::Transformation(void* user_data) { void* TizenEmbedderEngine::GlProcResolver(void* user_data, const char* name) { return reinterpret_cast(user_data) - ->tizen_surface->OnProcResolver(name); + ->tizen_renderer->OnProcResolver(name); } diff --git a/shell/platform/tizen/tizen_embedder_engine.h b/shell/platform/tizen/tizen_embedder_engine.h index f6c84373ede59..d992daa19744b 100644 --- a/shell/platform/tizen/tizen_embedder_engine.h +++ b/shell/platform/tizen/tizen_embedder_engine.h @@ -23,8 +23,12 @@ #include "flutter/shell/platform/tizen/public/flutter_texture_registrar.h" #include "flutter/shell/platform/tizen/public/flutter_tizen.h" #include "flutter/shell/platform/tizen/tizen_event_loop.h" -#include "flutter/shell/platform/tizen/tizen_surface.h" -#include "flutter/shell/platform/tizen/tizen_surface_gl.h" +#include "flutter/shell/platform/tizen/tizen_renderer.h" +#ifdef FLUTTER_TIZEN_4 +#include "flutter/shell/platform/tizen/tizen_renderer_ecore_wl.h" +#else +#include "flutter/shell/platform/tizen/tizen_renderer_ecore_wl2.h" +#endif #include "flutter/shell/platform/tizen/tizen_vsync_waiter.h" #include "flutter/shell/platform/tizen/touch_event_handler.h" @@ -94,8 +98,7 @@ class TizenEmbedderEngine { std::unique_ptr message_dispatcher; // The interface between the Flutter rasterizer and the platform. - std::unique_ptr tizen_surface; - std::shared_ptr tizen_native_window; + std::unique_ptr tizen_renderer; // The system channels for communicating between Flutter and the platform. std::unique_ptr key_event_channel; diff --git a/shell/platform/tizen/tizen_native_window.cc b/shell/platform/tizen/tizen_native_window.cc deleted file mode 100644 index 86b3efee5397d..0000000000000 --- a/shell/platform/tizen/tizen_native_window.cc +++ /dev/null @@ -1,174 +0,0 @@ -// 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. - -#include "tizen_native_window.h" - -#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() { - if (!ecore_wl2_init()) { - FT_LOGE("Could not initialize ecore_wl2"); - return; - } - // ecore_wl2 DISPLAY - wl2_display_ = ecore_wl2_display_connect(nullptr); - if (wl2_display_ == nullptr) { - FT_LOGE("Display not found"); - return; - } - ecore_wl2_sync(); - } - - ~TizenWl2Display() { - if (wl2_display_) { - ecore_wl2_display_disconnect(wl2_display_); - wl2_display_ = nullptr; - } - ecore_wl2_shutdown(); - } - Ecore_Wl2_Display* GetHandle() { return wl2_display_; } - - private: - Ecore_Wl2_Display* wl2_display_{nullptr}; -}; -TizenWl2Display g_tizen_wl2_display; - -TizenNativeEGLWindow::TizenNativeEGLWindow( - TizenNativeWindow* tizen_native_window, int32_t w, int32_t h) { - egl_window_ = - ecore_wl2_egl_window_create(tizen_native_window->GetWindowHandle(), w, h); - - egl_display_ = eglGetDisplay((EGLNativeDisplayType)ecore_wl2_display_get( - 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_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; - } -} - -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, - int32_t h) { - if (g_tizen_wl2_display.GetHandle() == nullptr) { - FT_LOGE("Faild to get display handle"); - return; - } - if (w == 0 || h == 0) { - FT_LOGE("Failed to create because of the wrong size"); - return; - } - - wl2_window_ = ecore_wl2_window_new(g_tizen_wl2_display.GetHandle(), nullptr, - x, y, w, h); - - ecore_wl2_window_type_set(wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL); - ecore_wl2_window_alpha_set(wl2_window_, EINA_FALSE); - ecore_wl2_window_aux_hint_add(wl2_window_, 0, "wm.policy.win.user.geometry", - "1"); - ecore_wl2_window_show(wl2_window_); - - tizen_native_egl_window_ = std::make_shared(this, w, h); - is_valid_ = true; -} - -TizenNativeWindow::~TizenNativeWindow() { - tizen_native_egl_window_ = nullptr; - if (wl2_window_) { - ecore_wl2_window_free(wl2_window_); - wl2_window_ = nullptr; - } -} - -TizenNativeWindow::TizenNativeWindowGeometry TizenNativeWindow::GetGeometry() { - TizenNativeWindowGeometry result; - ecore_wl2_window_geometry_get(wl2_window_, &result.x, &result.y, &result.w, - &result.h); - return result; -} diff --git a/shell/platform/tizen/tizen_native_window.h b/shell/platform/tizen/tizen_native_window.h deleted file mode 100644 index 8ae0f2fb12ecf..0000000000000 --- a/shell/platform/tizen/tizen_native_window.h +++ /dev/null @@ -1,57 +0,0 @@ -// 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. - -#ifndef EMBEDDER_TIZEN_WINDOW_H_ -#define EMBEDDER_TIZEN_WINDOW_H_ -#include -#define EFL_BETA_API_SUPPORT -#include - -#include - -void LogLastEGLError(); - -class TizenNativeWindow; - -class TizenNativeEGLWindow { - public: - TizenNativeEGLWindow(TizenNativeWindow* tizen_native_window, int32_t w, - int32_t h); - ~TizenNativeEGLWindow(); - bool IsValid() { - return egl_window_ != nullptr && egl_display_ != EGL_NO_DISPLAY; - }; - - 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; - EGLDisplay egl_display_ = EGL_NO_DISPLAY; -}; - -class TizenNativeWindow { - public: - struct TizenNativeWindowGeometry { - int32_t x{0}, y{0}, w{0}, h{0}; - }; - - TizenNativeWindow(int32_t x, int32_t y, int32_t w, int32_t h); - ~TizenNativeWindow(); - bool IsValid() { return is_valid_; } - Ecore_Wl2_Window* GetWindowHandle() { return wl2_window_; } - std::shared_ptr GetTizenNativeEGLWindow() { - return tizen_native_egl_window_; - }; - TizenNativeWindowGeometry GetGeometry(); - - private: - std::shared_ptr tizen_native_egl_window_; - Ecore_Wl2_Window* wl2_window_{nullptr}; - bool is_valid_{false}; -}; - -#endif diff --git a/shell/platform/tizen/tizen_renderer.cc b/shell/platform/tizen/tizen_renderer.cc new file mode 100644 index 0000000000000..0dd6f83af2d0e --- /dev/null +++ b/shell/platform/tizen/tizen_renderer.cc @@ -0,0 +1,455 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#include "tizen_renderer.h" + +#include +#include + +#include "flutter/shell/platform/tizen/tizen_log.h" + +TizenRenderer::~TizenRenderer() = default; + +bool TizenRenderer::OnMakeCurrent() { + if (!IsValid()) { + FT_LOGE("Invalid TizenRenderer"); + return false; + } + if (eglMakeCurrent(egl_display_, egl_surface_, egl_surface_, egl_context_) != + EGL_TRUE) { + FT_LOGE("Could not make the onscreen context current"); + PrintEGLError(); + return false; + } + return true; +} + +bool TizenRenderer::OnClearCurrent() { + if (!IsValid()) { + FT_LOGE("Invalid TizenRenderer"); + return false; + } + if (eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT) != EGL_TRUE) { + FT_LOGE("Could not clear context"); + PrintEGLError(); + return false; + } + return true; +} + +bool TizenRenderer::OnMakeResourceCurrent() { + if (!IsValid()) { + FT_LOGE("Invalid TizenRenderer"); + return false; + } + if (eglMakeCurrent(egl_display_, egl_resource_surface_, egl_resource_surface_, + egl_resource_context_) != EGL_TRUE) { + FT_LOGE("Could not make the offscreen context current"); + PrintEGLError(); + return false; + } + return true; +} + +bool TizenRenderer::OnPresent() { + if (!is_valid_) { + FT_LOGE("Invalid TizenRenderer"); + return false; + } + if (eglSwapBuffers(egl_display_, egl_surface_) != EGL_TRUE) { + FT_LOGE("Could not swap EGl buffer"); + PrintEGLError(); + return false; + } + return true; +} + +uint32_t TizenRenderer::OnGetFBO() { + if (!is_valid_) { + FT_LOGE("Invalid TizenRenderer"); + return 999; + } + FT_LOGD("OnGetFBO"); + return 0; +} + +#define GL_FUNC(FunctionName) \ + else if (strcmp(name, #FunctionName) == 0) { \ + return reinterpret_cast(FunctionName); \ + } +void* TizenRenderer::OnProcResolver(const char* name) { + auto address = eglGetProcAddress(name); + if (address != nullptr) { + return reinterpret_cast(address); + } + GL_FUNC(eglGetCurrentDisplay) + GL_FUNC(eglQueryString) + GL_FUNC(glActiveTexture) + GL_FUNC(glAttachShader) + GL_FUNC(glBindAttribLocation) + GL_FUNC(glBindBuffer) + GL_FUNC(glBindFramebuffer) + GL_FUNC(glBindRenderbuffer) + GL_FUNC(glBindTexture) + GL_FUNC(glBlendColor) + GL_FUNC(glBlendEquation) + GL_FUNC(glBlendFunc) + GL_FUNC(glBufferData) + GL_FUNC(glBufferSubData) + GL_FUNC(glCheckFramebufferStatus) + GL_FUNC(glClear) + GL_FUNC(glClearColor) + GL_FUNC(glClearStencil) + GL_FUNC(glColorMask) + GL_FUNC(glCompileShader) + GL_FUNC(glCompressedTexImage2D) + GL_FUNC(glCompressedTexSubImage2D) + GL_FUNC(glCopyTexSubImage2D) + GL_FUNC(glCreateProgram) + GL_FUNC(glCreateShader) + GL_FUNC(glCullFace) + GL_FUNC(glDeleteBuffers) + GL_FUNC(glDeleteFramebuffers) + GL_FUNC(glDeleteProgram) + GL_FUNC(glDeleteRenderbuffers) + GL_FUNC(glDeleteShader) + GL_FUNC(glDeleteTextures) + GL_FUNC(glDepthMask) + GL_FUNC(glDisable) + GL_FUNC(glDisableVertexAttribArray) + GL_FUNC(glDrawArrays) + GL_FUNC(glDrawElements) + GL_FUNC(glEnable) + GL_FUNC(glEnableVertexAttribArray) + GL_FUNC(glFinish) + GL_FUNC(glFlush) + GL_FUNC(glFramebufferRenderbuffer) + GL_FUNC(glFramebufferTexture2D) + GL_FUNC(glFrontFace) + GL_FUNC(glGenBuffers) + GL_FUNC(glGenerateMipmap) + GL_FUNC(glGenFramebuffers) + GL_FUNC(glGenRenderbuffers) + GL_FUNC(glGenTextures) + GL_FUNC(glGetBufferParameteriv) + GL_FUNC(glGetError) + GL_FUNC(glGetFramebufferAttachmentParameteriv) + GL_FUNC(glGetIntegerv) + GL_FUNC(glGetProgramInfoLog) + GL_FUNC(glGetProgramiv) + GL_FUNC(glGetRenderbufferParameteriv) + GL_FUNC(glGetShaderInfoLog) + GL_FUNC(glGetShaderiv) + GL_FUNC(glGetShaderPrecisionFormat) + GL_FUNC(glGetString) + GL_FUNC(glGetUniformLocation) + GL_FUNC(glIsTexture) + GL_FUNC(glLineWidth) + GL_FUNC(glLinkProgram) + GL_FUNC(glPixelStorei) + GL_FUNC(glReadPixels) + GL_FUNC(glRenderbufferStorage) + GL_FUNC(glScissor) + GL_FUNC(glShaderSource) + GL_FUNC(glStencilFunc) + GL_FUNC(glStencilFuncSeparate) + GL_FUNC(glStencilMask) + GL_FUNC(glStencilMaskSeparate) + GL_FUNC(glStencilOp) + GL_FUNC(glStencilOpSeparate) + GL_FUNC(glTexImage2D) + GL_FUNC(glTexParameterf) + GL_FUNC(glTexParameterfv) + GL_FUNC(glTexParameteri) + GL_FUNC(glTexParameteriv) + GL_FUNC(glTexSubImage2D) + GL_FUNC(glUniform1f) + GL_FUNC(glUniform1fv) + GL_FUNC(glUniform1i) + GL_FUNC(glUniform1iv) + GL_FUNC(glUniform2f) + GL_FUNC(glUniform2fv) + GL_FUNC(glUniform2i) + GL_FUNC(glUniform2iv) + GL_FUNC(glUniform3f) + GL_FUNC(glUniform3fv) + GL_FUNC(glUniform3i) + GL_FUNC(glUniform3iv) + GL_FUNC(glUniform4f) + GL_FUNC(glUniform4fv) + GL_FUNC(glUniform4i) + GL_FUNC(glUniform4iv) + GL_FUNC(glUniformMatrix2fv) + GL_FUNC(glUniformMatrix3fv) + GL_FUNC(glUniformMatrix4fv) + GL_FUNC(glUseProgram) + GL_FUNC(glVertexAttrib1f) + GL_FUNC(glVertexAttrib2fv) + GL_FUNC(glVertexAttrib3fv) + GL_FUNC(glVertexAttrib4fv) + GL_FUNC(glVertexAttribPointer) + GL_FUNC(glViewport) + + FT_LOGW("Could not resolve: %s", name); + return nullptr; +} +#undef GL_FUNC + +bool TizenRenderer::InitializeRenderer(int32_t x, int32_t y, int32_t w, + int32_t h) { + if (!SetupDisplay()) { + FT_LOGE("setupDisplay fail"); + return false; + } + if (!SetupEcoreWlWindow(x, y, w, h)) { + FT_LOGE("SetupEcoreWlWindow fail"); + return false; + } + + if (!SetupEglWindow(w, h)) { + FT_LOGE("SetupEglWindow fail"); + return false; + } + + if (!SetupEglSurface()) { + FT_LOGE("setupEglSurface fail"); + return false; + } + is_valid_ = true; + return true; +} + +bool TizenRenderer::IsValid() { return is_valid_; } + +bool TizenRenderer::SetupEglSurface() { + if (!ChooseEGLConfiguration()) { + FT_LOGE("ChooseEGLConfiguration fail"); + return false; + } + const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE}; + egl_context_ = eglCreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT, + contextAttribs); + if (EGL_NO_CONTEXT == egl_context_) { + PrintEGLError(); + return false; + } + + egl_resource_context_ = eglCreateContext(egl_display_, egl_config_, + EGL_NO_CONTEXT, contextAttribs); + if (EGL_NO_CONTEXT == egl_resource_context_) { + PrintEGLError(); + return false; + } + EGLint* ptr = nullptr; + const EGLint attribs[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE}; + egl_surface_ = eglCreateWindowSurface(egl_display_, egl_config_, + GetEGLNativeWindowType(), ptr); + if (egl_surface_ == EGL_NO_SURFACE) { + FT_LOGE("eglCreateWindowSurface is Failed"); + return false; + } + egl_resource_surface_ = + eglCreatePbufferSurface(egl_display_, egl_config_, attribs); + if (egl_resource_surface_ == EGL_NO_SURFACE) { + FT_LOGE("eglCreatePbufferSurface is Failed"); + return false; + } + return true; +} + +bool TizenRenderer::ChooseEGLConfiguration() { + // egl CONTEXT + EGLint configAttribs[] = {EGL_SURFACE_TYPE, + EGL_WINDOW_BIT, + EGL_RED_SIZE, + 8, + EGL_GREEN_SIZE, + 8, + EGL_BLUE_SIZE, + 8, + EGL_ALPHA_SIZE, + EGL_DONT_CARE, + EGL_RENDERABLE_TYPE, + EGL_OPENGL_ES2_BIT, + EGL_SAMPLE_BUFFERS, + EGL_DONT_CARE, + EGL_SAMPLES, + EGL_DONT_CARE, + EGL_NONE}; + + EGLint major = 0; + EGLint minor = 0; + int bufferSize = 32; + egl_display_ = GetEGLDisplay(); + if (EGL_NO_DISPLAY == egl_display_) { + FT_LOGE("EGL Get Display is failed"); + return false; + } + + if (!eglInitialize(egl_display_, &major, &minor)) { + FT_LOGE("EGL Intialize is Failed major [%d] minor [%d]", major, minor); + PrintEGLError(); + return false; + } + + if (!eglBindAPI(EGL_OPENGL_ES_API)) { + PrintEGLError(); + return false; + } + + EGLint numOfConfig = 0; + // Query all framebuffer configurations + if (!eglGetConfigs(egl_display_, NULL, 0, &numOfConfig)) { + FT_LOGE("eglGetConfigs is Failed!!"); + PrintEGLError(); + return false; + } + EGLConfig* configs = (EGLConfig*)calloc(numOfConfig, sizeof(EGLConfig)); + EGLint n; + // Get the List of EGL framebuffer configuration matches with configAttribs in + // list "configs" + if (!eglChooseConfig(egl_display_, configAttribs, configs, numOfConfig, &n)) { + free(configs); + configs = NULL; + PrintEGLError(); + return false; + } + + EGLint size; + for (int i = 0; i < n; i++) { + eglGetConfigAttrib(egl_display_, configs[i], EGL_BUFFER_SIZE, &size); + if (bufferSize == size) { + egl_config_ = configs[i]; + break; + } + } + free(configs); + configs = NULL; + return true; +} + +void TizenRenderer::PrintEGLError() { + EGLint error = eglGetError(); + switch (error) { + case EGL_BAD_DISPLAY: { + FT_LOGE("EGL_BAD_DISPLAY : Display is not an EGL display connection\n"); + break; + } + case EGL_NOT_INITIALIZED: { + FT_LOGE("EGL_NOT_INITIALIZED : Display has not been initialized\n"); + break; + } + case EGL_BAD_SURFACE: { + FT_LOGE("EGL_BAD_SURFACE : Draw or read is not an EGL surface\n"); + break; + } + case EGL_BAD_CONTEXT: { + FT_LOGE("EGL_BAD_CONTEXT : Context is not an EGL rendering context\n"); + break; + } + case EGL_BAD_CONFIG: { + FT_LOGE( + "EGL_BAD_CONFIG : Config is not an EGL frame buffer configuration\n"); + break; + } + case EGL_BAD_MATCH: { + FT_LOGE( + "EGL_BAD_MATCH : Draw or read are not compatible with context, or if " + "context is set to EGL_NO_CONTEXT and draw or read are not set to " + "EGL_NO_SURFACE, or if draw or read are set to EGL_NO_SURFACE and " + "context is not set to EGL_NO_CONTEXT\n"); + break; + } + case EGL_BAD_ACCESS: { + FT_LOGE("EGL_BAD_ACCESS : Context is current to some other thread\n"); + break; + } + case EGL_BAD_NATIVE_PIXMAP: { + FT_LOGE( + "EGL_BAD_NATIVE_PIXMAP : A native pixmap underlying either draw or " + "read is no longer valid\n"); + break; + } + case EGL_BAD_NATIVE_WINDOW: { + FT_LOGE( + "EGL_BAD_NATIVE_WINDOW : A native window underlying either draw or " + "read is no longer valid\n"); + break; + } + case EGL_BAD_CURRENT_SURFACE: { + FT_LOGE( + "EGL_BAD_CURRENT_SURFACE : The previous context has unflushed " + "commands and the previous surface is no longer valid\n"); + break; + } + case EGL_BAD_ALLOC: { + FT_LOGE( + "EGL_BAD_ALLOC : Allocation of ancillary buffers for draw or read " + "were delayed until eglMakeCurrent is called, and there are not " + "enough resources to allocate them\n"); + break; + } + case EGL_CONTEXT_LOST: { + FT_LOGE( + "EGL_CONTEXT_LOST : If a power management event has occurred. The " + "application must destroy all contexts and reinitialise OpenGL ES " + "state and objects to continue rendering\n"); + break; + } + case EGL_BAD_PARAMETER: { + FT_LOGE("Invalid parameter is passed\n"); + break; + } + case EGL_BAD_ATTRIBUTE: { + FT_LOGE( + "The parameter configAttribs contains an invalid frame buffer " + "configuration attribute or an attribute value that is unrecognized " + "or out of range\n"); + break; + } + default: { + FT_LOGE("Unknown error with code: %d\n", error); + break; + } + } +} + +void TizenRenderer::DestoryRenderer() { + DestoryEglSurface(); + DestoryEglWindow(); + DestoryEcoreWlWindow(); + ShutdownDisplay(); +} + +void TizenRenderer::DestoryEglSurface() { + if (EGL_NO_DISPLAY != egl_display_) { + eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT); + + if (EGL_NO_SURFACE != egl_surface_) { + eglDestroySurface(egl_display_, egl_surface_); + egl_surface_ = EGL_NO_SURFACE; + } + + if (EGL_NO_CONTEXT != egl_context_) { + eglDestroyContext(egl_display_, egl_context_); + egl_context_ = EGL_NO_CONTEXT; + } + + if (EGL_NO_SURFACE != egl_resource_surface_) { + eglDestroySurface(egl_display_, egl_resource_surface_); + egl_resource_surface_ = EGL_NO_SURFACE; + } + + if (EGL_NO_CONTEXT != egl_resource_context_) { + eglDestroyContext(egl_display_, egl_resource_context_); + egl_resource_context_ = EGL_NO_CONTEXT; + } + + eglTerminate(egl_display_); + egl_display_ = EGL_NO_DISPLAY; + } +} diff --git a/shell/platform/tizen/tizen_renderer.h b/shell/platform/tizen/tizen_renderer.h new file mode 100644 index 0000000000000..56ddfa361bb10 --- /dev/null +++ b/shell/platform/tizen/tizen_renderer.h @@ -0,0 +1,56 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#ifndef EMBEDDER_TIZEN_RENDERER_H +#define EMBEDDER_TIZEN_RENDERER_H + +#include +class TizenRenderer { + public: + struct TizenWindowGeometry { + int32_t x{0}, y{0}, w{0}, h{0}; + }; + TizenRenderer() = default; + virtual ~TizenRenderer(); + bool OnMakeCurrent(); + bool OnClearCurrent(); + bool OnMakeResourceCurrent(); + bool OnPresent(); + uint32_t OnGetFBO(); + void* OnProcResolver(const char* name); + virtual TizenWindowGeometry GetGeometry() = 0; + bool IsValid(); + virtual int GetEcoreWindowId() = 0; + virtual void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, + int32_t height, int32_t degree) = 0; + + protected: + bool InitializeRenderer(int32_t x, int32_t y, int32_t w, int32_t h); + virtual bool SetupDisplay() = 0; + virtual bool SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, + int32_t h) = 0; + virtual bool SetupEglWindow(int32_t w, int32_t h) = 0; + bool SetupEglSurface(); + virtual EGLDisplay GetEGLDisplay() = 0; + virtual EGLNativeWindowType GetEGLNativeWindowType() = 0; + + void DestoryRenderer(); + void DestoryEglSurface(); + virtual void DestoryEglWindow() = 0; + virtual void DestoryEcoreWlWindow() = 0; + virtual void ShutdownDisplay() = 0; + + private: + bool is_valid_ = false; + EGLConfig egl_config_; + EGLDisplay egl_display_ = EGL_NO_DISPLAY; + EGLContext egl_context_ = EGL_NO_CONTEXT; + EGLSurface egl_surface_ = EGL_NO_SURFACE; + EGLContext egl_resource_context_ = EGL_NO_CONTEXT; + EGLSurface egl_resource_surface_ = EGL_NO_SURFACE; + bool ChooseEGLConfiguration(); + void PrintEGLError(); +}; +#endif \ No newline at end of file diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl.cc b/shell/platform/tizen/tizen_renderer_ecore_wl.cc new file mode 100644 index 0000000000000..58fd5a95009f0 --- /dev/null +++ b/shell/platform/tizen/tizen_renderer_ecore_wl.cc @@ -0,0 +1,101 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#include "tizen_renderer_ecore_wl.h" + +#include "flutter/shell/platform/tizen/tizen_log.h" + +TizenRendererEcoreWl::TizenRendererEcoreWl(int32_t x, int32_t y, int32_t w, + int32_t h) { + InitializeRenderer(x, y, w, h); +} +TizenRendererEcoreWl::~TizenRendererEcoreWl() { DestoryRenderer(); } + +bool TizenRendererEcoreWl::SetupDisplay() { + // ecore_wl INIT + if (!ecore_wl_init(NULL)) { + FT_LOGE("Could not initialize ecore_wl"); + return false; + } + wl_display_ = ecore_wl_display_get(); + if (nullptr == wl_display_) { + FT_LOGE("ecore_wl_display_get failed"); + return false; + } + return true; +} +bool TizenRendererEcoreWl::SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, + int32_t h) { + if (w == 0 || h == 0) { + FT_LOGE("Failed to create because of the wrong size"); + return false; + } + ecore_wl_window_ = ecore_wl_window_new( + nullptr, x, y, w, h, ECORE_WL_WINDOW_BUFFER_TYPE_EGL_WINDOW); + FT_LOGD("ecore_wl_window_: %p", ecore_wl_window_); + if (ecore_wl_window_ == nullptr) { + FT_LOGE("ecore_wl_window_new fail"); + return false; + } + ecore_wl_window_type_set(ecore_wl_window_, ECORE_WL_WINDOW_TYPE_TOPLEVEL); + // ecore_wl_window_alpha_set(ecore_wl_window_, EINA_FALSE); + ecore_wl_window_aux_hint_add(ecore_wl_window_, 0, + "wm.policy.win.user.geometry", "1"); + ecore_wl_window_show(ecore_wl_window_); + return true; +} +bool TizenRendererEcoreWl::SetupEglWindow(int32_t w, int32_t h) { + wl_egl_window_ = + wl_egl_window_create(ecore_wl_window_surface_get(ecore_wl_window_), w, h); + if (nullptr == wl_egl_window_) { + FT_LOGE("wl_egl_window_create is Failed"); + return false; + } + return true; +} +EGLDisplay TizenRendererEcoreWl::GetEGLDisplay() { + return eglGetDisplay((EGLNativeDisplayType)wl_display_); +} +EGLNativeWindowType TizenRendererEcoreWl::GetEGLNativeWindowType() { + return (EGLNativeWindowType)wl_egl_window_; +} + +void TizenRendererEcoreWl::DestoryEglWindow() { + if (wl_egl_window_) { + wl_egl_window_destroy(wl_egl_window_); + wl_egl_window_ = nullptr; + } +} +void TizenRendererEcoreWl::DestoryEcoreWlWindow() { + if (ecore_wl_window_) { + ecore_wl_window_free(ecore_wl_window_); + ecore_wl_window_ = nullptr; + } +} +void TizenRendererEcoreWl::ShutdownDisplay() { ecore_wl_shutdown(); } + +TizenRenderer::TizenWindowGeometry TizenRendererEcoreWl::GetGeometry() { + TizenWindowGeometry result; + ecore_wl_window_geometry_get(ecore_wl_window_, &result.x, &result.y, + &result.w, &result.h); + return result; +} + +void TizenRendererEcoreWl::ResizeWithRotation(int32_t dx, int32_t dy, + int32_t width, int32_t height, + int32_t degree) { + wl_egl_window_resize(wl_egl_window_, width, height, dx, dy); + wl_egl_window_rotation rotations[4] = {ROTATION_0, ROTATION_90, ROTATION_180, + ROTATION_270}; + int index = 0; + if (degree > 0) { + index = (degree / 90) % 4; + } + wl_egl_window_set_rotation(wl_egl_window_, rotations[index]); +} + +int TizenRendererEcoreWl::GetEcoreWindowId() { + return ecore_wl_window_id_get(ecore_wl_window_); +} \ No newline at end of file diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl.h b/shell/platform/tizen/tizen_renderer_ecore_wl.h new file mode 100644 index 0000000000000..80a02b2c59387 --- /dev/null +++ b/shell/platform/tizen/tizen_renderer_ecore_wl.h @@ -0,0 +1,39 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#ifndef EMBEDDER_TIZEN_RENDERER_ECORE_WL_H +#define EMBEDDER_TIZEN_RENDERER_ECORE_WL_H + +#include +#include + +#include "tizen_renderer.h" +#define EFL_BETA_API_SUPPORT +#include +class TizenRendererEcoreWl : public TizenRenderer { + public: + TizenRendererEcoreWl(int32_t x, int32_t y, int32_t w, int32_t h); + ~TizenRendererEcoreWl(); + TizenRenderer::TizenWindowGeometry GetGeometry() override; + int GetEcoreWindowId() override; + void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height, + int32_t degree) override; + + protected: + void DestoryEglWindow() override; + void DestoryEcoreWlWindow() override; + EGLDisplay GetEGLDisplay() override; + EGLNativeWindowType GetEGLNativeWindowType() override; + bool SetupDisplay() override; + bool SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, int32_t h) override; + bool SetupEglWindow(int32_t w, int32_t h) override; + void ShutdownDisplay() override; + + private: + Ecore_Wl_Window* ecore_wl_window_ = nullptr; + wl_egl_window* wl_egl_window_ = nullptr; + wl_display* wl_display_ = nullptr; +}; +#endif \ No newline at end of file diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc new file mode 100644 index 0000000000000..35f20ff2ed895 --- /dev/null +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc @@ -0,0 +1,98 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#include "tizen_renderer_ecore_wl2.h" + +#include "flutter/shell/platform/tizen/tizen_log.h" + +TizenRendererEcoreWl2::TizenRendererEcoreWl2(int32_t x, int32_t y, int32_t w, + int32_t h) { + InitializeRenderer(x, y, w, h); +} +TizenRendererEcoreWl2::~TizenRendererEcoreWl2() { DestoryRenderer(); } +bool TizenRendererEcoreWl2::SetupDisplay() { + if (!ecore_wl2_init()) { + FT_LOGE("Could not initialize ecore_wl2"); + return false; + } + ecore_wl2_display_ = ecore_wl2_display_connect(nullptr); + if (ecore_wl2_display_ == nullptr) { + FT_LOGE("Disyplay not found"); + return false; + } + FT_LOGD("ecore_wl2_display_: %p", ecore_wl2_display_); + ecore_wl2_sync(); + return true; +} + +bool TizenRendererEcoreWl2::SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, + int32_t h) { + if (w == 0 || h == 0) { + FT_LOGE("Failed to create because of the wrong size"); + return false; + } + ecore_wl2_window_ = + ecore_wl2_window_new(ecore_wl2_display_, nullptr, x, y, w, h); + ecore_wl2_window_type_set(ecore_wl2_window_, ECORE_WL2_WINDOW_TYPE_TOPLEVEL); + ecore_wl2_window_alpha_set(ecore_wl2_window_, EINA_FALSE); + ecore_wl2_window_aux_hint_add(ecore_wl2_window_, 0, + "wm.policy.win.user.geometry", "1"); + ecore_wl2_window_show(ecore_wl2_window_); + return true; +} + +bool TizenRendererEcoreWl2::SetupEglWindow(int32_t w, int32_t h) { + ecore_wl2_egl_window_ = ecore_wl2_egl_window_create(ecore_wl2_window_, w, h); + return true; +} + +EGLDisplay TizenRendererEcoreWl2::GetEGLDisplay() { + return eglGetDisplay( + (EGLNativeDisplayType)ecore_wl2_display_get(ecore_wl2_display_)); +} + +EGLNativeWindowType TizenRendererEcoreWl2::GetEGLNativeWindowType() { + return (EGLNativeWindowType)ecore_wl2_egl_window_native_get( + ecore_wl2_egl_window_); +} + +void TizenRendererEcoreWl2::DestoryEglWindow() { + if (ecore_wl2_egl_window_) { + ecore_wl2_egl_window_destroy(ecore_wl2_egl_window_); + ecore_wl2_egl_window_ = nullptr; + } +} + +void TizenRendererEcoreWl2::DestoryEcoreWlWindow() { + if (ecore_wl2_window_) { + ecore_wl2_window_free(ecore_wl2_window_); + ecore_wl2_window_ = nullptr; + } +} +void TizenRendererEcoreWl2::ShutdownDisplay() { + if (ecore_wl2_display_) { + ecore_wl2_display_disconnect(ecore_wl2_display_); + ecore_wl2_display_ = nullptr; + } + ecore_wl2_shutdown(); +} + +TizenRenderer::TizenWindowGeometry TizenRendererEcoreWl2::GetGeometry() { + TizenWindowGeometry result; + ecore_wl2_window_geometry_get(ecore_wl2_window_, &result.x, &result.y, + &result.w, &result.h); + return result; +} + +int TizenRendererEcoreWl2::GetEcoreWindowId() { + return ecore_wl2_window_id_get(ecore_wl2_window_); +} + +void TizenRendererEcoreWl2::ResizeWithRotation(int32_t dx, int32_t dy, + int32_t width, int32_t height, + int32_t degree) { + ecore_wl2_egl_window_resize_with_rotation(ecore_wl2_egl_window_, dx, dy, + width, height, degree); +} \ No newline at end of file diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.h b/shell/platform/tizen/tizen_renderer_ecore_wl2.h new file mode 100644 index 0000000000000..df5cc1593d95e --- /dev/null +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.h @@ -0,0 +1,38 @@ +// Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. +// 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. + +#ifndef EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H +#define EMBEDDER_TIZEN_RENDERER_ECORE_WL2_H + +#include "tizen_renderer.h" + +#define EFL_BETA_API_SUPPORT +#include + +class TizenRendererEcoreWl2 : public TizenRenderer { + public: + TizenRendererEcoreWl2(int32_t x, int32_t y, int32_t w, int32_t h); + ~TizenRendererEcoreWl2(); + TizenWindowGeometry GetGeometry() override; + int GetEcoreWindowId() override; + void ResizeWithRotation(int32_t dx, int32_t dy, int32_t width, int32_t height, + int32_t degree) override; + + protected: + void DestoryEglWindow() override; + void DestoryEcoreWlWindow() override; + EGLDisplay GetEGLDisplay() override; + EGLNativeWindowType GetEGLNativeWindowType() override; + bool SetupDisplay() override; + bool SetupEcoreWlWindow(int32_t x, int32_t y, int32_t w, int32_t h) override; + bool SetupEglWindow(int32_t w, int32_t h) override; + void ShutdownDisplay() override; + + private: + Ecore_Wl2_Display *ecore_wl2_display_ = nullptr; + Ecore_Wl2_Window *ecore_wl2_window_ = nullptr; + Ecore_Wl2_Egl_Window *ecore_wl2_egl_window_ = nullptr; +}; +#endif \ No newline at end of file diff --git a/shell/platform/tizen/tizen_surface.cc b/shell/platform/tizen/tizen_surface.cc deleted file mode 100644 index 62e0432825ab4..0000000000000 --- a/shell/platform/tizen/tizen_surface.cc +++ /dev/null @@ -1,7 +0,0 @@ -// 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. - -#include "tizen_surface.h" - -TizenSurface::~TizenSurface() = default; diff --git a/shell/platform/tizen/tizen_surface.h b/shell/platform/tizen/tizen_surface.h deleted file mode 100644 index d8b954ce47a2d..0000000000000 --- a/shell/platform/tizen/tizen_surface.h +++ /dev/null @@ -1,22 +0,0 @@ -// 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. - -#ifndef EMBEDDER_TIZEN_SURFACE_H_ -#define EMBEDDER_TIZEN_SURFACE_H_ - -#include - -class TizenSurface { - public: - virtual ~TizenSurface(); - virtual bool OnMakeCurrent() = 0; - virtual bool OnClearCurrent() = 0; - virtual bool OnMakeResourceCurrent() = 0; - virtual bool OnPresent() = 0; - virtual uint32_t OnGetFBO() = 0; - virtual void* OnProcResolver(const char* name) = 0; - virtual bool IsValid() = 0; -}; - -#endif // EMBEDDER_TIZEN_SURFACE_H_ diff --git a/shell/platform/tizen/tizen_surface_gl.cc b/shell/platform/tizen/tizen_surface_gl.cc deleted file mode 100644 index b02cecdc95023..0000000000000 --- a/shell/platform/tizen/tizen_surface_gl.cc +++ /dev/null @@ -1,371 +0,0 @@ -// 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. - -#include "tizen_surface_gl.h" - -#include -#include - -#include "flutter/shell/platform/tizen/tizen_log.h" - -template -using EGLResult = std::pair; - -static EGLResult CreateContext(EGLDisplay display, EGLConfig config, - EGLContext share = EGL_NO_CONTEXT) { - 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}; -} - -static EGLResult ChooseEGLConfiguration(EGLDisplay display) { - EGLint attributes[] = { - // clang-format off - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_SURFACE_TYPE, EGL_WINDOW_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_DEPTH_SIZE, 0, - EGL_STENCIL_SIZE, 0, - EGL_NONE, // termination sentinel - // clang-format on - }; - - EGLint config_count = 0; - EGLConfig egl_config = nullptr; - - if (eglChooseConfig(display, attributes, &egl_config, 1, &config_count) != - EGL_TRUE) { - LogLastEGLError(); - return {false, nullptr}; - } - - bool success = config_count > 0 && egl_config != nullptr; - - return {success, success ? egl_config : nullptr}; -} - -TizenEGLSurface::~TizenEGLSurface() { - if (eglDestroySurface(tizen_native_egl_window_->GetEGLDisplayHandle(), - egl_surface_) != EGL_TRUE) { - LogLastEGLError(); - } - tizen_native_egl_window_ = nullptr; -} - -TizenEGLContext::TizenEGLContext( - std::shared_ptr tizen_native_egl_window) - : tizen_native_egl_window_(tizen_native_egl_window) { - EGLDisplay egl_display = tizen_native_egl_window_->GetEGLDisplayHandle(); - auto config = ChooseEGLConfiguration(egl_display); - if (!config.first) { - FT_LOGE("Failed to ChooseEGLConfiguration"); - return; - } - egl_config_ = config.second; - - auto ctx = CreateContext(egl_display, egl_config_, EGL_NO_CONTEXT); - if (!ctx.first) { - FT_LOGE("Failed to create egl context"); - return; - } - egl_context_ = ctx.second; - - auto resource_ctx = CreateContext(egl_display, egl_config_, egl_context_); - if (!resource_ctx.first) { - FT_LOGE("Failed to create egl resource context"); - return; - } - egl_resource_context_ = resource_ctx.second; -} - -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); -} - -TizenSurfaceGL::TizenSurfaceGL( - std::shared_ptr tizen_native_window) - : tizen_native_window_(tizen_native_window) { - if (!tizen_native_window_->IsValid()) { - FT_LOGE("Invalid native window"); - return; - } - - tizen_context_gl_ = std::make_unique( - tizen_native_window_->GetTizenNativeEGLWindow()); - if (!tizen_context_gl_->IsValid()) { - FT_LOGE("Invalid context gl"); - return; - } - - tizen_egl_window_surface_ = tizen_context_gl_->CreateTizenEGLWindowSurface(); - if (!tizen_egl_window_surface_->IsValid()) { - FT_LOGE("Invalid egl window surface"); - return; - } - - tizen_egl_pbuffer_surface_ = - tizen_context_gl_->CreateTizenEGLPbufferSurface(); - if (!tizen_egl_pbuffer_surface_->IsValid()) { - FT_LOGE("Invalid egl puffer surface"); - return; - } - - is_valid_ = true; -} - -bool TizenSurfaceGL::OnMakeCurrent() { - if (!is_valid_) { - FT_LOGE("Invalid TizenSurfaceGL"); - return false; - } - if (eglMakeCurrent(tizen_native_window_->GetTizenNativeEGLWindow() - ->GetEGLDisplayHandle(), - tizen_egl_window_surface_->GetEGLSurfaceHandle(), - 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; -} - -bool TizenSurfaceGL::OnMakeResourceCurrent() { - if (!is_valid_) { - FT_LOGE("Invalid TizenSurfaceGL"); - return false; - } - if (eglMakeCurrent(tizen_native_window_->GetTizenNativeEGLWindow() - ->GetEGLDisplayHandle(), - tizen_egl_pbuffer_surface_->GetEGLSurfaceHandle(), - tizen_egl_pbuffer_surface_->GetEGLSurfaceHandle(), - tizen_context_gl_->GetEGLResourceContextHandle()) != - EGL_TRUE) { - FT_LOGE("Could not make the offscreen context current"); - LogLastEGLError(); - return false; - } - return true; -} - -bool TizenSurfaceGL::OnClearCurrent() { - if (!is_valid_) { - FT_LOGE("Invalid TizenSurfaceGL"); - return false; - } - - if (eglMakeCurrent(tizen_native_window_->GetTizenNativeEGLWindow() - ->GetEGLDisplayHandle(), - EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT) != EGL_TRUE) { - FT_LOGE("Could not clear context"); - LogLastEGLError(); - return false; - } - return true; -} - -bool TizenSurfaceGL::OnPresent() { - if (!is_valid_) { - FT_LOGE("Invalid TizenSurfaceGL"); - return false; - } - - if (eglSwapBuffers(tizen_native_window_->GetTizenNativeEGLWindow() - ->GetEGLDisplayHandle(), - tizen_egl_window_surface_->GetEGLSurfaceHandle()) != - EGL_TRUE) { - FT_LOGE("Could not swap EGl buffer"); - LogLastEGLError(); - return false; - } - return true; -} - -uint32_t TizenSurfaceGL::OnGetFBO() { - if (!is_valid_) { - FT_LOGE("Invalid TizenSurfaceGL"); - return 999; - } - FT_LOGD("OnApplicationGetOnscreenFBO"); - return 0; // FBO0 -} - -#define GL_FUNC(FunctionName) \ - else if (strcmp(name, #FunctionName) == 0) { \ - return reinterpret_cast(FunctionName); \ - } - -void* TizenSurfaceGL::OnProcResolver(const char* name) { - auto address = eglGetProcAddress(name); - if (address != nullptr) { - return reinterpret_cast(address); - } - GL_FUNC(eglGetCurrentDisplay) - GL_FUNC(eglQueryString) - GL_FUNC(glActiveTexture) - GL_FUNC(glAttachShader) - GL_FUNC(glBindAttribLocation) - GL_FUNC(glBindBuffer) - GL_FUNC(glBindFramebuffer) - GL_FUNC(glBindRenderbuffer) - GL_FUNC(glBindTexture) - GL_FUNC(glBlendColor) - GL_FUNC(glBlendEquation) - GL_FUNC(glBlendFunc) - GL_FUNC(glBufferData) - GL_FUNC(glBufferSubData) - GL_FUNC(glCheckFramebufferStatus) - GL_FUNC(glClear) - GL_FUNC(glClearColor) - GL_FUNC(glClearStencil) - GL_FUNC(glColorMask) - GL_FUNC(glCompileShader) - GL_FUNC(glCompressedTexImage2D) - GL_FUNC(glCompressedTexSubImage2D) - GL_FUNC(glCopyTexSubImage2D) - GL_FUNC(glCreateProgram) - GL_FUNC(glCreateShader) - GL_FUNC(glCullFace) - GL_FUNC(glDeleteBuffers) - GL_FUNC(glDeleteFramebuffers) - GL_FUNC(glDeleteProgram) - GL_FUNC(glDeleteRenderbuffers) - GL_FUNC(glDeleteShader) - GL_FUNC(glDeleteTextures) - GL_FUNC(glDepthMask) - GL_FUNC(glDisable) - GL_FUNC(glDisableVertexAttribArray) - GL_FUNC(glDrawArrays) - GL_FUNC(glDrawElements) - GL_FUNC(glEnable) - GL_FUNC(glEnableVertexAttribArray) - GL_FUNC(glFinish) - GL_FUNC(glFlush) - GL_FUNC(glFramebufferRenderbuffer) - GL_FUNC(glFramebufferTexture2D) - GL_FUNC(glFrontFace) - GL_FUNC(glGenBuffers) - GL_FUNC(glGenerateMipmap) - GL_FUNC(glGenFramebuffers) - GL_FUNC(glGenRenderbuffers) - GL_FUNC(glGenTextures) - GL_FUNC(glGetBufferParameteriv) - GL_FUNC(glGetError) - GL_FUNC(glGetFramebufferAttachmentParameteriv) - GL_FUNC(glGetIntegerv) - GL_FUNC(glGetProgramInfoLog) - GL_FUNC(glGetProgramiv) - GL_FUNC(glGetRenderbufferParameteriv) - GL_FUNC(glGetShaderInfoLog) - GL_FUNC(glGetShaderiv) - GL_FUNC(glGetShaderPrecisionFormat) - GL_FUNC(glGetString) - GL_FUNC(glGetUniformLocation) - GL_FUNC(glIsTexture) - GL_FUNC(glLineWidth) - GL_FUNC(glLinkProgram) - GL_FUNC(glPixelStorei) - GL_FUNC(glReadPixels) - GL_FUNC(glRenderbufferStorage) - GL_FUNC(glScissor) - GL_FUNC(glShaderSource) - GL_FUNC(glStencilFunc) - GL_FUNC(glStencilFuncSeparate) - GL_FUNC(glStencilMask) - GL_FUNC(glStencilMaskSeparate) - GL_FUNC(glStencilOp) - GL_FUNC(glStencilOpSeparate) - GL_FUNC(glTexImage2D) - GL_FUNC(glTexParameterf) - GL_FUNC(glTexParameterfv) - GL_FUNC(glTexParameteri) - GL_FUNC(glTexParameteriv) - GL_FUNC(glTexSubImage2D) - GL_FUNC(glUniform1f) - GL_FUNC(glUniform1fv) - GL_FUNC(glUniform1i) - GL_FUNC(glUniform1iv) - GL_FUNC(glUniform2f) - GL_FUNC(glUniform2fv) - GL_FUNC(glUniform2i) - GL_FUNC(glUniform2iv) - GL_FUNC(glUniform3f) - GL_FUNC(glUniform3fv) - GL_FUNC(glUniform3i) - GL_FUNC(glUniform3iv) - GL_FUNC(glUniform4f) - GL_FUNC(glUniform4fv) - GL_FUNC(glUniform4i) - GL_FUNC(glUniform4iv) - GL_FUNC(glUniformMatrix2fv) - GL_FUNC(glUniformMatrix3fv) - GL_FUNC(glUniformMatrix4fv) - GL_FUNC(glUseProgram) - GL_FUNC(glVertexAttrib1f) - GL_FUNC(glVertexAttrib2fv) - GL_FUNC(glVertexAttrib3fv) - GL_FUNC(glVertexAttrib4fv) - GL_FUNC(glVertexAttribPointer) - GL_FUNC(glViewport) - FT_LOGD("Could not resolve: %s", name); - return nullptr; -} -#undef GL_FUNC - -TizenSurfaceGL::~TizenSurfaceGL() { - OnClearCurrent(); - tizen_egl_window_surface_ = nullptr; - tizen_egl_pbuffer_surface_ = nullptr; - tizen_context_gl_ = nullptr; - tizen_native_window_ = nullptr; -} diff --git a/shell/platform/tizen/tizen_surface_gl.h b/shell/platform/tizen/tizen_surface_gl.h deleted file mode 100644 index 8a83c82d4f85d..0000000000000 --- a/shell/platform/tizen/tizen_surface_gl.h +++ /dev/null @@ -1,75 +0,0 @@ -// 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. - -#ifndef EMBEDDER_TIZEN_SURFACE_GL_H_ -#define EMBEDDER_TIZEN_SURFACE_GL_H_ - -#include -#include - -#include -#include -#include -#define EFL_BETA_API_SUPPORT -#include -#include - -#include "flutter/shell/platform/embedder/embedder.h" -#include "flutter/shell/platform/tizen/tizen_native_window.h" -#include "flutter/shell/platform/tizen/tizen_surface.h" - -class TizenEGLSurface { - public: - TizenEGLSurface(std::shared_ptr tizen_native_egl_window, - EGLSurface egl_surface) - : tizen_native_egl_window_(tizen_native_egl_window), - egl_surface_(egl_surface){}; - ~TizenEGLSurface(); - bool IsValid() { return egl_surface_ != EGL_NO_SURFACE; } - EGLSurface GetEGLSurfaceHandle() { return egl_surface_; }; - - private: - std::shared_ptr tizen_native_egl_window_; - EGLSurface egl_surface_{EGL_NO_SURFACE}; -}; - -class TizenEGLContext { - public: - TizenEGLContext( - std::shared_ptr tizen_native_egl_window); - ~TizenEGLContext(); - bool IsValid(); - std::unique_ptr CreateTizenEGLWindowSurface(); - std::unique_ptr CreateTizenEGLPbufferSurface(); - EGLContext GetEGLContextHandle() { return egl_context_; } - EGLContext GetEGLResourceContextHandle() { return egl_resource_context_; } - - public: - std::shared_ptr tizen_native_egl_window_; - EGLConfig egl_config_{nullptr}; - EGLContext egl_context_{EGL_NO_CONTEXT}; - EGLContext egl_resource_context_{EGL_NO_CONTEXT}; -}; - -class TizenSurfaceGL : public TizenSurface { - public: - TizenSurfaceGL(std::shared_ptr tizen_native_window); - ~TizenSurfaceGL(); - bool OnMakeCurrent() override; - bool OnClearCurrent() override; - bool OnMakeResourceCurrent() override; - bool OnPresent() override; - uint32_t OnGetFBO() override; - void* OnProcResolver(const char* name) override; - bool IsValid() override { return is_valid_; }; - - private: - bool is_valid_{false}; - std::shared_ptr tizen_native_window_; - std::unique_ptr tizen_context_gl_; - std::unique_ptr tizen_egl_window_surface_; - std::unique_ptr tizen_egl_pbuffer_surface_; -}; - -#endif // EMBEDDER_TIZEN_SURFACE_GL_H_ diff --git a/shell/platform/tizen/tizen_vsync_waiter.cc b/shell/platform/tizen/tizen_vsync_waiter.cc index 8a5169ea38ff7..1486a1d8faf39 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.cc +++ b/shell/platform/tizen/tizen_vsync_waiter.cc @@ -9,66 +9,20 @@ #include "flutter/shell/platform/tizen/tizen_embedder_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" -static std::atomic g_vblank_ecore_pipe = nullptr; - -static const int VBLANK_LOOP_REQUEST = 1; -static const int VBLANK_LOOP_DEL_PIPE = 2; - -static void SendVblankLoopRequest(int event_type) { - if (ecore_pipe_write(g_vblank_ecore_pipe.load(), &event_type, - sizeof(event_type)) == EINA_FALSE) { - FT_LOGE("Failed to Send Reqeust [%s]", event_type == VBLANK_LOOP_REQUEST - ? "VBLANK_LOOP_REQUEST" - : "VBLANK_LOOP_DEL_PIPE"); - } +static void RequestVblank(void* data, Ecore_Thread* thread) { + TizenVsyncWaiter* tizen_vsync_waiter = + reinterpret_cast(data); + tizen_vsync_waiter->HandleVblankLoopRequest(); } TizenVsyncWaiter::TizenVsyncWaiter(TizenEmbedderEngine* engine) : engine_(engine) { if (!CreateTDMVblank()) { FT_LOGE("Failed to create TDM vblank"); - return; - } - - std::thread t( - [this](void* data) { - if (!ecore_init()) { - FT_LOGE("Failed to init Ecore"); - return; - } - Ecore_Pipe* vblank_ecore_pipe = ecore_pipe_add( - [](void* data, void* buffer, unsigned int nbyte) { - TizenVsyncWaiter* tizen_vsync_waiter = - reinterpret_cast(data); - int event_type = *(reinterpret_cast(buffer)); - if (event_type == VBLANK_LOOP_REQUEST) { - tizen_vsync_waiter->HandleVblankLoopRequest(); - } else if (event_type == VBLANK_LOOP_DEL_PIPE) { - if (g_vblank_ecore_pipe.load()) { - ecore_pipe_del(g_vblank_ecore_pipe); - g_vblank_ecore_pipe = NULL; - } - ecore_main_loop_quit(); - } - }, - this); - - g_vblank_ecore_pipe.store(vblank_ecore_pipe); - ecore_main_loop_begin(); - ecore_shutdown(); - }, - nullptr); - t.join(); - - if (g_vblank_ecore_pipe.load() == nullptr) { - FT_LOGE("Failed to create Ecore Pipe"); } } TizenVsyncWaiter::~TizenVsyncWaiter() { - if (g_vblank_ecore_pipe.load()) { - SendVblankLoopRequest(VBLANK_LOOP_DEL_PIPE); - } if (vblank_) { tdm_client_vblank_destroy(vblank_); } @@ -79,12 +33,7 @@ TizenVsyncWaiter::~TizenVsyncWaiter() { void TizenVsyncWaiter::AsyncWaitForVsync(intptr_t baton) { baton_ = baton; - SendVblankLoopRequest(VBLANK_LOOP_REQUEST); -} - -bool TizenVsyncWaiter::IsValid() { - return g_vblank_ecore_pipe.load() && client_ && output_ && vblank_ && - engine_ && engine_->flutter_engine; + ecore_thread_run(RequestVblank, NULL, NULL, this); } bool TizenVsyncWaiter::CreateTDMVblank() { @@ -108,7 +57,6 @@ bool TizenVsyncWaiter::CreateTDMVblank() { } tdm_client_vblank_set_enable_fake(vblank_, 1); - return true; } diff --git a/shell/platform/tizen/tizen_vsync_waiter.h b/shell/platform/tizen/tizen_vsync_waiter.h index 494e65a4aee9f..07032ab457b0c 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.h +++ b/shell/platform/tizen/tizen_vsync_waiter.h @@ -7,8 +7,6 @@ #include -#include - #include "flutter/shell/platform/embedder/embedder.h" class TizenEmbedderEngine; @@ -18,12 +16,11 @@ class TizenVsyncWaiter { TizenVsyncWaiter(TizenEmbedderEngine* engine); virtual ~TizenVsyncWaiter(); void AsyncWaitForVsync(intptr_t baton); - - bool IsValid(); + void HandleVblankLoopRequest(); private: bool CreateTDMVblank(); - void HandleVblankLoopRequest(); + static void TdmClientVblankCallback(tdm_client_vblank* vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, diff --git a/shell/platform/tizen/touch_event_handler.cc b/shell/platform/tizen/touch_event_handler.cc index b54ec35980425..8b3bc6056b131 100644 --- a/shell/platform/tizen/touch_event_handler.cc +++ b/shell/platform/tizen/touch_event_handler.cc @@ -39,7 +39,7 @@ void TouchEventHandler::SendFlutterPointerEvent(FlutterPointerPhase phase, } // Correct errors caused by window rotation. - auto window_geometry = engine_->tizen_native_window->GetGeometry(); + auto window_geometry = engine_->tizen_renderer->GetGeometry(); double width = window_geometry.w; double height = window_geometry.h; double new_x = x, new_y = y; diff --git a/tools/gn b/tools/gn index 55014651439d9..8646fc5c35e9d 100755 --- a/tools/gn +++ b/tools/gn @@ -117,6 +117,7 @@ def to_gn_args(args): gn_args['embedder_for_target'] = args.embedder_for_target gn_args['build_tizen_shell'] = args.build_tizen_shell + gn_args['tizen_sdk_4'] = args.tizen_sdk_4 gn_args['enable_coverage'] = args.coverage @@ -344,6 +345,7 @@ def parse_args(args): parser.add_argument('--embedder-for-target', dest='embedder_for_target', action='store_true', default=False) parser.add_argument('--build-tizen-shell', dest='build_tizen_shell', action='store_true', default=False) + parser.add_argument('--tizen-sdk-4', dest='tizen_sdk_4', action='store_true', default=False) parser.add_argument('--coverage', default=False, action='store_true') From 1a2c865bc5cd304f1025ad64a9f8e82e1b7aaf27 Mon Sep 17 00:00:00 2001 From: xiaowei guan Date: Wed, 13 Jan 2021 23:30:19 +0800 Subject: [PATCH 2/3] Add destory vblank method 1.If create tdm vblank failed, need destory vblank or tdm client. 2.Before request vblank, need check the thread is marked pending cancellation. --- shell/platform/tizen/tizen_vsync_waiter.cc | 51 ++++++++++++---------- shell/platform/tizen/tizen_vsync_waiter.h | 8 ++-- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/shell/platform/tizen/tizen_vsync_waiter.cc b/shell/platform/tizen/tizen_vsync_waiter.cc index 1486a1d8faf39..d7ef6accb56d0 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.cc +++ b/shell/platform/tizen/tizen_vsync_waiter.cc @@ -4,36 +4,38 @@ #include "tizen_vsync_waiter.h" -#include - #include "flutter/shell/platform/tizen/tizen_embedder_engine.h" #include "flutter/shell/platform/tizen/tizen_log.h" -static void RequestVblank(void* data, Ecore_Thread* thread) { +void TizenVsyncWaiter::RequestVblank(void* data, Ecore_Thread* thread) { TizenVsyncWaiter* tizen_vsync_waiter = reinterpret_cast(data); - tizen_vsync_waiter->HandleVblankLoopRequest(); + if (!ecore_thread_check(thread)) { + tdm_error error = tdm_client_vblank_wait(tizen_vsync_waiter->vblank_, 1, + TdmClientVblankCallback, data); + if (error != TDM_ERROR_NONE) { + FT_LOGE("tdm_client_vblank_wait error %d", error); + return; + } + tdm_client_handle_events(tizen_vsync_waiter->client_); + } } TizenVsyncWaiter::TizenVsyncWaiter(TizenEmbedderEngine* engine) : engine_(engine) { if (!CreateTDMVblank()) { FT_LOGE("Failed to create TDM vblank"); + DestoryTDMVblank(); } } -TizenVsyncWaiter::~TizenVsyncWaiter() { - if (vblank_) { - tdm_client_vblank_destroy(vblank_); - } - if (client_) { - tdm_client_destroy(client_); - } -} +TizenVsyncWaiter::~TizenVsyncWaiter() { DestoryTDMVblank(); } void TizenVsyncWaiter::AsyncWaitForVsync(intptr_t baton) { baton_ = baton; - ecore_thread_run(RequestVblank, NULL, NULL, this); + if (TDMValid()) { + ecore_thread_run(RequestVblank, NULL, NULL, this); + } } bool TizenVsyncWaiter::CreateTDMVblank() { @@ -60,6 +62,19 @@ bool TizenVsyncWaiter::CreateTDMVblank() { return true; } +void TizenVsyncWaiter::DestoryTDMVblank() { + if (vblank_) { + tdm_client_vblank_destroy(vblank_); + vblank_ = nullptr; + } + if (client_) { + tdm_client_destroy(client_); + client_ = nullptr; + } +} + +bool TizenVsyncWaiter::TDMValid() { return vblank_ && client_; } + void TizenVsyncWaiter::TdmClientVblankCallback( tdm_client_vblank* vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void* user_data) { @@ -76,13 +91,3 @@ void TizenVsyncWaiter::TdmClientVblankCallback( tizen_vsync_waiter->baton_, frame_start_time_nanos, frame_target_time_nanos); } - -void TizenVsyncWaiter::HandleVblankLoopRequest() { - tdm_error ret; - ret = tdm_client_vblank_wait(vblank_, 1, TdmClientVblankCallback, this); - if (ret != TDM_ERROR_NONE) { - FT_LOGE("ERROR, ret = %d", ret); - return; - } - tdm_client_handle_events(client_); -} diff --git a/shell/platform/tizen/tizen_vsync_waiter.h b/shell/platform/tizen/tizen_vsync_waiter.h index 07032ab457b0c..7566e3a2d980b 100644 --- a/shell/platform/tizen/tizen_vsync_waiter.h +++ b/shell/platform/tizen/tizen_vsync_waiter.h @@ -5,8 +5,8 @@ #ifndef EMBEDDER_TIZEN_VSYNC_WAITER_H_ #define EMBEDDER_TIZEN_VSYNC_WAITER_H_ +#include #include - #include "flutter/shell/platform/embedder/embedder.h" class TizenEmbedderEngine; @@ -16,16 +16,16 @@ class TizenVsyncWaiter { TizenVsyncWaiter(TizenEmbedderEngine* engine); virtual ~TizenVsyncWaiter(); void AsyncWaitForVsync(intptr_t baton); - void HandleVblankLoopRequest(); private: bool CreateTDMVblank(); - + void DestoryTDMVblank(); + bool TDMValid(); static void TdmClientVblankCallback(tdm_client_vblank* vblank, tdm_error error, unsigned int sequence, unsigned int tv_sec, unsigned int tv_usec, void* user_data); - + static void RequestVblank(void* data, Ecore_Thread* thread); tdm_client* client_{nullptr}; tdm_client_output* output_{nullptr}; tdm_client_vblank* vblank_{nullptr}; From 37d49b3c26cd1f76c6e1ab77af9dd0849c7bd338 Mon Sep 17 00:00:00 2001 From: xiaowei guan Date: Thu, 14 Jan 2021 01:35:51 +0800 Subject: [PATCH 3/3] Format code according to review opinions --- shell/platform/tizen/BUILD.gn | 12 ++-- shell/platform/tizen/tizen_renderer.cc | 60 ++++++++----------- shell/platform/tizen/tizen_renderer.h | 2 +- .../platform/tizen/tizen_renderer_ecore_wl.cc | 1 - .../platform/tizen/tizen_renderer_ecore_wl.h | 1 - .../tizen/tizen_renderer_ecore_wl2.cc | 1 - .../platform/tizen/tizen_renderer_ecore_wl2.h | 1 - 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 27d38501f5fe2..b88ca8746af30 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -107,13 +107,13 @@ source_set("flutter_tizen") { "wayland-client", ] - if(tizen_sdk_4){ - sources += ["tizen_renderer_ecore_wl.cc",] - libs += ["ecore_wayland", "wayland-egl"] + if (tizen_sdk_4) { + sources += [ "tizen_renderer_ecore_wl.cc" ] + libs += [ "ecore_wayland", "wayland-egl" ] defines = [ "FLUTTER_TIZEN_4" ] - }else { - sources += ["tizen_renderer_ecore_wl2.cc",] - libs += ["ecore_wl2"] + } else { + sources += [ "tizen_renderer_ecore_wl2.cc" ] + libs += [ "ecore_wl2" ] } } diff --git a/shell/platform/tizen/tizen_renderer.cc b/shell/platform/tizen/tizen_renderer.cc index 0dd6f83af2d0e..1d8877e1d76b4 100644 --- a/shell/platform/tizen/tizen_renderer.cc +++ b/shell/platform/tizen/tizen_renderer.cc @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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. @@ -248,7 +247,7 @@ bool TizenRenderer::SetupEglSurface() { egl_surface_ = eglCreateWindowSurface(egl_display_, egl_config_, GetEGLNativeWindowType(), ptr); if (egl_surface_ == EGL_NO_SURFACE) { - FT_LOGE("eglCreateWindowSurface is Failed"); + FT_LOGE("eglCreateWindowSurface failed"); return false; } egl_resource_surface_ = @@ -262,23 +261,16 @@ bool TizenRenderer::SetupEglSurface() { bool TizenRenderer::ChooseEGLConfiguration() { // egl CONTEXT - EGLint configAttribs[] = {EGL_SURFACE_TYPE, - EGL_WINDOW_BIT, - EGL_RED_SIZE, - 8, - EGL_GREEN_SIZE, - 8, - EGL_BLUE_SIZE, - 8, - EGL_ALPHA_SIZE, - EGL_DONT_CARE, - EGL_RENDERABLE_TYPE, - EGL_OPENGL_ES2_BIT, - EGL_SAMPLE_BUFFERS, - EGL_DONT_CARE, - EGL_SAMPLES, - EGL_DONT_CARE, - EGL_NONE}; + EGLint configAttribs[] = { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RED_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_BLUE_SIZE, 8, + EGL_ALPHA_SIZE, EGL_DONT_CARE, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SAMPLE_BUFFERS, EGL_DONT_CARE, + EGL_SAMPLES, EGL_DONT_CARE, + EGL_NONE}; EGLint major = 0; EGLint minor = 0; @@ -335,24 +327,24 @@ void TizenRenderer::PrintEGLError() { EGLint error = eglGetError(); switch (error) { case EGL_BAD_DISPLAY: { - FT_LOGE("EGL_BAD_DISPLAY : Display is not an EGL display connection\n"); + FT_LOGE("EGL_BAD_DISPLAY : Display is not an EGL display connection"); break; } case EGL_NOT_INITIALIZED: { - FT_LOGE("EGL_NOT_INITIALIZED : Display has not been initialized\n"); + FT_LOGE("EGL_NOT_INITIALIZED : Display has not been initialized"); break; } case EGL_BAD_SURFACE: { - FT_LOGE("EGL_BAD_SURFACE : Draw or read is not an EGL surface\n"); + FT_LOGE("EGL_BAD_SURFACE : Draw or read is not an EGL surface"); break; } case EGL_BAD_CONTEXT: { - FT_LOGE("EGL_BAD_CONTEXT : Context is not an EGL rendering context\n"); + FT_LOGE("EGL_BAD_CONTEXT : Context is not an EGL rendering context"); break; } case EGL_BAD_CONFIG: { FT_LOGE( - "EGL_BAD_CONFIG : Config is not an EGL frame buffer configuration\n"); + "EGL_BAD_CONFIG : Config is not an EGL frame buffer configuration"); break; } case EGL_BAD_MATCH: { @@ -364,54 +356,54 @@ void TizenRenderer::PrintEGLError() { break; } case EGL_BAD_ACCESS: { - FT_LOGE("EGL_BAD_ACCESS : Context is current to some other thread\n"); + FT_LOGE("EGL_BAD_ACCESS : Context is current to some other thread"); break; } case EGL_BAD_NATIVE_PIXMAP: { FT_LOGE( "EGL_BAD_NATIVE_PIXMAP : A native pixmap underlying either draw or " - "read is no longer valid\n"); + "read is no longer valid"); break; } case EGL_BAD_NATIVE_WINDOW: { FT_LOGE( "EGL_BAD_NATIVE_WINDOW : A native window underlying either draw or " - "read is no longer valid\n"); + "read is no longer valid"); break; } case EGL_BAD_CURRENT_SURFACE: { FT_LOGE( "EGL_BAD_CURRENT_SURFACE : The previous context has unflushed " - "commands and the previous surface is no longer valid\n"); + "commands and the previous surface is no longer valid"); break; } case EGL_BAD_ALLOC: { FT_LOGE( "EGL_BAD_ALLOC : Allocation of ancillary buffers for draw or read " "were delayed until eglMakeCurrent is called, and there are not " - "enough resources to allocate them\n"); + "enough resources to allocate them"); break; } case EGL_CONTEXT_LOST: { FT_LOGE( - "EGL_CONTEXT_LOST : If a power management event has occurred. The " + "EGL_CONTEXT_LOST : A power management event has occurred. The " "application must destroy all contexts and reinitialise OpenGL ES " - "state and objects to continue rendering\n"); + "state and objects to continue rendering"); break; } case EGL_BAD_PARAMETER: { - FT_LOGE("Invalid parameter is passed\n"); + FT_LOGE("Invalid parameter is passed"); break; } case EGL_BAD_ATTRIBUTE: { FT_LOGE( "The parameter configAttribs contains an invalid frame buffer " "configuration attribute or an attribute value that is unrecognized " - "or out of range\n"); + "or out of range"); break; } default: { - FT_LOGE("Unknown error with code: %d\n", error); + FT_LOGE("Unknown error with code: %d", error); break; } } diff --git a/shell/platform/tizen/tizen_renderer.h b/shell/platform/tizen/tizen_renderer.h index 56ddfa361bb10..83640fe9b112a 100644 --- a/shell/platform/tizen/tizen_renderer.h +++ b/shell/platform/tizen/tizen_renderer.h @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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. @@ -7,6 +6,7 @@ #define EMBEDDER_TIZEN_RENDERER_H #include + class TizenRenderer { public: struct TizenWindowGeometry { diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl.cc b/shell/platform/tizen/tizen_renderer_ecore_wl.cc index 58fd5a95009f0..97e4fa81ba8fd 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl.cc +++ b/shell/platform/tizen/tizen_renderer_ecore_wl.cc @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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. diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl.h b/shell/platform/tizen/tizen_renderer_ecore_wl.h index 80a02b2c59387..727d11d0dfdc0 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl.h +++ b/shell/platform/tizen/tizen_renderer_ecore_wl.h @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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. diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc index 35f20ff2ed895..9fac5f254f3e6 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl2.cc +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.cc @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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. diff --git a/shell/platform/tizen/tizen_renderer_ecore_wl2.h b/shell/platform/tizen/tizen_renderer_ecore_wl2.h index df5cc1593d95e..c8bb7ea606d33 100644 --- a/shell/platform/tizen/tizen_renderer_ecore_wl2.h +++ b/shell/platform/tizen/tizen_renderer_ecore_wl2.h @@ -1,5 +1,4 @@ // Copyright 2020 Samsung Electronics Co., Ltd. All rights reserved. -// 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.