Fix issue sharing OpenGL context from render thread on OS X
On OS X when running in QtQuick 2 examples in debug mode we fail an assert because we try to set a dynamic property using QObject::setProperty from the render thread, while the object exists in the main thread. Now we call setProperty from the correct thread. Change-Id: I3f26ead0f68fadcded472bf5c9014a4025f0a03e Reviewed-by: Christian Stromme <christian.stromme@digia.com> Reviewed-by: Jason Barron <jason.barron@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
13ce3d921a
commit
bc7e9fe7c7
@@ -171,7 +171,7 @@ QSGNode *QDeclarativeVideoRendererBackend::updatePaintNode(QSGNode *oldNode,
|
|||||||
|
|
||||||
if (!m_glContext) {
|
if (!m_glContext) {
|
||||||
m_glContext = QOpenGLContext::currentContext();
|
m_glContext = QOpenGLContext::currentContext();
|
||||||
m_surface->setProperty("GLContext", QVariant::fromValue<QObject*>(m_glContext));
|
m_surface->scheduleOpenGLContextUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_frameChanged) {
|
if (m_frameChanged) {
|
||||||
@@ -223,6 +223,11 @@ QAbstractVideoSurface *QDeclarativeVideoRendererBackend::videoSurface() const
|
|||||||
return m_surface;
|
return m_surface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QOpenGLContext *QDeclarativeVideoRendererBackend::glContext() const
|
||||||
|
{
|
||||||
|
return m_glContext;
|
||||||
|
}
|
||||||
|
|
||||||
void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame)
|
void QDeclarativeVideoRendererBackend::present(const QVideoFrame &frame)
|
||||||
{
|
{
|
||||||
m_frameMutex.lock();
|
m_frameMutex.lock();
|
||||||
@@ -287,4 +292,16 @@ bool QSGVideoItemSurface::present(const QVideoFrame &frame)
|
|||||||
return true;
|
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
|
QT_END_NAMESPACE
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public:
|
|||||||
void updateGeometry();
|
void updateGeometry();
|
||||||
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data);
|
QSGNode *updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data);
|
||||||
QAbstractVideoSurface *videoSurface() const;
|
QAbstractVideoSurface *videoSurface() const;
|
||||||
|
QOpenGLContext *glContext() const;
|
||||||
|
|
||||||
friend class QSGVideoItemSurface;
|
friend class QSGVideoItemSurface;
|
||||||
void present(const QVideoFrame &frame);
|
void present(const QVideoFrame &frame);
|
||||||
@@ -93,6 +94,7 @@ private:
|
|||||||
|
|
||||||
class QSGVideoItemSurface : public QAbstractVideoSurface
|
class QSGVideoItemSurface : public QAbstractVideoSurface
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0);
|
explicit QSGVideoItemSurface(QDeclarativeVideoRendererBackend *backend, QObject *parent = 0);
|
||||||
~QSGVideoItemSurface();
|
~QSGVideoItemSurface();
|
||||||
@@ -100,6 +102,10 @@ public:
|
|||||||
bool start(const QVideoSurfaceFormat &format);
|
bool start(const QVideoSurfaceFormat &format);
|
||||||
void stop();
|
void stop();
|
||||||
bool present(const QVideoFrame &frame);
|
bool present(const QVideoFrame &frame);
|
||||||
|
void scheduleOpenGLContextUpdate();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateOpenGLContext();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDeclarativeVideoRendererBackend *m_backend;
|
QDeclarativeVideoRendererBackend *m_backend;
|
||||||
|
|||||||
Reference in New Issue
Block a user