Ensure raster pixmap cache key is the same as that of pixmap.toImage()
This is done to support texture uploads in an image provider. It ensures we can load the texture using QImage in the image provider, and when it is later painted as a pixmap, the cacheKey will be identical (assuming no format conversion was required). Change-Id: I54229511ed91ce5430cc478af5aff0d96685a2da Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>bb10
parent
9fa5191b6e
commit
f156e578d7
|
|
@ -353,7 +353,9 @@ void QRasterPlatformPixmap::createPixmapForImage(QImage &sourceImage, Qt::ImageC
|
|||
is_null = (w <= 0 || h <= 0);
|
||||
|
||||
image.d->devicePixelRatio = sourceImage.devicePixelRatio();
|
||||
//ensure the pixmap and the image resulting from toImage() have the same cacheKey();
|
||||
setSerialNumber(image.cacheKey() >> 32);
|
||||
setDetachNumber(image.d->detach_no);
|
||||
}
|
||||
|
||||
QImage* QRasterPlatformPixmap::buffer()
|
||||
|
|
|
|||
|
|
@ -173,6 +173,11 @@ void QPlatformPixmap::setSerialNumber(int serNo)
|
|||
ser_no = serNo;
|
||||
}
|
||||
|
||||
void QPlatformPixmap::setDetachNumber(int detNo)
|
||||
{
|
||||
detach_no = detNo;
|
||||
}
|
||||
|
||||
QImage QPlatformPixmap::toImage(const QRect &rect) const
|
||||
{
|
||||
if (rect.contains(QRect(0, 0, w, h)))
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ public:
|
|||
protected:
|
||||
|
||||
void setSerialNumber(int serNo);
|
||||
void setDetachNumber(int detNo);
|
||||
int w;
|
||||
int h;
|
||||
int d;
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ private slots:
|
|||
|
||||
void convertFromImageNoDetach();
|
||||
void convertFromImageDetach();
|
||||
void convertFromImageCacheKey();
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
void toWinHBITMAP_data();
|
||||
|
|
@ -779,6 +780,28 @@ void tst_QPixmap::convertFromImageDetach()
|
|||
QVERIFY(copy.isDetached());
|
||||
}
|
||||
|
||||
void tst_QPixmap::convertFromImageCacheKey()
|
||||
{
|
||||
QPixmap randomPixmap(10, 10);
|
||||
if (randomPixmap.handle()->classId() != QPlatformPixmap::RasterClass)
|
||||
QSKIP("Test only valid for raster pixmaps");
|
||||
|
||||
//first get the screen format
|
||||
QImage::Format screenFormat = randomPixmap.toImage().format();
|
||||
QVERIFY(screenFormat != QImage::Format_Invalid);
|
||||
|
||||
QImage orig(100,100, screenFormat);
|
||||
orig.fill(0);
|
||||
|
||||
QPixmap pix = QPixmap::fromImage(orig);
|
||||
QImage copy = pix.toImage();
|
||||
|
||||
QVERIFY(copy.format() == screenFormat);
|
||||
|
||||
QCOMPARE(orig.cacheKey(), pix.cacheKey());
|
||||
QCOMPARE(copy.cacheKey(), pix.cacheKey());
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
|
|
|||
Loading…
Reference in New Issue