aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2019-12-02 20:13:26 +0100
committerSylvain Munaut <tnt@246tNt.com>2019-12-08 15:22:38 +0100
commitcaa88f0a31190bc8f053ba54058636d278be73c7 (patch)
tree84447c122fad8e4c1513457c60cb531e4cc1dca8 /lib
parentef55b4f5afb58bc422ee53b4eb685b12a07c2464 (diff)
gr-fosphor/qt: Qt5 - Associate GL context to the worker thread
Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/QGLSurface.cc35
-rw-r--r--lib/QGLSurface.h9
-rw-r--r--lib/qt_sink_c_impl.cc4
-rw-r--r--lib/qt_sink_c_impl.h6
4 files changed, 48 insertions, 6 deletions
diff --git a/lib/QGLSurface.cc b/lib/QGLSurface.cc
index f9e7613..7abdcd3 100644
--- a/lib/QGLSurface.cc
+++ b/lib/QGLSurface.cc
@@ -19,6 +19,8 @@
*/
#include <QtEvents>
+#include <QThread>
+
#include "QGLSurface.h"
#include "qt_sink_c_impl.h"
@@ -30,7 +32,10 @@ namespace gr {
QGLSurface::QGLSurface(QWidget *parent, qt_sink_c_impl *block)
: QGLWidget(parent), d_block(block)
{
- this->doneCurrent();
+ /* Save the pointer to the main GUI thread */
+ this->d_gui_thread = this->thread();
+
+ /* QWidget policies */
this->setFocusPolicy(Qt::StrongFocus);
this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
}
@@ -102,5 +107,33 @@ QGLSurface::keyPressEvent(QKeyEvent *ke)
}
}
+
+void
+QGLSurface::grabContext()
+{
+ QMetaObject::invokeMethod(
+ this,
+ "giveContext",
+ Qt::BlockingQueuedConnection,
+ Q_ARG(QThread*, QThread::currentThread())
+ );
+
+ this->makeCurrent();
+}
+
+void
+QGLSurface::releaseContext()
+{
+ this->doneCurrent();
+ this->context()->moveToThread(this->d_gui_thread);
+}
+
+void
+QGLSurface::giveContext(QThread *thread)
+{
+ this->doneCurrent();
+ this->context()->moveToThread(thread);
+}
+
} /* namespace fosphor */
} /* namespace gr */
diff --git a/lib/QGLSurface.h b/lib/QGLSurface.h
index cf49a1c..65afd8a 100644
--- a/lib/QGLSurface.h
+++ b/lib/QGLSurface.h
@@ -23,6 +23,8 @@
#include <QGLWidget>
+class QThread;
+
namespace gr {
namespace fosphor {
@@ -33,14 +35,21 @@ namespace gr {
Q_OBJECT
qt_sink_c_impl *d_block;
+ QThread *d_gui_thread;
protected:
void paintEvent(QPaintEvent *pe);
void resizeEvent(QResizeEvent *re);
void keyPressEvent(QKeyEvent *ke);
+ private slots:
+ void giveContext(QThread *thread);
+
public:
QGLSurface(QWidget *parent, qt_sink_c_impl *d_block);
+
+ void grabContext();
+ void releaseContext();
};
} // namespace fosphor
diff --git a/lib/qt_sink_c_impl.cc b/lib/qt_sink_c_impl.cc
index 91a5413..d91f766 100644
--- a/lib/qt_sink_c_impl.cc
+++ b/lib/qt_sink_c_impl.cc
@@ -64,7 +64,7 @@ qt_sink_c_impl::qt_sink_c_impl(QWidget *parent)
void
qt_sink_c_impl::glctx_init()
{
- this->d_gui->makeCurrent();
+ this->d_gui->grabContext();
this->d_gui->setFocus();
}
@@ -83,7 +83,7 @@ qt_sink_c_impl::glctx_poll()
void
qt_sink_c_impl::glctx_fini()
{
- this->d_gui->doneCurrent();
+ this->d_gui->releaseContext();
}
void
diff --git a/lib/qt_sink_c_impl.h b/lib/qt_sink_c_impl.h
index fadeae7..eb3ac0a 100644
--- a/lib/qt_sink_c_impl.h
+++ b/lib/qt_sink_c_impl.h
@@ -26,11 +26,11 @@
#include "base_sink_c_impl.h"
-class QGLWidget;
-
namespace gr {
namespace fosphor {
+ class QGLSurface;
+
/*!
* \brief Qt version of fosphor sink (implementation)
* \ingroup fosphor
@@ -40,7 +40,7 @@ namespace gr {
friend class QGLSurface;
private:
- QGLWidget *d_gui;
+ QGLSurface *d_gui;
protected:
/* Delegated implementation of GL context management */