Win bg fg buffer (#4)
* better frame available Signed-off-by: fufesou <shuanglongchen@yeah.net> * fix win, bg fg buffers Signed-off-by: fufesou <shuanglongchen@yeah.net> * swap -1 Signed-off-by: fufesou <shuanglongchen@yeah.net> --------- Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
749acc2f87
commit
69a51033bf
3 changed files with 41 additions and 23 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "texture_rgba.h"
|
||||
#include <iostream>
|
||||
|
||||
|
||||
TextureRgba::TextureRgba(flutter::TextureRegistrar *texture_registrar)
|
||||
{
|
||||
this->texture_registrar_ = texture_registrar;
|
||||
|
|
@ -19,28 +20,35 @@ TextureRgba::~TextureRgba()
|
|||
void TextureRgba::MarkVideoFrameAvailable(
|
||||
std::vector<uint8_t> &buffer, size_t width, size_t height)
|
||||
{
|
||||
int bg_index = 0;
|
||||
if (buffer.empty() || buffer.size() != width * height * 4)
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (last_fg_index_ != fg_index_)
|
||||
{
|
||||
flutter_pixel_buffer_.buffer = static_cast<const uint8_t *>(buffer_tmp_[fg_index_].data());
|
||||
flutter_pixel_buffer_.width = width_[fg_index_];
|
||||
flutter_pixel_buffer_.height = height_[fg_index_];
|
||||
last_fg_index_ = fg_index_;
|
||||
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
|
||||
}
|
||||
bg_index = fg_index_ ^ 1;
|
||||
return;
|
||||
}
|
||||
|
||||
const std::lock_guard<std::mutex> lock(mutex_);
|
||||
int bg_index = fg_index_ ^ 1;
|
||||
buffer.swap(buffer_tmp_[bg_index]);
|
||||
width_[bg_index] = width;
|
||||
height_[bg_index] = height;
|
||||
if (!buff_ready_)
|
||||
{
|
||||
buff_ready_ = true;
|
||||
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
|
||||
}
|
||||
}
|
||||
|
||||
// This function may be called
|
||||
// event texture_registrar_->MarkTextureFrameAvailable(texture_id_); is not called before.
|
||||
inline const FlutterDesktopPixelBuffer *TextureRgba::buffer()
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(mutex_);
|
||||
fg_index_ ^= 1;
|
||||
if (buff_ready_)
|
||||
{
|
||||
fg_index_ ^= 1;
|
||||
flutter_pixel_buffer_.buffer = static_cast<const uint8_t *>(buffer_tmp_[fg_index_].data());
|
||||
flutter_pixel_buffer_.width = width_[fg_index_];
|
||||
flutter_pixel_buffer_.height = height_[fg_index_];
|
||||
buff_ready_ = false;
|
||||
}
|
||||
return &this->flutter_pixel_buffer_;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue