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>
bb10
Laszlo Agocs 2019-09-02 15:30:02 +02:00
parent 6de5cf2df8
commit 228f0c1d2e
2 changed files with 16 additions and 7 deletions

View File

@ -446,14 +446,22 @@ void QPlatformBackingStore::composeAndFlush(QWindow *window, const QRegion &regi
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);
}

View File

@ -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)