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:
itsmattkc
2020-06-19 17:06:14 +10:00
parent ab74c1579e
commit b2a3cede2c
7 changed files with 52 additions and 41 deletions
+7 -3
View File
@@ -181,6 +181,9 @@ void Core::Start()
// the fact that some of the config paths set by default rely on the app name having been set (in main())
Config::Current().SetDefaults();
// Load application config
Config::Load();
// Declare custom types for Qt signal/slot system
DeclareTypesForQt();
@@ -193,9 +196,8 @@ void Core::Start()
// Initialize task manager
TaskManager::CreateInstance();
// Load application config
Config::Load();
// Initialize OpenGL service
OpenGLProxy::CreateInstance();
//
// Start application
@@ -223,6 +225,8 @@ void Core::Stop()
}
}
OpenGLProxy::DestroyInstance();
MenuShared::DestroyInstance();
TaskManager::DestroyInstance();
+1 -22
View File
@@ -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
+26
View File
@@ -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
+11
View File
@@ -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();
+6 -7
View File
@@ -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),
+1 -4
View File
@@ -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