qmlglsink: Schedule onSceneGrpahInitialized to execute on render thread

onSceneGraphInitialized() is called from non render thread currently when
scene graph is already initialized.

https://bugzilla.gnome.org/show_bug.cgi?id=761003
This commit is contained in:
Sergey Borovkov 2016-01-24 17:40:37 +03:00 committed by Matthew Waters
parent f3e126df88
commit 472b396528
2 changed files with 33 additions and 3 deletions

View file

@ -28,6 +28,7 @@
#include "qtitem.h" #include "qtitem.h"
#include "gstqsgtexture.h" #include "gstqsgtexture.h"
#include <QtCore/QRunnable>
#include <QtGui/QGuiApplication> #include <QtGui/QGuiApplication>
#include <QtQuick/QQuickWindow> #include <QtQuick/QQuickWindow>
#include <QtQuick/QSGSimpleTextureNode> #include <QtQuick/QSGSimpleTextureNode>
@ -99,6 +100,26 @@ struct _QtGLVideoItemPrivate
GstGLContext *context; GstGLContext *context;
}; };
class InitializeSceneGraph : public QRunnable
{
public:
InitializeSceneGraph(QtGLVideoItem *item);
void run();
private:
QtGLVideoItem *item_;
};
InitializeSceneGraph::InitializeSceneGraph(QtGLVideoItem *item) :
item_(item)
{
}
void InitializeSceneGraph::run()
{
item_->onSceneGraphInitialized();
}
QtGLVideoItem::QtGLVideoItem() QtGLVideoItem::QtGLVideoItem()
{ {
QGuiApplication *app = dynamic_cast<QGuiApplication *> (QCoreApplication::instance ()); QGuiApplication *app = dynamic_cast<QGuiApplication *> (QCoreApplication::instance ());
@ -110,7 +131,7 @@ QtGLVideoItem::QtGLVideoItem()
GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwidget", 0, "Qt GL Widget"); GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwidget", 0, "Qt GL Widget");
g_once_init_leave (&_debug, 1); g_once_init_leave (&_debug, 1);
} }
this->m_openGlContextInitialized = false;
this->setFlag (QQuickItem::ItemHasContents, true); this->setFlag (QQuickItem::ItemHasContents, true);
this->priv = g_new0 (QtGLVideoItemPrivate, 1); this->priv = g_new0 (QtGLVideoItemPrivate, 1);
@ -188,6 +209,10 @@ QSGNode *
QtGLVideoItem::updatePaintNode(QSGNode * oldNode, QtGLVideoItem::updatePaintNode(QSGNode * oldNode,
UpdatePaintNodeData * updatePaintNodeData) UpdatePaintNodeData * updatePaintNodeData)
{ {
if (!m_openGlContextInitialized) {
return oldNode;
}
QSGSimpleTextureNode *texNode = static_cast<QSGSimpleTextureNode *> (oldNode); QSGSimpleTextureNode *texNode = static_cast<QSGSimpleTextureNode *> (oldNode);
GstVideoRectangle src, dst, result; GstVideoRectangle src, dst, result;
GstQSGTexture *tex; GstQSGTexture *tex;
@ -354,6 +379,7 @@ QtGLVideoItem::onSceneGraphInitialized ()
} else { } else {
gst_gl_display_filter_gl_api (this->priv->display, gst_gl_context_get_gl_api (this->priv->other_context)); gst_gl_display_filter_gl_api (this->priv->display, gst_gl_context_get_gl_api (this->priv->other_context));
gst_gl_context_activate (this->priv->other_context, FALSE); gst_gl_context_activate (this->priv->other_context, FALSE);
m_openGlContextInitialized = true;
} }
} }
@ -414,7 +440,7 @@ QtGLVideoItem::handleWindowChanged(QQuickWindow *win)
{ {
if (win) { if (win) {
if (win->isSceneGraphInitialized()) if (win->isSceneGraphInitialized())
onSceneGraphInitialized(); win->scheduleRenderJob(new InitializeSceneGraph(this), QQuickWindow::BeforeSynchronizingStage);
else else
connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection); connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection);

View file

@ -31,6 +31,8 @@
typedef struct _QtGLVideoItemPrivate QtGLVideoItemPrivate; typedef struct _QtGLVideoItemPrivate QtGLVideoItemPrivate;
class InitializeSceneGraph;
class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions class QtGLVideoItem : public QQuickItem, protected QOpenGLFunctions
{ {
Q_OBJECT Q_OBJECT
@ -55,10 +57,12 @@ protected:
QSGNode * updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData); QSGNode * updatePaintNode (QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData);
private: private:
friend class InitializeSceneGraph;
void setViewportSize(const QSize &size); void setViewportSize(const QSize &size);
void shareContext(); void shareContext();
QSize m_viewportSize; QSize m_viewportSize;
bool m_openGlContextInitialized;
}; };
extern "C" extern "C"