render: implemented frame pool

Optimization
This commit is contained in:
itsmattkc
2021-04-28 17:31:25 +10:00
parent 2e96b57319
commit 51ccaedc78
8 changed files with 270 additions and 15 deletions
+27 -3
View File
@@ -26,14 +26,22 @@
#include <QtMath>
#include "common/oiioutils.h"
#include "render/framemanager.h"
namespace olive {
Frame::Frame() :
data_(nullptr),
data_size_(0),
timestamp_(0)
{
}
Frame::~Frame()
{
destroy();
}
FramePtr Frame::Create()
{
return std::make_shared<Frame>();
@@ -66,7 +74,7 @@ Color Frame::get_pixel(int x, int y) const
int byte_offset = y * linesize_bytes() + x * video_params().GetBytesPerPixel();
return Color(data_.data() + byte_offset, video_params().format(), video_params().channel_count());
return Color(reinterpret_cast<const char*>(data_ + byte_offset), video_params().format(), video_params().channel_count());
}
bool Frame::contains_pixel(int x, int y) const
@@ -82,7 +90,7 @@ void Frame::set_pixel(int x, int y, const Color &c)
int byte_offset = y * linesize_bytes() + x * video_params().GetBytesPerPixel();
c.toData(data_.data() + byte_offset, video_params().format(), video_params().channel_count());
c.toData(reinterpret_cast<char*>(data_ + byte_offset), video_params().format(), video_params().channel_count());
}
bool Frame::allocate()
@@ -93,11 +101,27 @@ bool Frame::allocate()
return false;
}
data_.resize(VideoParams::GetBufferSize(linesize_, height(), params_.format(), params_.channel_count()));
if (is_allocated()) {
// Already allocated
return true;
}
data_size_ = VideoParams::GetBufferSize(linesize_, height(), params_.format(), params_.channel_count());
data_ = FrameManager::Allocate(data_size_);
return true;
}
void Frame::destroy()
{
if (is_allocated()) {
FrameManager::Deallocate(data_size_, data_);
data_size_ = 0;
data_ = nullptr;
}
}
FramePtr Frame::convert(VideoParams::Format format) const
{
// Create new params with destination format