[Libreoffice-commits] core.git: vcl/inc vcl/qa vcl/skia
LuboÅ¡ LuÅák (via logerrit)
logerrit at kemper.freedesktop.org
Wed Oct 14 14:03:01 UTC 2020
vcl/inc/skia/salbmp.hxx | 3 +++
vcl/qa/cppunit/skia/skia.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++
vcl/skia/salbmp.cxx | 1 +
3 files changed, 46 insertions(+)
New commits:
commit fde7bb6ddc9c2f9b515e1b3aac791635bcf813fa
Author: Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Wed Oct 14 14:33:28 2020 +0200
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Wed Oct 14 16:02:18 2020 +0200
add unittest for SkiaSalBitmap copy-on-write data sharing
Change-Id: I2e331785d49c55116bf9cb893be25da1067df8ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104283
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx
index 49aabcf69a7f..9edb1d620e3a 100644
--- a/vcl/inc/skia/salbmp.hxx
+++ b/vcl/inc/skia/salbmp.hxx
@@ -94,6 +94,9 @@ public:
bool unittestHasImage() const { return mImage.get(); }
bool unittestHasAlphaImage() const { return mAlphaImage.get(); }
bool unittestHasEraseColor() const { return mEraseColorSet; }
+ const sal_uInt8* unittestGetBuffer() const { return mBuffer.get(); }
+ const SkImage* unittestGetImage() const { return mImage.get(); }
+ const SkImage* unittestGetAlphaImage() const { return mAlphaImage.get(); }
private:
// Reset the state to pixel data (resets cached images allocated in GetSkImage()/GetAlphaSkImage()).
diff --git a/vcl/qa/cppunit/skia/skia.cxx b/vcl/qa/cppunit/skia/skia.cxx
index c3f1c215b570..00c99823e986 100644
--- a/vcl/qa/cppunit/skia/skia.cxx
+++ b/vcl/qa/cppunit/skia/skia.cxx
@@ -34,12 +34,14 @@ public:
void testDrawShaders();
void testInterpretAs8Bit();
void testAlphaBlendWith();
+ void testBitmapCopyOnWrite();
CPPUNIT_TEST_SUITE(SkiaTest);
CPPUNIT_TEST(testBitmapErase);
CPPUNIT_TEST(testDrawShaders);
CPPUNIT_TEST(testInterpretAs8Bit);
CPPUNIT_TEST(testAlphaBlendWith);
+ CPPUNIT_TEST(testBitmapCopyOnWrite);
CPPUNIT_TEST_SUITE_END();
private:
@@ -261,6 +263,46 @@ void SkiaTest::testAlphaBlendWith()
AlphaMask::ScopedReadAccess(alpha)->GetPixelIndex(0, 0));
}
+void SkiaTest::testBitmapCopyOnWrite()
+{
+ if (!SkiaHelper::isVCLSkiaEnabled())
+ return;
+ SkiaSalBitmap bitmap;
+ CPPUNIT_ASSERT(bitmap.Create(Size(10, 10), 24, BitmapPalette()));
+ bitmap.GetSkImage();
+ bitmap.GetAlphaSkImage();
+ CPPUNIT_ASSERT(bitmap.unittestHasBuffer());
+ CPPUNIT_ASSERT(bitmap.unittestHasImage());
+ CPPUNIT_ASSERT(bitmap.unittestHasAlphaImage());
+ SkiaSalBitmap bitmap2;
+ CPPUNIT_ASSERT(bitmap2.Create(bitmap));
+ // Data should be shared.
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetBuffer(), bitmap2.unittestGetBuffer());
+ CPPUNIT_ASSERT(bitmap2.unittestHasImage());
+ CPPUNIT_ASSERT(bitmap2.unittestHasAlphaImage());
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetImage(), bitmap2.unittestGetImage());
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetAlphaImage(), bitmap2.unittestGetAlphaImage());
+ // Reading still should keep the data shrared.
+ const SkImage* oldImage = bitmap.unittestGetImage();
+ const SkImage* oldAlphaImage = bitmap.unittestGetAlphaImage();
+ BitmapBuffer* buffer = bitmap.AcquireBuffer(BitmapAccessMode::Read);
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetBuffer(), bitmap2.unittestGetBuffer());
+ bitmap.ReleaseBuffer(buffer, BitmapAccessMode::Read);
+ // Images get possibly updated only after releasing the buffer.
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetImage(), bitmap2.unittestGetImage());
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetAlphaImage(), bitmap2.unittestGetAlphaImage());
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetImage(), oldImage);
+ CPPUNIT_ASSERT_EQUAL(bitmap.unittestGetAlphaImage(), oldAlphaImage);
+ // Writing should unshare.
+ buffer = bitmap.AcquireBuffer(BitmapAccessMode::Write);
+ CPPUNIT_ASSERT(bitmap.unittestGetBuffer() != bitmap2.unittestGetBuffer());
+ bitmap.ReleaseBuffer(buffer, BitmapAccessMode::Write);
+ CPPUNIT_ASSERT(bitmap.unittestGetImage() != bitmap2.unittestGetImage());
+ CPPUNIT_ASSERT(bitmap.unittestGetAlphaImage() != bitmap2.unittestGetAlphaImage());
+ CPPUNIT_ASSERT(bitmap.unittestGetImage() != oldImage);
+ CPPUNIT_ASSERT(bitmap.unittestGetAlphaImage() != oldAlphaImage);
+}
+
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(SkiaTest);
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index d1cd76b61d5f..49ca73beac0f 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -289,6 +289,7 @@ void SkiaSalBitmap::ReleaseBuffer(BitmapBuffer* pBuffer, BitmapAccessMode nMode)
assert(pBuffer->mnWidth == mSize.Width());
assert(pBuffer->mnHeight == mSize.Height());
assert(pBuffer->mnBitCount == mBitCount);
+ assert(pBuffer->mpBits == mBuffer.get());
verify();
delete pBuffer;
}
More information about the Libreoffice-commits
mailing list