diff options
author | Alexandru Croitor <alexandru.croitor@theqtcompany.com> | 2016-01-28 15:33:25 +0100 |
---|---|---|
committer | Jani Heikkinen <jani.heikkinen@theqtcompany.com> | 2016-02-04 12:58:06 +0000 |
commit | 32929885f44bb9621ac8cfa2b5c592b0977a123f (patch) | |
tree | 9102f9e61d299f9d5fdd1fafddc26b6030b736a8 /src/webengine | |
parent | 46b561970579c08af6e2b2df0713f84396e0da0d (diff) |
OS X: Fix crash when setting a custom default QSurfaceFormat.
Setting a new default QSurfaceFormat after
QtWebEngineCore::initialize() is called, might lead to a crash.
This happens when the new surface format has a different OpenGL profile,
compared to the profile created by web engine in the
RenderWidgetHostViewQtDelegateWidget constructor. The default
constructed QSurfaceFormat has an OpenGL Compatibility profile.
Inside the Cocoa platform plugin when a new shared OpenGL context is
created, it fails to initialize the new context because of the
difference in profiles, and thus ultimately creates an unshared
context, which leads to a crash.
Fix consists in using the shared context QSurfaceFormat in the
RenderWidgetHostViewQtDelegateWidget constructor, and also printing
a fatal warning to notify the developer only to set the new
QSurfaceFormat before the application instance is declared.
Bottom line, if the QSurfaceFormat OpenGL profile has to be
changed, it should be done before QtWebEngineCore::initialize() is
called. Doing so after initialize() is called, will lead to a crash.
Change-Id: I8a07211b592143d736b001556b944d4759802396
Task-number: QTBUG-50665
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Reviewed-by: Michal Klocek <michal.klocek@theqtcompany.com>
Diffstat (limited to 'src/webengine')
-rw-r--r-- | src/webengine/doc/src/qtwebengine-platform-notes.qdoc | 10 | ||||
-rw-r--r-- | src/webengine/render_widget_host_view_qt_delegate_quick.cpp | 15 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/webengine/doc/src/qtwebengine-platform-notes.qdoc b/src/webengine/doc/src/qtwebengine-platform-notes.qdoc index 3e30e9606..f177c9598 100644 --- a/src/webengine/doc/src/qtwebengine-platform-notes.qdoc +++ b/src/webengine/doc/src/qtwebengine-platform-notes.qdoc @@ -116,4 +116,14 @@ be configured for use with several codecs, which rises licensing issues during distribution with the codec libraries. For some codecs, open source implementations, such as \l {OpenH264}, are available. + + \section1 Default QSurfaceFormat OpenGL Profile Support + + If a new default QSurfaceFormat with a modified OpenGL profile has to be set, it should be set + before the application instance is declared, to make sure that all created OpenGL contexts use + the same OpenGL profile. + + On OS X, if the default QSurfaceFormat is set after the application instance, the application + will exit with qFatal(), and print a message that the default QSurfaceFormat should be set + before the application instance. */ diff --git a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp index 508420cf8..b667bbc5c 100644 --- a/src/webengine/render_widget_host_view_qt_delegate_quick.cpp +++ b/src/webengine/render_widget_host_view_qt_delegate_quick.cpp @@ -41,6 +41,7 @@ #include <QGuiApplication> #include <QQuickPaintedItem> #include <QQuickWindow> +#include <QSurfaceFormat> #include <QVariant> #include <QWindow> #include <private/qquickwindow_p.h> @@ -60,6 +61,20 @@ RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderW return; setFocus(true); setActiveFocusOnTab(true); + +#ifdef Q_OS_OSX + // Check that the default QSurfaceFormat OpenGL profile matches the global OpenGL shared + // context profile, otherwise this could lead to a nasty crash. + QOpenGLContext *globalSharedContext = QOpenGLContext::globalShareContext(); + if (globalSharedContext) { + QSurfaceFormat sharedFormat = globalSharedContext->format(); + QSurfaceFormat defaultFormat = QSurfaceFormat::defaultFormat(); + if (defaultFormat.profile() != sharedFormat.profile()) { + qFatal("QWebEngine: Default QSurfaceFormat OpenGL profile does not match global shared context OpenGL profile. Please make sure you set a new QSurfaceFormat before the QtGui application instance is created."); + } + } +#endif + } void RenderWidgetHostViewQtDelegateQuick::initAsChild(WebContentsAdapterClient* container) |