win test commit (#2)

Signed-off-by: fufesou <shuanglongchen@yeah.net>
Co-authored-by: fufesou <shuanglongchen@yeah.net>
Co-authored-by: fufesou <fufesou@users.noreply.github.com>
This commit is contained in:
Kingtous 2023-02-18 04:39:00 -08:00 • committed by GitHub
parent 35e480aa73
commit e118e96341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 20 deletions

View file

@ -1,12 +1,16 @@
#include "texture_rgba.h" #include "texture_rgba.h"
#include <iostream>
TextureRgba::TextureRgba(flutter::TextureRegistrar *texture_registrar) TextureRgba::TextureRgba(flutter::TextureRegistrar *texture_registrar)
{ {
this->texture_registrar_ = texture_registrar; this->texture_registrar_ = texture_registrar;
// TODO: flutter only support PixelBuffer in 2023.02.17. // TODO: flutter only support PixelBuffer in 2023.02.17.
auto buffer = flutter::PixelBufferTexture([=](size_t width, size_t height) -> const FlutterDesktopPixelBuffer* { auto buffer = flutter::PixelBufferTexture([=](size_t width, size_t height) -> const FlutterDesktopPixelBuffer *
return this->buffer(); {
}); std::cout << " GL. C++ rendering interval " << timer_.elapsed() << " ms" << std::endl;
timer_.reset();
const std::lock_guard<std::mutex> lock(mutex_);
return this->buffer(); });
texture_ = std::make_unique<flutter::TextureVariant>(buffer); texture_ = std::make_unique<flutter::TextureVariant>(buffer);
this->texture_id_ = texture_registrar->RegisterTexture(texture_.get()); this->texture_id_ = texture_registrar->RegisterTexture(texture_.get());
} }
@ -17,7 +21,8 @@ TextureRgba::~TextureRgba()
} }
void TextureRgba::MarkVideoFrameAvailable( void TextureRgba::MarkVideoFrameAvailable(
std::vector<uint8_t>& buffer, size_t width, size_t height) { std::vector<uint8_t> &buffer, size_t width, size_t height)
{
const std::lock_guard<std::mutex> lock(mutex_); const std::lock_guard<std::mutex> lock(mutex_);
// FIXME: remove copy. // FIXME: remove copy.
std::swap(buffer, buffer_tmp_); std::swap(buffer, buffer_tmp_);
@ -27,16 +32,6 @@ void TextureRgba::MarkVideoFrameAvailable(
texture_registrar_->MarkTextureFrameAvailable(texture_id_); texture_registrar_->MarkTextureFrameAvailable(texture_id_);
} }
void TextureRgba::MarkVideoFrameAvailablePtr(
const uint8_t* buffer, size_t width, size_t height) {
const std::lock_guard<std::mutex> 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_; return &this->flutter_pixel_buffer_;

View file

@ -1,7 +1,45 @@
#include <flutter/texture_registrar.h> #include <flutter/texture_registrar.h>
#include <mutex> #include <mutex>
#include <chrono>
#pragma once #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<chrono::milliseconds>(high_resolution_clock::now() - m_begin).count();
}
int64_t elapsed_micro() const
{
return duration_cast<chrono::microseconds>(high_resolution_clock::now() - m_begin).count();
}
int64_t elapsed_nano() const
{
return duration_cast<chrono::nanoseconds>(high_resolution_clock::now() - m_begin).count();
}
int64_t elapsed_seconds() const
{
return duration_cast<chrono::seconds>(high_resolution_clock::now() - m_begin).count();
}
int64_t elapsed_minutes() const
{
return duration_cast<chrono::minutes>(high_resolution_clock::now() - m_begin).count();
}
int64_t elapsed_hours() const
{
return duration_cast<chrono::hours>(high_resolution_clock::now() - m_begin).count();
}
private:
time_point<high_resolution_clock> m_begin;
};
class TextureRgba class TextureRgba
{ {
public: public:
@ -10,8 +48,6 @@ public:
void MarkVideoFrameAvailable(std::vector<uint8_t>& buffer, size_t width, size_t height); void MarkVideoFrameAvailable(std::vector<uint8_t>& 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_; }; int64_t texture_id() const { return texture_id_; };
const FlutterDesktopPixelBuffer* buffer(); const FlutterDesktopPixelBuffer* buffer();
@ -23,5 +59,6 @@ private:
int64_t texture_id_; int64_t texture_id_;
mutable std::mutex mutex_; mutable std::mutex mutex_;
std::vector<uint8_t> buffer_tmp_; std::vector<uint8_t> buffer_tmp_;
Timer timer_;
}; };

View file

@ -80,14 +80,18 @@ void TextureRgbaRendererPlugin::HandleMethodCall(
} }
} }
else if (method_call.method_name().compare("getTexturePtr") == 0) { else if (method_call.method_name().compare("getTexturePtr") == 0) {
std::cout << "REMOVE ME ==================== getTexturePtr 111" << std::endl;
auto args = std::get<flutter::EncodableMap>(*method_call.arguments()); auto args = std::get<flutter::EncodableMap>(*method_call.arguments());
auto key = std::get<int>(args.at(flutter::EncodableValue("key"))); auto key = std::get<int>(args.at(flutter::EncodableValue("key")));
std::cout << "REMOVE ME ==================== getTexturePtr 222 key " << key << std::endl;
if (textures_.find(key) == textures_.end()) { if (textures_.find(key) == textures_.end()) {
std::cout << "REMOVE ME ==================== getTexturePtr 333" << std::endl;
result->Success(flutter::EncodableValue(-1)); result->Success(flutter::EncodableValue(-1));
} }
else { else {
// Return an address. // Return an address.
size_t rgba = reinterpret_cast<size_t>((void*) textures_[key].get()); size_t rgba = reinterpret_cast<size_t>((void*) textures_[key].get());
std::cout << "REMOVE ME ==================== getTexturePtr 444" << std::endl;
result->Success(flutter::EncodableValue(int64_t(rgba))); result->Success(flutter::EncodableValue(int64_t(rgba)));
} }
} }

View file

@ -14,5 +14,6 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int width, int height) { void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int width, int height) {
TextureRgba* rgba = static_cast<TextureRgba*>(texture_rgba); TextureRgba* rgba = static_cast<TextureRgba*>(texture_rgba);
rgba->MarkVideoFrameAvailablePtr(buffer, width, height); std::vector<uint8_t> data(buffer, buffer + width * height * 4);
rgba->MarkVideoFrameAvailable(data, width, height);
} }