summaryrefslogtreecommitdiff
path: root/vcl/skia/salbmp.cxx
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2019-10-30 12:04:47 +0100
committerLuboš Luňák <l.lunak@collabora.com>2019-11-27 09:55:13 +0100
commitd3a864bb2ded44c21aa7ebc6b04e7df7a3271a99 (patch)
treeeddba853204f196b2ac23a6920c340ed62a59841 /vcl/skia/salbmp.cxx
parent9fc9c5f7354590e3cc74b2f01af526df455792ba (diff)
hopefully finally fix SkiaSalGraphicsImpl::drawMask()
It now passes BackendTest::testDrawMask, so it should be checked. Change-Id: Ib3e1df03aefe6e9487737bec036a943377414735
Diffstat (limited to 'vcl/skia/salbmp.cxx')
-rw-r--r--vcl/skia/salbmp.cxx31
1 files changed, 24 insertions, 7 deletions
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx
index 89d9d4937a0c..05f9fb777bbf 100644
--- a/vcl/skia/salbmp.cxx
+++ b/vcl/skia/salbmp.cxx
@@ -321,10 +321,9 @@ const SkBitmap& SkiaSalBitmap::GetSkBitmap() const
const SkBitmap& SkiaSalBitmap::GetAlphaSkBitmap() const
{
- assert(mBitCount <= 8);
if (mAlphaBitmap.drawsNothing())
{
- if (mBuffer)
+ if (mBuffer && mBitCount <= 8)
{
assert(mBuffer.get());
verify();
@@ -341,17 +340,35 @@ const SkBitmap& SkiaSalBitmap::GetAlphaSkBitmap() const
}
else
{
- assert(mBitmap.colorType() == kGray_8_SkColorType);
+ GetSkBitmap(); // make sure we have mBitmap, in case (mBuffer && mBitCount > 8)
+ // To make things more interesting, some LO code creates masks as 24bpp,
+ // so we first need to convert to 8bit to be able to convert that to 8bit alpha.
+ SkBitmap* convertedBitmap = nullptr;
+ const SkBitmap* bitmap8 = &mBitmap;
+ dump("/tmp/a1.png");
+ if (mBitmap.colorType() != kGray_8_SkColorType)
+ {
+ convertedBitmap = new SkBitmap;
+ if (!convertedBitmap->tryAllocPixels(SkImageInfo::Make(
+ mSize.Width(), mSize.Height(), kGray_8_SkColorType, kOpaque_SkAlphaType)))
+ abort();
+ SkCanvas canvas(*convertedBitmap);
+ SkPaint paint;
+ paint.setBlendMode(SkBlendMode::kSrc); // copy and convert depth
+ canvas.drawBitmap(mBitmap, 0, 0, &paint);
+ bitmap8 = convertedBitmap;
+ }
// Skia uses a bitmap as an alpha channel only if it's set as kAlpha_8_SkColorType.
// But in SalBitmap::Create() it's not quite clear if the 8-bit image will be used
- // as a mask or as a real bitmap. So mBitmap is always kGray_8_SkColorType
+ // as a mask or as a real bitmap. So mBitmap is always kGray_8_SkColorType for 8bpp
// and mAlphaBitmap is kAlpha_8_SkColorType that can be used as a mask.
// Make mAlphaBitmap share mBitmap's data.
const_cast<SkBitmap&>(mAlphaBitmap)
- .setInfo(mBitmap.info().makeColorType(kAlpha_8_SkColorType), mBitmap.rowBytes());
+ .setInfo(bitmap8->info().makeColorType(kAlpha_8_SkColorType), bitmap8->rowBytes());
const_cast<SkBitmap&>(mAlphaBitmap)
- .setPixelRef(sk_ref_sp(mBitmap.pixelRef()), mBitmap.pixelRefOrigin().x(),
- mBitmap.pixelRefOrigin().y());
+ .setPixelRef(sk_ref_sp(bitmap8->pixelRef()), bitmap8->pixelRefOrigin().x(),
+ bitmap8->pixelRefOrigin().y());
+ delete convertedBitmap;
return mAlphaBitmap;
}
}