summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2019-09-18 10:53:38 +0200
committerMichal Klocek <michal.klocek@qt.io>2019-09-26 10:28:20 +0000
commite77ec61b7ba1fb71b397ef358036b5057a0cb39b (patch)
treed92613a60773af306b0c78fbae2622bedacdf8ea /src
parente31acc86e991d6f83bd56eebb7371914fc9ca5ac (diff)
Unify shared context initialization
Setting shared context on core application object should be done before core application is initialised. This is handled correctly in widgets part but not in qml part. Unify our shared context creation and call WebEngine::initialize() before QCoreaApplication is created. Context has to be set shared before first window's QPlatformOpenGLContext is created and not before window itself is created as documentation claimed. Keep the older code running, but print the warning. Update one test to test new initialization order, but keep the others to check if they still works. [ChangeLog] WebEngine::initialize() has to be called before QCoreApplication is created. Task-number: QTBUG-76391 Change-Id: Iff938493a4d21f360110136192daedb6199584c1 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/api/qtwebenginecoreglobal.cpp2
-rw-r--r--src/core/content_browser_client_qt.cpp2
-rw-r--r--src/webengine/api/qtwebengineglobal.cpp15
3 files changed, 14 insertions, 5 deletions
diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp
index 25d0bd3be..3c7fc54a1 100644
--- a/src/core/api/qtwebenginecoreglobal.cpp
+++ b/src/core/api/qtwebenginecoreglobal.cpp
@@ -108,7 +108,7 @@ Q_WEBENGINECORE_PRIVATE_EXPORT void initialize()
QCoreApplication *app = QCoreApplication::instance();
if (!app) {
- qFatal("QtWebEngine::initialize() must be called after the construction of the application object.");
+ qFatal("QtWebEngine::initialize() but no core application instance.");
return;
}
diff --git a/src/core/content_browser_client_qt.cpp b/src/core/content_browser_client_qt.cpp
index 16945020b..04a8fc363 100644
--- a/src/core/content_browser_client_qt.cpp
+++ b/src/core/content_browser_client_qt.cpp
@@ -235,7 +235,7 @@ void ShareGroupQtQuick::AboutToAddFirstContext()
// This currently has to be setup by ::main in all applications using QQuickWebEngineView with delegated rendering.
QOpenGLContext *shareContext = qt_gl_global_share_context();
if (!shareContext) {
- qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function.");
+ qFatal("QWebEngine: OpenGL resource sharing is not set up in QtQuick. Please make sure to call QtWebEngine::initialize() in your main() function before QCoreApplication is created.");
}
m_shareContextQtQuick = new QtShareGLContext(shareContext);
#endif
diff --git a/src/webengine/api/qtwebengineglobal.cpp b/src/webengine/api/qtwebengineglobal.cpp
index a11618dba..4346832c9 100644
--- a/src/webengine/api/qtwebengineglobal.cpp
+++ b/src/webengine/api/qtwebengineglobal.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "qtwebengineglobal.h"
+#include <QCoreApplication>
namespace QtWebEngineCore
{
@@ -62,8 +63,8 @@ namespace QtWebEngine {
/*!
\fn QtWebEngine::initialize()
- Sets up an OpenGL Context that can be shared between threads. This has to be done after
- QGuiApplication is created, but before a Qt Quick window is created.
+ Sets up an OpenGL Context that can be shared between threads. This has to be done before
+ QGuiApplication is created and before window's QPlatformOpenGLContext is created.
This has the same effect as setting the Qt::AA_ShareOpenGLContexts
attribute with QCoreApplication::setAttribute before constructing
@@ -71,7 +72,15 @@ namespace QtWebEngine {
*/
void initialize()
{
- QtWebEngineCore::initialize();
+ QCoreApplication *app = QCoreApplication::instance();
+ if (app) {
+ qWarning("QtWebEngine::initialize() called with QCoreApplication object already created and should be call before. "\
+ "This is depreciated and may fail in the future.");
+ QtWebEngineCore::initialize();
+ return;
+ }
+ // call initialize the same way as widgets do
+ qAddPreRoutine(QtWebEngineCore::initialize);
}
} // namespace QtWebEngine