if (!m_glContext) {
m_glContext = QOpenGLContext::currentContext();
- m_surface->setProperty("GLContext", QVariant::fromValue<QObject*>(m_glContext));
+ m_surface->scheduleOpenGLContextUpdate();
}
if (m_frameChanged) {
return m_surface;
}
+QOpenGLContext *QDeclarativeVideoRendererBackend::glContext() const
+{
+ return m_glContext;
+}
+
void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame)
{
m_frameMutex.lock();
return true;
}
+void QSGVideoItemSurface::scheduleOpenGLContextUpdate()
+{
+ //This method is called from render thread
+ QMetaObject::invokeMethod(this, "updateOpenGLContext");
+}
+
+void QSGVideoItemSurface::updateOpenGLContext()
+{
+ //Set a dynamic property to access the OpenGL context in Qt Quick render thread.
+ this->setProperty("GLContext", QVariant::fromValue<QObject*>(m_backend->glContext()));
+}
+
QT_END_NAMESPACE
void updateGeometry();
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data);
QAbstractVideoSurface *videoSurface() const;
+ QOpenGLContext *glContext() const;
friend class QSGVideoItemSurface;
void present(const QVideoFrame &frame);
class QSGVideoItemSurface : public QAbstractVideoSurface
{
+ Q_OBJECT
public:
explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0);
~QSGVideoItemSurface();
bool start(const QVideoSurfaceFormat &format);
void stop();
bool present(const QVideoFrame &frame);
+ void scheduleOpenGLContextUpdate();
+
+private slots:
+ void updateOpenGLContext();
private:
QDeclarativeVideoRendererBackend *m_backend;