diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp index ea119bba648245d3ff3fd69d41d9388990e7a82c..b179da2fe44e9726c98a5af17c08d67eee959dd2 100644 --- a/src/webengine/api/qtwebengineglobal.cpp +++ b/src/webengine/api/qtwebengineglobal.cpp @@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE Q_GUI_EXPORT void qt_gl_set_global_share_context(QOpenGLContext *context); +Q_GUI_EXPORT QOpenGLContext *qt_gl_global_share_context(); namespace QtWebEngine { @@ -54,8 +55,20 @@ static void deleteShareContext() shareContext = 0; } +// ### Qt 6: unify this logic and Qt::AA_ShareOpenGLContexts. +// QtWebEngine::initialize was introduced first and meant to be called +// after the QGuiApplication creation, when AA_ShareOpenGLContexts fills +// the same need but the flag has to be set earlier. void initialize() { +#ifdef Q_OS_WIN32 + qputenv("QT_D3DCREATE_MULTITHREADED", "1"); +#endif + + // No need to override the shared context if QApplication already set one (e.g with Qt::AA_ShareOpenGLContexts). + if (qt_gl_global_share_context()) + return; + QCoreApplication *app = QCoreApplication::instance(); if (!app) { qFatal("QWebEngine(Widgets)::initialize() must be called after the construction of the application object."); @@ -69,10 +82,6 @@ void initialize() if (shareContext) return; -#ifdef Q_OS_WIN32 - qputenv("QT_D3DCREATE_MULTITHREADED", "1"); -#endif - shareContext = new QOpenGLContext; shareContext->create(); qAddPostRoutine(deleteShareContext);