summaryrefslogtreecommitdiff
path: root/vcl/qa/cppunit/skia
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-12-09 13:09:57 +0100
committerLuboš Luňák <l.lunak@collabora.com>2021-12-10 11:02:15 +0100
commit63b8d83fd0d135af4ac04f78d26bfd3322ab65f6 (patch)
treed535b6761bb65f5b1c65e4eaed9b2af3cac01ef3 /vcl/qa/cppunit/skia
parenta78040cabc6878e06e7519d6d53a0ef6e5c4d658 (diff)
make sure Skia bitmap checksum is invalidated properly
Change-Id: I85e81b730dcb0fdc7728d5a956974ef09a73de87 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126585 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/qa/cppunit/skia')
-rw-r--r--vcl/qa/cppunit/skia/skia.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx
index b94e2ede7eba..21e3d0baf696 100644
--- a/vcl/qa/cppunit/skia/skia.cxx
+++ b/vcl/qa/cppunit/skia/skia.cxx
@@ -44,6 +44,7 @@ public:
void testDelayedScale();
void testDelayedScaleAlphaImage();
void testDrawDelayedScaleImage();
+ void testChecksum();
void testTdf137329();
void testTdf140848();
void testTdf132367();
@@ -58,6 +59,7 @@ public:
CPPUNIT_TEST(testDelayedScale);
CPPUNIT_TEST(testDelayedScaleAlphaImage);
CPPUNIT_TEST(testDrawDelayedScaleImage);
+ CPPUNIT_TEST(testChecksum);
CPPUNIT_TEST(testTdf137329);
CPPUNIT_TEST(testTdf140848);
CPPUNIT_TEST(testTdf132367);
@@ -468,6 +470,45 @@ void SkiaTest::testDrawDelayedScaleImage()
CPPUNIT_ASSERT_EQUAL(Size(10, 10), SkiaHelper::imageSize(image3));
}
+void SkiaTest::testChecksum()
+{
+ if (!SkiaHelper::isVCLSkiaEnabled())
+ return;
+ Bitmap bitmap(Size(10, 10), vcl::PixelFormat::N24_BPP);
+ bitmap.Erase(COL_RED);
+ BitmapChecksum checksum1 = bitmap.GetChecksum();
+ // Set a pixel to create pixel data, that should change checksum.
+ BitmapWriteAccess(bitmap).SetPixel(0, 0, COL_BLUE);
+ BitmapChecksum checksum2 = bitmap.GetChecksum();
+ CPPUNIT_ASSERT(checksum2 != checksum1);
+ SkiaSalBitmap* skiaBitmap1 = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get());
+ // Creating an image should not change the checksum.
+ sk_sp<SkImage> image1 = skiaBitmap1->GetSkImage();
+ BitmapChecksum checksum3 = bitmap.GetChecksum();
+ CPPUNIT_ASSERT_EQUAL(checksum2, checksum3);
+ // Delayed scaling should change checksum even if the scaling has not taken place.
+ bitmap.Scale(Size(20, 20));
+ BitmapChecksum checksum4 = bitmap.GetChecksum();
+ CPPUNIT_ASSERT(checksum4 != checksum3);
+ // Setting back to the original red content should have the original checksum.
+ // (This also makes sure this next step is not affected by the delayed scaling
+ // above possibly taking place now.)
+ bitmap = Bitmap(Size(10, 10), vcl::PixelFormat::N24_BPP);
+ bitmap.Erase(COL_RED);
+ BitmapChecksum checksum5 = bitmap.GetChecksum();
+ CPPUNIT_ASSERT_EQUAL(checksum1, checksum5);
+ // The optimized changing of images to greyscale should change the checksum.
+ SkiaSalBitmap* skiaBitmap2 = dynamic_cast<SkiaSalBitmap*>(bitmap.ImplGetSalBitmap().get());
+ skiaBitmap2->unittestResetToImage();
+ BitmapChecksum checksum6;
+ skiaBitmap2->GetChecksum(checksum6);
+ CPPUNIT_ASSERT_EQUAL(checksum5, checksum6);
+ CPPUNIT_ASSERT(skiaBitmap2->ConvertToGreyscale());
+ BitmapChecksum checksum7;
+ skiaBitmap2->GetChecksum(checksum7);
+ CPPUNIT_ASSERT(checksum7 != checksum6);
+}
+
void SkiaTest::testTdf137329()
{
if (!SkiaHelper::isVCLSkiaEnabled())