windows: avoid unnecessary memory allocation
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
parent
96ed6df4a9
commit
c615e9507a
3 changed files with 20 additions and 2 deletions
|
|
@ -39,6 +39,23 @@ void TextureRgba::MarkVideoFrameAvailable(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextureRgba::MarkVideoFrameAvailable2(const uint8_t* buffer, const size_t buffer_length, size_t width, size_t height) {
|
||||||
|
if (!buffer || buffer_length < width * height * 4)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
int bg_index = fg_index_ ^ 1;
|
||||||
|
buffer_tmp_[bg_index].assign(buffer, buffer + buffer_length);
|
||||||
|
width_[bg_index] = width;
|
||||||
|
height_[bg_index] = height;
|
||||||
|
if (!buff_ready_)
|
||||||
|
{
|
||||||
|
buff_ready_ = true;
|
||||||
|
texture_registrar_->MarkTextureFrameAvailable(texture_id_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This function may be called
|
// This function may be called
|
||||||
// event texture_registrar_->MarkTextureFrameAvailable(texture_id_); is not called before.
|
// event texture_registrar_->MarkTextureFrameAvailable(texture_id_); is not called before.
|
||||||
inline const FlutterDesktopPixelBuffer *TextureRgba::buffer()
|
inline const FlutterDesktopPixelBuffer *TextureRgba::buffer()
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ 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 MarkVideoFrameAvailable2(const uint8_t* buffer, size_t buffer_length, 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();
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,5 @@ void FlutterRgbaRendererPluginOnRgba(void *texture_rgba, const uint8_t *buffer,
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureRgba *rgba = static_cast<TextureRgba *>(texture_rgba);
|
TextureRgba *rgba = static_cast<TextureRgba *>(texture_rgba);
|
||||||
std::vector<uint8_t> data(buffer, buffer + len);
|
rgba->MarkVideoFrameAvailable2(buffer, len, width, height);
|
||||||
rgba->MarkVideoFrameAvailable(data, width, height);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue