From 211aaaf8b8acbaf7efeb299d81f0782c8cdaea22 Mon Sep 17 00:00:00 2001 From: Dmitry Shusharin Date: Fri, 30 Jul 2021 17:20:07 +0700 Subject: [PATCH] gstqmlgl: create helper QRunnable-based class for render jobs Part-of: --- ext/qt/gstqtglutility.h | 12 ++++++++++++ ext/qt/qtitem.cc | 24 +----------------------- ext/qt/qtitem.h | 3 --- ext/qt/qtwindow.cc | 23 +---------------------- ext/qt/qtwindow.h | 3 --- 5 files changed, 14 insertions(+), 51 deletions(-) diff --git a/ext/qt/gstqtglutility.h b/ext/qt/gstqtglutility.h index 6b878ca..7b02bca 100644 --- a/ext/qt/gstqtglutility.h +++ b/ext/qt/gstqtglutility.h @@ -25,9 +25,21 @@ #include #include +#include G_BEGIN_DECLS +struct RenderJob : public QRunnable { + using Callable = std::function; + + explicit RenderJob(Callable c) : _c(c) { } + + void run() { _c(); } + +private: + Callable _c; +}; + GstGLDisplay * gst_qt_get_gl_display (gboolean sink); gboolean gst_qt_get_gl_wrapcontext (GstGLDisplay * display, GstGLContext **wrap_glcontext, GstGLContext **context); diff --git a/ext/qt/qtitem.cc b/ext/qt/qtitem.cc index e16533f..9876f8e 100644 --- a/ext/qt/qtitem.cc +++ b/ext/qt/qtitem.cc @@ -29,7 +29,6 @@ #include "gstqsgtexture.h" #include "gstqtglutility.h" -#include #include #include #include @@ -90,27 +89,6 @@ struct _QtGLVideoItemPrivate GQueue potentially_unbound_buffers; }; -class InitializeSceneGraph : public QRunnable -{ -public: - InitializeSceneGraph(QtGLVideoItem *item); - void run(); - -private: - QPointer item_; -}; - -InitializeSceneGraph::InitializeSceneGraph(QtGLVideoItem *item) : - item_(item) -{ -} - -void InitializeSceneGraph::run() -{ - if(item_) - item_->onSceneGraphInitialized(); -} - QtGLVideoItem::QtGLVideoItem() { static gsize _debug; @@ -625,7 +603,7 @@ QtGLVideoItem::handleWindowChanged(QQuickWindow *win) { if (win) { if (win->isSceneGraphInitialized()) - win->scheduleRenderJob(new InitializeSceneGraph(this), QQuickWindow::BeforeSynchronizingStage); + win->scheduleRenderJob(new RenderJob(std::bind(&QtGLVideoItem::onSceneGraphInitialized, this)), QQuickWindow::BeforeSynchronizingStage); else connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection); diff --git a/ext/qt/qtitem.h b/ext/qt/qtitem.h index 6fc1808..649bccc 100644 --- a/ext/qt/qtitem.h +++ b/ext/qt/qtitem.h @@ -60,8 +60,6 @@ private: QMutex lock; }; -class InitializeSceneGraph; - class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions { Q_OBJECT @@ -108,7 +106,6 @@ protected: private: - friend class InitializeSceneGraph; void setViewportSize(const QSize &size); void shareContext(); diff --git a/ext/qt/qtwindow.cc b/ext/qt/qtwindow.cc index 3995966..a2d931b 100644 --- a/ext/qt/qtwindow.cc +++ b/ext/qt/qtwindow.cc @@ -31,7 +31,6 @@ #include "gstqtglutility.h" #include -#include #include #include #include @@ -80,26 +79,6 @@ struct _QtGLWindowPrivate quint64 stop; }; -class InitQtGLContext : public QRunnable -{ -public: - InitQtGLContext(QtGLWindow *window); - void run(); - -private: - QtGLWindow *window_; -}; - -InitQtGLContext::InitQtGLContext(QtGLWindow *window) : - window_(window) -{ -} - -void InitQtGLContext::run() -{ - window_->onSceneGraphInitialized(); -} - QtGLWindow::QtGLWindow ( QWindow * parent, QQuickWindow *src ) : QQuickWindow( parent ), source (src) { @@ -124,7 +103,7 @@ QtGLWindow::QtGLWindow ( QWindow * parent, QQuickWindow *src ) : connect (source, SIGNAL(afterRendering()), this, SLOT(afterRendering()), Qt::DirectConnection); connect (app, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()), Qt::DirectConnection); if (source->isSceneGraphInitialized()) - source->scheduleRenderJob(new InitQtGLContext(this), QQuickWindow::BeforeSynchronizingStage); + source->scheduleRenderJob(new RenderJob(std::bind(&QtGLWindow::onSceneGraphInitialized, this)), QQuickWindow::BeforeSynchronizingStage); else connect (source, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection); diff --git a/ext/qt/qtwindow.h b/ext/qt/qtwindow.h index a607a31..b6b529e 100644 --- a/ext/qt/qtwindow.h +++ b/ext/qt/qtwindow.h @@ -31,8 +31,6 @@ typedef struct _QtGLWindowPrivate QtGLWindowPrivate; -class InitQtGLContext; - class QtGLWindow : public QQuickWindow, protected QOpenGLFunctions { Q_OBJECT @@ -52,7 +50,6 @@ private Q_SLOTS: void aboutToQuit(); private: - friend class InitQtGLContext; QQuickWindow * source; QScopedPointer fbo; }; -- 2.7.4