This commit is contained in:
itsmattkc
2019-09-13 02:13:11 +10:00
11 changed files with 112 additions and 58 deletions
+10 -10
View File
@@ -15,7 +15,7 @@ extern "C" {
using namespace std;
typedef long intType;
typedef int64_t intType;
/*
* Zero Handling
* 0/0 = 0
@@ -33,7 +33,7 @@ public:
if(numer == 0)
denom = 0;
}
rational(const intType &numerator, const intType &denominator)
:numer(numerator), denom(denominator)
{
@@ -51,7 +51,7 @@ public:
else
numer = intType(0);
}
rational(const rational &rhs)
:numer(rhs.numer), denom(rhs.denom)
{
@@ -59,10 +59,10 @@ public:
}
rational(const AVRational& r);
//destructor
~rational();
//Assignment Operators
const rational& operator=(const rational &rhs);
const rational& operator+=(const rational &rhs);
@@ -75,7 +75,7 @@ public:
rational operator-(const rational &rhs) const;
rational operator/(const rational &rhs) const;
rational operator*(const rational &rhs) const;
//Relational and equality operators
bool operator<(const rational &rhs) const;
bool operator<=(const rational &rhs) const;
@@ -83,7 +83,7 @@ public:
bool operator>=(const rational &rhs) const;
bool operator==(const rational &rhs) const;
bool operator!=(const rational &rhs) const;
//Unary operators
const rational& operator++(); //prefix
rational operator++(int); //postfix
@@ -101,7 +101,7 @@ public:
// Returns whether the rational is null or not
bool isNull() const;
//Function: print number to cout
void print(ostream &out = cout) const;
@@ -114,7 +114,7 @@ public:
const intType& numerator() const;
const intType& denominator() const;
private:
//number of active instances
static int activeInstances;
@@ -122,7 +122,7 @@ private:
//numerator and denominator
intType numer;
intType denom;
//Function: ensures denom >= 0
void fixSigns();
//Function: ensures lowest form
+10 -8
View File
@@ -37,7 +37,16 @@ extern "C" {
#include "core.h"
#include "common/debug.h"
int main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
// Set OpenGL display profile (3.2 Core)
QSurfaceFormat format;
format.setVersion(3, 2);
format.setDepthBufferSize(24);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
// Create application instance
QApplication a(argc, argv);
@@ -63,13 +72,6 @@ int main(int argc, char *argv[]) {
// Set up debug handler
qInstallMessageHandler(DebugHandler);
// Set OpenGL display profile (3.2 Core)
QSurfaceFormat format;
format.setVersion(3, 2);
format.setDepthBufferSize(24);
format.setProfile(QSurfaceFormat::CoreProfile);
QSurfaceFormat::setDefaultFormat(format);
// Register FFmpeg codecs and filters (deprecated in 4.0+)
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100)
av_register_all();
+7
View File
@@ -254,6 +254,10 @@ void RendererProcessor::Start()
int background_thread_count = QThread::idealThreadCount();
// Some OpenGL implementations (notably wgl) require the context not to be current before sharing
QSurface* old_surface = ctx->surface();
ctx->doneCurrent();
threads_.resize(background_thread_count);
for (int i=0;i<threads_.size();i++) {
@@ -297,6 +301,9 @@ void RendererProcessor::Start()
last_download_thread_ = 0;
// Restore context now that thread creation is complete
ctx->makeCurrent(old_surface);
// Create master texture (the one sent to the viewer)
master_texture_ = std::make_shared<RenderTexture>();
master_texture_->Create(ctx, effective_width_, effective_height_, format_);
@@ -24,19 +24,14 @@
RendererThreadBase::RendererThreadBase(QOpenGLContext *share_ctx, const int &width, const int &height, const int &divider, const olive::PixelFormat &format, const olive::RenderMode &mode) :
share_ctx_(share_ctx),
width_(width),
height_(height),
divider_(divider),
format_(format),
mode_(mode),
render_instance_(nullptr)
render_instance_(width, height, divider, format, mode)
{
connect(share_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Cancel()));
}
RenderInstance *RendererThreadBase::render_instance()
{
return render_instance_;
return &render_instance_;
}
void RendererThreadBase::run()
@@ -44,18 +39,15 @@ void RendererThreadBase::run()
// Lock mutex for main loop
mutex_.lock();
// Signal that main thread can continue now
caller_mutex_.lock();
wait_cond_.wakeAll();
caller_mutex_.unlock();
RenderInstance instance(width_, height_, divider_, format_, mode_);
render_instance_ = &instance;
instance.SetShareContext(share_ctx_);
render_instance_.SetShareContext(share_ctx_);
// Allocate and create resources
if (instance.Start()) {
bool started = render_instance_.Start();
// Signal that main thread can continue now
WakeCaller();
if (started) {
// Main loop (use Cancel() to exit it)
ProcessLoop();
@@ -63,13 +55,20 @@ void RendererThreadBase::run()
}
// Free all resources
render_instance_ = nullptr;
instance.Stop();
render_instance_.Stop();
// Unlock mutex before exiting
mutex_.unlock();
}
void RendererThreadBase::WakeCaller()
{
// Signal that main thread can continue now
caller_mutex_.lock();
wait_cond_.wakeAll();
caller_mutex_.unlock();
}
void RendererThreadBase::StartThread(QThread::Priority priority)
{
caller_mutex_.lock();
@@ -59,19 +59,11 @@ protected:
QMutex caller_mutex_;
private:
void WakeCaller();
QOpenGLContext* share_ctx_;
const int& width_;
const int& height_;
const int& divider_;
const olive::PixelFormat& format_;
const olive::RenderMode& mode_;
RenderInstance* render_instance_;
RenderInstance render_instance_;
};
+2
View File
@@ -29,6 +29,8 @@ set(OLIVE_SOURCES
render/rendermodes.h
render/renderframebuffer.h
render/renderframebuffer.cpp
render/renderservice.h
render/renderservice.cpp
render/rendertexture.h
render/rendertexture.cpp
render/sampleformat.h
+9 -9
View File
@@ -26,7 +26,7 @@
RenderInstance::RenderInstance(const int& width,
const int& height,
const int &divider,
const int& divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode) :
share_ctx_(nullptr),
@@ -36,6 +36,14 @@ RenderInstance::RenderInstance(const int& width,
mode_(mode),
divider_(divider)
{
// Create offscreen surface
surface_.create();
}
RenderInstance::~RenderInstance()
{
// Destroy offscreen surface
surface_.destroy();
}
void RenderInstance::SetShareContext(QOpenGLContext *share)
@@ -65,13 +73,9 @@ bool RenderInstance::Start()
return false;
}
// Create offscreen surface
surface_.create();
// Make context current on that surface
if (!ctx_->makeCurrent(&surface_)) {
qWarning() << tr("Failed to makeCurrent() on offscreen surface in thread %1").arg(reinterpret_cast<quintptr>(this));
surface_.destroy();
return false;
}
@@ -100,11 +104,7 @@ void RenderInstance::Stop()
buffer_.Destroy();
// Destroy context
delete ctx_;
// Destroy offscreen surface
surface_.destroy();
}
bool RenderInstance::IsStarted()
+24 -1
View File
@@ -34,7 +34,8 @@
*
* RenderInstance contains everything that Nodes will need to draw with on a per-thread basis.
*
* In OpenGL,
* Due to its usage of QOffscreenSurface, a RenderInstance instance must be constructed in the main (GUI) thread. From
* there it is safe to call Start() on in another thread.
*/
class RenderInstance : public QObject
{
@@ -45,6 +46,28 @@ public:
const olive::PixelFormat& format,
const olive::RenderMode& mode);
virtual ~RenderInstance() override;
/**
* @brief Deleted copy constructor
*/
RenderInstance(const RenderInstance& other) = delete;
/**
* @brief Deleted move constructor
*/
RenderInstance(RenderInstance&& other) = delete;
/**
* @brief Deleted copy assignment
*/
RenderInstance& operator=(const RenderInstance& other) = delete;
/**
* @brief Deleted move assignment
*/
RenderInstance& operator=(RenderInstance&& other) = delete;
void SetShareContext(QOpenGLContext* share);
bool Start();
+8
View File
@@ -0,0 +1,8 @@
#include "renderservice.h"
RenderService* RenderService::render_service_;
RenderService::RenderService()
{
}
+19
View File
@@ -0,0 +1,19 @@
#ifndef RENDERSERVICE_H
#define RENDERSERVICE_H
class RenderService
{
public:
RenderService();
static RenderService* CreateInstance();
static RenderService* GetInstance();
static RenderService* DestroyInstance();
private:
static RenderService* render_service_;
};
#endif // RENDERSERVICE_H
+2
View File
@@ -37,6 +37,8 @@ void olive::style::AppSetDefault()
void olive::style::SetOliveStyle(const QString &style_name)
{
qApp->setStyle(QStyleFactory::create("Fusion"));
// Set CSS style for this
QFile css_file(QString(":/style/%1/style.css").arg(style_name));