Windows: Delay creation of the static OpenGL context.

Delay initialization/GL detection until a surface is requested.
Remove member variable from window and access static context
from QWindowsIntegration only.

Task-number: QTBUG-43832
Change-Id: I4b9a324b58af4399df5c314bfb2b952455b1e080
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
This commit is contained in:
Friedemann Kleint 2015-01-15 17:04:29 +01:00 committed by Jani Heikkinen
parent 5ee8ed27e0
commit a8f37e4775
3 changed files with 20 additions and 28 deletions

View File

@ -130,7 +130,6 @@ struct QWindowsIntegrationPrivate
{
explicit QWindowsIntegrationPrivate(const QStringList &paramList);
~QWindowsIntegrationPrivate();
bool ensureStaticOpenGLContext();
unsigned m_options;
QWindowsContext m_context;
@ -266,7 +265,9 @@ bool QWindowsIntegration::hasCapability(QPlatformIntegration::Capability cap) co
case OpenGL:
return true;
case ThreadedOpenGL:
return d->ensureStaticOpenGLContext() ? d->m_staticOpenGLContext->supportsThreadedOpenGL() : false;
if (const QWindowsStaticOpenGLContext *glContext = QWindowsIntegration::staticOpenGLContext())
return glContext->supportsThreadedOpenGL();
return false;
#endif // !QT_NO_OPENGL
case WindowMasks:
return true;
@ -312,11 +313,6 @@ QWindowsWindowData QWindowsIntegration::createWindowData(QWindow *window) const
QWindowSystemInterface::handleGeometryChange(window, QWindowsScaling::mapFromNative(obtained.geometry));
}
#ifndef QT_NO_OPENGL
d->ensureStaticOpenGLContext();
obtained.staticOpenGLContext = d->m_staticOpenGLContext;
#endif // QT_NO_OPENGL
return obtained;
}
@ -377,26 +373,16 @@ QWindowsStaticOpenGLContext *QWindowsStaticOpenGLContext::doCreate()
#endif
}
static QWindowsStaticOpenGLContext *q_staticOpenGLContext = 0;
QWindowsStaticOpenGLContext *QWindowsStaticOpenGLContext::create()
{
q_staticOpenGLContext = QWindowsStaticOpenGLContext::doCreate();
return q_staticOpenGLContext;
}
bool QWindowsIntegrationPrivate::ensureStaticOpenGLContext()
{
if (m_staticOpenGLContext.isNull())
m_staticOpenGLContext = QSharedPointer<QWindowsStaticOpenGLContext>(QWindowsStaticOpenGLContext::create());
return !m_staticOpenGLContext.isNull();
return QWindowsStaticOpenGLContext::doCreate();
}
QPlatformOpenGLContext *QWindowsIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
{
qCDebug(lcQpaGl) << __FUNCTION__ << context->format();
if (d->ensureStaticOpenGLContext()) {
QScopedPointer<QWindowsOpenGLContext> result(d->m_staticOpenGLContext->createContext(context));
if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext()) {
QScopedPointer<QWindowsOpenGLContext> result(staticOpenGLContext->createContext(context));
if (result->isValid())
return result.take();
}
@ -410,13 +396,18 @@ QOpenGLContext::OpenGLModuleType QWindowsIntegration::openGLModuleType()
#elif !defined(QT_OPENGL_DYNAMIC)
return QOpenGLContext::LibGL;
#else
return d->ensureStaticOpenGLContext() ? d->m_staticOpenGLContext->moduleType() : QOpenGLContext::LibGL;
if (const QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext())
return staticOpenGLContext->moduleType();
return QOpenGLContext::LibGL;
#endif
}
QWindowsStaticOpenGLContext *QWindowsIntegration::staticOpenGLContext()
{
return q_staticOpenGLContext;
QWindowsIntegrationPrivate *d = QWindowsIntegration::instance()->d.data();
if (d->m_staticOpenGLContext.isNull())
d->m_staticOpenGLContext = QSharedPointer<QWindowsStaticOpenGLContext>(QWindowsStaticOpenGLContext::create());
return d->m_staticOpenGLContext.data();
}
#endif // !QT_NO_OPENGL

View File

@ -37,6 +37,7 @@
#include "qwindowsdrag.h"
#include "qwindowsscreen.h"
#include "qwindowsscaling.h"
#include "qwindowsintegration.h"
#ifdef QT_NO_CURSOR
# include "qwindowscursor.h"
#endif
@ -958,7 +959,8 @@ void QWindowsWindow::destroyWindow()
setDropSiteEnabled(false);
#ifndef QT_NO_OPENGL
if (m_surface) {
m_data.staticOpenGLContext->destroyWindowSurface(m_surface);
if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext())
staticOpenGLContext->destroyWindowSurface(m_surface);
m_surface = 0;
}
#endif
@ -2302,8 +2304,10 @@ void *QWindowsWindow::surface(void *nativeConfig)
#ifdef QT_NO_OPENGL
return 0;
#else
if (!m_surface)
m_surface = m_data.staticOpenGLContext->createWindowSurface(m_data.hwnd, nativeConfig);
if (!m_surface) {
if (QWindowsStaticOpenGLContext *staticOpenGLContext = QWindowsIntegration::staticOpenGLContext())
m_surface = staticOpenGLContext->createWindowSurface(m_data.hwnd, nativeConfig);
}
return m_surface;
#endif

View File

@ -107,9 +107,6 @@ struct QWindowsWindowData
QMargins customMargins; // User-defined, additional frame for NCCALCSIZE
HWND hwnd;
bool embedded;
#ifndef QT_NO_OPENGL
QSharedPointer<QWindowsStaticOpenGLContext> staticOpenGLContext;
#endif // QT_NO_OPENGL
static QWindowsWindowData create(const QWindow *w,
const QWindowsWindowData &parameters,