diff --git a/shell/platform/tizen/BUILD.gn b/shell/platform/tizen/BUILD.gn index 7ba6921815728..800800582e2ec 100644 --- a/shell/platform/tizen/BUILD.gn +++ b/shell/platform/tizen/BUILD.gn @@ -115,6 +115,7 @@ template("embedder") { "channels/settings_channel.cc", "channels/text_input_channel.cc", "channels/window_channel.cc", + "external_texture_pixel_evas_gl.cc", "external_texture_surface_evas_gl.cc", "flutter_project_bundle.cc", "flutter_tizen.cc", @@ -160,10 +161,7 @@ template("embedder") { "evas", "feedback", "tbm", - "tdm-client", "wayland-client", - "EGL", - "GLESv2", ] if (target_name == "flutter_tizen_common") { @@ -189,6 +187,7 @@ template("embedder") { if (target_name != "flutter_tizen_wearable") { sources += [ + "external_texture_pixel_egl.cc", "external_texture_surface_egl.cc", "tizen_renderer_egl.cc", "tizen_vsync_waiter.cc", @@ -197,7 +196,10 @@ template("embedder") { libs += [ "ecore_wl2", + "tdm-client", "tizen-extension-client", + "EGL", + "GLESv2", ] } diff --git a/shell/platform/tizen/external_texture_pixel_egl.cc b/shell/platform/tizen/external_texture_pixel_egl.cc new file mode 100644 index 0000000000000..997c5cb3d2b54 --- /dev/null +++ b/shell/platform/tizen/external_texture_pixel_egl.cc @@ -0,0 +1,70 @@ +// 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 "external_texture_pixel_egl.h" + +#include +#include +#include + +namespace flutter { + +bool ExternalTexturePixelEGL::PopulateTexture( + size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) { + if (!CopyPixelBuffer(width, height)) { + return false; + } + + // Populate the texture object used by the engine. + opengl_texture->target = GL_TEXTURE_2D; + opengl_texture->name = state_->gl_texture; + opengl_texture->format = GL_RGBA8; + opengl_texture->destruction_callback = nullptr; + opengl_texture->user_data = nullptr; + opengl_texture->width = width; + opengl_texture->height = height; + return true; +} + +ExternalTexturePixelEGL::ExternalTexturePixelEGL( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data) + : ExternalTexture(), + texture_callback_(texture_callback), + user_data_(user_data) {} + +bool ExternalTexturePixelEGL::CopyPixelBuffer(size_t& width, size_t& height) { + if (!texture_callback_) { + return false; + } + + const FlutterDesktopPixelBuffer* pixel_buffer = + texture_callback_(width, height, user_data_); + + if (!pixel_buffer || !pixel_buffer->buffer) { + return false; + } + + width = pixel_buffer->width; + height = pixel_buffer->height; + + if (state_->gl_texture == 0) { + glGenTextures(1, static_cast(&state_->gl_texture)); + glBindTexture(GL_TEXTURE_2D, static_cast(state_->gl_texture)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glBindTexture(GL_TEXTURE_2D, static_cast(state_->gl_texture)); + } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer); + return true; +} + +} // namespace flutter diff --git a/shell/platform/tizen/external_texture_pixel_egl.h b/shell/platform/tizen/external_texture_pixel_egl.h new file mode 100644 index 0000000000000..16260b4190a80 --- /dev/null +++ b/shell/platform/tizen/external_texture_pixel_egl.h @@ -0,0 +1,35 @@ +// 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_EXTERNAL_TEXTURE_PIXEL_EGL_H +#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EGL_H + +#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" +#include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/tizen/external_texture.h" + +namespace flutter { + +class ExternalTexturePixelEGL : public ExternalTexture { + public: + ExternalTexturePixelEGL( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data); + + ~ExternalTexturePixelEGL() = default; + + bool PopulateTexture(size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) override; + + bool CopyPixelBuffer(size_t& width, size_t& height); + + private: + FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; + void* user_data_ = nullptr; +}; + +} // namespace flutter + +#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EGL_H diff --git a/shell/platform/tizen/external_texture_pixel_evas_gl.cc b/shell/platform/tizen/external_texture_pixel_evas_gl.cc new file mode 100644 index 0000000000000..10a68a0080c3f --- /dev/null +++ b/shell/platform/tizen/external_texture_pixel_evas_gl.cc @@ -0,0 +1,71 @@ +// 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 "external_texture_pixel_evas_gl.h" + +#include "tizen_evas_gl_helper.h" +extern Evas_GL* g_evas_gl; +EVAS_GL_GLOBAL_GLES2_DECLARE(); + +namespace flutter { + +bool ExternalTexturePixelEvasGL::PopulateTexture( + size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) { + if (!CopyPixelBuffer(width, height)) { + return false; + } + + // Populate the texture object used by the engine. + opengl_texture->target = GL_TEXTURE_2D; + opengl_texture->name = state_->gl_texture; + opengl_texture->format = GL_RGBA8; + opengl_texture->destruction_callback = nullptr; + opengl_texture->user_data = nullptr; + opengl_texture->width = width; + opengl_texture->height = height; + return true; +} + +ExternalTexturePixelEvasGL::ExternalTexturePixelEvasGL( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data) + : ExternalTexture(), + texture_callback_(texture_callback), + user_data_(user_data) {} + +bool ExternalTexturePixelEvasGL::CopyPixelBuffer(size_t& width, + size_t& height) { + if (!texture_callback_) { + return false; + } + + const FlutterDesktopPixelBuffer* pixel_buffer = + texture_callback_(width, height, user_data_); + + if (!pixel_buffer || !pixel_buffer->buffer) { + return false; + } + + width = pixel_buffer->width; + height = pixel_buffer->height; + + if (state_->gl_texture == 0) { + glGenTextures(1, static_cast(&state_->gl_texture)); + glBindTexture(GL_TEXTURE_2D, static_cast(state_->gl_texture)); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glBindTexture(GL_TEXTURE_2D, static_cast(state_->gl_texture)); + } + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer); + return true; +} + +} // namespace flutter diff --git a/shell/platform/tizen/external_texture_pixel_evas_gl.h b/shell/platform/tizen/external_texture_pixel_evas_gl.h new file mode 100644 index 0000000000000..49fd2460df094 --- /dev/null +++ b/shell/platform/tizen/external_texture_pixel_evas_gl.h @@ -0,0 +1,35 @@ +// 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_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_H +#define EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_H + +#include "flutter/shell/platform/common/public/flutter_texture_registrar.h" +#include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/tizen/external_texture.h" + +namespace flutter { + +class ExternalTexturePixelEvasGL : public ExternalTexture { + public: + ExternalTexturePixelEvasGL( + FlutterDesktopPixelBufferTextureCallback texture_callback, + void* user_data); + + ~ExternalTexturePixelEvasGL() = default; + + bool PopulateTexture(size_t width, + size_t height, + FlutterOpenGLTexture* opengl_texture) override; + + bool CopyPixelBuffer(size_t& width, size_t& height); + + private: + FlutterDesktopPixelBufferTextureCallback texture_callback_ = nullptr; + void* user_data_ = nullptr; +}; + +} // namespace flutter + +#endif // EMBEDDER_EXTERNAL_TEXTURE_PIXEL_EVAS_GL_H diff --git a/shell/platform/tizen/flutter_tizen_texture_registrar.cc b/shell/platform/tizen/flutter_tizen_texture_registrar.cc index 628af06ff597c..830641538e3d1 100644 --- a/shell/platform/tizen/flutter_tizen_texture_registrar.cc +++ b/shell/platform/tizen/flutter_tizen_texture_registrar.cc @@ -8,8 +8,10 @@ #include #ifndef WEARABLE_PROFILE +#include "flutter/shell/platform/tizen/external_texture_pixel_egl.h" #include "flutter/shell/platform/tizen/external_texture_surface_egl.h" #endif +#include "flutter/shell/platform/tizen/external_texture_pixel_evas_gl.h" #include "flutter/shell/platform/tizen/external_texture_surface_evas_gl.h" #include "flutter/shell/platform/tizen/flutter_tizen_engine.h" #include "flutter/shell/platform/tizen/logger.h" @@ -102,8 +104,18 @@ FlutterTizenTextureRegistrar::CreateExternalTexture( FlutterDesktopRendererType renderer_type) { switch (texture_info->type) { case kFlutterDesktopPixelBufferTexture: - FT_UNIMPLEMENTED(); + if (renderer_type == FlutterDesktopRendererType::kEvasGL) { + return std::make_unique( + texture_info->pixel_buffer_config.callback, + texture_info->pixel_buffer_config.user_data); + } +#ifndef WEARABLE_PROFILE + return std::make_unique( + texture_info->pixel_buffer_config.callback, + texture_info->pixel_buffer_config.user_data); +#else return nullptr; +#endif case kFlutterDesktopGpuBufferTexture: ExternalTextureExtensionType gl_extension = ExternalTextureExtensionType::kNone; @@ -115,7 +127,7 @@ FlutterTizenTextureRegistrar::CreateExternalTexture( "EGL_EXT_image_dma_buf_import")) { gl_extension = ExternalTextureExtensionType::kDmaBuffer; } - if (FlutterDesktopRendererType::kEvasGL == renderer_type) { + if (renderer_type == FlutterDesktopRendererType::kEvasGL) { return std::make_unique( gl_extension, texture_info->gpu_buffer_config.callback, texture_info->gpu_buffer_config.user_data);