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

@ -6,7 +6,7 @@ packages:
description: description:
name: async name: async
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0 sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.10.0" version: "2.10.0"
boolean_selector: boolean_selector:
@ -14,7 +14,7 @@ packages:
description: description:
name: boolean_selector name: boolean_selector
sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66" sha256: "6cfb5af12253eaf2b368f07bacc5a80d1301a071c73360d746b7f2e32d762c66"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
characters: characters:
@ -22,7 +22,7 @@ packages:
description: description:
name: characters name: characters
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
clock: clock:
@ -30,7 +30,7 @@ packages:
description: description:
name: clock name: clock
sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf sha256: cb6d7f03e1de671e34607e909a7213e31d7752be4fb66a86d29fe1eb14bfb5cf
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.1.1" version: "1.1.1"
collection: collection:
@ -38,7 +38,7 @@ packages:
description: description:
name: collection name: collection
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0 sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.17.0" version: "1.17.0"
cupertino_icons: cupertino_icons:
@ -46,7 +46,7 @@ packages:
description: description:
name: cupertino_icons name: cupertino_icons
sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be sha256: e35129dc44c9118cee2a5603506d823bab99c68393879edb440e0090d07586be
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.0.5" version: "1.0.5"
fake_async: fake_async:
@ -54,7 +54,7 @@ packages:
description: description:
name: fake_async name: fake_async
sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78" sha256: "511392330127add0b769b75a987850d136345d9227c6b94c96a04cf4a391bf78"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.3.1" version: "1.3.1"
flutter: flutter:
@ -67,7 +67,7 @@ packages:
description: description:
name: flutter_lints name: flutter_lints
sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c sha256: aeb0b80a8b3709709c9cc496cdc027c5b3216796bc0af0ce1007eaf24464fd4c
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
flutter_test: flutter_test:
@ -80,7 +80,7 @@ packages:
description: description:
name: js name: js
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7" sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.6.5" version: "0.6.5"
lints: lints:
@ -88,7 +88,7 @@ packages:
description: description:
name: lints name: lints
sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593" sha256: "5e4a9cd06d447758280a8ac2405101e0e2094d2a1dbdd3756aec3fe7775ba593"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.0.1" version: "2.0.1"
matcher: matcher:
@ -96,7 +96,7 @@ packages:
description: description:
name: matcher name: matcher
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72" sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.12.13" version: "0.12.13"
material_color_utilities: material_color_utilities:
@ -104,7 +104,7 @@ packages:
description: description:
name: material_color_utilities name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724 sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.2.0" version: "0.2.0"
meta: meta:
@ -112,7 +112,7 @@ packages:
description: description:
name: meta name: meta
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42" sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.8.0" version: "1.8.0"
path: path:
@ -120,7 +120,7 @@ packages:
description: description:
name: path name: path
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.8.2" version: "1.8.2"
plugin_platform_interface: plugin_platform_interface:
@ -128,7 +128,7 @@ packages:
description: description:
name: plugin_platform_interface name: plugin_platform_interface
sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.3" version: "2.1.3"
sky_engine: sky_engine:
@ -141,7 +141,7 @@ packages:
description: description:
name: source_span name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250 sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.9.1" version: "1.9.1"
stack_trace: stack_trace:
@ -149,7 +149,7 @@ packages:
description: description:
name: stack_trace name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5 sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.11.0" version: "1.11.0"
stream_channel: stream_channel:
@ -157,7 +157,7 @@ packages:
description: description:
name: stream_channel name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8" sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
string_scanner: string_scanner:
@ -165,7 +165,7 @@ packages:
description: description:
name: string_scanner name: string_scanner
sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde" sha256: "556692adab6cfa87322a115640c11f13cb77b3f076ddcc5d6ae3c20242bedcde"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.2.0" version: "1.2.0"
term_glyph: term_glyph:
@ -173,7 +173,7 @@ packages:
description: description:
name: term_glyph name: term_glyph
sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84 sha256: a29248a84fbb7c79282b40b8c72a1209db169a2e0542bce341da992fe1bc7e84
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "1.2.1" version: "1.2.1"
test_api: test_api:
@ -181,7 +181,7 @@ packages:
description: description:
name: test_api name: test_api
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206 sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "0.4.16" version: "0.4.16"
texture_rgba_renderer: texture_rgba_renderer:
@ -196,7 +196,7 @@ packages:
description: description:
name: vector_math name: vector_math
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
url: "https://pub.dev" url: "https://pub.flutter-io.cn"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
sdks: sdks:

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. # Any new source files that you add to the plugin should be added here.
list(APPEND PLUGIN_SOURCES list(APPEND PLUGIN_SOURCES
"texture_rgba_renderer_plugin.cpp" "texture_rgba_renderer_plugin.cpp"
"texture_rgba.cpp"
"texture_rgba.h"
"texture_rgba_renderer_plugin.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()); &flutter::StandardMethodCodec::GetInstance());
auto plugin = std::make_unique<TextureRgbaRendererPlugin>(); auto plugin = std::make_unique<TextureRgbaRendererPlugin>();
plugin->texture_registrar = registrar->texture_registrar();
channel->SetMethodCallHandler( channel->SetMethodCallHandler(
[plugin_pointer = plugin.get()](const auto &call, auto result) { [plugin_pointer = plugin.get()](const auto &call, auto result) {
@ -40,17 +41,9 @@ TextureRgbaRendererPlugin::~TextureRgbaRendererPlugin() {}
void TextureRgbaRendererPlugin::HandleMethodCall( void TextureRgbaRendererPlugin::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue> &method_call, const flutter::MethodCall<flutter::EncodableValue> &method_call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) { std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
if (method_call.method_name().compare("getPlatformVersion") == 0) { if (method_call.method_name().compare("createTexture") == 0) {
std::ostringstream version_stream; auto args = std::get<flutter::EncodableMap*>(method_call.arguments());
version_stream << "Windows "; arg
if (IsWindows10OrGreater()) {
version_stream << "10+";
} else if (IsWindows8OrGreater()) {
version_stream << "8";
} else if (IsWindows7OrGreater()) {
version_stream << "7";
}
result->Success(flutter::EncodableValue(version_stream.str()));
} else { } else {
result->NotImplemented(); result->NotImplemented();
} }

View file

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