After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761003 - Error getting OpenGL context when qml item when scene graph is initialized.
Error getting OpenGL context when qml item when scene graph is initialized.
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal normal
: 1.7.90
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2016-01-22 20:47 UTC by Sergey Borovkov
Modified: 2016-02-22 09:57 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Get context on OpenGL thread when context is initialized (2.52 KB, patch)
2016-02-16 15:05 UTC, Sergey Borovkov
none Details | Review
Return old node when there is no initialized context yet (1.36 KB, patch)
2016-02-16 15:08 UTC, Sergey Borovkov
none Details | Review
Get OpenGL context on render thread when scene graph is alreadyt initialized. (3.57 KB, patch)
2016-02-19 15:52 UTC, Sergey Borovkov
none Details | Review

Description Sergey Borovkov 2016-01-22 20:47:01 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;
  }
}
Comment 1 Matthew Waters (ystreet00) 2016-01-22 23:57:34 UTC
That's entirely possible.

In the already initialized case we may need to delegate to the render thread.
Comment 2 Sebastian Dröge (slomo) 2016-02-16 14:56:10 UTC
Sergey, can you provide a testcase for this problem?
Comment 3 Sergey Borovkov 2016-02-16 15:04:56 UTC
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.
Comment 4 Sergey Borovkov 2016-02-16 15:05:51 UTC
Created attachment 321397 [details] [review]
Get context on OpenGL thread when context is initialized
Comment 5 Sergey Borovkov 2016-02-16 15:08:50 UTC
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 6 Sergey Borovkov 2016-02-16 15:13:23 UTC
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
Comment 7 Matthew Waters (ystreet00) 2016-02-16 22:48:02 UTC
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.
Comment 8 Sergey Borovkov 2016-02-19 15:52:30 UTC
Created attachment 321666 [details] [review]
Get OpenGL context on render thread when scene graph is alreadyt initialized.
Comment 9 Matthew Waters (ystreet00) 2016-02-22 09:57:26 UTC
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