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:
parent
35e480aa73
commit
e118e96341
4 changed files with 57 additions and 20 deletions
|
|
@ -1,12 +1,16 @@
|
|||
#include "texture_rgba.h"
|
||||
#include <iostream>
|
||||
|
||||
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<std::mutex> lock(mutex_);
|
||||
return this->buffer(); });
|
||||
texture_ = std::make_unique<flutter::TextureVariant>(buffer);
|
||||
this->texture_id_ = texture_registrar->RegisterTexture(texture_.get());
|
||||
}
|
||||
|
|
@ -17,8 +21,9 @@ TextureRgba::~TextureRgba()
|
|||
}
|
||||
|
||||
void TextureRgba::MarkVideoFrameAvailable(
|
||||
std::vector<uint8_t>& buffer, size_t width, size_t height) {
|
||||
const std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::vector<uint8_t> &buffer, size_t width, size_t height)
|
||||
{
|
||||
const std::lock_guard<std::mutex> 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<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_;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,45 @@
|
|||
#include <flutter/texture_registrar.h>
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
|
||||
#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
|
||||
{
|
||||
public:
|
||||
|
|
@ -10,8 +48,6 @@ public:
|
|||
|
||||
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_; };
|
||||
|
||||
const FlutterDesktopPixelBuffer* buffer();
|
||||
|
|
@ -23,5 +59,6 @@ private:
|
|||
int64_t texture_id_;
|
||||
mutable std::mutex mutex_;
|
||||
std::vector<uint8_t> buffer_tmp_;
|
||||
Timer timer_;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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<flutter::EncodableMap>(*method_call.arguments());
|
||||
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()) {
|
||||
std::cout << "REMOVE ME ==================== getTexturePtr 333" << std::endl;
|
||||
result->Success(flutter::EncodableValue(-1));
|
||||
}
|
||||
else {
|
||||
// Return an address.
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,5 +14,6 @@ void TextureRgbaRendererPluginCApiRegisterWithRegistrar(
|
|||
|
||||
void FlutterRgbaRendererPluginOnRgba(void* texture_rgba, const uint8_t* buffer, int width, int height) {
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue