summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2021-06-10 17:42:54 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-18 21:10:37 +0000
commit52fc2c2ce081d56903c0b465a15e2a0f52c0dbbd (patch)
treed6ad9be6d741e8ac651a9c20e8ed9e6d75c561d4 /src
parentd172956ce4d218c4943a61cdb8dfe022bfabc7c3 (diff)
Do not alter a widget's backing window's format once created
Changing anything on a QWindow's QSurfaceFormat has zero and null effects once the underlying native window has been created. Letting QWidget update the format is wrong in this case, because we always expect that the value returned from QWindow::format() reflects reality. (reality being the settings with which the underlying native resource was created, which is typically frozen after QWindow::create(), not the state of some QWidget attribute. There are certain exceptions to this, such as when preparing to recreate the underlying native window, in which case one will want to update all relevant fields of the format based on the current values of the widget attributes, which is exactly what QWidgetPrivate::create() implements, and that's good.) Such a mismatch can have fatal consequences when OpenGL and friends are involved, but this always depends heavily on the platform and windowing system. For example, claiming that the alpha buffer size is 0 when the native window was created with 8, or vice versa, can break OpenGL-related code (both in Qt itself and in applications), that tries to create a QOpengGLContext configured based on what QWindow::format() returns. If that format describes settings that are incompatible with the actual underlying native window, we end up with the classic Invalid pixel format, EGL_BAD_MATCH, and alike errors. This is exactly what is happening when a QOpenGLWidget (or QQuickWidget) is placed in a QDockWidget where one of the ancestors is forced to native (winId() was called or WA_NativeWindow was set). When undocking, various code paths in QWidget will try to update the opaque flag of the widget, which in turn calls updateIsTranslucent. Now, if this function unconditionally changes the alphaBufferSize in the QWindow's QSurfaceFormat (even though this is completely futile to do, it has no visible effect in practice), we get the problem described above: rendering breaking down due to OpenGL contexts created with a pixel format incompatible with the native window. Prevent all this by not touching the format once the QWindow has a QPlatformWindow. This is the right thing to do, regardless of the bug in question: a window's (or context's or any other native resource wrapping class's) format must describe the underlying native resource and must never deviate, unless we are preparing to create a new native resource underneath. When it comes to the autotest, this changes the test added in 555661b625c40f21a6a3e4c73e928a6e8a46db20: the autotest logic is inverted because what we should test for is that the QSurfaceFormat stays untouched once the application makes a - futile - attribute change on the widget. Fixes: QTBUG-85714 Change-Id: I7bf90711867e8a0fd474895625bf9530a7821fd5 Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io> (cherry picked from commit e6a969954a9e6865e5f662acd1d949561f8ef3be) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/kernel/qwidget.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 14012219f9..a5ad101201 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -2191,8 +2191,26 @@ void QWidgetPrivate::updateIsTranslucent()
const int oldAlpha = format.alphaBufferSize();
const int newAlpha = q->testAttribute(Qt::WA_TranslucentBackground)? 8 : 0;
if (oldAlpha != newAlpha) {
- format.setAlphaBufferSize(newAlpha);
- window->setFormat(format);
+ // QTBUG-85714: Do this only when the QWindow has not yet been create()'ed yet.
+ //
+ // If that is not the case, then the setFormat() is not just futile
+ // but downright dangerous. Futile because the format matters only
+ // when creating the native window, no point in changing it
+ // afterwards. Dangerous because a QOpenGLContext or something else
+ // may eventually query the QWindow's format(), in order to ensure
+ // compatibility (in terms of native concepts such as pixel format,
+ // EGLConfig, etc.), and if we change it here, then the returned
+ // format does not describe reality anymore. (reality being the
+ // settings with which the native resource was created).
+ //
+ // Whereas if one does a destroy()-create() then this all here
+ // won't matter because the format is updated in
+ // QWidgetPrivate::create() again.
+ //
+ if (!window->handle()) {
+ format.setAlphaBufferSize(newAlpha);
+ window->setFormat(format);
+ }
}
}
}