From 08e9d0782e361ca902879c969c0de697601241d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=96=E5=8C=97=E6=8D=B7=E6=99=BA=E4=BA=91=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=9C=89=E9=99=90=E5=85=AC=E5=8F=B8?= Date: Thu, 11 Jul 2019 22:23:52 +0800 Subject: [PATCH 01/26] Add Texture support for GLFW. --- shell/platform/common/cpp/BUILD.gn | 1 + .../common/cpp/client_wrapper/BUILD.gn | 2 + .../include/flutter/event_channel.h | 100 ++++++++++++++++++ .../include/flutter/plugin_registrar.h | 5 + .../include/flutter/texture_registrar.h | 44 ++++++++ .../cpp/client_wrapper/plugin_registrar.cc | 40 +++++++ .../cpp/public/flutter_plugin_registrar.h | 5 + .../cpp/public/flutter_texture_registrar.h | 43 ++++++++ shell/platform/glfw/BUILD.gn | 2 + shell/platform/glfw/external_texture_gl.cc | 66 ++++++++++++ shell/platform/glfw/external_texture_gl.h | 43 ++++++++ shell/platform/glfw/flutter_glfw.cc | 66 ++++++++++++ 12 files changed, 417 insertions(+) create mode 100644 shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h create mode 100644 shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h create mode 100644 shell/platform/common/cpp/public/flutter_texture_registrar.h create mode 100644 shell/platform/glfw/external_texture_gl.cc create mode 100644 shell/platform/glfw/external_texture_gl.h diff --git a/shell/platform/common/cpp/BUILD.gn b/shell/platform/common/cpp/BUILD.gn index 265cb37b906ab..e6624941f0d77 100644 --- a/shell/platform/common/cpp/BUILD.gn +++ b/shell/platform/common/cpp/BUILD.gn @@ -10,6 +10,7 @@ _public_headers = [ "public/flutter_export.h", "public/flutter_messenger.h", "public/flutter_plugin_registrar.h", + "public/flutter_texture_registrar.h", ] # Any files that are built by clients (client_wrapper code, library headers for diff --git a/shell/platform/common/cpp/client_wrapper/BUILD.gn b/shell/platform/common/cpp/client_wrapper/BUILD.gn index 8f79589ba6473..81d3b8181e511 100644 --- a/shell/platform/common/cpp/client_wrapper/BUILD.gn +++ b/shell/platform/common/cpp/client_wrapper/BUILD.gn @@ -10,6 +10,7 @@ _wrapper_includes = [ "include/flutter/binary_messenger.h", "include/flutter/encodable_value.h", "include/flutter/engine_method_result.h", + "include/flutter/event_channel.h", "include/flutter/json_message_codec.h", "include/flutter/json_method_codec.h", "include/flutter/json_type.h", @@ -19,6 +20,7 @@ _wrapper_includes = [ "include/flutter/method_codec.h", "include/flutter/method_result.h", "include/flutter/plugin_registrar.h", + "include/flutter/texture_registrar.h", "include/flutter/standard_message_codec.h", "include/flutter/standard_method_codec.h", ] diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h new file mode 100644 index 0000000000000..27b204fc46a25 --- /dev/null +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h @@ -0,0 +1,100 @@ +// 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 FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ + +#include +#include + +#include "binary_messenger.h" +#include "engine_method_result.h" +#include "message_codec.h" +#include "method_call.h" +#include "method_codec.h" +#include "method_result.h" + +namespace flutter { + +template +using EventSink = std::function; + +template +struct StreamHandler { + std::function *(const T *arguments, + const EventSink *event)> + onListen; + std::function *(const T *arguments)> onCancel; +}; + +template +class EventChannel { + public: + EventChannel(BinaryMessenger *messenger, const std::string &name, + const MethodCodec *codec, + const MessageCodec *message_codec) + : messenger_(messenger), + name_(name), + codec_(codec), + message_code_(message_codec) {} + ~EventChannel() {} + + // Prevent copying. + EventChannel(EventChannel const &) = delete; + EventChannel &operator=(EventChannel const &) = delete; + + void SetStreamHandler(StreamHandler stream_handler) { + stream_handler_ = stream_handler; + const auto message_codec = message_code_; + const auto messenger = messenger_; + std::string channel_name = name_; + EventSink sink = [messenger, channel_name, + message_codec](const T *events) { + std::unique_ptr> message = + message_codec->EncodeMessage(events); + messenger->Send(channel_name, message->data(), message->size()); + }; + + const auto *codec = codec_; + BinaryMessageHandler binary_handler = [&, sink, codec, channel_name]( + const uint8_t *message, + const size_t message_size, + BinaryReply reply) { + auto result = + std::make_unique>(std::move(reply), codec); + std::unique_ptr> method_call = + codec->DecodeMethodCall(message, message_size); + if (!method_call) { + std::cerr << "Unable to construct method call from message on channel " + << channel_name << std::endl; + result->NotImplemented(); + return; + } + if (method_call->method_name().compare("listen") == 0) { + stream_handler_.onListen(method_call->arguments(), &sink); + result->Success(nullptr); + return; + } else if (method_call->method_name().compare("cancel") == 0) { + stream_handler_.onCancel(method_call->arguments()); + result->Success(nullptr); + return; + } else { + result->NotImplemented(); + } + }; + + messenger_->SetMessageHandler(name_, std::move(binary_handler)); + } + + private: + BinaryMessenger *messenger_; + std::string name_; + const MethodCodec *codec_; + const MessageCodec *message_code_; + StreamHandler stream_handler_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h index 5fbe1b5b6297c..c2f8034503355 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h @@ -12,6 +12,7 @@ #include #include "binary_messenger.h" +#include "texture_registrar.h" namespace flutter { @@ -39,6 +40,8 @@ class PluginRegistrar { // // This pointer will remain valid for the lifetime of this instance. BinaryMessenger* messenger() { return messenger_.get(); } + + TextureRegistrar* textures() { return textures_.get(); } // Takes ownership of |plugin|. // @@ -58,6 +61,8 @@ class PluginRegistrar { FlutterDesktopPluginRegistrarRef registrar_; std::unique_ptr messenger_; + + std::unique_ptr textures_; // Plugins registered for ownership. std::set> plugins_; diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h new file mode 100644 index 0000000000000..b710f6fd910ca --- /dev/null +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -0,0 +1,44 @@ +// 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 FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ + +#include + +#include +#include + +namespace flutter { + +class Texture { + public: + virtual ~Texture(){} + + virtual std::shared_ptr CopyTextureBuffer(size_t width, size_t height) = 0; +}; + +class TextureRegistrar { + public: + virtual ~TextureRegistrar() {} + + /** + * Register a |texture| object and return textureId. + */ + virtual int64_t RegisterTexture(Texture *texture) = 0; + + /** + * Mark a texture buffer is ready. + */ + virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; + + /** + * Unregister an existing Texture object. + */ + virtual void UnregisterTexture(int64_t texture_id) = 0; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_TEXTURE_REGISTRAR_H_ diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index 46c117377b22e..b353124c8b69c 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -103,12 +103,52 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel, ForwardToHandler, message_handler); } +// Wrapper around a FlutterDesktopTextureRegistrarRef that implements the +// TextureRegistrar API. +class TextureRegistrarImpl : public TextureRegistrar { + public: + explicit TextureRegistrarImpl(FlutterDesktopTextureRegistrarRef texture_registrar) + : texture_registrar_(texture_registrar) {} + + virtual ~TextureRegistrarImpl() = default; + + // Prevent copying. + TextureRegistrarImpl(TextureRegistrarImpl const&) = delete; + TextureRegistrarImpl& operator=(TextureRegistrarImpl const&) = delete; + + virtual int64_t RegisterTexture(Texture* texture) override { + FlutterTexutreCallback callback = + [](size_t width, size_t height, + void* user_data) -> std::shared_ptr { + return ((Texture*)user_data)->CopyTextureBuffer(width, height); + }; + int64_t texture_id = + FlutterDesktopRegisterExternalTexture(texture_registrar_, callback, texture); + return texture_id; + } + + virtual void MarkTextureFrameAvailable(int64_t texture_id) override { + FlutterDesktopMarkExternalTextureFrameAvailable(texture_registrar_, + texture_id); + } + + virtual void UnregisterTexture(int64_t texture_id) override { + FlutterDesktopUnregisterExternalTexture(texture_registrar_, texture_id); + } + + private: + // Handle for interacting with the C API. + FlutterDesktopTextureRegistrarRef texture_registrar_; +}; + // PluginRegistrar: PluginRegistrar::PluginRegistrar(FlutterDesktopPluginRegistrarRef registrar) : registrar_(registrar) { auto core_messenger = FlutterDesktopRegistrarGetMessenger(registrar_); messenger_ = std::make_unique(core_messenger); + auto texture_registrar = FlutterDesktopGetTextureRegistrar(registrar_); + textures_ = std::make_unique(texture_registrar); } PluginRegistrar::~PluginRegistrar() {} diff --git a/shell/platform/common/cpp/public/flutter_plugin_registrar.h b/shell/platform/common/cpp/public/flutter_plugin_registrar.h index 1caa3cee1f9e4..1cde2eae06008 100644 --- a/shell/platform/common/cpp/public/flutter_plugin_registrar.h +++ b/shell/platform/common/cpp/public/flutter_plugin_registrar.h @@ -10,6 +10,7 @@ #include "flutter_export.h" #include "flutter_messenger.h" +#include "flutter_texture_registrar.h" #if defined(__cplusplus) extern "C" { @@ -22,6 +23,10 @@ typedef struct FlutterDesktopPluginRegistrar* FlutterDesktopPluginRegistrarRef; FLUTTER_EXPORT FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger(FlutterDesktopPluginRegistrarRef registrar); +// Returns the texture registrar associated with this registrar. +FLUTTER_EXPORT FlutterDesktopTextureRegistrarRef +FlutterDesktopGetTextureRegistrar(FlutterDesktopPluginRegistrarRef registrar); + // Enables input blocking on the given channel. // // If set, then the Flutter window will disable input callbacks diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h new file mode 100644 index 0000000000000..9bd6906eb2653 --- /dev/null +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -0,0 +1,43 @@ +// 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 FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ +#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ + +#include +#include +#include + +#include "flutter_export.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +// Opaque reference to a texture registrar. +typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; + +typedef std::shared_ptr (*FlutterTexutreCallback)(size_t width, + size_t height, + void* user_data); + +FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + FlutterTexutreCallback texture_callback, + void* user_data); + +FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id); + +// Mark that a new texture frame is available for a given texture identifier. +FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id); + +#if defined(__cplusplus) +} // extern "C" +#endif + +#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_PUBLIC_FLUTTER_TEXTURE_REGISTRAR_H_ diff --git a/shell/platform/glfw/BUILD.gn b/shell/platform/glfw/BUILD.gn index 95118a7cf6f70..bee5a5db180fd 100644 --- a/shell/platform/glfw/BUILD.gn +++ b/shell/platform/glfw/BUILD.gn @@ -32,6 +32,8 @@ source_set("flutter_glfw_headers") { source_set("flutter_glfw") { sources = [ + "external_texture_gl.h", + "external_texture_gl.cc", "flutter_glfw.cc", "glfw_event_loop.cc", "glfw_event_loop.h", diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc new file mode 100644 index 0000000000000..85bc60e404c5f --- /dev/null +++ b/shell/platform/glfw/external_texture_gl.cc @@ -0,0 +1,66 @@ +// Copyright 2018 Google LLC +// 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 "flutter/shell/platform/glfw/external_texture_gl.h" + +#include "glad/glad.h" +#include "GLFW/glfw3.h" + +namespace flutter { + +static void OnGLBufferRelease(void* user_data) {} + +ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, + void* user_data) + : texture_callback_(texture_callback), user_data_(user_data){ + window_ = glfwGetCurrentContext(); + /*Create offscreen contexts*/ + if (!window_) { + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + window_ = glfwCreateWindow(1, 1, "", NULL, NULL); + glfwMakeContextCurrent(window_); + gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); + } + glGenTextures(1, &glTexture); + glBindTexture(GL_TEXTURE_2D, glTexture); + // set the texture wrapping parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + // set texture filtering parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +} + +ExternalTextureGL::~ExternalTextureGL() { + glDeleteTextures(1, &glTexture); +} + +bool ExternalTextureGL::PopulateTextureWithIdentifier( + size_t width, + size_t height, + FlutterOpenGLTexture* texture) { + if (!texture_callback_) + return false; + std::shared_ptr buffer = + texture_callback_(width, height, user_data_); + if (!buffer) + return false; + /*Fill texture.*/ + { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindTexture(GL_TEXTURE_2D, glTexture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, + GL_UNSIGNED_BYTE, buffer.get()); + glEnable(GL_TEXTURE_2D); + } + texture->target = GL_TEXTURE_2D; + texture->name = glTexture; + texture->format = GL_RGBA8; + texture->destruction_callback = (VoidCallback)&OnGLBufferRelease; + texture->user_data = (void*)this; + return true; +} + +} // namespace flutter diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h new file mode 100644 index 0000000000000..5d0b22dc7948e --- /dev/null +++ b/shell/platform/glfw/external_texture_gl.h @@ -0,0 +1,43 @@ +// 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 FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ +#define FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ + +#include "flutter/shell/platform/embedder/embedder.h" + +#include +#include + +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" +#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" +#include "flutter/shell/platform/glfw/public/flutter_glfw.h" + +typedef unsigned int GLuint; +typedef struct GLFWwindow GLFWwindow; + +namespace flutter { + +class ExternalTextureGL { + public: + ExternalTextureGL(FlutterTexutreCallback texture_callback, + void* user_data); + + virtual ~ExternalTextureGL(); + + int64_t texutre_id() { return reinterpret_cast(this); } + + virtual bool PopulateTextureWithIdentifier(size_t width, + size_t height, + FlutterOpenGLTexture* texture); + private: + FlutterTexutreCallback texture_callback_ = nullptr; + void* user_data_ = nullptr; + GLuint glTexture = 0; + GLFWwindow* window_; +}; + +} // namespace flutter + +#endif // FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 438c93506357c..d1f4277af5d1b 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -13,8 +13,10 @@ #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" #include "flutter/shell/platform/embedder/embedder.h" +#include "flutter/shell/platform/glfw/external_texture_gl.h" #include "flutter/shell/platform/glfw/glfw_event_loop.h" #include "flutter/shell/platform/glfw/key_event_handler.h" #include "flutter/shell/platform/glfw/keyboard_hook_handler.h" @@ -121,10 +123,19 @@ struct FlutterDesktopPluginRegistrar { // The plugin messenger handle given to API clients. std::unique_ptr messenger; + std::unique_ptr texture_registrar; + // The handle for the window associated with this registrar. FlutterDesktopWindow* window; }; +// State associated with the texture registrar. +struct FlutterDesktopTextureRegistrar { + FlutterEngine engine; + // The texture registrar managing external texture adapters. + std::map> textures; +}; + // State associated with the messenger used to communicate with the engine. struct FlutterDesktopMessenger { // The Flutter engine this messenger sends outgoing messages to. @@ -482,6 +493,17 @@ static void* GLFWProcResolver(void* user_data, const char* name) { return reinterpret_cast(glfwGetProcAddress(name)); } +static bool OnAcquireExternalTexture(void* user_data, + int64_t texture_id, + size_t width, + size_t height, + FlutterOpenGLTexture* texture) { + GLFWwindow* window = reinterpret_cast(user_data); + auto state = GetSavedWindowState(window); + return state->plugin_registrar->texture_registrar->textures[texture_id]->PopulateTextureWithIdentifier( + width, height, texture); +} + static void GLFWErrorCallback(int error_code, const char* description) { std::cerr << "GLFW error " << error_code << ": " << description << std::endl; } @@ -526,6 +548,8 @@ static FlutterEngine RunFlutterEngine( config.open_gl.fbo_callback = GLFWGetActiveFbo; config.open_gl.make_resource_current = GLFWMakeResourceContextCurrent; config.open_gl.gl_proc_resolver = GLFWProcResolver; + config.open_gl.gl_external_texture_frame_callback = + OnAcquireExternalTexture; } FlutterProjectArgs args = {}; args.struct_size = sizeof(FlutterProjectArgs); @@ -636,6 +660,11 @@ FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow( state->plugin_registrar->messenger = std::move(messenger); state->plugin_registrar->window = state->window_wrapper.get(); + std::unique_ptr textures = + std::make_unique(); + textures->engine = state->engine; + state->plugin_registrar->texture_registrar = std::move(textures); + state->internal_plugin_registrar = std::make_unique(state->plugin_registrar.get()); @@ -805,6 +834,11 @@ FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger( return registrar->messenger.get(); } +FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + return registrar->texture_registrar.get(); +} + FlutterDesktopWindowRef FlutterDesktopRegistrarGetWindow( FlutterDesktopPluginRegistrarRef registrar) { return registrar->window; @@ -839,3 +873,35 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, void* user_data) { messenger->dispatcher->SetMessageCallback(channel, callback, user_data); } + +int64_t FlutterDesktopRegisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + FlutterTexutreCallback texture_callback, + void* user_data) { + std::unique_ptr texture_gl( + new flutter::ExternalTextureGL(texture_callback, user_data)); + int64_t texture_id = texture_gl->texutre_id(); + texture_registrar->textures[texture_id] = std::move(texture_gl); + if (FlutterEngineRegisterExternalTexture(texture_registrar->engine, + texture_id) == kSuccess) { + return texture_id; + } + return -1; +} + +bool FlutterDesktopUnregisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + auto it = texture_registrar->textures.find(texture_id); + if (it != texture_registrar->textures.end()) + texture_registrar->textures.erase(it); + return (FlutterEngineUnregisterExternalTexture(texture_registrar->engine, + texture_id) == kSuccess); +} + +bool FlutterDesktopMarkExternalTextureFrameAvailable( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + return (FlutterEngineMarkExternalTextureFrameAvailable( + texture_registrar->engine, texture_id) == kSuccess); +} \ No newline at end of file From 0af9192c846c3e292beb0372cc92bb06915e8bcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=96=E5=8C=97=E6=8D=B7=E6=99=BA=E4=BA=91=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=9C=89=E9=99=90=E5=85=AC=E5=8F=B8?= Date: Sat, 13 Jul 2019 01:08:05 +0800 Subject: [PATCH 02/26] Fixed EventChannel for embedder. - Add Success and Error handler for EventSink. - Send Event message or error using MethodCodec. --- .../include/flutter/event_channel.h | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h index 27b204fc46a25..acd0b0a34e34b 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h @@ -18,12 +18,26 @@ namespace flutter { template -using EventSink = std::function; +using SuccessHandler = + std::function; + +template +using ErrorHandler = +std::function; + +template +struct EventSink { + SuccessHandler Success; + ErrorHandler Error; +}; template struct StreamHandler { std::function *(const T *arguments, - const EventSink *event)> + const EventSink *event_sink)> onListen; std::function *(const T *arguments)> onCancel; }; @@ -32,12 +46,10 @@ template class EventChannel { public: EventChannel(BinaryMessenger *messenger, const std::string &name, - const MethodCodec *codec, - const MessageCodec *message_codec) + const MethodCodec *codec) : messenger_(messenger), name_(name), - codec_(codec), - message_code_(message_codec) {} + codec_(codec){} ~EventChannel() {} // Prevent copying. @@ -46,18 +58,29 @@ class EventChannel { void SetStreamHandler(StreamHandler stream_handler) { stream_handler_ = stream_handler; - const auto message_codec = message_code_; const auto messenger = messenger_; std::string channel_name = name_; - EventSink sink = [messenger, channel_name, - message_codec](const T *events) { - std::unique_ptr> message = - message_codec->EncodeMessage(events); - messenger->Send(channel_name, message->data(), message->size()); + const auto* codec = codec_; + + EventSink event_sink = {}; + + event_sink.Success = [messenger, channel_name, codec](const T* events) { + std::unique_ptr> message = + codec->EncodeSuccessEnvelope(events); + messenger->Send(channel_name, message->data(), message->size()); + }; + + event_sink.Error = [messenger, channel_name, codec]( + const std::string& errorCode, + const std::string& errorMessage, + const T* errorDetails) { + std::unique_ptr> message = + codec->EncodeErrorEnvelope(errorCode, errorMessage, + errorDetails); + messenger->Send(channel_name, message->data(), message->size()); }; - const auto *codec = codec_; - BinaryMessageHandler binary_handler = [&, sink, codec, channel_name]( + BinaryMessageHandler binary_handler = [&, event_sink, codec, channel_name]( const uint8_t *message, const size_t message_size, BinaryReply reply) { @@ -72,7 +95,7 @@ class EventChannel { return; } if (method_call->method_name().compare("listen") == 0) { - stream_handler_.onListen(method_call->arguments(), &sink); + stream_handler_.onListen(method_call->arguments(), &event_sink); result->Success(nullptr); return; } else if (method_call->method_name().compare("cancel") == 0) { @@ -91,7 +114,6 @@ class EventChannel { BinaryMessenger *messenger_; std::string name_; const MethodCodec *codec_; - const MessageCodec *message_code_; StreamHandler stream_handler_; }; From bfb06c2c402e4d62df577c37326e631b07482278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=96=E5=8C=97=E6=8D=B7=E6=99=BA=E4=BA=91=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=9C=89=E9=99=90=E5=85=AC=E5=8F=B8?= Date: Sat, 13 Jul 2019 01:15:33 +0800 Subject: [PATCH 03/26] Fixed compiler error for stub_flutter_api.cc. --- .../testing/stub_flutter_api.cc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc index 55f4100b72efb..a48858fc5b299 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc @@ -44,6 +44,30 @@ FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger( return reinterpret_cast(1); } +FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + return reinterpret_cast(1); + } + +int64_t FlutterDesktopRegisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + FlutterTexutreCallback texture_callback, + void* user_data) { + return -1; + } + + bool FlutterDesktopUnregisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + return false; + } + + bool FlutterDesktopMarkExternalTextureFrameAvailable( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + return false; + } + void FlutterDesktopRegistrarEnableInputBlocking( FlutterDesktopPluginRegistrarRef registrar, const char* channel) { From d6529fb6cd50cd94fa3679628eed9695af733c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=96=E5=8C=97=E6=8D=B7=E6=99=BA=E4=BA=91=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=9C=89=E9=99=90=E5=85=AC=E5=8F=B8?= Date: Sat, 13 Jul 2019 01:19:58 +0800 Subject: [PATCH 04/26] Update texture registrar for glfw. - Add GLFWPixelBuffer to manage Texture buffer copy. - Remove unnecessary offscreen context in ExternalTextureGL. - Create GL_TEXTURE_2D Texture using the height and width of GLFWPixelBuffer. --- .../include/flutter/plugin_registrar.h | 1 + .../include/flutter/texture_registrar.h | 2 +- .../cpp/client_wrapper/plugin_registrar.cc | 2 +- .../cpp/public/flutter_texture_registrar.h | 10 ++- shell/platform/glfw/external_texture_gl.cc | 61 +++++++++++-------- shell/platform/glfw/external_texture_gl.h | 5 +- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h index c2f8034503355..2262c07a64c60 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h @@ -10,6 +10,7 @@ #include #include +#include #include "binary_messenger.h" #include "texture_registrar.h" diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index b710f6fd910ca..bb6b17feab2f0 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -16,7 +16,7 @@ class Texture { public: virtual ~Texture(){} - virtual std::shared_ptr CopyTextureBuffer(size_t width, size_t height) = 0; + virtual std::shared_ptr CopyTextureBuffer(size_t width, size_t height) = 0; }; class TextureRegistrar { diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index b353124c8b69c..9ece20d72031e 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -119,7 +119,7 @@ class TextureRegistrarImpl : public TextureRegistrar { virtual int64_t RegisterTexture(Texture* texture) override { FlutterTexutreCallback callback = [](size_t width, size_t height, - void* user_data) -> std::shared_ptr { + void* user_data) -> std::shared_ptr { return ((Texture*)user_data)->CopyTextureBuffer(width, height); }; int64_t texture_id = diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 9bd6906eb2653..08b6192736318 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -18,9 +18,13 @@ extern "C" { // Opaque reference to a texture registrar. typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; -typedef std::shared_ptr (*FlutterTexutreCallback)(size_t width, - size_t height, - void* user_data); +struct GLFWPixelBuffer { + std::shared_ptr buffer; + size_t width; + size_t height; +}; + +typedef std::shared_ptr (*FlutterTexutreCallback)(size_t width, size_t height, void* user_data); FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 85bc60e404c5f..3302864beebbc 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -14,45 +14,56 @@ static void OnGLBufferRelease(void* user_data) {} ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) - : texture_callback_(texture_callback), user_data_(user_data){ - window_ = glfwGetCurrentContext(); - /*Create offscreen contexts*/ - if (!window_) { - glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); - window_ = glfwCreateWindow(1, 1, "", NULL, NULL); - glfwMakeContextCurrent(window_); - gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); - } - glGenTextures(1, &glTexture); - glBindTexture(GL_TEXTURE_2D, glTexture); - // set the texture wrapping parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - // set texture filtering parameters - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + : texture_callback_(texture_callback), + user_data_(user_data) { } ExternalTextureGL::~ExternalTextureGL() { - glDeleteTextures(1, &glTexture); + if(glTexture!=0) + glDeleteTextures(1, &glTexture); } bool ExternalTextureGL::PopulateTextureWithIdentifier( size_t width, size_t height, FlutterOpenGLTexture* texture) { - if (!texture_callback_) - return false; - std::shared_ptr buffer = + + if (!window_) { + window_ = glfwGetCurrentContext(); + if (window_) { + glfwMakeContextCurrent(window_); + gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); + } + } else { + glfwMakeContextCurrent(window_); + } + + if(!window_) return false; + + std::shared_ptr pixel_buffer = texture_callback_(width, height, user_data_); - if (!buffer) - return false; + + if (!pixel_buffer.get()) return false; + + if (glTexture == 0) { + glGenTextures(1, &glTexture); + glBindTexture(GL_TEXTURE_2D, glTexture); + // set the texture wrapping parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); + // set texture filtering parameters + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + /*Fill texture.*/ { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, glTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, - GL_UNSIGNED_BYTE, buffer.get()); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, + GL_RGBA, + GL_UNSIGNED_BYTE, pixel_buffer->buffer.get()); glEnable(GL_TEXTURE_2D); } texture->target = GL_TEXTURE_2D; diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 5d0b22dc7948e..e77c10118964a 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -21,8 +21,7 @@ namespace flutter { class ExternalTextureGL { public: - ExternalTextureGL(FlutterTexutreCallback texture_callback, - void* user_data); + ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data); virtual ~ExternalTextureGL(); @@ -35,7 +34,7 @@ class ExternalTextureGL { FlutterTexutreCallback texture_callback_ = nullptr; void* user_data_ = nullptr; GLuint glTexture = 0; - GLFWwindow* window_; + GLFWwindow* window_ = nullptr; }; } // namespace flutter From 689f6e662ae84f5b3bcc0e371264c8373cd497d7 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sat, 13 Jul 2019 22:22:08 +0800 Subject: [PATCH 05/26] clang format. --- .../include/flutter/event_channel.h | 42 ++++++++----------- .../include/flutter/texture_registrar.h | 39 ++++++++--------- .../cpp/client_wrapper/plugin_registrar.cc | 7 ++-- .../cpp/public/flutter_texture_registrar.h | 15 ++++--- shell/platform/glfw/external_texture_gl.cc | 25 ++++------- shell/platform/glfw/external_texture_gl.h | 4 +- shell/platform/glfw/flutter_glfw.cc | 11 ++--- 7 files changed, 64 insertions(+), 79 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h index acd0b0a34e34b..8e5f8c4b5d86d 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h @@ -18,20 +18,17 @@ namespace flutter { template -using SuccessHandler = - std::function; +using SuccessHandler = std::function; template using ErrorHandler = -std::function; + std::function; template struct EventSink { - SuccessHandler Success; - ErrorHandler Error; + SuccessHandler Success; + ErrorHandler Error; }; template @@ -47,9 +44,7 @@ class EventChannel { public: EventChannel(BinaryMessenger *messenger, const std::string &name, const MethodCodec *codec) - : messenger_(messenger), - name_(name), - codec_(codec){} + : messenger_(messenger), name_(name), codec_(codec) {} ~EventChannel() {} // Prevent copying. @@ -60,24 +55,23 @@ class EventChannel { stream_handler_ = stream_handler; const auto messenger = messenger_; std::string channel_name = name_; - const auto* codec = codec_; - + const auto *codec = codec_; + EventSink event_sink = {}; - event_sink.Success = [messenger, channel_name, codec](const T* events) { - std::unique_ptr> message = - codec->EncodeSuccessEnvelope(events); - messenger->Send(channel_name, message->data(), message->size()); + event_sink.Success = [messenger, channel_name, codec](const T *events) { + std::unique_ptr> message = + codec->EncodeSuccessEnvelope(events); + messenger->Send(channel_name, message->data(), message->size()); }; event_sink.Error = [messenger, channel_name, codec]( - const std::string& errorCode, - const std::string& errorMessage, - const T* errorDetails) { - std::unique_ptr> message = - codec->EncodeErrorEnvelope(errorCode, errorMessage, - errorDetails); - messenger->Send(channel_name, message->data(), message->size()); + const std::string &errorCode, + const std::string &errorMessage, + const T *errorDetails) { + std::unique_ptr> message = + codec->EncodeErrorEnvelope(errorCode, errorMessage, errorDetails); + messenger->Send(channel_name, message->data(), message->size()); }; BinaryMessageHandler binary_handler = [&, event_sink, codec, channel_name]( diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index bb6b17feab2f0..782f512f4be90 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -7,36 +7,37 @@ #include -#include #include +#include namespace flutter { class Texture { public: - virtual ~Texture(){} - - virtual std::shared_ptr CopyTextureBuffer(size_t width, size_t height) = 0; + virtual ~Texture() {} + + virtual std::shared_ptr CopyTextureBuffer(size_t width, + size_t height) = 0; }; class TextureRegistrar { public: virtual ~TextureRegistrar() {} - - /** - * Register a |texture| object and return textureId. - */ - virtual int64_t RegisterTexture(Texture *texture) = 0; - - /** - * Mark a texture buffer is ready. - */ - virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; - - /** - * Unregister an existing Texture object. - */ - virtual void UnregisterTexture(int64_t texture_id) = 0; + + /** + * Register a |texture| object and return textureId. + */ + virtual int64_t RegisterTexture(Texture *texture) = 0; + + /** + * Mark a texture buffer is ready. + */ + virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; + + /** + * Unregister an existing Texture object. + */ + virtual void UnregisterTexture(int64_t texture_id) = 0; }; } // namespace flutter diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index 9ece20d72031e..ef51efe04824d 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -107,7 +107,8 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel, // TextureRegistrar API. class TextureRegistrarImpl : public TextureRegistrar { public: - explicit TextureRegistrarImpl(FlutterDesktopTextureRegistrarRef texture_registrar) + explicit TextureRegistrarImpl( + FlutterDesktopTextureRegistrarRef texture_registrar) : texture_registrar_(texture_registrar) {} virtual ~TextureRegistrarImpl() = default; @@ -122,8 +123,8 @@ class TextureRegistrarImpl : public TextureRegistrar { void* user_data) -> std::shared_ptr { return ((Texture*)user_data)->CopyTextureBuffer(width, height); }; - int64_t texture_id = - FlutterDesktopRegisterExternalTexture(texture_registrar_, callback, texture); + int64_t texture_id = FlutterDesktopRegisterExternalTexture( + texture_registrar_, callback, texture); return texture_id; } diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 08b6192736318..c9b4c3e837b31 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -16,7 +16,8 @@ extern "C" { #endif // Opaque reference to a texture registrar. -typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; +typedef struct FlutterDesktopTextureRegistrar* + FlutterDesktopTextureRegistrarRef; struct GLFWPixelBuffer { std::shared_ptr buffer; @@ -24,21 +25,19 @@ struct GLFWPixelBuffer { size_t height; }; -typedef std::shared_ptr (*FlutterTexutreCallback)(size_t width, size_t height, void* user_data); +typedef std::shared_ptr (*FlutterTexutreCallback)( + size_t width, size_t height, void* user_data); FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, - void* user_data); + FlutterTexutreCallback texture_callback, void* user_data); FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id); + FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); // Mark that a new texture frame is available for a given texture identifier. FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id); + FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); #if defined(__cplusplus) } // extern "C" diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 3302864beebbc..d7cc0e7179dc2 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -5,8 +5,8 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" -#include "glad/glad.h" #include "GLFW/glfw3.h" +#include "glad/glad.h" namespace flutter { @@ -14,20 +14,14 @@ static void OnGLBufferRelease(void* user_data) {} ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) - : texture_callback_(texture_callback), - user_data_(user_data) { -} + : texture_callback_(texture_callback), user_data_(user_data) {} ExternalTextureGL::~ExternalTextureGL() { - if(glTexture!=0) - glDeleteTextures(1, &glTexture); + if (glTexture != 0) glDeleteTextures(1, &glTexture); } bool ExternalTextureGL::PopulateTextureWithIdentifier( - size_t width, - size_t height, - FlutterOpenGLTexture* texture) { - + size_t width, size_t height, FlutterOpenGLTexture* texture) { if (!window_) { window_ = glfwGetCurrentContext(); if (window_) { @@ -38,13 +32,13 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( glfwMakeContextCurrent(window_); } - if(!window_) return false; - + if (!window_) return false; + std::shared_ptr pixel_buffer = texture_callback_(width, height, user_data_); if (!pixel_buffer.get()) return false; - + if (glTexture == 0) { glGenTextures(1, &glTexture); glBindTexture(GL_TEXTURE_2D, glTexture); @@ -61,9 +55,8 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, glTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, - pixel_buffer->height, 0, - GL_RGBA, - GL_UNSIGNED_BYTE, pixel_buffer->buffer.get()); + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer.get()); glEnable(GL_TEXTURE_2D); } texture->target = GL_TEXTURE_2D; diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index e77c10118964a..45cea01e6ad03 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -27,9 +27,9 @@ class ExternalTextureGL { int64_t texutre_id() { return reinterpret_cast(this); } - virtual bool PopulateTextureWithIdentifier(size_t width, - size_t height, + virtual bool PopulateTextureWithIdentifier(size_t width, size_t height, FlutterOpenGLTexture* texture); + private: FlutterTexutreCallback texture_callback_ = nullptr; void* user_data_ = nullptr; diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index d1f4277af5d1b..09bb3f1ff708f 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -876,8 +876,7 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, - void* user_data) { + FlutterTexutreCallback texture_callback, void* user_data) { std::unique_ptr texture_gl( new flutter::ExternalTextureGL(texture_callback, user_data)); int64_t texture_id = texture_gl->texutre_id(); @@ -890,8 +889,7 @@ int64_t FlutterDesktopRegisterExternalTexture( } bool FlutterDesktopUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { auto it = texture_registrar->textures.find(texture_id); if (it != texture_registrar->textures.end()) texture_registrar->textures.erase(it); @@ -900,8 +898,7 @@ bool FlutterDesktopUnregisterExternalTexture( } bool FlutterDesktopMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { return (FlutterEngineMarkExternalTextureFrameAvailable( texture_registrar->engine, texture_id) == kSuccess); -} \ No newline at end of file +} From e93c57c477917a5d1958d8826b09ef3aa292750a Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sun, 14 Jul 2019 12:41:17 +0800 Subject: [PATCH 06/26] Update. - Remove event_channel.h from this PR - Remove the GLFW prefix for PixelBuffer. --- .../include/flutter/event_channel.h | 116 ------------------ 1 file changed, 116 deletions(-) delete mode 100644 shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h b/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h deleted file mode 100644 index 8e5f8c4b5d86d..0000000000000 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/event_channel.h +++ /dev/null @@ -1,116 +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. - -#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ -#define FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ - -#include -#include - -#include "binary_messenger.h" -#include "engine_method_result.h" -#include "message_codec.h" -#include "method_call.h" -#include "method_codec.h" -#include "method_result.h" - -namespace flutter { - -template -using SuccessHandler = std::function; - -template -using ErrorHandler = - std::function; - -template -struct EventSink { - SuccessHandler Success; - ErrorHandler Error; -}; - -template -struct StreamHandler { - std::function *(const T *arguments, - const EventSink *event_sink)> - onListen; - std::function *(const T *arguments)> onCancel; -}; - -template -class EventChannel { - public: - EventChannel(BinaryMessenger *messenger, const std::string &name, - const MethodCodec *codec) - : messenger_(messenger), name_(name), codec_(codec) {} - ~EventChannel() {} - - // Prevent copying. - EventChannel(EventChannel const &) = delete; - EventChannel &operator=(EventChannel const &) = delete; - - void SetStreamHandler(StreamHandler stream_handler) { - stream_handler_ = stream_handler; - const auto messenger = messenger_; - std::string channel_name = name_; - const auto *codec = codec_; - - EventSink event_sink = {}; - - event_sink.Success = [messenger, channel_name, codec](const T *events) { - std::unique_ptr> message = - codec->EncodeSuccessEnvelope(events); - messenger->Send(channel_name, message->data(), message->size()); - }; - - event_sink.Error = [messenger, channel_name, codec]( - const std::string &errorCode, - const std::string &errorMessage, - const T *errorDetails) { - std::unique_ptr> message = - codec->EncodeErrorEnvelope(errorCode, errorMessage, errorDetails); - messenger->Send(channel_name, message->data(), message->size()); - }; - - BinaryMessageHandler binary_handler = [&, event_sink, codec, channel_name]( - const uint8_t *message, - const size_t message_size, - BinaryReply reply) { - auto result = - std::make_unique>(std::move(reply), codec); - std::unique_ptr> method_call = - codec->DecodeMethodCall(message, message_size); - if (!method_call) { - std::cerr << "Unable to construct method call from message on channel " - << channel_name << std::endl; - result->NotImplemented(); - return; - } - if (method_call->method_name().compare("listen") == 0) { - stream_handler_.onListen(method_call->arguments(), &event_sink); - result->Success(nullptr); - return; - } else if (method_call->method_name().compare("cancel") == 0) { - stream_handler_.onCancel(method_call->arguments()); - result->Success(nullptr); - return; - } else { - result->NotImplemented(); - } - }; - - messenger_->SetMessageHandler(name_, std::move(binary_handler)); - } - - private: - BinaryMessenger *messenger_; - std::string name_; - const MethodCodec *codec_; - StreamHandler stream_handler_; -}; - -} // namespace flutter - -#endif // FLUTTER_SHELL_PLATFORM_COMMON_CPP_CLIENT_WRAPPER_INCLUDE_FLUTTER_EVENT_CHANNEL_H_ From eaec810a1d05a640b4847ba07946fd6a7f289fe2 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sun, 14 Jul 2019 12:50:07 +0800 Subject: [PATCH 07/26] Update. - Remove event_channel.h from this PR - Remove the GLFW prefix for PixelBuffer. --- shell/platform/common/cpp/client_wrapper/BUILD.gn | 1 - .../cpp/client_wrapper/include/flutter/texture_registrar.h | 2 +- .../platform/common/cpp/client_wrapper/plugin_registrar.cc | 2 +- .../platform/common/cpp/public/flutter_texture_registrar.h | 4 ++-- shell/platform/glfw/external_texture_gl.cc | 5 +---- shell/platform/glfw/external_texture_gl.h | 6 +++--- 6 files changed, 8 insertions(+), 12 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/BUILD.gn b/shell/platform/common/cpp/client_wrapper/BUILD.gn index 81d3b8181e511..8f449d8352b1a 100644 --- a/shell/platform/common/cpp/client_wrapper/BUILD.gn +++ b/shell/platform/common/cpp/client_wrapper/BUILD.gn @@ -10,7 +10,6 @@ _wrapper_includes = [ "include/flutter/binary_messenger.h", "include/flutter/encodable_value.h", "include/flutter/engine_method_result.h", - "include/flutter/event_channel.h", "include/flutter/json_message_codec.h", "include/flutter/json_method_codec.h", "include/flutter/json_type.h", diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index 782f512f4be90..d1247cc220d1c 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -16,7 +16,7 @@ class Texture { public: virtual ~Texture() {} - virtual std::shared_ptr CopyTextureBuffer(size_t width, + virtual std::shared_ptr CopyTextureBuffer(size_t width, size_t height) = 0; }; diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index ef51efe04824d..d62115be77c0a 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -120,7 +120,7 @@ class TextureRegistrarImpl : public TextureRegistrar { virtual int64_t RegisterTexture(Texture* texture) override { FlutterTexutreCallback callback = [](size_t width, size_t height, - void* user_data) -> std::shared_ptr { + void* user_data) -> std::shared_ptr { return ((Texture*)user_data)->CopyTextureBuffer(width, height); }; int64_t texture_id = FlutterDesktopRegisterExternalTexture( diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index c9b4c3e837b31..563e2f299bf69 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -19,13 +19,13 @@ extern "C" { typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; -struct GLFWPixelBuffer { +struct PixelBuffer { std::shared_ptr buffer; size_t width; size_t height; }; -typedef std::shared_ptr (*FlutterTexutreCallback)( +typedef std::shared_ptr (*FlutterTexutreCallback)( size_t width, size_t height, void* user_data); FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index d7cc0e7179dc2..77f704dab8c36 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -5,9 +5,6 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" -#include "GLFW/glfw3.h" -#include "glad/glad.h" - namespace flutter { static void OnGLBufferRelease(void* user_data) {} @@ -34,7 +31,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( if (!window_) return false; - std::shared_ptr pixel_buffer = + std::shared_ptr pixel_buffer = texture_callback_(width, height, user_data_); if (!pixel_buffer.get()) return false; diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 45cea01e6ad03..525ea3c308105 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -10,13 +10,13 @@ #include #include +#include "glad/glad.h" +#include "GLFW/glfw3.h" + #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" #include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" #include "flutter/shell/platform/glfw/public/flutter_glfw.h" -typedef unsigned int GLuint; -typedef struct GLFWwindow GLFWwindow; - namespace flutter { class ExternalTextureGL { From 63ad1813fb427547d226335f540ff2a6661e34fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B9=96=E5=8C=97=E6=8D=B7=E6=99=BA=E4=BA=91=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E6=9C=89=E9=99=90=E5=85=AC=E5=8F=B8?= Date: Tue, 16 Jul 2019 20:34:27 +0800 Subject: [PATCH 08/26] Add comments and code modify. - Add comments to related classes. - Remove std::shared_ptr<> for PixelBuffer. - Optimize texture rendering code. --- .../include/flutter/texture_registrar.h | 11 +++--- .../cpp/client_wrapper/plugin_registrar.cc | 17 +++++---- .../cpp/public/flutter_texture_registrar.h | 22 ++++++++---- shell/platform/glfw/BUILD.gn | 8 +++-- shell/platform/glfw/external_texture_gl.cc | 36 +++++++++---------- shell/platform/glfw/external_texture_gl.h | 17 ++++----- 6 files changed, 62 insertions(+), 49 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index d1247cc220d1c..01eb327f92a9d 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -12,12 +12,15 @@ namespace flutter { +// An external texture interface declaration. class Texture { public: virtual ~Texture() {} - - virtual std::shared_ptr CopyTextureBuffer(size_t width, - size_t height) = 0; + // This is in response to the texture copy request interface, providing the + // |height | and |width| parameters of bounds. + // In some cases, we need to scale the texture to the bounds size to reduce + // memory usage. + virtual const PixelBuffer* CopyPixelBuffer(size_t width, size_t height) = 0; }; class TextureRegistrar { @@ -27,7 +30,7 @@ class TextureRegistrar { /** * Register a |texture| object and return textureId. */ - virtual int64_t RegisterTexture(Texture *texture) = 0; + virtual int64_t RegisterTexture(Texture* texture) = 0; /** * Mark a texture buffer is ready. diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index d62115be77c0a..1e4d301f87612 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -108,8 +108,8 @@ void BinaryMessengerImpl::SetMessageHandler(const std::string& channel, class TextureRegistrarImpl : public TextureRegistrar { public: explicit TextureRegistrarImpl( - FlutterDesktopTextureRegistrarRef texture_registrar) - : texture_registrar_(texture_registrar) {} + FlutterDesktopTextureRegistrarRef texture_registrar_ref) + : texture_registrar_ref_(texture_registrar_ref) {} virtual ~TextureRegistrarImpl() = default; @@ -119,27 +119,26 @@ class TextureRegistrarImpl : public TextureRegistrar { virtual int64_t RegisterTexture(Texture* texture) override { FlutterTexutreCallback callback = - [](size_t width, size_t height, - void* user_data) -> std::shared_ptr { - return ((Texture*)user_data)->CopyTextureBuffer(width, height); + [](size_t width, size_t height, void* user_data) -> const PixelBuffer* { + return ((Texture*)user_data)->CopyPixelBuffer(width, height); }; int64_t texture_id = FlutterDesktopRegisterExternalTexture( - texture_registrar_, callback, texture); + texture_registrar_ref_, callback, texture); return texture_id; } virtual void MarkTextureFrameAvailable(int64_t texture_id) override { - FlutterDesktopMarkExternalTextureFrameAvailable(texture_registrar_, + FlutterDesktopMarkExternalTextureFrameAvailable(texture_registrar_ref_, texture_id); } virtual void UnregisterTexture(int64_t texture_id) override { - FlutterDesktopUnregisterExternalTexture(texture_registrar_, texture_id); + FlutterDesktopUnregisterExternalTexture(texture_registrar_ref_, texture_id); } private: // Handle for interacting with the C API. - FlutterDesktopTextureRegistrarRef texture_registrar_; + FlutterDesktopTextureRegistrarRef texture_registrar_ref_; }; // PluginRegistrar: diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 563e2f299bf69..3bf7627c2a897 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -7,7 +7,6 @@ #include #include -#include #include "flutter_export.h" @@ -19,23 +18,32 @@ extern "C" { typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; -struct PixelBuffer { - std::shared_ptr buffer; +typedef struct { + // RGBA pixel buffer. + const uint8_t* buffer; + // height and width. size_t width; size_t height; -}; +} PixelBuffer; -typedef std::shared_ptr (*FlutterTexutreCallback)( - size_t width, size_t height, void* user_data); +// The pixel buffer copy callback definition is provided to +// the flutter engine to copy the texture. +typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, + size_t height, + void* user_data); +// Register an new texture to the flutter engine and return the texture id, +// The engine will use the | texture_callback | +// function to copy the pixel buffer from the plugin caller. FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, FlutterTexutreCallback texture_callback, void* user_data); +// Unregister an existing texture from the flutter engine for a |texture_id|. FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); -// Mark that a new texture frame is available for a given texture identifier. +// Mark that a new texture frame is available for a given |texture_id|. FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); diff --git a/shell/platform/glfw/BUILD.gn b/shell/platform/glfw/BUILD.gn index bee5a5db180fd..04e028e045339 100644 --- a/shell/platform/glfw/BUILD.gn +++ b/shell/platform/glfw/BUILD.gn @@ -46,7 +46,7 @@ source_set("flutter_glfw") { "text_input_plugin.h", ] - defines = [ "USE_RAPID_JSON" ] + defines = [ "USE_RAPID_JSON", "GLFW_INCLUDE_NONE" ] configs += [ "$flutter_root/shell/platform/common/cpp:desktop_library_implementation", @@ -61,14 +61,16 @@ source_set("flutter_glfw") { "//build/secondary/third_party/glfw", "//third_party/rapidjson", ] - - if (is_linux) { + if (is_win) { + deps += [ "//build/secondary/third_party/glfw:glad" ] + }else if (is_linux) { libs = [ "GL" ] configs += [ "$flutter_root/shell/platform/linux/config:gtk3", "$flutter_root/shell/platform/linux/config:x11", ] + deps += [ "//build/secondary/third_party/glfw:glad" ] } else if (is_mac) { libs = [ "CoreVideo.framework", diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 77f704dab8c36..0125131109d2b 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -14,31 +14,35 @@ ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, : texture_callback_(texture_callback), user_data_(user_data) {} ExternalTextureGL::~ExternalTextureGL() { - if (glTexture != 0) glDeleteTextures(1, &glTexture); + if (gl_texture_ != 0) glDeleteTextures(1, &gl_texture_); +} + + int64_t ExternalTextureGL::texutre_id() { + return reinterpret_cast(this); } bool ExternalTextureGL::PopulateTextureWithIdentifier( size_t width, size_t height, FlutterOpenGLTexture* texture) { + // Confirm that the current window context is available. if (!window_) { window_ = glfwGetCurrentContext(); if (window_) { glfwMakeContextCurrent(window_); + // Load glad functions. gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); } - } else { - glfwMakeContextCurrent(window_); } if (!window_) return false; - std::shared_ptr pixel_buffer = + const PixelBuffer* pixel_buffer = texture_callback_(width, height, user_data_); - if (!pixel_buffer.get()) return false; + if (!pixel_buffer || !pixel_buffer->buffer) return false; - if (glTexture == 0) { - glGenTextures(1, &glTexture); - glBindTexture(GL_TEXTURE_2D, glTexture); + if (gl_texture_ == 0) { + glGenTextures(1, &gl_texture_); + glBindTexture(GL_TEXTURE_2D, gl_texture_); // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); @@ -47,17 +51,13 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } - /*Fill texture.*/ - { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBindTexture(GL_TEXTURE_2D, glTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, - pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, - pixel_buffer->buffer.get()); - glEnable(GL_TEXTURE_2D); - } + glBindTexture(GL_TEXTURE_2D, gl_texture_); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixel_buffer->width, + pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, + pixel_buffer->buffer); + texture->target = GL_TEXTURE_2D; - texture->name = glTexture; + texture->name = gl_texture_; texture->format = GL_RGBA8; texture->destruction_callback = (VoidCallback)&OnGLBufferRelease; texture->user_data = (void*)this; diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 525ea3c308105..f6ae1c5cd7bec 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -8,10 +8,9 @@ #include "flutter/shell/platform/embedder/embedder.h" #include -#include -#include "glad/glad.h" -#include "GLFW/glfw3.h" +#include +#include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" #include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" @@ -19,22 +18,24 @@ namespace flutter { +// An adaptation class of flutter engine and external texture interface. class ExternalTextureGL { public: ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data); virtual ~ExternalTextureGL(); + + int64_t texutre_id(); - int64_t texutre_id() { return reinterpret_cast(this); } - - virtual bool PopulateTextureWithIdentifier(size_t width, size_t height, - FlutterOpenGLTexture* texture); + bool PopulateTextureWithIdentifier(size_t width, + size_t height, + FlutterOpenGLTexture* texture); private: FlutterTexutreCallback texture_callback_ = nullptr; void* user_data_ = nullptr; - GLuint glTexture = 0; GLFWwindow* window_ = nullptr; + GLuint gl_texture_ = 0; }; } // namespace flutter From f07279e38fe181670a38cff3885a73bc54b44bb5 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 16 Jul 2019 20:56:50 +0800 Subject: [PATCH 09/26] Update DEPS --- DEPS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DEPS b/DEPS index 1bfb42d5a70a9..8102c1f0e17c2 100644 --- a/DEPS +++ b/DEPS @@ -126,7 +126,8 @@ allowed_hosts = [ ] deps = { - 'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c5a493b255a32f0946a70155592a5f43790dc890', + #'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c5a493b255a32f0946a70155592a5f43790dc890', + 'src': 'https://github.com/cloudwebrtc/buildroot.git' + '@' + 'c4667a7f095d153798cc01d9ec74d6bac6597ef5', # Fuchsia compatibility # From d1266a87064935178897db150ff36a1e59ef484b Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 16 Jul 2019 21:19:14 +0800 Subject: [PATCH 10/26] Update external_texture_gl.h --- shell/platform/glfw/external_texture_gl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index f6ae1c5cd7bec..e6f0c0cb15e7d 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -13,7 +13,6 @@ #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" -#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" #include "flutter/shell/platform/glfw/public/flutter_glfw.h" namespace flutter { From 7391e42fe28411213d226366a16f4b5d6112d3e5 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Wed, 17 Jul 2019 01:51:30 +0800 Subject: [PATCH 11/26] Fix compilation errors for linux and clang/gn format. --- .../include/flutter/plugin_registrar.h | 4 +-- .../testing/stub_flutter_api.cc | 36 +++++++++---------- .../cpp/public/flutter_texture_registrar.h | 9 +++-- shell/platform/glfw/BUILD.gn | 11 +++--- shell/platform/glfw/external_texture_gl.cc | 15 +++++--- shell/platform/glfw/external_texture_gl.h | 10 +++--- shell/platform/glfw/flutter_glfw.cc | 13 ++++--- 7 files changed, 55 insertions(+), 43 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h index 2262c07a64c60..1e9713764de84 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h @@ -41,7 +41,7 @@ class PluginRegistrar { // // This pointer will remain valid for the lifetime of this instance. BinaryMessenger* messenger() { return messenger_.get(); } - + TextureRegistrar* textures() { return textures_.get(); } // Takes ownership of |plugin|. @@ -62,7 +62,7 @@ class PluginRegistrar { FlutterDesktopPluginRegistrarRef registrar_; std::unique_ptr messenger_; - + std::unique_ptr textures_; // Plugins registered for ownership. diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc index a48858fc5b299..fba049058ab0c 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc @@ -47,26 +47,26 @@ FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger( FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( FlutterDesktopPluginRegistrarRef registrar) { return reinterpret_cast(1); - } +} int64_t FlutterDesktopRegisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, - void* user_data) { - return -1; - } - - bool FlutterDesktopUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id) { - return false; - } - - bool FlutterDesktopMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, - int64_t texture_id) { - return false; - } + FlutterDesktopTextureRegistrarRef texture_registrar, + FlutterTexutreCallback texture_callback, + void* user_data) { + return -1; +} + +bool FlutterDesktopUnregisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + return false; +} + +bool FlutterDesktopMarkExternalTextureFrameAvailable( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + return false; +} void FlutterDesktopRegistrarEnableInputBlocking( FlutterDesktopPluginRegistrarRef registrar, diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 3bf7627c2a897..3d3e1c13b3f99 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -37,15 +37,18 @@ typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, // function to copy the pixel buffer from the plugin caller. FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, void* user_data); + FlutterTexutreCallback texture_callback, + void* user_data); // Unregister an existing texture from the flutter engine for a |texture_id|. FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id); // Mark that a new texture frame is available for a given |texture_id|. FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id); #if defined(__cplusplus) } // extern "C" diff --git a/shell/platform/glfw/BUILD.gn b/shell/platform/glfw/BUILD.gn index 04e028e045339..895a767c8e428 100644 --- a/shell/platform/glfw/BUILD.gn +++ b/shell/platform/glfw/BUILD.gn @@ -32,8 +32,8 @@ source_set("flutter_glfw_headers") { source_set("flutter_glfw") { sources = [ - "external_texture_gl.h", "external_texture_gl.cc", + "external_texture_gl.h", "flutter_glfw.cc", "glfw_event_loop.cc", "glfw_event_loop.h", @@ -46,7 +46,10 @@ source_set("flutter_glfw") { "text_input_plugin.h", ] - defines = [ "USE_RAPID_JSON", "GLFW_INCLUDE_NONE" ] + defines = [ + "USE_RAPID_JSON", + "GLFW_INCLUDE_NONE", + ] configs += [ "$flutter_root/shell/platform/common/cpp:desktop_library_implementation", @@ -62,8 +65,8 @@ source_set("flutter_glfw") { "//third_party/rapidjson", ] if (is_win) { - deps += [ "//build/secondary/third_party/glfw:glad" ] - }else if (is_linux) { + deps += [ "//build/secondary/third_party/glfw:glad" ] + } else if (is_linux) { libs = [ "GL" ] configs += [ diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 0125131109d2b..2dfc83d883cf0 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -14,15 +14,18 @@ ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, : texture_callback_(texture_callback), user_data_(user_data) {} ExternalTextureGL::~ExternalTextureGL() { - if (gl_texture_ != 0) glDeleteTextures(1, &gl_texture_); + if (gl_texture_ != 0) + glDeleteTextures(1, &gl_texture_); } - int64_t ExternalTextureGL::texutre_id() { +int64_t ExternalTextureGL::texutre_id() { return reinterpret_cast(this); } bool ExternalTextureGL::PopulateTextureWithIdentifier( - size_t width, size_t height, FlutterOpenGLTexture* texture) { + size_t width, + size_t height, + FlutterOpenGLTexture* texture) { // Confirm that the current window context is available. if (!window_) { window_ = glfwGetCurrentContext(); @@ -33,12 +36,14 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( } } - if (!window_) return false; + if (!window_) + return false; const PixelBuffer* pixel_buffer = texture_callback_(width, height, user_data_); - if (!pixel_buffer || !pixel_buffer->buffer) return false; + if (!pixel_buffer || !pixel_buffer->buffer) + return false; if (gl_texture_ == 0) { glGenTextures(1, &gl_texture_); diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index e6f0c0cb15e7d..f1f4ab588fb12 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -5,15 +5,13 @@ #ifndef FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ #define FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ -#include "flutter/shell/platform/embedder/embedder.h" - #include -#include #include +#include -#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" -#include "flutter/shell/platform/glfw/public/flutter_glfw.h" +#include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" +#include "flutter/shell/platform/embedder/embedder.h" namespace flutter { @@ -23,7 +21,7 @@ class ExternalTextureGL { ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data); virtual ~ExternalTextureGL(); - + int64_t texutre_id(); bool PopulateTextureWithIdentifier(size_t width, diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 09bb3f1ff708f..98d35fa8fdbf6 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -500,8 +500,8 @@ static bool OnAcquireExternalTexture(void* user_data, FlutterOpenGLTexture* texture) { GLFWwindow* window = reinterpret_cast(user_data); auto state = GetSavedWindowState(window); - return state->plugin_registrar->texture_registrar->textures[texture_id]->PopulateTextureWithIdentifier( - width, height, texture); + return state->plugin_registrar->texture_registrar->textures[texture_id] + ->PopulateTextureWithIdentifier(width, height, texture); } static void GLFWErrorCallback(int error_code, const char* description) { @@ -876,7 +876,8 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, void* user_data) { + FlutterTexutreCallback texture_callback, + void* user_data) { std::unique_ptr texture_gl( new flutter::ExternalTextureGL(texture_callback, user_data)); int64_t texture_id = texture_gl->texutre_id(); @@ -889,7 +890,8 @@ int64_t FlutterDesktopRegisterExternalTexture( } bool FlutterDesktopUnregisterExternalTexture( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { auto it = texture_registrar->textures.find(texture_id); if (it != texture_registrar->textures.end()) texture_registrar->textures.erase(it); @@ -898,7 +900,8 @@ bool FlutterDesktopUnregisterExternalTexture( } bool FlutterDesktopMarkExternalTextureFrameAvailable( - FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { return (FlutterEngineMarkExternalTextureFrameAvailable( texture_registrar->engine, texture_id) == kSuccess); } From 4c5f065d467a9c36e90cea6e14d64ea6e68ad227 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Wed, 17 Jul 2019 02:58:16 +0800 Subject: [PATCH 12/26] Fix license check error. --- ci/licenses_golden/licenses_flutter | 4 ++++ shell/platform/glfw/external_texture_gl.cc | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 06b0d17ac1d79..14882def369af 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -645,6 +645,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/ FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h +FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_message_codec.cc FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/json_method_codec.cc FILE: ../../../flutter/shell/platform/common/cpp/client_wrapper/method_call_unittests.cc @@ -659,6 +660,7 @@ FILE: ../../../flutter/shell/platform/common/cpp/incoming_message_dispatcher.h FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_export.h FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_messenger.h FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_plugin_registrar.h +FILE: ../../../flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h FILE: ../../../flutter/shell/platform/common/cpp/text_input_model.cc FILE: ../../../flutter/shell/platform/common/cpp/text_input_model.h FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h @@ -932,6 +934,8 @@ FILE: ../../../flutter/shell/platform/glfw/client_wrapper/flutter_window_control FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window.h FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/flutter_window_controller.h FILE: ../../../flutter/shell/platform/glfw/client_wrapper/include/flutter/plugin_registrar_glfw.h +FILE: ../../../flutter/shell/platform/glfw/external_texture_gl.cc +FILE: ../../../flutter/shell/platform/glfw/external_texture_gl.h FILE: ../../../flutter/shell/platform/glfw/flutter_glfw.cc FILE: ../../../flutter/shell/platform/glfw/glfw_event_loop.cc FILE: ../../../flutter/shell/platform/glfw/glfw_event_loop.h diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 2dfc83d883cf0..fa7c1cedac320 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -1,4 +1,3 @@ -// Copyright 2018 Google LLC // 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. From 93fc359fda5bb2659d6458d1ea6456fbe776246a Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sun, 21 Jul 2019 19:45:10 +0800 Subject: [PATCH 13/26] Fixed the order of glad.h contains a run error. --- shell/platform/glfw/BUILD.gn | 5 +-- shell/platform/glfw/external_texture_gl.cc | 45 +++++++++++++++------- shell/platform/glfw/external_texture_gl.h | 8 ++-- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/shell/platform/glfw/BUILD.gn b/shell/platform/glfw/BUILD.gn index 895a767c8e428..a6b34b801f498 100644 --- a/shell/platform/glfw/BUILD.gn +++ b/shell/platform/glfw/BUILD.gn @@ -46,10 +46,7 @@ source_set("flutter_glfw") { "text_input_plugin.h", ] - defines = [ - "USE_RAPID_JSON", - "GLFW_INCLUDE_NONE", - ] + defines = [ "USE_RAPID_JSON" ] configs += [ "$flutter_root/shell/platform/common/cpp:desktop_library_implementation", diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index fa7c1cedac320..0a6c078c69902 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -4,17 +4,36 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" +#include + +#include + +// glad.h must be included before glfw3.h. +#include + namespace flutter { +// Just to not declare GLFWwindow and GLuint in the header. +struct ExternalTextureGLState { + GLFWwindow* window; + GLuint gl_texture; +}; + static void OnGLBufferRelease(void* user_data) {} ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) - : texture_callback_(texture_callback), user_data_(user_data) {} + : texture_callback_(texture_callback), + user_data_(user_data), + state_(new ExternalTextureGLState()) { + memset(state_, 0, sizeof(ExternalTextureGLState)); +} ExternalTextureGL::~ExternalTextureGL() { - if (gl_texture_ != 0) - glDeleteTextures(1, &gl_texture_); + if (state_->gl_texture != 0) + glDeleteTextures(1, &state_->gl_texture); + + delete state_; } int64_t ExternalTextureGL::texutre_id() { @@ -26,16 +45,16 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( size_t height, FlutterOpenGLTexture* texture) { // Confirm that the current window context is available. - if (!window_) { - window_ = glfwGetCurrentContext(); - if (window_) { - glfwMakeContextCurrent(window_); + if (!state_->window) { + state_->window = glfwGetCurrentContext(); + if (state_->window) { + glfwMakeContextCurrent(state_->window); // Load glad functions. gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); } } - if (!window_) + if (!state_->window) return false; const PixelBuffer* pixel_buffer = @@ -44,9 +63,9 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( if (!pixel_buffer || !pixel_buffer->buffer) return false; - if (gl_texture_ == 0) { - glGenTextures(1, &gl_texture_); - glBindTexture(GL_TEXTURE_2D, gl_texture_); + if (state_->gl_texture == 0) { + glGenTextures(1, &state_->gl_texture); + glBindTexture(GL_TEXTURE_2D, state_->gl_texture); // set the texture wrapping parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); @@ -55,13 +74,13 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } - glBindTexture(GL_TEXTURE_2D, gl_texture_); + glBindTexture(GL_TEXTURE_2D, 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); texture->target = GL_TEXTURE_2D; - texture->name = gl_texture_; + texture->name = state_->gl_texture; texture->format = GL_RGBA8; texture->destruction_callback = (VoidCallback)&OnGLBufferRelease; texture->user_data = (void*)this; diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index f1f4ab588fb12..2ef8fd773002e 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -7,14 +7,13 @@ #include -#include -#include - #include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" #include "flutter/shell/platform/embedder/embedder.h" namespace flutter { +typedef struct ExternalTextureGLState ExternalTextureGLState; + // An adaptation class of flutter engine and external texture interface. class ExternalTextureGL { public: @@ -31,8 +30,7 @@ class ExternalTextureGL { private: FlutterTexutreCallback texture_callback_ = nullptr; void* user_data_ = nullptr; - GLFWwindow* window_ = nullptr; - GLuint gl_texture_ = 0; + ExternalTextureGLState* state_ = nullptr; }; } // namespace flutter From 184a13a2ffc844d2a452c0ae13d7fe084162af95 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sat, 14 Sep 2019 00:09:58 +0800 Subject: [PATCH 14/26] Update. --- DEPS | 3 +-- .../include/flutter/texture_registrar.h | 2 +- .../cpp/public/flutter_texture_registrar.h | 2 +- shell/platform/glfw/BUILD.gn | 6 ++---- shell/platform/glfw/external_texture_gl.cc | 16 +++------------- shell/platform/glfw/external_texture_gl.h | 5 +++-- shell/platform/glfw/flutter_glfw.cc | 2 +- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/DEPS b/DEPS index 8102c1f0e17c2..1bfb42d5a70a9 100644 --- a/DEPS +++ b/DEPS @@ -126,8 +126,7 @@ allowed_hosts = [ ] deps = { - #'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c5a493b255a32f0946a70155592a5f43790dc890', - 'src': 'https://github.com/cloudwebrtc/buildroot.git' + '@' + 'c4667a7f095d153798cc01d9ec74d6bac6597ef5', + 'src': 'https://github.com/flutter/buildroot.git' + '@' + 'c5a493b255a32f0946a70155592a5f43790dc890', # Fuchsia compatibility # diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index 01eb327f92a9d..19139679ea4f7 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -17,7 +17,7 @@ class Texture { public: virtual ~Texture() {} // This is in response to the texture copy request interface, providing the - // |height | and |width| parameters of bounds. + // |height| and |width| parameters of bounds. // In some cases, we need to scale the texture to the bounds size to reduce // memory usage. virtual const PixelBuffer* CopyPixelBuffer(size_t width, size_t height) = 0; diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 3d3e1c13b3f99..1ff7853247423 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -33,7 +33,7 @@ typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, void* user_data); // Register an new texture to the flutter engine and return the texture id, -// The engine will use the | texture_callback | +// The engine will use the |texture_callback| // function to copy the pixel buffer from the plugin caller. FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, diff --git a/shell/platform/glfw/BUILD.gn b/shell/platform/glfw/BUILD.gn index a6b34b801f498..cf3c12a2f06d7 100644 --- a/shell/platform/glfw/BUILD.gn +++ b/shell/platform/glfw/BUILD.gn @@ -58,19 +58,17 @@ source_set("flutter_glfw") { "$flutter_root/shell/platform/common/cpp/client_wrapper:client_wrapper", "$flutter_root/shell/platform/embedder:embedder", "$flutter_root/shell/platform/glfw/client_wrapper:client_wrapper_glfw", + "$flutter_root/third_party/glad", "//build/secondary/third_party/glfw", "//third_party/rapidjson", ] - if (is_win) { - deps += [ "//build/secondary/third_party/glfw:glad" ] - } else if (is_linux) { + if (is_linux) { libs = [ "GL" ] configs += [ "$flutter_root/shell/platform/linux/config:gtk3", "$flutter_root/shell/platform/linux/config:x11", ] - deps += [ "//build/secondary/third_party/glfw:glad" ] } else if (is_mac) { libs = [ "CoreVideo.framework", diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 0a6c078c69902..1a1fed6865554 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -4,8 +4,6 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" -#include - #include // glad.h must be included before glfw3.h. @@ -23,21 +21,13 @@ static void OnGLBufferRelease(void* user_data) {} ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) - : texture_callback_(texture_callback), - user_data_(user_data), - state_(new ExternalTextureGLState()) { - memset(state_, 0, sizeof(ExternalTextureGLState)); -} + : state_(new ExternalTextureGLState()), + texture_callback_(texture_callback), + user_data_(user_data) {} ExternalTextureGL::~ExternalTextureGL() { if (state_->gl_texture != 0) glDeleteTextures(1, &state_->gl_texture); - - delete state_; -} - -int64_t ExternalTextureGL::texutre_id() { - return reinterpret_cast(this); } bool ExternalTextureGL::PopulateTextureWithIdentifier( diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 2ef8fd773002e..a648636dff7ac 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -6,6 +6,7 @@ #define FLUTTER_SHELL_PLATFORM_GLFW_EXTERNAL_TEXTURE_GL_H_ #include +#include #include "flutter/shell/platform/common/cpp/public/flutter_texture_registrar.h" #include "flutter/shell/platform/embedder/embedder.h" @@ -21,16 +22,16 @@ class ExternalTextureGL { virtual ~ExternalTextureGL(); - int64_t texutre_id(); + int64_t texture_id() { return reinterpret_cast(this); } bool PopulateTextureWithIdentifier(size_t width, size_t height, FlutterOpenGLTexture* texture); private: + std::unique_ptr state_; FlutterTexutreCallback texture_callback_ = nullptr; void* user_data_ = nullptr; - ExternalTextureGLState* state_ = nullptr; }; } // namespace flutter diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 98d35fa8fdbf6..8513f86cf4a27 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -880,7 +880,7 @@ int64_t FlutterDesktopRegisterExternalTexture( void* user_data) { std::unique_ptr texture_gl( new flutter::ExternalTextureGL(texture_callback, user_data)); - int64_t texture_id = texture_gl->texutre_id(); + int64_t texture_id = texture_gl->texture_id(); texture_registrar->textures[texture_id] = std::move(texture_gl); if (FlutterEngineRegisterExternalTexture(texture_registrar->engine, texture_id) == kSuccess) { From 63e1469f2ef54b6756576ea40d310bf159cfefae Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Sat, 14 Sep 2019 13:14:07 +0800 Subject: [PATCH 15/26] Fixed engine type definition error. --- shell/platform/glfw/flutter_glfw.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index abe74b2bee134..9dd905b9baf19 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -122,7 +122,7 @@ struct FlutterDesktopPluginRegistrar { // State associated with the texture registrar. struct FlutterDesktopTextureRegistrar { - FlutterEngine engine; + FLUTTER_API_SYMBOL(FlutterEngine) engine; // The texture registrar managing external texture adapters. std::map> textures; }; From 2ccfeef3e85187832c81c0b8963321f1bf343d56 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 24 Sep 2019 10:27:04 +0800 Subject: [PATCH 16/26] Use the new `glad' dependency. --- shell/platform/glfw/external_texture_gl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 1a1fed6865554..69beddef12750 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -4,7 +4,7 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" -#include +#include // glad.h must be included before glfw3.h. #include @@ -39,8 +39,8 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( state_->window = glfwGetCurrentContext(); if (state_->window) { glfwMakeContextCurrent(state_->window); - // Load glad functions. - gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); + // Load GL functions. + gladLoadGL((GLADloadfunc)glfwGetProcAddress); } } From dd1bffb7362cbbb6ec62d0a24d5a5978fc17d70b Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 24 Sep 2019 15:36:46 +0800 Subject: [PATCH 17/26] Update. --- shell/platform/glfw/external_texture_gl.cc | 14 ++++++-------- shell/platform/glfw/external_texture_gl.h | 11 ++++++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 69beddef12750..bce8da72d5c11 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -17,8 +17,6 @@ struct ExternalTextureGLState { GLuint gl_texture; }; -static void OnGLBufferRelease(void* user_data) {} - ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) : state_(new ExternalTextureGLState()), @@ -33,7 +31,7 @@ ExternalTextureGL::~ExternalTextureGL() { bool ExternalTextureGL::PopulateTextureWithIdentifier( size_t width, size_t height, - FlutterOpenGLTexture* texture) { + FlutterOpenGLTexture* opengl_texture) { // Confirm that the current window context is available. if (!state_->window) { state_->window = glfwGetCurrentContext(); @@ -69,11 +67,11 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( pixel_buffer->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixel_buffer->buffer); - texture->target = GL_TEXTURE_2D; - texture->name = state_->gl_texture; - texture->format = GL_RGBA8; - texture->destruction_callback = (VoidCallback)&OnGLBufferRelease; - texture->user_data = (void*)this; + opengl_texture->target = GL_TEXTURE_2D; + opengl_texture->name = state_->gl_texture; + opengl_texture->format = GL_RGBA8; + opengl_texture->destruction_callback = (VoidCallback)nullptr; + opengl_texture->user_data = (void*)this; return true; } diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index a648636dff7ac..4fc6d605758e6 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -22,11 +22,20 @@ class ExternalTextureGL { virtual ~ExternalTextureGL(); + /** + * Returns the unique id for the ExternalTextureGL instance. + */ int64_t texture_id() { return reinterpret_cast(this); } + /** + * Accepts texture buffer copy request from the flutter engine. + * When the user side marks the texture_id as available, the flutter engine will + * callback to this method and ask for populate the |opengl_texture| object, + * such as the texture type and the format of the pixel buffer and the texture object. + */ bool PopulateTextureWithIdentifier(size_t width, size_t height, - FlutterOpenGLTexture* texture); + FlutterOpenGLTexture* opengl_texture); private: std::unique_ptr state_; From c4009373002934fa9ad1d3eab1c42f23743e1899 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 24 Sep 2019 15:41:17 +0800 Subject: [PATCH 18/26] fix typo. --- .../cpp/client_wrapper/include/flutter/texture_registrar.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index 19139679ea4f7..66eb47c07229d 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -28,7 +28,7 @@ class TextureRegistrar { virtual ~TextureRegistrar() {} /** - * Register a |texture| object and return textureId. + * Registers a |texture| object and return textureId. */ virtual int64_t RegisterTexture(Texture* texture) = 0; @@ -38,7 +38,7 @@ class TextureRegistrar { virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; /** - * Unregister an existing Texture object. + * Unregisters an existing Texture object. */ virtual void UnregisterTexture(int64_t texture_id) = 0; }; From 6456082af06ba88fa407d6e7569e2e8c79071e1e Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 24 Sep 2019 15:42:32 +0800 Subject: [PATCH 19/26] clang-format. --- shell/platform/glfw/external_texture_gl.cc | 2 +- shell/platform/glfw/external_texture_gl.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index bce8da72d5c11..3e7baab0ce2c2 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -70,7 +70,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( opengl_texture->target = GL_TEXTURE_2D; opengl_texture->name = state_->gl_texture; opengl_texture->format = GL_RGBA8; - opengl_texture->destruction_callback = (VoidCallback)nullptr; + opengl_texture->destruction_callback = (VoidCallback) nullptr; opengl_texture->user_data = (void*)this; return true; } diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 4fc6d605758e6..589c189762d31 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -23,15 +23,16 @@ class ExternalTextureGL { virtual ~ExternalTextureGL(); /** - * Returns the unique id for the ExternalTextureGL instance. - */ + * Returns the unique id for the ExternalTextureGL instance. + */ int64_t texture_id() { return reinterpret_cast(this); } /** * Accepts texture buffer copy request from the flutter engine. - * When the user side marks the texture_id as available, the flutter engine will - * callback to this method and ask for populate the |opengl_texture| object, - * such as the texture type and the format of the pixel buffer and the texture object. + * When the user side marks the texture_id as available, the flutter engine + * will callback to this method and ask for populate the |opengl_texture| + * object, such as the texture type and the format of the pixel buffer and the + * texture object. */ bool PopulateTextureWithIdentifier(size_t width, size_t height, From a46b562d69642ea40bd2dbc37fcd3654187689d4 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Mon, 7 Oct 2019 22:29:01 +0800 Subject: [PATCH 20/26] update. --- .../include/flutter/plugin_registrar.h | 1 - .../cpp/client_wrapper/plugin_registrar.cc | 2 +- .../cpp/public/flutter_texture_registrar.h | 15 +++++---- shell/platform/glfw/external_texture_gl.cc | 29 ++++++++++------- shell/platform/glfw/flutter_glfw.cc | 5 +-- shell/platform/windows/flutter_windows.cc | 31 +++++++++++++++++++ 6 files changed, 61 insertions(+), 22 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h index 1e9713764de84..8c82c21d84c2d 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h @@ -10,7 +10,6 @@ #include #include -#include #include "binary_messenger.h" #include "texture_registrar.h" diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index 48902efd65ec8..1b2aed911b9f2 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -155,7 +155,7 @@ class TextureRegistrarImpl : public TextureRegistrar { virtual int64_t RegisterTexture(Texture* texture) override { FlutterTexutreCallback callback = [](size_t width, size_t height, void* user_data) -> const PixelBuffer* { - return ((Texture*)user_data)->CopyPixelBuffer(width, height); + return static_cast(user_data)->CopyPixelBuffer(width, height); }; int64_t texture_id = FlutterDesktopRegisterExternalTexture( texture_registrar_ref_, callback, texture); diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 1ff7853247423..2283a2eacbeb6 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -18,21 +18,24 @@ extern "C" { typedef struct FlutterDesktopTextureRegistrar* FlutterDesktopTextureRegistrarRef; +// Constructs a pixel buffer object for the plugin side, providing +// height/width and buffer pointers. typedef struct { - // RGBA pixel buffer. + // Bitmap buffer pointer, currently only supports RGBA. const uint8_t* buffer; - // height and width. + // Width of the pixel buffer. size_t width; + // Height of the pixel buffer. size_t height; } PixelBuffer; // The pixel buffer copy callback definition is provided to -// the flutter engine to copy the texture. +// the Flutter engine to copy the texture. typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, size_t height, void* user_data); -// Register an new texture to the flutter engine and return the texture id, +// Registers a new texture with the Flutter engine and returns the texture ID, // The engine will use the |texture_callback| // function to copy the pixel buffer from the plugin caller. FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( @@ -40,12 +43,12 @@ FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterTexutreCallback texture_callback, void* user_data); -// Unregister an existing texture from the flutter engine for a |texture_id|. +// Unregisters an existing texture from the Flutter engine for a |texture_id|. FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); -// Mark that a new texture frame is available for a given |texture_id|. +// Marks that a new texture frame is available for a given |texture_id|. FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index 3e7baab0ce2c2..fec78340e1242 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -6,9 +6,11 @@ #include -// glad.h must be included before glfw3.h. +// glad/gl.h must be included before GLFW/glfw3.h. #include +#include + namespace flutter { // Just to not declare GLFWwindow and GLuint in the header. @@ -19,7 +21,7 @@ struct ExternalTextureGLState { ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data) - : state_(new ExternalTextureGLState()), + : state_(std::make_unique()), texture_callback_(texture_callback), user_data_(user_data) {} @@ -35,21 +37,23 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( // Confirm that the current window context is available. if (!state_->window) { state_->window = glfwGetCurrentContext(); - if (state_->window) { - glfwMakeContextCurrent(state_->window); - // Load GL functions. - gladLoadGL((GLADloadfunc)glfwGetProcAddress); + if (!state_->window) { + std::cerr << "Failed to get window context in current thread." + << std::endl; + return false; } + glfwMakeContextCurrent(state_->window); + // Load GL functions. + gladLoadGL((GLADloadfunc)glfwGetProcAddress); } - if (!state_->window) - return false; - const PixelBuffer* pixel_buffer = texture_callback_(width, height, user_data_); - if (!pixel_buffer || !pixel_buffer->buffer) + if (!pixel_buffer || !pixel_buffer->buffer) { + std::cerr << "Failed to copy pixel buffer from plugin." << std::endl; return false; + } if (state_->gl_texture == 0) { glGenTextures(1, &state_->gl_texture); @@ -60,9 +64,10 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( // set texture filtering parameters 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, state_->gl_texture); } - glBindTexture(GL_TEXTURE_2D, 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); @@ -71,7 +76,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( opengl_texture->name = state_->gl_texture; opengl_texture->format = GL_RGBA8; opengl_texture->destruction_callback = (VoidCallback) nullptr; - opengl_texture->user_data = (void*)this; + opengl_texture->user_data = static_cast(this); return true; } diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 323b377dfa444..ab49104691964 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -114,6 +114,7 @@ struct FlutterDesktopPluginRegistrar { // The plugin messenger handle given to API clients. std::unique_ptr messenger; + // The plugin texture registrar handle given to API clients. std::unique_ptr texture_registrar; // The handle for the window associated with this registrar. @@ -897,8 +898,8 @@ int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, FlutterTexutreCallback texture_callback, void* user_data) { - std::unique_ptr texture_gl( - new flutter::ExternalTextureGL(texture_callback, user_data)); + auto texture_gl = + std::make_unique(texture_callback, user_data); int64_t texture_id = texture_gl->texture_id(); texture_registrar->textures[texture_id] = std::move(texture_gl); if (FlutterEngineRegisterExternalTexture(texture_registrar->engine, diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index beff9bed1ac7f..22b7d71f03b4e 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -13,6 +13,7 @@ #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" #include "flutter/shell/platform/common/cpp/incoming_message_dispatcher.h" #include "flutter/shell/platform/embedder/embedder.h" #include "flutter/shell/platform/windows/key_event_handler.h" @@ -239,3 +240,33 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, void* user_data) { messenger->dispatcher->SetMessageCallback(channel, callback, user_data); } + +// Texture support isn't implemented yet for Windows, +// Please refer to https://github.com/flutter/flutter/issues/38601. +FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( + FlutterDesktopPluginRegistrarRef registrar) { + std::cout << "Not yet implemented.\n"; + return reinterpret_cast(nullptr); +} + +int64_t FlutterDesktopRegisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + FlutterTexutreCallback texture_callback, + void* user_data) { + std::cout << "Not yet implemented.\n"; + return -1; +} + +bool FlutterDesktopUnregisterExternalTexture( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + std::cout << "Not yet implemented.\n"; + return false; +} + +bool FlutterDesktopMarkExternalTextureFrameAvailable( + FlutterDesktopTextureRegistrarRef texture_registrar, + int64_t texture_id) { + std::cout << "Not yet implemented.\n"; + return false; +} From 3ecb5fd07b189623313ab891a1f68f3e231393d2 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Mon, 7 Oct 2019 22:36:31 +0800 Subject: [PATCH 21/26] Add comment. --- .../cpp/client_wrapper/include/flutter/plugin_registrar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h index 8c82c21d84c2d..fffa66d37471b 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h @@ -41,6 +41,8 @@ class PluginRegistrar { // This pointer will remain valid for the lifetime of this instance. BinaryMessenger* messenger() { return messenger_.get(); } + // Returns the texture registrar to use for the plugin to render a pixel + // buffer. TextureRegistrar* textures() { return textures_.get(); } // Takes ownership of |plugin|. From e1b7a8b68c887e0f211c5bb3cd97cd94a92766c5 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Tue, 8 Oct 2019 15:06:39 +0800 Subject: [PATCH 22/26] Add unit tests for texture. --- .../plugin_registrar_unittests.cc | 46 +++++++++++++++++++ .../testing/stub_flutter_api.cc | 19 ++++++-- .../client_wrapper/testing/stub_flutter_api.h | 13 ++++++ 3 files changed, 75 insertions(+), 3 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc index 22ca10ea58f27..7d36fdfad3761 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc @@ -6,6 +6,7 @@ #include #include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/plugin_registrar.h" +#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h" #include "flutter/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h" #include "gtest/gtest.h" @@ -34,8 +35,34 @@ class TestApi : public testing::StubFlutterApi { const uint8_t* last_data_sent() { return last_data_sent_; } + int64_t RegisterExternalTexture( + FlutterTexutreCallback texture_callback, + void* user_data) override { + last_texture_id_ = 1; + return last_texture_id_; + } + + bool UnregisterExternalTexture(int64_t texture_id) override { + if(texture_id == 2) { + last_texture_id_ = -2; + return true; + } + return false; + } + + bool TextureFrameAvailable(int64_t texture_id) override { + if(texture_id == 1) { + last_texture_id_ = 2; + return true; + } + return false; + } + + int64_t last_texture_id() { return last_texture_id_; } + private: const uint8_t* last_data_sent_ = nullptr; + int64_t last_texture_id_ = -1; }; } // namespace @@ -55,4 +82,23 @@ TEST(MethodCallTest, MessengerSend) { EXPECT_EQ(test_api->last_data_sent(), &message[0]); } +// Tests texture register that calls through to the C API. +TEST(MethodCallTest, RegisterTexture) { + testing::ScopedStubFlutterApi scoped_api_stub(std::make_unique()); + auto test_api = static_cast(scoped_api_stub.stub()); + + auto dummy_registrar_handle = + reinterpret_cast(1); + PluginRegistrar registrar(dummy_registrar_handle); + TextureRegistrar* textures = registrar.textures(); + + EXPECT_EQ(test_api->last_texture_id(), -1); + int64_t texture_id = textures->RegisterTexture(nullptr); + EXPECT_EQ(texture_id, 1); + textures->MarkTextureFrameAvailable(texture_id); + EXPECT_EQ(test_api->last_texture_id(), 2); + textures->UnregisterTexture(2); + EXPECT_EQ(test_api->last_texture_id(), -2); +} + } // namespace flutter diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc index b9273b2253041..7e4e4884cd00a 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc @@ -53,19 +53,32 @@ int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, FlutterTexutreCallback texture_callback, void* user_data) { - return -1; + uint64_t result = -1; + if (s_stub_implementation) { + result = s_stub_implementation->RegisterExternalTexture(texture_callback, + user_data); + } + return result; } bool FlutterDesktopUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { - return false; + bool result = false; + if (s_stub_implementation) { + result = s_stub_implementation->UnregisterExternalTexture(texture_id); + } + return result; } bool FlutterDesktopMarkExternalTextureFrameAvailable( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { - return false; + bool result = false; + if (s_stub_implementation) { + result = s_stub_implementation->TextureFrameAvailable(texture_id); + } + return result; } void FlutterDesktopRegistrarEnableInputBlocking( diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h index c5f9dbbb2a2a5..750eb6bc38ff1 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h @@ -63,6 +63,19 @@ class StubFlutterApi { virtual void MessengerSetCallback(const char* channel, FlutterDesktopMessageCallback callback, void* user_data) {} + + // Called for FlutterDesktopRegisterExternalTexture. + virtual int64_t RegisterExternalTexture( + FlutterTexutreCallback texture_callback, + void* user_data) { + return -1; + } + + // Called for FlutterDesktopUnregisterExternalTexture. + virtual bool UnregisterExternalTexture(int64_t texture_id) { return false; } + + // Called for FlutterDesktopMarkExternalTextureFrameAvailable. + virtual bool TextureFrameAvailable(int64_t texture_id) { return false; } }; // A test helper that owns a stub implementation, making it the test stub for From 49036666ed74b5adf781286232c18cb2f772cc58 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Thu, 10 Oct 2019 23:19:02 +0800 Subject: [PATCH 23/26] update. --- shell/platform/glfw/external_texture_gl.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index fec78340e1242..f87c8f5cb1c59 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -4,7 +4,7 @@ #include "flutter/shell/platform/glfw/external_texture_gl.h" -#include +#include // glad/gl.h must be included before GLFW/glfw3.h. #include @@ -44,7 +44,7 @@ bool ExternalTextureGL::PopulateTextureWithIdentifier( } glfwMakeContextCurrent(state_->window); // Load GL functions. - gladLoadGL((GLADloadfunc)glfwGetProcAddress); + gladLoadGL(); } const PixelBuffer* pixel_buffer = From eed131a81f22c87566851e9569fd610b7d3ecc82 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Thu, 7 Nov 2019 13:21:17 +0800 Subject: [PATCH 24/26] update. --- .../include/flutter/texture_registrar.h | 5 +++-- .../client_wrapper/plugin_registrar_unittests.cc | 13 ++++++------- .../cpp/client_wrapper/testing/stub_flutter_api.h | 6 +++--- shell/platform/glfw/flutter_glfw.cc | 10 +++++++--- shell/platform/windows/flutter_windows.cc | 8 ++++---- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index 66eb47c07229d..f8e7092ac9dbf 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -28,12 +28,13 @@ class TextureRegistrar { virtual ~TextureRegistrar() {} /** - * Registers a |texture| object and return textureId. + * Registers a |texture| object and returns the ID for that texture. */ virtual int64_t RegisterTexture(Texture* texture) = 0; /** - * Mark a texture buffer is ready. + * Notify the flutter engine that the texture object corresponding + * to |texure_id| needs to render a new texture. */ virtual void MarkTextureFrameAvailable(int64_t texture_id) = 0; diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc index 7d36fdfad3761..e10fc8fdc65ae 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc @@ -35,15 +35,14 @@ class TestApi : public testing::StubFlutterApi { const uint8_t* last_data_sent() { return last_data_sent_; } - int64_t RegisterExternalTexture( - FlutterTexutreCallback texture_callback, - void* user_data) override { - last_texture_id_ = 1; - return last_texture_id_; + int64_t RegisterExternalTexture(FlutterTexutreCallback texture_callback, + void* user_data) override { + last_texture_id_ = 1; + return last_texture_id_; } bool UnregisterExternalTexture(int64_t texture_id) override { - if(texture_id == 2) { + if (texture_id == 2) { last_texture_id_ = -2; return true; } @@ -51,7 +50,7 @@ class TestApi : public testing::StubFlutterApi { } bool TextureFrameAvailable(int64_t texture_id) override { - if(texture_id == 1) { + if (texture_id == 1) { last_texture_id_ = 2; return true; } diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h index 750eb6bc38ff1..bbe00594f3ac9 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h @@ -66,9 +66,9 @@ class StubFlutterApi { // Called for FlutterDesktopRegisterExternalTexture. virtual int64_t RegisterExternalTexture( - FlutterTexutreCallback texture_callback, - void* user_data) { - return -1; + FlutterTexutreCallback texture_callback, + void* user_data) { + return -1; } // Called for FlutterDesktopUnregisterExternalTexture. diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index ab49104691964..5c765cfb13414 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -56,6 +56,9 @@ struct FlutterDesktopWindowControllerState { // The plugin registrar handle given to API clients. std::unique_ptr plugin_registrar; + // The plugin texture registrar handle given to API clients. + std::unique_ptr texture_registrar; + // Message dispatch manager for messages from the Flutter engine. std::unique_ptr message_dispatcher; @@ -115,7 +118,7 @@ struct FlutterDesktopPluginRegistrar { std::unique_ptr messenger; // The plugin texture registrar handle given to API clients. - std::unique_ptr texture_registrar; + FlutterDesktopTextureRegistrar* texture_registrar; // The handle for the window associated with this registrar. FlutterDesktopWindow* window; @@ -653,7 +656,8 @@ FlutterDesktopWindowControllerRef FlutterDesktopCreateWindow( std::unique_ptr textures = std::make_unique(); textures->engine = state->engine; - state->plugin_registrar->texture_registrar = std::move(textures); + state->texture_registrar = std::move(textures); + state->plugin_registrar->texture_registrar = state->texture_registrar.get(); state->internal_plugin_registrar = std::make_unique(state->plugin_registrar.get()); @@ -827,7 +831,7 @@ FlutterDesktopMessengerRef FlutterDesktopRegistrarGetMessenger( FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - return registrar->texture_registrar.get(); + return registrar->texture_registrar; } FlutterDesktopWindowRef FlutterDesktopRegistrarGetWindow( diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index 22b7d71f03b4e..fe0c29ee4b2b4 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -245,7 +245,7 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, // Please refer to https://github.com/flutter/flutter/issues/38601. FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - std::cout << "Not yet implemented.\n"; + std::cout << "Texture support is not yet implemented." << std::endl; return reinterpret_cast(nullptr); } @@ -253,20 +253,20 @@ int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, FlutterTexutreCallback texture_callback, void* user_data) { - std::cout << "Not yet implemented.\n"; + std::cout << "Texture support is not yet implemented." << std::endl; return -1; } bool FlutterDesktopUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { - std::cout << "Not yet implemented.\n"; + std::cout << "Texture support is not yet implemented." << std::endl; return false; } bool FlutterDesktopMarkExternalTextureFrameAvailable( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id) { - std::cout << "Not yet implemented.\n"; + std::cout << "Texture support is not yet implemented." << std::endl; return false; } From aba2fa29e6df21864f3760bdb7d7493d103400b5 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Thu, 7 Nov 2019 14:51:50 +0800 Subject: [PATCH 25/26] update unit test. --- .../include/flutter/texture_registrar.h | 8 +-- .../plugin_registrar_unittests.cc | 63 ++++++++++++++++--- .../cpp/public/flutter_texture_registrar.h | 2 + .../fuchsia/runtime/dart/utils/BUILD.gn | 4 +- shell/platform/glfw/external_texture_gl.h | 5 +- 5 files changed, 64 insertions(+), 18 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h index f8e7092ac9dbf..b3cff321c6e0a 100644 --- a/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h +++ b/shell/platform/common/cpp/client_wrapper/include/flutter/texture_registrar.h @@ -16,10 +16,10 @@ namespace flutter { class Texture { public: virtual ~Texture() {} - // This is in response to the texture copy request interface, providing the - // |height| and |width| parameters of bounds. - // In some cases, we need to scale the texture to the bounds size to reduce - // memory usage. + // This interface is used to respond to texture copy requests from the Flutter + // engine, Flutter engine will be providing the |height| and |width| + // parameters of bounds. In some cases, the user can be scale the texture to + // the size of the bounds to reduce memory usage. virtual const PixelBuffer* CopyPixelBuffer(size_t width, size_t height) = 0; }; diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc index e10fc8fdc65ae..982f713a56f89 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include #include #include @@ -16,6 +17,14 @@ namespace { // Stub implementation to validate calls to the API. class TestApi : public testing::StubFlutterApi { + public: + struct FakeTexture { + int64_t texture_id; + int32_t mark_count; + FlutterTexutreCallback texture_callback; + void* user_data; + }; + public: // |flutter::testing::StubFlutterApi| bool MessengerSend(const char* channel, @@ -37,31 +46,51 @@ class TestApi : public testing::StubFlutterApi { int64_t RegisterExternalTexture(FlutterTexutreCallback texture_callback, void* user_data) override { - last_texture_id_ = 1; + last_texture_id_++; + + auto texture = std::make_unique(); + texture->texture_callback = texture_callback; + texture->user_data = user_data; + texture->mark_count = 0; + texture->texture_id = last_texture_id_; + + textures_[last_texture_id_] = std::move(texture); return last_texture_id_; } bool UnregisterExternalTexture(int64_t texture_id) override { - if (texture_id == 2) { - last_texture_id_ = -2; + auto it = textures_.find(texture_id); + if (it != textures_.end()) { + textures_.erase(it); return true; } return false; } bool TextureFrameAvailable(int64_t texture_id) override { - if (texture_id == 1) { - last_texture_id_ = 2; + auto it = textures_.find(texture_id); + if (it != textures_.end()) { + it->second->mark_count++; return true; } return false; } + FakeTexture* GetFakeTexture(int64_t texture_id) { + auto it = textures_.find(texture_id); + if (it != textures_.end()) + return it->second.get(); + return nullptr; + } + int64_t last_texture_id() { return last_texture_id_; } + size_t textures_size() { return textures_.size(); } + private: const uint8_t* last_data_sent_ = nullptr; int64_t last_texture_id_ = -1; + std::map> textures_; }; } // namespace @@ -92,12 +121,26 @@ TEST(MethodCallTest, RegisterTexture) { TextureRegistrar* textures = registrar.textures(); EXPECT_EQ(test_api->last_texture_id(), -1); - int64_t texture_id = textures->RegisterTexture(nullptr); - EXPECT_EQ(texture_id, 1); + auto texture = test_api->GetFakeTexture(0); + EXPECT_EQ(texture, nullptr); + + int64_t texture_id = textures->RegisterTexture(reinterpret_cast(2)); + EXPECT_EQ(test_api->last_texture_id(), texture_id); + EXPECT_EQ(test_api->textures_size(), static_cast(1)); + + texture = test_api->GetFakeTexture(texture_id); + EXPECT_EQ(texture->texture_id, texture_id); + EXPECT_EQ(texture->user_data, reinterpret_cast(2)); + textures->MarkTextureFrameAvailable(texture_id); - EXPECT_EQ(test_api->last_texture_id(), 2); - textures->UnregisterTexture(2); - EXPECT_EQ(test_api->last_texture_id(), -2); + textures->MarkTextureFrameAvailable(texture_id); + textures->MarkTextureFrameAvailable(texture_id); + EXPECT_EQ(texture->mark_count, 3); + + textures->UnregisterTexture(texture_id); + texture = test_api->GetFakeTexture(texture_id); + EXPECT_EQ(texture, nullptr); + EXPECT_EQ(test_api->textures_size(), static_cast(0)); } } // namespace flutter diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 2283a2eacbeb6..2c4551022f42c 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -44,11 +44,13 @@ FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( void* user_data); // Unregisters an existing texture from the Flutter engine for a |texture_id|. +// Returns true on success, false on failure. FLUTTER_EXPORT bool FlutterDesktopUnregisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); // Marks that a new texture frame is available for a given |texture_id|. +// Returns true on success, false on failure. FLUTTER_EXPORT bool FlutterDesktopMarkExternalTextureFrameAvailable( FlutterDesktopTextureRegistrarRef texture_registrar, int64_t texture_id); diff --git a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn index b1c94a762da59..1dca94e3c2acd 100644 --- a/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn +++ b/shell/platform/fuchsia/runtime/dart/utils/BUILD.gn @@ -34,10 +34,10 @@ source_set("utils") { "$fuchsia_sdk_root/pkg:async-loop-default", "$fuchsia_sdk_root/pkg:fdio", "$fuchsia_sdk_root/pkg:memfs", - "$fuchsia_sdk_root/pkg:syslog", - "$fuchsia_sdk_root/pkg:zx", "$fuchsia_sdk_root/pkg:sys_cpp", + "$fuchsia_sdk_root/pkg:syslog", "$fuchsia_sdk_root/pkg:vfs_cpp", + "$fuchsia_sdk_root/pkg:zx", "//third_party/tonic", ] diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index 589c189762d31..e9d822baf622a 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -28,11 +28,12 @@ class ExternalTextureGL { int64_t texture_id() { return reinterpret_cast(this); } /** - * Accepts texture buffer copy request from the flutter engine. - * When the user side marks the texture_id as available, the flutter engine + * Accepts texture buffer copy request from the Flutter engine. + * When the user side marks the texture_id as available, the Flutter engine * will callback to this method and ask for populate the |opengl_texture| * object, such as the texture type and the format of the pixel buffer and the * texture object. + * Returns true on success, false on failure. */ bool PopulateTextureWithIdentifier(size_t width, size_t height, From d8efcdb3b48d064befde113ebc4b7a4d430af6a0 Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Mon, 9 Dec 2019 20:13:41 +0800 Subject: [PATCH 26/26] Fixed typo. --- shell/platform/common/cpp/client_wrapper/plugin_registrar.cc | 2 +- .../common/cpp/client_wrapper/plugin_registrar_unittests.cc | 4 ++-- .../common/cpp/client_wrapper/testing/stub_flutter_api.cc | 2 +- .../common/cpp/client_wrapper/testing/stub_flutter_api.h | 2 +- shell/platform/common/cpp/public/flutter_texture_registrar.h | 4 ++-- shell/platform/glfw/external_texture_gl.cc | 2 +- shell/platform/glfw/external_texture_gl.h | 4 ++-- shell/platform/glfw/flutter_glfw.cc | 2 +- shell/platform/windows/flutter_windows.cc | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc index 1b2aed911b9f2..352a390ddff8e 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar.cc @@ -153,7 +153,7 @@ class TextureRegistrarImpl : public TextureRegistrar { TextureRegistrarImpl& operator=(TextureRegistrarImpl const&) = delete; virtual int64_t RegisterTexture(Texture* texture) override { - FlutterTexutreCallback callback = + FlutterTextureCallback callback = [](size_t width, size_t height, void* user_data) -> const PixelBuffer* { return static_cast(user_data)->CopyPixelBuffer(width, height); }; diff --git a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc index 982f713a56f89..1d06f17cf9d09 100644 --- a/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc +++ b/shell/platform/common/cpp/client_wrapper/plugin_registrar_unittests.cc @@ -21,7 +21,7 @@ class TestApi : public testing::StubFlutterApi { struct FakeTexture { int64_t texture_id; int32_t mark_count; - FlutterTexutreCallback texture_callback; + FlutterTextureCallback texture_callback; void* user_data; }; @@ -44,7 +44,7 @@ class TestApi : public testing::StubFlutterApi { const uint8_t* last_data_sent() { return last_data_sent_; } - int64_t RegisterExternalTexture(FlutterTexutreCallback texture_callback, + int64_t RegisterExternalTexture(FlutterTextureCallback texture_callback, void* user_data) override { last_texture_id_++; diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc index 7e4e4884cd00a..34e09c98673ec 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.cc @@ -51,7 +51,7 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, + FlutterTextureCallback texture_callback, void* user_data) { uint64_t result = -1; if (s_stub_implementation) { diff --git a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h index bbe00594f3ac9..cfe485188fbb5 100644 --- a/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h +++ b/shell/platform/common/cpp/client_wrapper/testing/stub_flutter_api.h @@ -66,7 +66,7 @@ class StubFlutterApi { // Called for FlutterDesktopRegisterExternalTexture. virtual int64_t RegisterExternalTexture( - FlutterTexutreCallback texture_callback, + FlutterTextureCallback texture_callback, void* user_data) { return -1; } diff --git a/shell/platform/common/cpp/public/flutter_texture_registrar.h b/shell/platform/common/cpp/public/flutter_texture_registrar.h index 2c4551022f42c..0f57ffc685b8f 100644 --- a/shell/platform/common/cpp/public/flutter_texture_registrar.h +++ b/shell/platform/common/cpp/public/flutter_texture_registrar.h @@ -31,7 +31,7 @@ typedef struct { // The pixel buffer copy callback definition is provided to // the Flutter engine to copy the texture. -typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, +typedef const PixelBuffer* (*FlutterTextureCallback)(size_t width, size_t height, void* user_data); @@ -40,7 +40,7 @@ typedef const PixelBuffer* (*FlutterTexutreCallback)(size_t width, // function to copy the pixel buffer from the plugin caller. FLUTTER_EXPORT int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, + FlutterTextureCallback texture_callback, void* user_data); // Unregisters an existing texture from the Flutter engine for a |texture_id|. diff --git a/shell/platform/glfw/external_texture_gl.cc b/shell/platform/glfw/external_texture_gl.cc index f87c8f5cb1c59..e4eafc18f89ad 100644 --- a/shell/platform/glfw/external_texture_gl.cc +++ b/shell/platform/glfw/external_texture_gl.cc @@ -19,7 +19,7 @@ struct ExternalTextureGLState { GLuint gl_texture; }; -ExternalTextureGL::ExternalTextureGL(FlutterTexutreCallback texture_callback, +ExternalTextureGL::ExternalTextureGL(FlutterTextureCallback texture_callback, void* user_data) : state_(std::make_unique()), texture_callback_(texture_callback), diff --git a/shell/platform/glfw/external_texture_gl.h b/shell/platform/glfw/external_texture_gl.h index e9d822baf622a..a7a544fe14b48 100644 --- a/shell/platform/glfw/external_texture_gl.h +++ b/shell/platform/glfw/external_texture_gl.h @@ -18,7 +18,7 @@ typedef struct ExternalTextureGLState ExternalTextureGLState; // An adaptation class of flutter engine and external texture interface. class ExternalTextureGL { public: - ExternalTextureGL(FlutterTexutreCallback texture_callback, void* user_data); + ExternalTextureGL(FlutterTextureCallback texture_callback, void* user_data); virtual ~ExternalTextureGL(); @@ -41,7 +41,7 @@ class ExternalTextureGL { private: std::unique_ptr state_; - FlutterTexutreCallback texture_callback_ = nullptr; + FlutterTextureCallback texture_callback_ = nullptr; void* user_data_ = nullptr; }; diff --git a/shell/platform/glfw/flutter_glfw.cc b/shell/platform/glfw/flutter_glfw.cc index 5c765cfb13414..eb56d8b977697 100644 --- a/shell/platform/glfw/flutter_glfw.cc +++ b/shell/platform/glfw/flutter_glfw.cc @@ -900,7 +900,7 @@ void FlutterDesktopMessengerSetCallback(FlutterDesktopMessengerRef messenger, int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, + FlutterTextureCallback texture_callback, void* user_data) { auto texture_gl = std::make_unique(texture_callback, user_data); diff --git a/shell/platform/windows/flutter_windows.cc b/shell/platform/windows/flutter_windows.cc index fe0c29ee4b2b4..8f86fe98f6130 100644 --- a/shell/platform/windows/flutter_windows.cc +++ b/shell/platform/windows/flutter_windows.cc @@ -251,7 +251,7 @@ FlutterDesktopTextureRegistrarRef FlutterDesktopGetTextureRegistrar( int64_t FlutterDesktopRegisterExternalTexture( FlutterDesktopTextureRegistrarRef texture_registrar, - FlutterTexutreCallback texture_callback, + FlutterTextureCallback texture_callback, void* user_data) { std::cout << "Texture support is not yet implemented." << std::endl; return -1;