opt: initial windows impl

This commit is contained in:
Kingtous 2023-02-17 09:21:17 +08:00
parent 4807594245
commit 59475c0020
6 changed files with 75 additions and 33 deletions

View file

@ -15,6 +15,8 @@ set(PLUGIN_NAME "texture_rgba_renderer_plugin")
# Any new source files that you add to the plugin should be added here.
list(APPEND PLUGIN_SOURCES
"texture_rgba_renderer_plugin.cpp"
"texture_rgba.cpp"
"texture_rgba.h"
"texture_rgba_renderer_plugin.h"
)

19
windows/texture_rgba.cpp Normal file
View file

@ -0,0 +1,19 @@
#include "texture_rgba.h"
TextureRgba::TextureRgba(flutter::TextureRegistrar* texture_registrar)
{
}
TextureRgba::~TextureRgba()
{
texture_registrar_->UnregisterTexture(texture_id_);
}
void TextureRgba::MarkVideoFrameAvailable(uint8_t* buffer, int32_t width, int32_t height)
{
const std::lock_guard<std::mutex> lock(mutex_);
flutter_pixel_buffer_.buffer = buffer;
flutter_pixel_buffer_.width = width;
flutter_pixel_buffer_.height = height;
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
}

22
windows/texture_rgba.h Normal file
View file

@ -0,0 +1,22 @@
#include <flutter/texture_registrar.h>
#include <mutex>
#pragma once
class TextureRgba
{
public:
TextureRgba(flutter::TextureRegistrar* texture_registrar);
~TextureRgba();
void MarkVideoFrameAvailable(uint8_t* buffer, int32_t width, int32_t height);
int64_t texture_id() const { return texture_id_; };
private:
FlutterDesktopPixelBuffer flutter_pixel_buffer_{};
flutter::TextureRegistrar* texture_registrar_ = nullptr;
std::unique_ptr<flutter::TextureVariant> texture_ = nullptr;
int64_t texture_id_;
mutable std::mutex mutex_;
};

View file

@ -24,6 +24,7 @@ void TextureRgbaRendererPlugin::RegisterWithRegistrar(
&flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<TextureRgbaRendererPlugin>();
plugin->texture_registrar = registrar->texture_registrar();
channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) {
@ -40,17 +41,9 @@ TextureRgbaRendererPlugin::~TextureRgbaRendererPlugin() {}
void TextureRgbaRendererPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if (method_call.method_name().compare("getPlatformVersion") == 0) {
std::ostringstream version_stream;
version_stream << "Windows ";
if (IsWindows10OrGreater()) {
version_stream << "10+";
} else if (IsWindows8OrGreater()) {
version_stream << "8";
} else if (IsWindows7OrGreater()) {
version_stream << "7";
}
result->Success(flutter::EncodableValue(version_stream.str()));
if (method_call.method_name().compare("createTexture") == 0) {
auto args = std::get<flutter::EncodableMap*>(method_call.arguments());
arg
} else {
result->NotImplemented();
}

View file

@ -3,8 +3,11 @@
#include <flutter/method_channel.h>
#include <flutter/plugin_registrar_windows.h>
#include <flutter/texture_registrar.h>
#include "texture_rgba.h"
#include <memory>
#include <unordered_map>
namespace texture_rgba_renderer {
@ -20,11 +23,14 @@ class TextureRgbaRendererPlugin : public flutter::Plugin {
TextureRgbaRendererPlugin(const TextureRgbaRendererPlugin&) = delete;
TextureRgbaRendererPlugin& operator=(const TextureRgbaRendererPlugin&) = delete;
flutter::TextureRegistrar* texture_registrar;
private:
// Called when a method is called on this plugin's channel from Dart.
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
std::unordered_map<uint64_t, std::unique_ptr<TextureRgba>> textures_;
};
} // namespace texture_rgba_renderer