|
|
|
@ -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<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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|