diff --git a/shell/platform/common/client_wrapper/core_implementations.cc b/shell/platform/common/client_wrapper/core_implementations.cc index 78efc6b3ad92b..cd64c3ba80d47 100644 --- a/shell/platform/common/client_wrapper/core_implementations.cc +++ b/shell/platform/common/client_wrapper/core_implementations.cc @@ -184,11 +184,6 @@ int64_t TextureRegistrarImpl::RegisterTexture(TextureVariant* texture) { return buffer; }; - info.gpu_buffer_config.destruction_callback = [](void* user_data) -> void { - auto texture = static_cast(user_data); - texture->Destruct(); - }; - int64_t texture_id = FlutterDesktopTextureRegistrarRegisterExternalTexture( texture_registrar_ref_, &info); return texture_id; diff --git a/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h index 0bc31d06bce16..1001dd2a0a71a 100644 --- a/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/client_wrapper/include/flutter/texture_registrar.h @@ -50,37 +50,23 @@ class GpuBufferTexture { size_t height)> ObtainGpuBufferCallback; - typedef std::function DestructGpuBufferCallback; - // Creates a gpu buffer texture that uses the provided |obtain_buffer_cb| to // retrieve the buffer. // As the callback is usually invoked from the render thread, the callee must // take care of proper synchronization. It also needs to be ensured that the // returned buffer isn't released prior to unregistering this texture. - GpuBufferTexture(ObtainGpuBufferCallback obtain_buffer_callback, - DestructGpuBufferCallback destruction_callback) - : obtain_gpu_buffer_callback_(obtain_buffer_callback), - destruct_gpu_buffer_callback_(destruction_callback), - buffer_(nullptr) {} + GpuBufferTexture(ObtainGpuBufferCallback obtain_buffer_callback) + : obtain_gpu_buffer_callback_(obtain_buffer_callback) {} // Returns the callback-provided FlutterDesktopGpuBuffer that contains the // actual gpu buffer pointer. The intended surface size is specified by // |width| and |height|. const FlutterDesktopGpuBuffer* ObtainGpuBuffer(size_t width, size_t height) { - const FlutterDesktopGpuBuffer* flutter_buffer = - obtain_gpu_buffer_callback_(width, height); - if (flutter_buffer) { - buffer_ = const_cast(flutter_buffer->buffer); - } - return flutter_buffer; + return obtain_gpu_buffer_callback_(width, height); } - void Destruct() { destruct_gpu_buffer_callback_(buffer_); } - private: const ObtainGpuBufferCallback obtain_gpu_buffer_callback_; - const DestructGpuBufferCallback destruct_gpu_buffer_callback_; - void* buffer_; }; // The available texture variants. diff --git a/shell/platform/common/public/flutter_texture_registrar.h b/shell/platform/common/public/flutter_texture_registrar.h index a4b4debe5f777..f3b47127e7a8d 100644 --- a/shell/platform/common/public/flutter_texture_registrar.h +++ b/shell/platform/common/public/flutter_texture_registrar.h @@ -50,6 +50,10 @@ typedef struct { size_t width; // Height of the gpu buffer. size_t height; + // An optional callback that gets invoked when the |buffer| can be released. + void (*release_callback)(void* release_context); + // Opaque data passed to |release_callback|. + void* release_context; } FlutterDesktopGpuBuffer; // The pixel buffer copy callback definition provided to @@ -71,8 +75,6 @@ typedef const FlutterDesktopGpuBuffer* ( size_t height, void* user_data); -typedef void (*FlutterDesktopGpuBufferDestructionCallback)(void* user_data); - // An object used to configure pixel buffer textures. typedef struct { // The callback used by the engine to copy the pixel buffer object. @@ -85,17 +87,15 @@ typedef struct { typedef struct { // The callback used by the engine to obtain the GPU buffer object. FlutterDesktopGpuBufferTextureCallback callback; - // The callback used by the engine to destruct the GPU buffer object. - FlutterDesktopGpuBufferDestructionCallback destruction_callback; // Opaque data that will get passed to the provided |callback|. void* user_data; -} FlutterDesktopGPUBufferTextureConfig; +} FlutterDesktopGpuBufferTextureConfig; typedef struct { FlutterDesktopTextureType type; union { FlutterDesktopPixelBufferTextureConfig pixel_buffer_config; - FlutterDesktopGPUBufferTextureConfig gpu_buffer_config; + FlutterDesktopGpuBufferTextureConfig gpu_buffer_config; }; } FlutterDesktopTextureInfo; diff --git a/shell/platform/tizen/external_texture.h b/shell/platform/tizen/external_texture.h index cd4d4e7c90407..4d3f6e913d030 100644 --- a/shell/platform/tizen/external_texture.h +++ b/shell/platform/tizen/external_texture.h @@ -30,7 +30,7 @@ struct ExternalTextureGLState { static std::atomic_long next_texture_id = {1}; // An adaptation class of flutter engine and external texture interface. -class ExternalTexture : public std::enable_shared_from_this { +class ExternalTexture { public: ExternalTexture(ExternalTextureExtensionType gl_extension = ExternalTextureExtensionType::kNone) @@ -46,7 +46,6 @@ class ExternalTexture : public std::enable_shared_from_this { virtual bool PopulateTexture(size_t width, size_t height, FlutterOpenGLTexture* opengl_texture) = 0; - virtual void OnDestruction(){}; protected: std::unique_ptr state_; diff --git a/shell/platform/tizen/external_texture_surface_gl.cc b/shell/platform/tizen/external_texture_surface_gl.cc index 4a36b3c3245ca..83ade4ae823cc 100644 --- a/shell/platform/tizen/external_texture_surface_gl.cc +++ b/shell/platform/tizen/external_texture_surface_gl.cc @@ -34,24 +34,12 @@ EVAS_GL_GLOBAL_GLES3_DECLARE(); namespace flutter { -static void OnCollectTexture(void* textureGL) { - auto* weak_texture = - reinterpret_cast*>(textureGL); - auto strong_texture = weak_texture->lock(); - delete weak_texture; - if (strong_texture) { - strong_texture->OnDestruction(); - } -} - ExternalTextureSurfaceGL::ExternalTextureSurfaceGL( ExternalTextureExtensionType gl_extension, FlutterDesktopGpuBufferTextureCallback texture_callback, - FlutterDesktopGpuBufferDestructionCallback destruction_callback, void* user_data) : ExternalTexture(gl_extension), texture_callback_(texture_callback), - destruction_callback_(destruction_callback), user_data_(user_data) {} ExternalTextureSurfaceGL::~ExternalTextureSurfaceGL() { @@ -77,6 +65,9 @@ bool ExternalTextureSurfaceGL::PopulateTexture( if (!gpu_buffer->buffer) { FT_LOG(Info) << "tbm_surface is null for texture ID: " << texture_id_; + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); + } return false; } const tbm_surface_h tbm_surface = @@ -85,6 +76,9 @@ bool ExternalTextureSurfaceGL::PopulateTexture( tbm_surface_info_s info; if (tbm_surface_get_info(tbm_surface, &info) != TBM_SURFACE_ERROR_NONE) { FT_LOG(Info) << "tbm_surface is invalid for texture ID: " << texture_id_; + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); + } return false; } @@ -98,9 +92,15 @@ bool ExternalTextureSurfaceGL::PopulateTexture( } else if (state_->gl_extension == ExternalTextureExtensionType::kDmaBuffer) { FT_LOG(Error) << "EGL_EXT_image_dma_buf_import is not supported this renderer."; + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); + } return false; } if (!egl_src_image) { + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); + } return false; } if (state_->gl_texture == 0) { @@ -179,6 +179,9 @@ bool ExternalTextureSurfaceGL::PopulateTexture( FT_LOG(Error) << "Either EGL_TIZEN_image_native_surface or " "EGL_EXT_image_dma_buf_import shoule be supported."; } + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); + } return false; } if (state_->gl_texture == 0) { @@ -206,22 +209,17 @@ bool ExternalTextureSurfaceGL::PopulateTexture( n_eglDestroyImageKHR(eglGetCurrentDisplay(), egl_src_image); } #endif - opengl_texture->target = GL_TEXTURE_EXTERNAL_OES; opengl_texture->name = state_->gl_texture; opengl_texture->format = GL_RGBA8; - opengl_texture->destruction_callback = OnCollectTexture; - auto* weak_texture = new std::weak_ptr(shared_from_this()); - opengl_texture->user_data = weak_texture; + opengl_texture->destruction_callback = nullptr; + opengl_texture->user_data = nullptr; opengl_texture->width = width; opengl_texture->height = height; - return true; -} - -void ExternalTextureSurfaceGL::OnDestruction() { - if (destruction_callback_) { - destruction_callback_(user_data_); + if (gpu_buffer->release_callback) { + gpu_buffer->release_callback(gpu_buffer->release_context); } + return true; } } // namespace flutter diff --git a/shell/platform/tizen/external_texture_surface_gl.h b/shell/platform/tizen/external_texture_surface_gl.h index b62fe404158d9..2d66d43aa0208 100644 --- a/shell/platform/tizen/external_texture_surface_gl.h +++ b/shell/platform/tizen/external_texture_surface_gl.h @@ -17,7 +17,6 @@ class ExternalTextureSurfaceGL : public ExternalTexture { ExternalTextureSurfaceGL( ExternalTextureExtensionType gl_extension, FlutterDesktopGpuBufferTextureCallback texture_callback, - FlutterDesktopGpuBufferDestructionCallback destruction_callback, void* user_data); virtual ~ExternalTextureSurfaceGL(); @@ -32,11 +31,9 @@ class ExternalTextureSurfaceGL : public ExternalTexture { bool PopulateTexture(size_t width, size_t height, FlutterOpenGLTexture* opengl_texture) override; - void OnDestruction() override; private: FlutterDesktopGpuBufferTextureCallback texture_callback_ = nullptr; - FlutterDesktopGpuBufferDestructionCallback destruction_callback_ = nullptr; void* user_data_ = nullptr; }; diff --git a/shell/platform/tizen/flutter_tizen_texture_registrar.cc b/shell/platform/tizen/flutter_tizen_texture_registrar.cc index 1e6cbb079ceec..23177b366e9f5 100644 --- a/shell/platform/tizen/flutter_tizen_texture_registrar.cc +++ b/shell/platform/tizen/flutter_tizen_texture_registrar.cc @@ -106,7 +106,6 @@ FlutterTizenTextureRegistrar::CreateExternalTexture( } return std::make_unique( gl_extension, texture_info->gpu_buffer_config.callback, - texture_info->gpu_buffer_config.destruction_callback, texture_info->gpu_buffer_config.user_data); break; } diff --git a/shell/platform/tizen/flutter_tizen_texture_registrar.h b/shell/platform/tizen/flutter_tizen_texture_registrar.h index 7ab3869b97840..2549bc07e30bc 100644 --- a/shell/platform/tizen/flutter_tizen_texture_registrar.h +++ b/shell/platform/tizen/flutter_tizen_texture_registrar.h @@ -52,7 +52,7 @@ class FlutterTizenTextureRegistrar { FlutterTizenEngine* engine_ = nullptr; // All registered textures, keyed by their IDs. - std::unordered_map> textures_; + std::unordered_map> textures_; std::mutex map_mutex_; };