From f79d080cf34837f7751372adb2f6f98ce0b38c45 Mon Sep 17 00:00:00 2001 From: Vitaliy Zarubin Date: Mon, 23 Oct 2023 20:44:11 +0300 Subject: [PATCH] [texture] Add start interface register --- .../aurora/embedder_texture_plugin.cpp | 41 +++++++++++++------ .../embedder_texture_plugin.h | 7 ++-- .../lib/embedder_texture_method_channel.dart | 6 +-- .../embedder_texture_platform_interface.dart | 2 +- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp index ed771a1..3f22718 100644 --- a/packages/embedder_texture/aurora/embedder_texture_plugin.cpp +++ b/packages/embedder_texture/aurora/embedder_texture_plugin.cpp @@ -8,42 +8,59 @@ void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar ®istrar) { + TextureRegistrar *plugin = registrar.GetRegisterTexture(); + registrar.RegisterMethodChannel("embedder_texture", MethodCodecType::Standard, - [this](const MethodCall &call) { this->onMethodCall(call); }); + [this, plugin](const MethodCall &call) { this->onMethodCall(call, plugin); }); } -void EmbedderTexturePlugin::onMethodCall(const MethodCall &call) -{ +FlutterPixelBuffer EmbedderTexturePlugin::getBuffer() { + uint8_t pixels[] = + { + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, + }; + return FlutterPixelBuffer { pixels }; +} + +void EmbedderTexturePlugin::onMethodCall(const MethodCall &call, TextureRegistrar *plugin) { const auto &method = call.GetMethod(); if (method == "create") { - onCreate(call); + onCreate(call, plugin); return; } if (method == "remove") { - onRemove(call); + onRemove(call, plugin); return; } unimplemented(call); } -void EmbedderTexturePlugin::onCreate(const MethodCall &call) +void EmbedderTexturePlugin::onCreate(const MethodCall &call, TextureRegistrar *plugin) { -// auto width = call.GetArgument("width"); -// auto height = call.GetArgument("height"); + auto textureId = plugin->RegisterTexture(TextureType::Pixels, + [this](size_t width, size_t height) { + return TextureVariant(this->getBuffer()); + }); - call.SendSuccessResponse(call.TextureRegister()); + call.SendSuccessResponse(textureId); } -void EmbedderTexturePlugin::onRemove(const MethodCall &call) +void EmbedderTexturePlugin::onRemove(const MethodCall &call, TextureRegistrar *plugin) { - call.SendSuccessResponse(nullptr); + auto textureId = call.GetArgument("textureId"); + + plugin->UnregisterTexture(textureId); + + call.SendSuccessResponse(true); } void EmbedderTexturePlugin::unimplemented(const MethodCall &call) { call.SendSuccessResponse(nullptr); -} \ No newline at end of file +} diff --git a/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h b/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h index a561068..eada95c 100644 --- a/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h +++ b/packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h @@ -19,10 +19,11 @@ public: void RegisterWithRegistrar(PluginRegistrar ®istrar) override; private: - void onMethodCall(const MethodCall &call); - void onCreate(const MethodCall &call); - void onRemove(const MethodCall &call); + void onMethodCall(const MethodCall &call, TextureRegistrar *plugin); + void onCreate(const MethodCall &call, TextureRegistrar *plugin); + void onRemove(const MethodCall &call, TextureRegistrar *plugin); void unimplemented(const MethodCall &call); + FlutterPixelBuffer getBuffer(); }; #endif /* EMBEDDER_TEXTURE_PLUGIN_H */ diff --git a/packages/embedder_texture/lib/embedder_texture_method_channel.dart b/packages/embedder_texture/lib/embedder_texture_method_channel.dart index d73f946..c7513a9 100644 --- a/packages/embedder_texture/lib/embedder_texture_method_channel.dart +++ b/packages/embedder_texture/lib/embedder_texture_method_channel.dart @@ -19,9 +19,9 @@ class MethodChannelEmbedderTexture extends EmbedderTexturePlatform { } @override - Future remove(int textureId) async { - await methodChannel.invokeMethod('remove', { + Future remove(int textureId) async { + return await methodChannel.invokeMethod('remove', { 'textureId': textureId, - }); + }) ?? false; } } diff --git a/packages/embedder_texture/lib/embedder_texture_platform_interface.dart b/packages/embedder_texture/lib/embedder_texture_platform_interface.dart index 1337c50..d120c4e 100644 --- a/packages/embedder_texture/lib/embedder_texture_platform_interface.dart +++ b/packages/embedder_texture/lib/embedder_texture_platform_interface.dart @@ -27,7 +27,7 @@ abstract class EmbedderTexturePlatform extends PlatformInterface { throw UnimplementedError('create() has not been implemented.'); } - Future remove(int textureId) { + Future remove(int textureId) { throw UnimplementedError('remove() has not been implemented.'); } }