summaryrefslogtreecommitdiffstats
path: root/src/core/api
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2020-07-08 17:36:56 +0200
committerMichal Klocek <michal.klocek@qt.io>2020-08-04 12:45:23 +0200
commitc570d4d36d415359e832d8f1da2bc703d5c68583 (patch)
treea94d7d3acb56b91026c532d58e5203c64637f15d /src/core/api
parentef432baaed4f8edb7ebe32fbcaf96a4c701e76e1 (diff)
Move macOS surface format check to initialize
Change-Id: I08171340c8b5de3b38f17c95a70e3a8931394057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'src/core/api')
-rw-r--r--src/core/api/qtwebenginecoreglobal.cpp157
1 files changed, 89 insertions, 68 deletions
diff --git a/src/core/api/qtwebenginecoreglobal.cpp b/src/core/api/qtwebenginecoreglobal.cpp
index 3c9387a10..0e0c4b63b 100644
--- a/src/core/api/qtwebenginecoreglobal.cpp
+++ b/src/core/api/qtwebenginecoreglobal.cpp
@@ -105,83 +105,104 @@ Q_WEBENGINECORE_PRIVATE_EXPORT void initialize()
qputenv("QT_MAC_PRO_WEBENGINE_WORKAROUND", "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;
+ if (!qt_gl_global_share_context()) {
- QCoreApplication *app = QCoreApplication::instance();
- if (!app) {
- qFatal("QtWebEngine::initialize() but no core application instance.");
- return;
- }
-
- // Bail out silently if the user did not construct a QGuiApplication.
- if (!qobject_cast<QGuiApplication *>(app))
- return;
-
- if (app->thread() != QThread::currentThread()) {
- qFatal("QtWebEngine::initialize() must be called from the Qt gui thread.");
- return;
- }
+ QCoreApplication *app = QCoreApplication::instance();
+ if (!app) {
+ qFatal("QtWebEngine::initialize() but no core application instance.");
+ return;
+ }
- if (shareContext)
- return;
+ // Bail out silently if the user did not construct a QGuiApplication.
+ if (!qobject_cast<QGuiApplication *>(app))
+ return;
- shareContext = new QOpenGLContext;
- QSurfaceFormat format = QSurfaceFormat::defaultFormat();
-// format.setOption(QSurfaceFormat::ResetNotification);
+ if (app->thread() != QThread::currentThread()) {
+ qFatal("QtWebEngine::initialize() must be called from the Qt gui thread.");
+ return;
+ }
-#ifdef Q_OS_MACOS
- if (format == QSurfaceFormat()) {
- QOpenGLContext testContext;
-
- // Chromium turns off OpenGL for CoreProfiles with versions < 4.1
- // The newest Mac that only supports 3.3 was released in Mid 2011,
- // so it should be safe to request 4.1, but we still double check it
- // works in order not to set an invalid default surface format.
- format.setVersion(4, 1);
- format.setProfile(QSurfaceFormat::CoreProfile);
-
- testContext.setFormat(format);
- if (testContext.create()) {
- QOffscreenSurface surface;
- surface.setFormat(format);
- surface.create();
-
- if (testContext.makeCurrent(&surface)) {
- // The Cocoa QPA integration allows sharing between OpenGL 3.2 and 4.1 contexts,
- // which means even though we requested a 4.1 context, if we only get a 3.2 context,
- // it will still work an Chromium will not black list it.
- if (testContext.format().version() >= qMakePair(3, 2) &&
- testContext.format().profile() == QSurfaceFormat::CoreProfile &&
- !isCurrentContextSoftware()) {
- QSurfaceFormat::setDefaultFormat(format);
- } else {
- qWarning("The available OpenGL surface format was either not version 3.2 or higher or not a Core Profile.\n"
- "Chromium on macOS will fall back to software rendering in this case.\n"
- "Hardware acceleration and features such as WebGL will not be available.");
- format = QSurfaceFormat::defaultFormat();
- }
- testContext.doneCurrent();
+ if (shareContext)
+ return;
+
+ shareContext = new QOpenGLContext;
+ QSurfaceFormat format = QSurfaceFormat::defaultFormat();
+
+#if defined(Q_OS_MACOS)
+ if (format == QSurfaceFormat()) {
+ QOpenGLContext testContext;
+
+ // Chromium turns off OpenGL for CoreProfiles with versions < 4.1
+ // The newest Mac that only supports 3.3 was released in Mid 2011,
+ // so it should be safe to request 4.1, but we still double check it
+ // works in order not to set an invalid default surface format.
+ format.setVersion(4, 1);
+ format.setProfile(QSurfaceFormat::CoreProfile);
+
+ testContext.setFormat(format);
+ if (testContext.create()) {
+ QOffscreenSurface surface;
+ surface.setFormat(format);
+ surface.create();
+
+ if (testContext.makeCurrent(&surface)) {
+ // The Cocoa QPA integration allows sharing between OpenGL 3.2 and 4.1 contexts,
+ // which means even though we requested a 4.1 context, if we only get a 3.2
+ // context, it will still work an Chromium will not black list it.
+ if (testContext.format().version() >= qMakePair(3, 2)
+ && testContext.format().profile() == QSurfaceFormat::CoreProfile
+ && !isCurrentContextSoftware()) {
+ QSurfaceFormat::setDefaultFormat(format);
+ } else {
+ qWarning("The available OpenGL surface format was either not version 3.2 "
+ "or higher or not a Core Profile.\n"
+ "Chromium on macOS will fall back to software rendering in this "
+ "case.\n"
+ "Hardware acceleration and features such as WebGL will not be "
+ "available.");
+ format = QSurfaceFormat::defaultFormat();
+ }
+ testContext.doneCurrent();
+ }
+ surface.destroy();
+ }
+ } else {
+ // The user explicitly requested a specific surface format that does not fit Chromium's
+ // requirements. Warn them about this.
+ if (format.version() < qMakePair(3, 2)
+ || format.profile() != QSurfaceFormat::CoreProfile) {
+ qWarning("An OpenGL surfcace format was requested that is either not version 3.2 "
+ "or higher or a not Core Profile.\n"
+ "Chromium on macOS will fall back to software rendering in this case.\n"
+ "Hardware acceleration and features such as WebGL will not be available.");
}
- surface.destroy();
- }
- } else {
- // The user explicitly requested a specific surface format that does not fit Chromium's requirements. Warn them about this.
- if (format.version() < qMakePair(3,2) || format.profile() != QSurfaceFormat::CoreProfile) {
- qWarning("An OpenGL surfcace format was requested that is either not version 3.2 or higher or a not Core Profile.\n"
- "Chromium on macOS will fall back to software rendering in this case.\n"
- "Hardware acceleration and features such as WebGL will not be available.");
}
- }
#endif
- shareContext->setFormat(format);
- shareContext->create();
- qAddPostRoutine(deleteShareContext);
- qt_gl_set_global_share_context(shareContext);
+ shareContext->setFormat(format);
+ shareContext->create();
+ qAddPostRoutine(deleteShareContext);
+ qt_gl_set_global_share_context(shareContext);
+
+ // Classes like QOpenGLWidget check for the attribute
+ app->setAttribute(Qt::AA_ShareOpenGLContexts);
+ }
+
+#if defined(Q_OS_MACOS)
+ // Check that the default QSurfaceFormat OpenGL profile is compatible with the global OpenGL
+ // shared context profile, otherwise this could lead to a nasty crash.
+ QSurfaceFormat sharedFormat = qt_gl_global_share_context()->format();
+ QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat();
+
+ if (defaultFormat.profile() != sharedFormat.profile()
+ && defaultFormat.profile() == QSurfaceFormat::CoreProfile
+ && defaultFormat.version() >= qMakePair(3, 2)) {
+ qFatal("QWebEngine: Default QSurfaceFormat OpenGL profile is not compatible with the "
+ "global shared context OpenGL profile. Please make sure you set a compatible "
+ "QSurfaceFormat before the QtGui application instance is created.");
+ }
+#endif
- // Classes like QOpenGLWidget check for the attribute
- app->setAttribute(Qt::AA_ShareOpenGLContexts);
#endif // QT_CONFIG(opengl)
}
} // namespace QtWebEngineCore