diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-06-08 18:09:23 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-06-10 11:37:36 +0000 |
commit | 3cb698c0fcd05334163ac86f1a5a599dae67025b (patch) | |
tree | 49ece4b20fe7546f95461b26cb6fd0f91e8f9da6 /src/plugins | |
parent | 269c64f47a0e356bc91a261b61f4e23f0b08fcfc (diff) | |
download | qtmultimedia-3cb698c0fcd05334163ac86f1a5a599dae67025b.tar.gz |
AVFoundation: don't use shared OpenGL contexts unless needed.
We were always using shared OpenGL contexts to render media player
frames into an OpenGL texture. There's no need to do that when there
already is a current context on the current thread. This happens in
non-QtQuick cases, when the OpenGL thread is also the main thread.
Change-Id: Icb97ed49609c764263007a43b6bb481e23768111
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm index fe3389a43..2d6eac540 100644 --- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm +++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm @@ -50,19 +50,13 @@ AVFVideoFrameRenderer::AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QOb : QObject(parent) , m_videoLayerRenderer(0) , m_surface(surface) + , m_offscreenSurface(0) , m_glContext(0) , m_currentBuffer(1) , m_isContextShared(true) { m_fbo[0] = 0; m_fbo[1] = 0; - - //Create Hidden QWindow surface to create context in this thread - m_offscreenSurface = new QWindow(); - m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); - //Needs geometry to be a valid surface, but size is not important - m_offscreenSurface->setGeometry(0, 0, 1, 1); - m_offscreenSurface->create(); } AVFVideoFrameRenderer::~AVFVideoFrameRenderer() @@ -94,7 +88,8 @@ GLuint AVFVideoFrameRenderer::renderLayerToTexture(AVPlayerLayer *layer) return 0; renderLayerToFBO(layer, fbo); - m_glContext->doneCurrent(); + if (m_glContext) + m_glContext->doneCurrent(); return fbo->texture(); } @@ -113,7 +108,8 @@ QImage AVFVideoFrameRenderer::renderLayerToImage(AVPlayerLayer *layer) renderLayerToFBO(layer, fbo); QImage fboImage = fbo->toImage(); - m_glContext->doneCurrent(); + if (m_glContext) + m_glContext->doneCurrent(); return fboImage; } @@ -125,7 +121,14 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height); //Make sure we have an OpenGL context to make current - if (!m_glContext) { + if (!QOpenGLContext::currentContext() && !m_glContext) { + //Create Hidden QWindow surface to create context in this thread + m_offscreenSurface = new QWindow(); + m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); + //Needs geometry to be a valid surface, but size is not important + 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) { @@ -151,7 +154,8 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay } //Need current context - m_glContext->makeCurrent(m_offscreenSurface); + if (m_glContext) + m_glContext->makeCurrent(m_offscreenSurface); //Create the CARenderer if needed if (!m_videoLayerRenderer) { |