From 28a264cfe2d161f2eba3b1efa3ea4985445cd2de Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 8 Mar 2019 10:55:14 +0100 Subject: Fix alpha blending regression with WA_StacksOnTop QOpenGLWidgets 0bc42886898 in Qt 5.6 introduced support for premultiplied alpha in the raster-rendered QWidget content. Unfortunately this introduced a regression for OpenGL content from QOpenGLWidgets with WA_StacksOnTop set: these used standard alpha blending in 5.5 and earlier, and switching them to premultiplied (in case the - unrelated - raster content has a _Premultiplied QImage format) breaks all content that was done with non-premultiplied alpha in mind, for example the qopenglwidget example's "Transparent background" checkbox. Restore the pre-5.6 behavior. Fixes: QTBUG-74285 Change-Id: I76fcadd53cd436efa2b619b8d6739270995d044f Reviewed-by: Allan Sandfeld Jensen --- src/gui/painting/qplatformbackingstore.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/gui') diff --git a/src/gui/painting/qplatformbackingstore.cpp b/src/gui/painting/qplatformbackingstore.cpp index afb4613ba5..c71d82546a 100644 --- a/src/gui/painting/qplatformbackingstore.cpp +++ b/src/gui/painting/qplatformbackingstore.cpp @@ -446,6 +446,11 @@ 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. for (int i = 0; i < textures->count(); ++i) { if (textures->flags(i).testFlag(QPlatformTextureList::StacksOnTop)) -- cgit v1.2.3 From 3b7db8ac90ba36949cb4168f07cc8dace47758a7 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Fri, 29 Mar 2019 10:36:21 +0100 Subject: Fix assert/crash when creating QBrush with null QGradient MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QBrush constructor taking a QGradient would assert or crash if passed a null (NoGradient) gradient. But it is not necessary for the API to be as brittle as that: instead the result can simply be a null QBrush object, i.e. the same as the default QBrush() constructor creates (style == NoBrush). This issue comes up now since with the recent introduction of QGradient presets, the API opens for using QGradient directly, whereas earlier, only the subclasses QLinearGradient etc. were to be used. Fixes: QTBUG-74648 Change-Id: I1a9b1c4654e4375aa6684700a262cc0946851448 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Tor Arne Vestbø --- src/gui/painting/qbrush.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 860653cc4c..bcc23fa683 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -545,9 +545,11 @@ QBrush::QBrush(const QBrush &other) */ QBrush::QBrush(const QGradient &gradient) { - Q_ASSERT_X(gradient.type() != QGradient::NoGradient, "QBrush::QBrush", - "QGradient should not be used directly, use the linear, radial\n" - "or conical gradients instead"); + if (Q_UNLIKELY(gradient.type() == QGradient::NoGradient)) { + d.reset(nullBrushInstance()); + d->ref.ref(); + return; + } const Qt::BrushStyle enum_table[] = { Qt::LinearGradientPattern, @@ -1376,8 +1378,10 @@ QGradient::QGradient(Preset preset) }(); const QJsonValue presetData = jsonPresets[preset - 1]; - if (!presetData.isObject()) + if (!presetData.isObject()) { + qWarning("QGradient: Undefined preset %i", preset); return; + } m_type = LinearGradient; setCoordinateMode(ObjectMode); -- cgit v1.2.3 From 685b8db13aa19e734f239678bae23607fcededbd Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 28 Mar 2019 16:49:57 +0300 Subject: Forward devicePixelRatio in QPixmap::mask() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add a test checking that devicePixelRatio is forwarded to derivatives of QPixmap. Change-Id: Idb2b3f033ccc0fd49bf54b11f5dffbce5a19b006 Reviewed-by: Morten Johan Sørvig --- src/gui/image/qplatformpixmap.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/image/qplatformpixmap.cpp b/src/gui/image/qplatformpixmap.cpp index 2209c3de4d..a2e01147c4 100644 --- a/src/gui/image/qplatformpixmap.cpp +++ b/src/gui/image/qplatformpixmap.cpp @@ -178,6 +178,7 @@ QBitmap QPlatformPixmap::mask() const if (mask.isNull()) // allocation failed return QBitmap(); + mask.setDevicePixelRatio(devicePixelRatio()); mask.setColorCount(2); mask.setColor(0, QColor(Qt::color0).rgba()); mask.setColor(1, QColor(Qt::color1).rgba()); -- cgit v1.2.3 From 011794130c8e4bb64dbc3c8c9b50849b278cdda3 Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 28 Mar 2019 13:59:35 +0300 Subject: Forward physical parameters for derived QImages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More specifically, for masks and rotated images. Add tests for it, also add tests that image metadata is forwarded for converted and copied images. Fixes: QTBUG-49259 Change-Id: I05d4a468b17f53a2625500b871c01b2c53b981a1 Reviewed-by: Morten Johan Sørvig --- src/gui/image/qimage.cpp | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index 3e18ca6528..ed6f23ee56 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -1089,15 +1089,31 @@ void QImage::detach() } -static void copyMetadata(QImageData *dst, const QImageData *src) +static void copyPhysicalMetadata(QImageData *dst, const QImageData *src) { - // Doesn't copy colortable and alpha_clut, or offset. dst->dpmx = src->dpmx; dst->dpmy = src->dpmy; dst->devicePixelRatio = src->devicePixelRatio; +} + +static void copyMetadata(QImageData *dst, const QImageData *src) +{ + // Doesn't copy colortable and alpha_clut, or offset. + copyPhysicalMetadata(dst, src); dst->text = src->text; } +static void copyMetadata(QImage *dst, const QImage &src) +{ + dst->setDotsPerMeterX(src.dotsPerMeterX()); + dst->setDotsPerMeterY(src.dotsPerMeterY()); + dst->setDevicePixelRatio(src.devicePixelRatio()); + const auto textKeys = src.textKeys(); + for (const auto &key: textKeys) + dst->setText(key, src.text(key)); + +} + /*! \fn QImage QImage::copy(int x, int y, int width, int height) const \overload @@ -2924,8 +2940,10 @@ QImage QImage::createAlphaMask(Qt::ImageConversionFlags flags) const } QImage mask(d->width, d->height, Format_MonoLSB); - if (!mask.isNull()) + if (!mask.isNull()) { dither_to_Mono(mask.d, d, flags, true); + copyPhysicalMetadata(mask.d, d); + } return mask; } @@ -3043,6 +3061,7 @@ QImage QImage::createHeuristicMask(bool clipTight) const #undef PIX + copyPhysicalMetadata(m.d, d); return m; } #endif //QT_NO_IMAGE_HEURISTIC_MASK @@ -3086,6 +3105,8 @@ QImage QImage::createMaskFromColor(QRgb color, Qt::MaskMode mode) const } if (mode == Qt::MaskOutColor) maskImage.invertPixels(); + + copyPhysicalMetadata(maskImage.d, d); return maskImage; } @@ -4655,8 +4676,7 @@ QImage QImage::smoothScaled(int w, int h) const { static QImage rotated90(const QImage &image) { QImage out(image.height(), image.width(), image.format()); - out.setDotsPerMeterX(image.dotsPerMeterY()); - out.setDotsPerMeterY(image.dotsPerMeterX()); + copyMetadata(&out, image); if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); @@ -4684,8 +4704,7 @@ static QImage rotated180(const QImage &image) return image.mirrored(true, true); QImage out(image.width(), image.height(), image.format()); - out.setDotsPerMeterX(image.dotsPerMeterY()); - out.setDotsPerMeterY(image.dotsPerMeterX()); + copyMetadata(&out, image); if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); @@ -4697,8 +4716,7 @@ static QImage rotated180(const QImage &image) static QImage rotated270(const QImage &image) { QImage out(image.height(), image.width(), image.format()); - out.setDotsPerMeterX(image.dotsPerMeterY()); - out.setDotsPerMeterY(image.dotsPerMeterX()); + copyMetadata(&out, image); if (image.colorCount() > 0) out.setColorTable(image.colorTable()); int w = image.width(); -- cgit v1.2.3