Windows: Delay creation of the static OpenGL context.
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Thu, 15 Jan 2015 16:04:29 +0000 (17:04 +0100)
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>
Mon, 19 Jan 2015 12:18:02 +0000 (13:18 +0100)
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>
src/plugins/platforms/windows/qwindowsintegration.cpp
src/plugins/platforms/windows/qwindowswindow.cpp
src/plugins/platforms/windows/qwindowswindow.h

index 82686f38ad584189ad8091ea6696bc32e413fdc6..58d675876b3c1621d3d4795aab9211fe9434ee19 100644 (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
 
index b8ad744d051a02cc250fdc108ac76d9f469e603f..926e7da67ea63fc67b81262a148f9e04a1107b50 100644 (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
index 9822ebce4594c425dcabd35fc9fbde70b99ee385..922d00f23095090fe44a6416be57f79b11b67e36 100644 (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,