diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-09-23 17:28:16 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-09-23 18:06:12 +0200 |
commit | 9e7b229fceae5d5c7073a115e108f710db741a06 (patch) | |
tree | 46111c4539bd10d591fa305bffe06f21c90a891a /vcl | |
parent | 46deb2de051c52f4a40ef72d8221dea222343e3e (diff) |
more work on SkiaSalGraphicsImpl, mainly drawBitmap
Change-Id: I153f71abe4612e2561e41ee923eb28e46cc31a98
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/skia/salbmp.hxx | 1 | ||||
-rw-r--r-- | vcl/skia/gdiimpl.cxx | 51 |
2 files changed, 41 insertions, 11 deletions
diff --git a/vcl/inc/skia/salbmp.hxx b/vcl/inc/skia/salbmp.hxx index c76398ffadaa..275f427a3907 100644 --- a/vcl/inc/skia/salbmp.hxx +++ b/vcl/inc/skia/salbmp.hxx @@ -71,6 +71,7 @@ private: Size mSize; std::unique_ptr<sal_uInt8[]> mBuffer; // for 1bpp and 4bpp, Skia doesn't support those int mScanlineSize; // size of one row in mBuffer + friend class SkiaSalGraphicsImpl; // TODO }; #endif // INCLUDED_VCL_INC_OPENGL_SALBMP_H diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx index 037855158666..b397abd6af66 100644 --- a/vcl/skia/gdiimpl.cxx +++ b/vcl/skia/gdiimpl.cxx @@ -112,7 +112,6 @@ void SkiaSalGraphicsImpl::drawRect(long nX, long nY, long nWidth, long nHeight) } if (mLineColor != SALCOLOR_NONE) { - SkPaint paint(mPaint); paint.setColor(toSkColor(mLineColor)); paint.setStyle(SkPaint::kStroke_Style); canvas->drawIRect(SkIRect::MakeXYWH(nX, nY, nWidth - 1, nHeight - 1), paint); @@ -224,9 +223,16 @@ bool SkiaSalGraphicsImpl::blendAlphaBitmap(const SalTwoRect&, const SalBitmap& r void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap) { - (void)rPosAry; - (void)rSalBitmap; - abort(); + if (rPosAry.mnSrcWidth <= 0 || rPosAry.mnSrcHeight <= 0 || rPosAry.mnDestWidth <= 0 + || rPosAry.mnDestHeight <= 0) + return; + assert(dynamic_cast<const SkiaSalBitmap*>(&rSalBitmap)); + mSurface->getCanvas()->drawBitmapRect( + static_cast<const SkiaSalBitmap&>(rSalBitmap).mBitmap, + SkRect::MakeXYWH(rPosAry.mnSrcX, rPosAry.mnSrcY, rPosAry.mnSrcWidth, rPosAry.mnSrcHeight), + SkRect::MakeXYWH(rPosAry.mnDestX, rPosAry.mnDestY, rPosAry.mnDestWidth, + rPosAry.mnDestHeight), + nullptr); } void SkiaSalGraphicsImpl::drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, @@ -256,9 +262,13 @@ std::shared_ptr<SalBitmap> SkiaSalGraphicsImpl::getBitmap(long nX, long nY, long Color SkiaSalGraphicsImpl::getPixel(long nX, long nY) { - (void)nX; - (void)nY; - abort(); + // TODO this is presumably slow, and possibly won't work with GPU surfaces + SkBitmap bitmap; + if (!bitmap.tryAllocN32Pixels(GetWidth(), GetHeight())) + abort(); + if (!mSurface->readPixels(bitmap, 0, 0)) + abort(); + return fromSkColor(bitmap.getColor(nX, nY)); } void SkiaSalGraphicsImpl::invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) @@ -291,12 +301,31 @@ bool SkiaSalGraphicsImpl::drawEPS(long nX, long nY, long nWidth, long nHeight, v return false; } -bool SkiaSalGraphicsImpl::drawAlphaBitmap(const SalTwoRect&, const SalBitmap& rSourceBitmap, +bool SkiaSalGraphicsImpl::drawAlphaBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSourceBitmap, const SalBitmap& rAlphaBitmap) { - (void)rSourceBitmap; - (void)rAlphaBitmap; - return false; + assert(dynamic_cast<const SkiaSalBitmap*>(&rSourceBitmap)); + assert(dynamic_cast<const SkiaSalBitmap*>(&rAlphaBitmap)); + SkBitmap tmpBitmap; + if (!tmpBitmap.tryAllocPixels(SkImageInfo::Make(rSourceBitmap.GetSize().Width(), + rSourceBitmap.GetSize().Height(), + kN32_SkColorType, kUnpremul_SkAlphaType))) + return false; + SkCanvas canvas(tmpBitmap); + SkPaint paint; + paint.setBlendMode(SkBlendMode::kDst); + canvas.drawBitmap(static_cast<const SkiaSalBitmap&>(rSourceBitmap).mBitmap, 0, 0, + &paint); // TODO bpp < 8? + paint.setBlendMode(SkBlendMode::kSrcIn); + canvas.drawBitmap(static_cast<const SkiaSalBitmap&>(rAlphaBitmap).mBitmap, 0, 0, + &paint); // TODO bpp < 8? + 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); + return true; } bool SkiaSalGraphicsImpl::drawTransformedBitmap(const basegfx::B2DPoint& rNull, |