renderer: re-use the same opengl instance for all background rendering
Previously the OpenGL instance was tied to each render/cache task, creating and destroying it each time one started and stopped. This was completely unnecessary since the instance holds no state and can be shared by all of the render tasks without having to expensively start a new one.
This commit is contained in:
@@ -27,38 +27,17 @@ OLIVE_NAMESPACE_ENTER
|
||||
OpenGLBackend::OpenGLBackend(QObject* parent) :
|
||||
RenderBackend(parent)
|
||||
{
|
||||
proxy_ = new OpenGLProxy();
|
||||
|
||||
QThread* proxy_thread = new QThread();
|
||||
proxy_thread->start(QThread::IdlePriority);
|
||||
proxy_->moveToThread(proxy_thread);
|
||||
|
||||
if (!proxy_->Init()) {
|
||||
ClearProxy();
|
||||
}
|
||||
}
|
||||
|
||||
OpenGLBackend::~OpenGLBackend()
|
||||
{
|
||||
Close();
|
||||
|
||||
ClearProxy();
|
||||
}
|
||||
|
||||
RenderWorker *OpenGLBackend::CreateNewWorker()
|
||||
{
|
||||
return new OpenGLWorker(this, proxy_);
|
||||
}
|
||||
|
||||
void OpenGLBackend::ClearProxy()
|
||||
{
|
||||
if (proxy_) {
|
||||
proxy_->thread()->quit();
|
||||
proxy_->thread()->wait();
|
||||
proxy_->thread()->deleteLater();
|
||||
proxy_->deleteLater();
|
||||
proxy_ = nullptr;
|
||||
}
|
||||
return new OpenGLWorker(this);
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -36,11 +36,6 @@ public:
|
||||
protected:
|
||||
virtual RenderWorker* CreateNewWorker() override;
|
||||
|
||||
private:
|
||||
void ClearProxy();
|
||||
|
||||
OpenGLProxy* proxy_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
OpenGLProxy* OpenGLProxy::instance_ = nullptr;
|
||||
|
||||
OpenGLProxy::OpenGLProxy(QObject *parent) :
|
||||
QObject(parent),
|
||||
ctx_(nullptr),
|
||||
@@ -48,6 +50,30 @@ OpenGLProxy::~OpenGLProxy()
|
||||
surface_.destroy();
|
||||
}
|
||||
|
||||
void OpenGLProxy::CreateInstance()
|
||||
{
|
||||
instance_ = new OpenGLProxy();
|
||||
|
||||
QThread* proxy_thread = new QThread();
|
||||
proxy_thread->start(QThread::IdlePriority);
|
||||
instance_->moveToThread(proxy_thread);
|
||||
|
||||
if (!instance_->Init()) {
|
||||
DestroyInstance();
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLProxy::DestroyInstance()
|
||||
{
|
||||
if (instance_) {
|
||||
instance_->thread()->quit();
|
||||
instance_->thread()->wait();
|
||||
instance_->thread()->deleteLater();
|
||||
instance_->deleteLater();
|
||||
instance_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool OpenGLProxy::Init()
|
||||
{
|
||||
// Create context object
|
||||
|
||||
@@ -41,6 +41,15 @@ public:
|
||||
|
||||
virtual ~OpenGLProxy() override;
|
||||
|
||||
static void CreateInstance();
|
||||
|
||||
static void DestroyInstance();
|
||||
|
||||
static OpenGLProxy* instance()
|
||||
{
|
||||
return instance_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize OpenGL instance in whatever thread this object is a part of
|
||||
*
|
||||
@@ -101,6 +110,8 @@ private:
|
||||
|
||||
OpenGLTextureCache texture_cache_;
|
||||
|
||||
static OpenGLProxy* instance_;
|
||||
|
||||
private slots:
|
||||
void FinishInit();
|
||||
|
||||
|
||||
@@ -22,15 +22,14 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
OpenGLWorker::OpenGLWorker(RenderBackend *parent, OpenGLProxy* proxy) :
|
||||
RenderWorker(parent),
|
||||
proxy_(proxy)
|
||||
OpenGLWorker::OpenGLWorker(RenderBackend *parent) :
|
||||
RenderWorker(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void OpenGLWorker::TextureToFrame(const QVariant &texture, FramePtr frame, const QMatrix4x4& mat) const
|
||||
{
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
QMetaObject::invokeMethod(OpenGLProxy::instance(),
|
||||
"TextureToBuffer",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_ARG(const QVariant&, texture),
|
||||
@@ -42,7 +41,7 @@ QVariant OpenGLWorker::FootageFrameToTexture(StreamPtr stream, FramePtr frame) c
|
||||
{
|
||||
QVariant value;
|
||||
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
QMetaObject::invokeMethod(OpenGLProxy::instance(),
|
||||
"FrameToValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
@@ -58,7 +57,7 @@ QVariant OpenGLWorker::CachedFrameToTexture(FramePtr frame) const
|
||||
{
|
||||
QVariant value;
|
||||
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
QMetaObject::invokeMethod(OpenGLProxy::instance(),
|
||||
"PreCachedFrameToValue",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
@@ -71,7 +70,7 @@ QVariant OpenGLWorker::ProcessShader(const Node *node, const TimeRange &range, c
|
||||
{
|
||||
QVariant value;
|
||||
|
||||
QMetaObject::invokeMethod(proxy_,
|
||||
QMetaObject::invokeMethod(OpenGLProxy::instance(),
|
||||
"RunNodeAccelerated",
|
||||
Qt::BlockingQueuedConnection,
|
||||
Q_RETURN_ARG(QVariant, value),
|
||||
|
||||
@@ -29,7 +29,7 @@ OLIVE_NAMESPACE_ENTER
|
||||
class OpenGLWorker : public RenderWorker
|
||||
{
|
||||
public:
|
||||
OpenGLWorker(RenderBackend* parent, OpenGLProxy* proxy);
|
||||
OpenGLWorker(RenderBackend* parent);
|
||||
|
||||
protected:
|
||||
virtual void TextureToFrame(const QVariant& texture, FramePtr frame, const QMatrix4x4 &mat) const override;
|
||||
@@ -42,9 +42,6 @@ protected:
|
||||
|
||||
virtual bool TextureHasAlpha(const QVariant& v) const override;
|
||||
|
||||
private:
|
||||
OpenGLProxy* proxy_;
|
||||
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Reference in New Issue
Block a user