diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-11-11 16:12:35 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-11-12 11:09:11 +0100 |
commit | 897130541646a37e358463cb76aa505b66a1d7ac (patch) | |
tree | f8171b32c6e422d8dc6c7a3fe365c2c6dd4871aa /vcl | |
parent | a8ea76779f8c0ab52f0200249a4a5cc279b914b3 (diff) |
fix assertion with scaled alpha image in SkiaSalBitmap
The size of the alpha image does not really depend in mPixelsSize,
it's created on demand and it's just necessary to check if it
has the right size.
Change-Id: Ic16c7c2b202be31c22b21b0c5ee720bda955bbbd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125059
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/skia/salbmp.hxx | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/skia/skia.cxx | 57 | ||||
-rw-r--r-- | vcl/skia/salbmp.cxx | 2 |
3 files changed, 59 insertions, 1 deletions
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx index 91b11ab6255b..455414fdd7fa 100644 --- a/vcl/inc/skia/salbmp.hxx +++ b/vcl/inc/skia/salbmp.hxx @@ -96,6 +96,7 @@ public: bool unittestHasImage() const { return mImage.get(); } bool unittestHasAlphaImage() const { return mAlphaImage.get(); } bool unittestHasEraseColor() const { return mEraseColorSet; } + bool unittestHasPendingScale() const { return mSize != mPixelsSize; } const sal_uInt8* unittestGetBuffer() const { return mBuffer.get(); } const SkImage* unittestGetImage() const { return mImage.get(); } const SkImage* unittestGetAlphaImage() const { return mAlphaImage.get(); } diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx index 4ff70306b3fe..128829aecc18 100644 --- a/vcl/qa/cppunit/skia/skia.cxx +++ b/vcl/qa/cppunit/skia/skia.cxx @@ -42,6 +42,7 @@ public: void testBitmapCopyOnWrite(); void testMatrixQuality(); void testDelayedScale(); + void testDelayedScaleAlphaImage(); void testTdf137329(); void testTdf140848(); void testTdf132367(); @@ -54,6 +55,7 @@ public: CPPUNIT_TEST(testBitmapCopyOnWrite); CPPUNIT_TEST(testMatrixQuality); CPPUNIT_TEST(testDelayedScale); + CPPUNIT_TEST(testDelayedScaleAlphaImage); CPPUNIT_TEST(testTdf137329); CPPUNIT_TEST(testTdf140848); CPPUNIT_TEST(testTdf132367); @@ -372,6 +374,61 @@ void SkiaTest::testDelayedScale() skiaBitmap2.ReleaseBuffer(buffer2, BitmapAccessMode::Read); } +void SkiaTest::testDelayedScaleAlphaImage() +{ + if (!SkiaHelper::isVCLSkiaEnabled()) + return; + auto bitmapTmp = std::make_unique<SkiaSalBitmap>(); + CPPUNIT_ASSERT(bitmapTmp->Create(Size(10, 10), vcl::PixelFormat::N24_BPP, BitmapPalette())); + bitmapTmp->Erase(COL_RED); + // Create a bitmap that has only an image, not a pixel buffer. + SkiaSalBitmap bitmap(bitmapTmp->GetSkImage()); + bitmapTmp.release(); + CPPUNIT_ASSERT(!bitmap.unittestHasBuffer()); + CPPUNIT_ASSERT(bitmap.unittestHasImage()); + CPPUNIT_ASSERT(!bitmap.unittestHasAlphaImage()); + // Set up pending scale. + CPPUNIT_ASSERT(bitmap.Scale(2.0, 2.0, BmpScaleFlag::Fast)); + CPPUNIT_ASSERT(bitmap.unittestHasPendingScale()); + CPPUNIT_ASSERT(bitmap.InterpretAs8Bit()); + // Ask for SkImage and make sure it's scaled up. + sk_sp<SkImage> image = bitmap.GetSkImage(); + CPPUNIT_ASSERT_EQUAL(20, image->width()); + // Ask again, this time it should be cached. + sk_sp<SkImage> image2 = bitmap.GetSkImage(); + CPPUNIT_ASSERT_EQUAL(image.get(), image2.get()); + // Add another scale. + CPPUNIT_ASSERT(bitmap.Scale(3.0, 3.0, BmpScaleFlag::Fast)); + // Ask for alpha SkImage and make sure it's scaled up. + sk_sp<SkImage> alphaImage = bitmap.GetAlphaSkImage(); + CPPUNIT_ASSERT_EQUAL(60, alphaImage->width()); + // Ask again, this time it should be cached. + sk_sp<SkImage> alphaImage2 = bitmap.GetAlphaSkImage(); + CPPUNIT_ASSERT_EQUAL(alphaImage.get(), alphaImage2.get()); + // Ask again for non-alpha image, it should be scaled again. + sk_sp<SkImage> image3 = bitmap.GetSkImage(); + CPPUNIT_ASSERT_EQUAL(60, image3->width()); + CPPUNIT_ASSERT(image3.get() != image2.get()); + CPPUNIT_ASSERT(image3.get() != image.get()); + // Create pixel buffer from the image (it should convert from alpha image because the bitmap is 8bpp + // and the alpha image size matches). + SkiaSalBitmap bitmapCopy; + bitmapCopy.Create(bitmap); + CPPUNIT_ASSERT(!bitmap.unittestHasBuffer()); + BitmapBuffer* buffer1 = bitmap.AcquireBuffer(BitmapAccessMode::Read); + CPPUNIT_ASSERT(bitmap.unittestHasBuffer()); + bitmap.ReleaseBuffer(buffer1, BitmapAccessMode::Read); + CPPUNIT_ASSERT_EQUAL(Size(60, 60), bitmap.GetSize()); + // Scale the copy before the buffer was created (this time it should convert from non-alpha image + // because of the different size). + CPPUNIT_ASSERT(!bitmapCopy.unittestHasBuffer()); + CPPUNIT_ASSERT(bitmapCopy.Scale(4.0, 4.0, BmpScaleFlag::Fast)); + BitmapBuffer* buffer2 = bitmapCopy.AcquireBuffer(BitmapAccessMode::Read); + CPPUNIT_ASSERT(bitmapCopy.unittestHasBuffer()); + bitmapCopy.ReleaseBuffer(buffer2, BitmapAccessMode::Read); + CPPUNIT_ASSERT_EQUAL(Size(240, 240), bitmapCopy.GetSize()); +} + void SkiaTest::testTdf137329() { if (!SkiaHelper::isVCLSkiaEnabled()) diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx index abcfb0326e3a..31a369724259 100644 --- a/vcl/skia/salbmp.cxx +++ b/vcl/skia/salbmp.cxx @@ -831,7 +831,7 @@ const sk_sp<SkImage>& SkiaSalBitmap::GetAlphaSkImage() const } if (mAlphaImage) { - assert(mSize == mPixelsSize); // data has already been scaled if needed + assert(imageSize(mAlphaImage) == mSize); // data has already been scaled if needed return mAlphaImage; } if (mImage) |