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)
{
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<Encodable::Float>("width");
// auto height = call.GetArgument<Encodable::Float>("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<Encodable::Int>("textureId");
plugin->UnregisterTexture(textureId);
call.SendSuccessResponse(true);
}
void EmbedderTexturePlugin::unimplemented(const MethodCall &call)
{
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;
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 */

6
packages/embedder_texture/lib/embedder_texture_method_channel.dart

@ -19,9 +19,9 @@ class MethodChannelEmbedderTexture extends EmbedderTexturePlatform {
}
@override
Future<void> remove(int textureId) async {
await methodChannel.invokeMethod<int>('remove', {
Future<bool> remove(int textureId) async {
return await methodChannel.invokeMethod<bool>('remove', {
'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.');
}
Future<void> remove(int textureId) {
Future<bool> remove(int textureId) {
throw UnimplementedError('remove() has not been implemented.');
}
}

Loading…
Cancel
Save