summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/BackendTest.cxx2
-rw-r--r--vcl/skia/gdiimpl.cxx16
-rw-r--r--vcl/skia/salbmp.cxx31
-rw-r--r--vcl/skia/win/gdiimpl.cxx20
4 files changed, 37 insertions, 32 deletions
diff --git a/vcl/qa/cppunit/BackendTest.cxx b/vcl/qa/cppunit/BackendTest.cxx
index 483d105bd2d2..db75583a981f 100644
--- a/vcl/qa/cppunit/BackendTest.cxx
+++ b/vcl/qa/cppunit/BackendTest.cxx
@@ -416,7 +416,7 @@ public:
CPPUNIT_TEST(testDrawBitmap);
CPPUNIT_TEST(testDrawTransformedBitmap);
CPPUNIT_TEST(testDrawBitmapExWithAlpha);
- // CPPUNIT_TEST(testDrawMask); TODO SKIA
+ CPPUNIT_TEST(testDrawMask);
CPPUNIT_TEST_SUITE_END();
};
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 0f07ebd5a1d9..a90b40bd9e09 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -683,23 +683,29 @@ void SkiaSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, const SalBitmap& r
Color nMaskColor)
{
assert(dynamic_cast<const SkiaSalBitmap*>(&rSalBitmap));
- drawMask(rPosAry, static_cast<const SkiaSalBitmap&>(rSalBitmap).GetSkBitmap(), nMaskColor);
+ drawMask(rPosAry, static_cast<const SkiaSalBitmap&>(rSalBitmap).GetAlphaSkBitmap(), nMaskColor);
}
void SkiaSalGraphicsImpl::drawMask(const SalTwoRect& rPosAry, const SkBitmap& rBitmap,
Color nMaskColor)
{
preDraw();
+ SkBitmap tmpBitmap;
+ if (!tmpBitmap.tryAllocN32Pixels(rBitmap.width(), rBitmap.height()))
+ abort();
+ tmpBitmap.eraseColor(toSkColor(nMaskColor));
SkPaint paint;
- // Draw the color with the given mask, and mask uses inversed alpha.
+ // Draw the color with the given mask.
+ // TODO figure out the right blend mode to avoid the temporary bitmap
paint.setBlendMode(SkBlendMode::kDstOut);
- paint.setColor(toSkColor(nMaskColor));
+ SkCanvas canvas(tmpBitmap);
+ canvas.drawBitmap(rBitmap, 0, 0, &paint);
mSurface->getCanvas()->drawBitmapRect(
- rBitmap,
+ tmpBitmap,
SkRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight),
SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
rPosAry.mnDestHeight),
- &paint);
+ nullptr);
postDraw();
}
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;
}
}
diff --git a/vcl/skia/win/gdiimpl.cxx b/vcl/skia/win/gdiimpl.cxx
index c1a6d45353cb..3be821c350ec 100644
--- a/vcl/skia/win/gdiimpl.cxx
+++ b/vcl/skia/win/gdiimpl.cxx
@@ -135,25 +135,7 @@ void WinSkiaSalGraphicsImpl::DrawTextMask(CompatibleDC::Texture* pTexture, Color
const SalTwoRect& rPosAry)
{
assert(dynamic_cast<SkiaCompatibleDC::Texture*>(pTexture));
- const SkBitmap& bitmap = static_cast<const SkiaCompatibleDC::Texture*>(pTexture)->bitmap;
- preDraw();
- SkBitmap tmpBitmap;
- if (!tmpBitmap.tryAllocN32Pixels(bitmap.width(), bitmap.height()))
- abort();
- tmpBitmap.eraseColor(toSkColor(nMaskColor));
- SkPaint paint;
- // Draw the color with the given mask.
- // TODO figure out the right blend mode to avoid the temporary bitmap
- paint.setBlendMode(SkBlendMode::kDstOut);
- SkCanvas canvas(tmpBitmap);
- canvas.drawBitmap(bitmap, 0, 0, &paint);
- mSurface->getCanvas()->drawBitmapRect(
- tmpBitmap,
- SkRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight),
- SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth,
- rPosAry.mnDestHeight),
- nullptr);
- postDraw();
+ drawMask(rPosAry, static_cast<const SkiaCompatibleDC::Texture*>(pTexture)->bitmap, nMaskColor);
}
SkiaCompatibleDC::SkiaCompatibleDC(SalGraphics& rGraphics, int x, int y, int width, int height)