Этот репозиторий содержит Flutter плагины для платформы ОС Аврора.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

66 lines
1.9 KiB

/**
* SPDX-FileCopyrightText: Copyright 2023 Open Mobile Platform LLC <community@omp.ru>
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <embedder_texture/embedder_texture_plugin.h>
#include <flutter/method-channel.h>
#include <flutter/platform-methods.h>
void EmbedderTexturePlugin::RegisterWithRegistrar(PluginRegistrar &registrar)
{
TextureRegistrar *plugin = registrar.GetRegisterTexture();
registrar.RegisterMethodChannel("embedder_texture",
MethodCodecType::Standard,
[this, plugin](const MethodCall &call) { this->onMethodCall(call, plugin); });
}
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, plugin);
return;
}
if (method == "remove") {
onRemove(call, plugin);
return;
}
unimplemented(call);
}
void EmbedderTexturePlugin::onCreate(const MethodCall &call, TextureRegistrar *plugin)
{
auto textureId = plugin->RegisterTexture(TextureType::Pixels,
[this](size_t width, size_t height) {
return TextureVariant(this->getBuffer());
});
call.SendSuccessResponse(textureId);
}
void EmbedderTexturePlugin::onRemove(const MethodCall &call, TextureRegistrar *plugin)
{
auto textureId = call.GetArgument<Encodable::Int>("textureId");
plugin->UnregisterTexture(textureId);
call.SendSuccessResponse(true);
}
void EmbedderTexturePlugin::unimplemented(const MethodCall &call)
{
call.SendSuccessResponse(nullptr);
}