diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-02 15:30:02 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2019-09-06 09:59:06 +0200 |
commit | 228f0c1d2e1e4a4b160172dbf254935bb8fa2460 (patch) | |
tree | db257342c669f2db47ae9c495f32ae20e498aa5b /src/gui/painting | |
parent | 6de5cf2df82e5025bd9f02e9f38922f8c7c4b3b5 (diff) |
Allow render-to-texture widgets to tell if they want premul blending
Instead of assuming they do not (like in >= 5.12.3) or they do (like
in < 5.12.3). QOpenGLWidget and QQuickWidget will likely want the
opposite. So allow specifying this with a QPlatformTextureList flag,
similarly to how we do it for sRGB for QOpenGLWidget.
Task-number: QTBUG-77471
Change-Id: I594ca919c8eca190fa70c6aa84f46f456fcd80e1
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/gui/painting')
-rw-r--r-- | src/gui/painting/qplatformbackingstore.cpp | 20 | ||||
-rw-r--r-- | src/gui/painting/qplatformbackingstore.h | 3 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index c71d82546a..601dc97be1 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -446,14 +446,22 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion ®i d_ptr->blitter->setRedBlueSwizzle(false); } - // There is no way to tell if the OpenGL-rendered content is premultiplied or not. - // For compatibility, assume that it is not, and use normal alpha blend always. - if (d_ptr->premultiplied) - funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); - // Textures for renderToTexture widgets that have WA_AlwaysStackOnTop set. + bool blendIsPremultiplied = d_ptr->premultiplied; for (int i = 0; i < textures->count(); ++i) { - if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) + const QPlatformTextureList::Flags flags = textures->flags(i); + if (flags.testFlag(QPlatformTextureList::NeedsPremultipliedAlphaBlending)) { + if (!blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = true; + } + } else { + if (blendIsPremultiplied) { + funcs->glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE); + blendIsPremultiplied = false; + } + } + if (flags.testFlag(QPlatformTextureList::StacksOnTop)) blitTextureForWidget(textures, i, window, deviceWindowRect, d_ptr->blitter, offset, canUseSrgb); } diff --git a/src/gui/painting/qplatformbackingstore.h b/src/gui/painting/qplatformbackingstore.h index 414d2bf0de..4f08b0092f 100644 --- a/src/gui/painting/qplatformbackingstore.h +++ b/src/gui/painting/qplatformbackingstore.h @@ -81,7 +81,8 @@ class Q_GUI_EXPORT QPlatformTextureList : public QObject public: enum Flag { StacksOnTop = 0x01, - TextureIsSrgb = 0x02 + TextureIsSrgb = 0x02, + NeedsPremultipliedAlphaBlending = 0x04 }; Q_DECLARE_FLAGS(Flags, Flag) |