diff options
author | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2018-06-25 15:21:10 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2018-08-02 11:46:55 +0000 |
commit | 02ac3f58721bb52db612acd3bb2e2c26bfc3e05b (patch) | |
tree | b6c8d1bb8c90a54a73d6b6e28c46b5b318552b33 /src/plugins/avfoundation/mediaplayer | |
parent | 1b58b96bdf32ab9a89cba0ae43170804c0571ede (diff) |
AVFoundation: Use opengl context from surface as shared
Since few opengl contexts could be used at the same time,
CARenderer could use wrong context to render the video frame.
If the video surface contains an opengl context then need to use it as shared
regardless of existing of current context.
Change-Id: Ie7e87682c73c0fd341b40c05e3f3c4a70d563242
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/plugins/avfoundation/mediaplayer')
-rw-r--r-- | src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm index 7e2f8722e..0759702e8 100644 --- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm +++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm @@ -126,8 +126,14 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay //Get size from AVPlayerLayer m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height); + QOpenGLContext *shareContext = !m_glContext && m_surface + ? qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>()) + : nullptr; + //Make sure we have an OpenGL context to make current - if (!QOpenGLContext::currentContext() && !m_glContext) { + if ((shareContext && shareContext != QOpenGLContext::currentContext()) + || (!QOpenGLContext::currentContext() && !m_glContext)) { + //Create Hidden QWindow surface to create context in this thread m_offscreenSurface = new QWindow(); m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); @@ -135,12 +141,6 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay m_offscreenSurface->setGeometry(0, 0, 1, 1); m_offscreenSurface->create(); - //Create OpenGL context and set share context from surface - QOpenGLContext *shareContext = 0; - if (m_surface) { - //QOpenGLContext *renderThreadContext = 0; - shareContext = qobject_cast<QOpenGLContext*>(m_surface->property("GLContext").value<QObject*>()); - } m_glContext = new QOpenGLContext(); m_glContext->setFormat(m_offscreenSurface->requestedFormat()); |