Browse Source

[texture] Add start interface register

embedder_texture
Vitaliy Zarubin 1 year ago
parent
commit
f79d080cf3
  1. 41
      packages/embedder_texture/aurora/embedder_texture_plugin.cpp
  2. 7
      packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h
  3. 6
      packages/embedder_texture/lib/embedder_texture_method_channel.dart
  4. 2
      packages/embedder_texture/lib/embedder_texture_platform_interface.dart

41
packages/embedder_texture/aurora/embedder_texture_plugin.cpp

@ -8,42 +8,59 @@
void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar &registrar) void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{ {
TextureRegistrar *plugin = registrar.GetRegisterTexture();
registrar.RegisterMethodChannel("embedder_texture", registrar.RegisterMethodChannel("embedder_texture",
MethodCodecType::Standard, 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(); const auto &method = call.GetMethod();
if (method == "create") { if (method == "create") {
onCreate(call); onCreate(call, plugin);
return; return;
} }
if (method == "remove") { if (method == "remove") {
onRemove(call); onRemove(call, plugin);
return; return;
} }
unimplemented(call); unimplemented(call);
} }
void EmbedderTexturePlugin::onCreate(const MethodCall &call) void EmbedderTexturePlugin::onCreate(const MethodCall &call, TextureRegistrar *plugin)
{ {
// auto width = call.GetArgument<Encodable::Float>("width"); auto textureId = plugin->RegisterTexture(TextureType::Pixels,
// auto height = call.GetArgument<Encodable::Float>("height"); [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<Encodable::Int>("textureId");
plugin->UnregisterTexture(textureId);
call.SendSuccessResponse(true);
} }
void EmbedderTexturePlugin::unimplemented(const MethodCall &call) void EmbedderTexturePlugin::unimplemented(const MethodCall &call)
{ {
call.SendSuccessResponse(nullptr); call.SendSuccessResponse(nullptr);
} }

7
packages/embedder_texture/aurora/include/embedder_texture/embedder_texture_plugin.h

@ -19,10 +19,11 @@ public:
void RegisterWithRegistrar(PluginRegistrar &registrar) override; void RegisterWithRegistrar(PluginRegistrar &registrar) override;
private: private:
void onMethodCall(const MethodCall &call); void onMethodCall(const MethodCall &call, TextureRegistrar *plugin);
void onCreate(const MethodCall &call); void onCreate(const MethodCall &call, TextureRegistrar *plugin);
void onRemove(const MethodCall &call); void onRemove(const MethodCall &call, TextureRegistrar *plugin);
void unimplemented(const MethodCall &call); void unimplemented(const MethodCall &call);
FlutterPixelBuffer getBuffer();
}; };
#endif /* EMBEDDER_TEXTURE_PLUGIN_H */ #endif /* EMBEDDER_TEXTURE_PLUGIN_H */

6
packages/embedder_texture/lib/embedder_texture_method_channel.dart

@ -19,9 +19,9 @@ class MethodChannelEmbedderTexture extends EmbedderTexturePlatform {
} }
@override @override
Future<void> remove(int textureId) async { Future<bool> remove(int textureId) async {
await methodChannel.invokeMethod<int>('remove', { return await methodChannel.invokeMethod<bool>('remove', {
'textureId': textureId, 'textureId': textureId,
}); }) ?? false;
} }
} }

2
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.'); throw UnimplementedError('create() has not been implemented.');
} }
Future<void> remove(int textureId) { Future<bool> remove(int textureId) {
throw UnimplementedError('remove() has not been implemented.'); throw UnimplementedError('remove() has not been implemented.');
} }
} }

Loading…
Cancel
Save