From e118e9634117d8031ba0bb4beee1b435efca02f1 Mon Sep 17 00:00:00 2001 From: Kingtous Date: Sat, 18 Feb 2023 04:39:00 -0800 Subject: [PATCH] win test commit (#2) Signed-off-by: fufesou Co-authored-by: fufesou Co-authored-by: fufesou --- windows/texture_rgba.cpp | 29 ++++++------- windows/texture_rgba.h | 41 ++++++++++++++++++- windows/texture_rgba_renderer_plugin.cpp | 4 ++ .../texture_rgba_renderer_plugin_c_api.cpp | 3 +- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/windows/texture_rgba.cpp b/windows/texture_rgba.cpp index 070a35f..5a1048d 100644 --- a/windows/texture_rgba.cpp +++ b/windows/texture_rgba.cpp @@ -1,12 +1,16 @@ #include "texture_rgba.h" +#include -TextureRgba::TextureRgba(flutter::TextureRegistrar* texture_registrar) +TextureRgba::TextureRgba(flutter::TextureRegistrar *texture_registrar) { this->texture_registrar_ = texture_registrar; // TODO: flutter only support PixelBuffer in 2023.02.17. - auto buffer = flutter::PixelBufferTexture([=](size_t width, size_t height) -> const FlutterDesktopPixelBuffer* { - return this->buffer(); - }); + auto buffer = flutter::PixelBufferTexture([=](size_t width, size_t height) -> const FlutterDesktopPixelBuffer * + { + std::cout << " GL. C++ rendering interval " << timer_.elapsed() << " ms" << std::endl; + timer_.reset(); + const std::lock_guard lock(mutex_); + return this->buffer(); }); texture_ = std::make_unique(buffer); this->texture_id_ = texture_registrar->RegisterTexture(texture_.get()); } @@ -17,8 +21,9 @@ TextureRgba::~TextureRgba() } void TextureRgba::MarkVideoFrameAvailable( - std::vector& buffer, size_t width, size_t height) { - const std::lock_guard lock(mutex_); + std::vector &buffer, size_t width, size_t height) +{ + const std::lock_guard lock(mutex_); // FIXME: remove copy. std::swap(buffer, buffer_tmp_); flutter_pixel_buffer_.buffer = &buffer_tmp_[0]; @@ -27,17 +32,7 @@ void TextureRgba::MarkVideoFrameAvailable( texture_registrar_->MarkTextureFrameAvailable(texture_id_); } -void TextureRgba::MarkVideoFrameAvailablePtr( - const uint8_t* buffer, size_t width, size_t height) { - const std::lock_guard lock(mutex_); - // FIXME: remove copy. - flutter_pixel_buffer_.buffer = buffer; - flutter_pixel_buffer_.width = width; - flutter_pixel_buffer_.height = height; - texture_registrar_->MarkTextureFrameAvailable(texture_id_); -} - -inline const FlutterDesktopPixelBuffer* TextureRgba::buffer() +inline const FlutterDesktopPixelBuffer *TextureRgba::buffer() { return &this->flutter_pixel_buffer_; } diff --git a/windows/texture_rgba.h b/windows/texture_rgba.h index 2fe5233..8d68505 100644 --- a/windows/texture_rgba.h +++ b/windows/texture_rgba.h @@ -1,7 +1,45 @@ #include #include +#include #pragma once + +using namespace std; +using namespace std::chrono; +class Timer +{ +public: +Timer() : m_begin(high_resolution_clock::now()) {} +void reset() { m_begin = high_resolution_clock::now(); } +int64_t elapsed() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +int64_t elapsed_micro() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +int64_t elapsed_nano() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +int64_t elapsed_seconds() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +int64_t elapsed_minutes() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +int64_t elapsed_hours() const +{ +return duration_cast(high_resolution_clock::now() - m_begin).count(); +} +private: +time_point m_begin; +}; + + class TextureRgba { public: @@ -10,8 +48,6 @@ public: void MarkVideoFrameAvailable(std::vector& buffer, size_t width, size_t height); - void MarkVideoFrameAvailablePtr(const uint8_t* buffer, size_t width, size_t height); - int64_t texture_id() const { return texture_id_; }; const FlutterDesktopPixelBuffer* buffer(); @@ -23,5 +59,6 @@ private: int64_t texture_id_; mutable std::mutex mutex_; std::vector buffer_tmp_; + Timer timer_; }; diff --git a/windows/texture_rgba_renderer_plugin.cpp b/windows/texture_rgba_renderer_plugin.cpp index a5186bf..d1e853c 100644 --- a/windows/texture_rgba_renderer_plugin.cpp +++ b/windows/texture_rgba_renderer_plugin.cpp @@ -80,14 +80,18 @@ void TextureRgbaRendererPlugin::HandleMethodCall( } } else if (method_call.method_name().compare("getTexturePtr") == 0) { + std::cout << "REMOVE ME ==================== getTexturePtr 111" << std::endl; auto args = std::get(*method_call.arguments()); auto key = std::get(args.at(flutter::EncodableValue("key"))); + std::cout << "REMOVE ME ==================== getTexturePtr 222 key " << key << std::endl; if (textures_.find(key) == textures_.end()) { + std::cout << "REMOVE ME ==================== getTexturePtr 333" << std::endl; result->Success(flutter::EncodableValue(-1)); } else { // Return an address. size_t rgba = reinterpret_cast((void*) textures_[key].get()); + std::cout << "REMOVE ME ==================== getTexturePtr 444" << std::endl; result->Success(flutter::EncodableValue(int64_t(rgba))); } } diff --git a/windows/texture_rgba_renderer_plugin_c_api.cpp b/windows/texture_rgba_renderer_plugin_c_api.cpp index ec68085..6737dd9 100644 --- a/windows/texture_rgba_renderer_plugin_c_api.cpp +++ b/windows/texture_rgba_renderer_plugin_c_api.cpp @@ -14,5 +14,6 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar( void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int width, int height) { TextureRgba* rgba = static_cast(texture_rgba); - rgba->MarkVideoFrameAvailablePtr(buffer, width, height); + std::vector data(buffer, buffer + width * height * 4); + rgba->MarkVideoFrameAvailable(data, width, height); }