GNOME Bugzilla – Bug 761003
Error getting OpenGL context when qml item when scene graph is initialized.
Last modified: 2016-02-22 09:57:26 UTC
I am getting this error gst_gl_context_activate: assertion 'GST_GL_IS_CONTEXT'. From this code it looks like for the case when scene graph is already initialized that onSceneGraphInitialized() is called from the wrong thread. When the condition is false it connects to signal which is emitted from render thread and ends up executing on that thread. But when it's initialized we are getting executed from the main thread. void QtGLVideoItem::handleWindowChanged(QQuickWindow *win) { if (win) { if (win->isSceneGraphInitialized()) onSceneGraphInitialized(); else connect(win, SIGNAL(sceneGraphInitialized()), this, SLOT(onSceneGraphInitialized()), Qt::DirectConnection); connect(win, SIGNAL(sceneGraphInvalidated()), this, SLOT(onSceneGraphInvalidated()), Qt::DirectConnection); } else { this->priv->qt_context = NULL; } }
That's entirely possible. In the already initialized case we may need to delegate to the render thread.
Sergey, can you provide a testcase for this problem?
I'll create test case once I have time. But it's pretty easy to reproduce - just need to create GstGLVideoItem dynamically after qmlscene is up and running. In that case scene graph would be initialized. But I actually have patch for this, just did not have time to submit it yet.
Created attachment 321397 [details] [review] Get context on OpenGL thread when context is initialized
Created attachment 321399 [details] [review] Return old node when there is no initialized context yet I am not sure that this is correct approach. But since GstGLVideoItem is created during synchronizing stage already. In the case when context is scheduled to be initialized in render thread we would try to paint first frame without context initialized yet still.
Comment on attachment 321399 [details] [review] Return old node when there is no initialized context yet From 6d311dc9954670e0224a928c24bf7c325668bea4 Mon Sep 17 00:00:00 2001 From: Sergey Borovkov <sergey.borovkov@wireload.net> Date: Tue, 16 Feb 2016 18:02:44 +0300 Subject: [PATCH 3/3] qt: return old node if shared opengl context is not initialized yet --- ext/qt/qtitem.cc | 7 ++++++- ext/qt/qtitem.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ext/qt/qtitem.cc b/ext/qt/qtitem.cc index b884ca0..282ad25 100644 --- a/ext/qt/qtitem.cc +++ b/ext/qt/qtitem.cc @@ -136,7 +136,7 @@ QtGLVideoItem::QtGLVideoItem() GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "qtglwidget", 0, "Qt GL Widget"); g_once_init_leave (&_debug, 1); } - + this->m_openGlContextInitialized = false; this->setFlag (QQuickItem::ItemHasContents, true); this->priv = g_new0 (QtGLVideoItemPrivate, 1); @@ -220,6 +220,10 @@ QSGNode * QtGLVideoItem::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * updatePaintNodeData) { + if (!m_openGlContextInitialized) { + return oldNode; + } + QSGSimpleTextureNode *texNode = static_cast<QSGSimpleTextureNode *> (oldNode); GstVideoRectangle src, dst, result; GstQSGTexture *tex; @@ -399,6 +403,7 @@ QtGLVideoItem::onSceneGraphInitialized () } else { 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); + m_openGlContextInitialized = true; } } diff --git a/ext/qt/qtitem.h b/ext/qt/qtitem.h index 701d639..ae23eff 100644 --- a/ext/qt/qtitem.h +++ b/ext/qt/qtitem.h @@ -62,6 +62,7 @@ private: void shareContext(); QSize m_viewportSize; + bool m_openGlContextInitialized; }; extern "C" -- 2.5.0
These patches don't really seem to line up with what their commit messages say they do... If I'm discerning all the patches correctly, you can squash all the commits into one for this.
Created attachment 321666 [details] [review] Get OpenGL context on render thread when scene graph is alreadyt initialized.
commit 0d80be0ce0fe523fad59a74d431767322161cb7b Author: Sergey Borovkov <sergey.borovkov@wireload.net> Date: Sun Jan 24 17:40:37 2016 +0300 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