QPixmap don't assume QPlatformScreen::format is opaque

QRasterPlatformPixmap::systemOpaqueFormat returned QPlatformScreen::format
without checking that the format was actually opaque.

This caused several QPixmap tests to fail on Wayland because Wayland
compositors don't communicate the native format of the screen, just a list of
supported pixel formats, so we just return ARGB32_premultiplied in
QWaylandScreen::format().

Rename the method systemOpaqueFormat to systemNativeFormat since that's how
it's used most of the time. And do a conversion when we actually care whether
the format is opaque or not.

Task-number: QTBUG-51748
Change-Id: I47dc1c3f185fb802016ca361206d47d02e8d3cf1
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
bb10
Johan Klokkhammer Helsing 2018-03-13 13:04:40 +01:00 committed by Johan Helsing
parent d3121e3888
commit efa6e98912
4 changed files with 36 additions and 19 deletions

View File

@ -172,6 +172,31 @@ inline int qt_depthForFormat(QImage::Format format)
#pragma optimize("", on)
#endif
inline QImage::Format qt_opaqueVersion(QImage::Format format)
{
switch (format) {
case QImage::Format_ARGB8565_Premultiplied:
return QImage::Format_RGB16;
case QImage::Format_ARGB8555_Premultiplied:
return QImage::Format_RGB555;
case QImage::Format_ARGB6666_Premultiplied:
return QImage::Format_RGB666;
case QImage::Format_ARGB4444_Premultiplied:
return QImage::Format_RGB444;
case QImage::Format_RGBA8888:
case QImage::Format_RGBA8888_Premultiplied:
return QImage::Format_RGBX8888;
case QImage::Format_A2BGR30_Premultiplied:
return QImage::Format_BGR30;
case QImage::Format_A2RGB30_Premultiplied:
return QImage::Format_RGB30;
case QImage::Format_ARGB32_Premultiplied:
case QImage::Format_ARGB32:
default:
return QImage::Format_RGB32;
}
}
inline QImage::Format qt_alphaVersion(QImage::Format format)
{
switch (format) {
@ -201,6 +226,11 @@ inline QImage::Format qt_maybeAlphaVersionWithSameDepth(QImage::Format format)
return qt_depthForFormat(format) == qt_depthForFormat(toFormat) ? toFormat : format;
}
inline QImage::Format qt_opaqueVersionForPainting(QImage::Format format)
{
return qt_opaqueVersion(format);
}
inline QImage::Format qt_alphaVersionForPainting(QImage::Format format)
{
QImage::Format toFormat = qt_alphaVersion(format);

View File

@ -89,7 +89,7 @@ QRasterPlatformPixmap::~QRasterPlatformPixmap()
{
}
QImage::Format QRasterPlatformPixmap::systemOpaqueFormat()
QImage::Format QRasterPlatformPixmap::systemNativeFormat()
{
if (!QGuiApplication::primaryScreen())
return QImage::Format_RGB32;
@ -107,7 +107,7 @@ void QRasterPlatformPixmap::resize(int width, int height)
if (pixelType() == BitmapType)
format = QImage::Format_MonoLSB;
else
format = systemOpaqueFormat();
format = systemNativeFormat();
image = QImage(width, height, format);
w = width;
@ -314,8 +314,9 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage sourceImage, Qt::ImageCo
? QImage::Format_ARGB32_Premultiplied
: QImage::Format_RGB32;
} else {
QImage::Format opaqueFormat = systemOpaqueFormat();
QImage::Format alphaFormat = qt_alphaVersionForPainting(opaqueFormat);
QImage::Format nativeFormat = systemNativeFormat();
QImage::Format opaqueFormat = qt_opaqueVersionForPainting(nativeFormat);
QImage::Format alphaFormat = qt_alphaVersionForPainting(nativeFormat);
if (!sourceImage.hasAlphaChannel()) {
format = opaqueFormat;

View File

@ -88,7 +88,7 @@ protected:
void createPixmapForImage(QImage sourceImage, Qt::ImageConversionFlags flags);
void setImage(const QImage &image);
QImage image;
static QImage::Format systemOpaqueFormat();
static QImage::Format systemNativeFormat();
private:
friend class QPixmap;

View File

@ -527,16 +527,8 @@ void tst_QPixmap::fill_transparent()
QVERIFY(pixmap.hasAlphaChannel());
}
static bool isPlatformWayland()
{
return QGuiApplication::platformName().startsWith(QLatin1String("wayland"), Qt::CaseInsensitive);
}
void tst_QPixmap::mask()
{
if (isPlatformWayland())
QSKIP("Wayland: This fails. See QTBUG-66983.");
QPixmap pm(100, 100);
QBitmap bm(100, 100);
@ -778,9 +770,6 @@ void tst_QPixmap::convertFromImageNoDetach()
void tst_QPixmap::convertFromImageNoDetach2()
{
if (isPlatformWayland())
QSKIP("Wayland: This fails. See QTBUG-66984.");
QPixmap randomPixmap(10, 10);
if (randomPixmap.handle()->classId() != QPlatformPixmap::RasterClass)
QSKIP("Test only valid for raster pixmaps");
@ -1455,9 +1444,6 @@ void tst_QPixmap::fromImageReaderAnimatedGif()
void tst_QPixmap::task_246446()
{
if (isPlatformWayland())
QSKIP("Wayland: This fails. See QTBUG-66985.");
// This crashed without the bugfix in 246446
QPixmap pm(10, 10);
pm.fill(Qt::transparent); // force 32-bit depth