From 7c7207b4722d5da981bb53b6c68ecd42338e01e1 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Fri, 8 Mar 2013 19:45:07 +0100 Subject: [PATCH] Create the sg render thread's opengl context on the GUI thread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: I710d80ebb4e5a12fda1f58f54089b0e72268dfcf Reviewed-by: Samuel Rødal --- src/quick/scenegraph/qsgthreadedrenderloop.cpp | 46 ++++++----------------- 1 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/quick/scenegraph/qsgthreadedrenderloop.cpp b/src/quick/scenegraph/qsgthreadedrenderloop.cpp index fb26f54..55b27dc 100644 --- a/src/quick/scenegraph/qsgthreadedrenderloop.cpp +++ b/src/quick/scenegraph/qsgthreadedrenderloop.cpp @@ -523,37 +523,6 @@ void QSGRenderThread::invalidateOpenGL(QQuickWindow *window, bool inDestructor) } } -void QSGRenderThread::initializeOpenGL() -{ - RLDEBUG1(" Render: initializeOpenGL()"); - QWindow *win = m_windows.at(0).window; - bool temp = false; - - // Workaround for broken expose logic... We should not get an - // expose when the size of a window is invalid, but we sometimes do. - // On Mac this leads to harmless, yet annoying, console warnings - if (m_windows.at(0).size.isEmpty()) { - temp = true; - win = new QWindow(); - win->setFormat(m_windows.at(0).window->requestedFormat()); - win->setSurfaceType(QWindow::OpenGLSurface); - win->setGeometry(0, 0, 64, 64); - win->create(); - } - - gl = new QOpenGLContext(); - // Pick up the surface format from one of them - gl->setFormat(win->requestedFormat()); - gl->create(); - if (!gl->makeCurrent(win)) - qWarning("QQuickWindow: makeCurrent() failed..."); - sg->initialize(gl); - - if (temp) { - delete win; - } -} - /*! Enters the mutex lock to make sure GUI is blocking and performs sync, then wakes GUI. @@ -692,10 +661,10 @@ void QSGRenderThread::run() while (!shouldExit) { if (m_windows.size() > 0) { - if (!gl) - initializeOpenGL(); - if (!sg->isReady()) + if (!sg->isReady()) { + gl->makeCurrent(m_windows.at(0).window); sg->initialize(gl); + } syncAndRender(); } @@ -879,6 +848,15 @@ void QSGThreadedRenderLoop::handleExposure(QQuickWindow *window) m_thread->shouldExit = false; RLDEBUG1("GUI: - starting render thread..."); + + if (!m_thread->gl) { + QOpenGLContext *ctx = new QOpenGLContext(); + ctx->setFormat(window->requestedFormat()); + ctx->create(); + ctx->moveToThread(m_thread); + m_thread->gl = ctx; + } + m_thread->start(); } else { -- 1.7.2.5