From 228f0c1d2e1e4a4b160172dbf254935bb8fa2460 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 2 Sep 2019 15:30:02 +0200 Subject: 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 --- src/gui/painting/qplatformbackingstore.cpp | 20 ++++++++++++++------ src/gui/painting/qplatformbackingstore.h | 3 ++- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src/gui/painting') 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) -- cgit v1.2.3