diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-01-11 14:56:37 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-01-12 13:52:35 +0000 |
commit | 3be24f151076def167c3a551c0e1811d457d2691 (patch) | |
tree | 13f1a27b09b375ebde697cbf5e2fdc93f8c25ed9 | |
parent | a11cabb47249257d8b6510fe91063ade03d0c636 (diff) |
move drawTransformedBitmap to CairoCommon and reuse for X11CairoSalGraphicsImpl
Change-Id: I9b03d2ec973e2dab28358d7e8041b9d26705e700
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145352
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | vcl/headless/CairoCommon.cxx | 78 | ||||
-rw-r--r-- | vcl/headless/SvpGraphicsBackend.cxx | 73 | ||||
-rw-r--r-- | vcl/inc/headless/CairoCommon.hxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx | 15 |
4 files changed, 92 insertions, 78 deletions
diff --git a/vcl/headless/CairoCommon.cxx b/vcl/headless/CairoCommon.cxx index a646ebd8d67a..1a93f405562c 100644 --- a/vcl/headless/CairoCommon.cxx +++ b/vcl/headless/CairoCommon.cxx @@ -1684,6 +1684,84 @@ bool CairoCommon::drawAlphaBitmap(const SalTwoRect& rTR, const SalBitmap& rSourc return true; } +bool CairoCommon::drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap, double fAlpha, + bool bAntiAlias) +{ + if (pAlphaBitmap && pAlphaBitmap->GetBitCount() != 8 && pAlphaBitmap->GetBitCount() != 1) + { + SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap alpha depth case: " + << pAlphaBitmap->GetBitCount()); + return false; + } + + if (fAlpha != 1.0) + return false; + + // MM02 try to access buffered BitmapHelper + std::shared_ptr<BitmapHelper> aSurface; + tryToUseSourceBuffer(rSourceBitmap, aSurface); + const tools::Long nDestWidth(basegfx::fround(basegfx::B2DVector(rX - rNull).getLength())); + const tools::Long nDestHeight(basegfx::fround(basegfx::B2DVector(rY - rNull).getLength())); + cairo_surface_t* source(aSurface->getSurface(nDestWidth, nDestHeight)); + + if (!source) + { + SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap case"); + return false; + } + + // MM02 try to access buffered MaskHelper + std::shared_ptr<MaskHelper> aMask; + if (nullptr != pAlphaBitmap) + { + tryToUseMaskBuffer(*pAlphaBitmap, aMask); + } + + // access cairo_surface_t from MaskHelper + cairo_surface_t* mask(nullptr); + if (aMask) + { + mask = aMask->getSurface(nDestWidth, nDestHeight); + } + + if (nullptr != pAlphaBitmap && nullptr == mask) + { + SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap case"); + return false; + } + + const Size aSize = rSourceBitmap.GetSize(); + cairo_t* cr = getCairoContext(false, bAntiAlias); + clipRegion(cr); + + // setup the image transformation + // using the rNull,rX,rY points as destinations for the (0,0),(0,Width),(Height,0) source points + const basegfx::B2DVector aXRel = rX - rNull; + const basegfx::B2DVector aYRel = rY - rNull; + cairo_matrix_t matrix; + cairo_matrix_init(&matrix, aXRel.getX() / aSize.Width(), aXRel.getY() / aSize.Width(), + aYRel.getX() / aSize.Height(), aYRel.getY() / aSize.Height(), rNull.getX(), + rNull.getY()); + + cairo_transform(cr, &matrix); + + cairo_rectangle(cr, 0, 0, aSize.Width(), aSize.Height()); + basegfx::B2DRange extents = getClippedFillDamage(cr); + cairo_clip(cr); + + cairo_set_source_surface(cr, source, 0, 0); + if (mask) + cairo_mask_surface(cr, mask, 0, 0); + else + cairo_paint(cr); + + releaseCairoContext(cr, false, extents); + + return true; +} + void CairoCommon::drawMask(const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor, bool bAntiAlias) { diff --git a/vcl/headless/SvpGraphicsBackend.cxx b/vcl/headless/SvpGraphicsBackend.cxx index 0f053bb28c17..dafbe75ff3ca 100644 --- a/vcl/headless/SvpGraphicsBackend.cxx +++ b/vcl/headless/SvpGraphicsBackend.cxx @@ -253,77 +253,8 @@ bool SvpGraphicsBackend::drawTransformedBitmap(const basegfx::B2DPoint& rNull, const SalBitmap& rSourceBitmap, const SalBitmap* pAlphaBitmap, double fAlpha) { - if (pAlphaBitmap && pAlphaBitmap->GetBitCount() != 8 && pAlphaBitmap->GetBitCount() != 1) - { - SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap alpha depth case: " - << pAlphaBitmap->GetBitCount()); - return false; - } - - if (fAlpha != 1.0) - return false; - - // MM02 try to access buffered BitmapHelper - std::shared_ptr<BitmapHelper> aSurface; - tryToUseSourceBuffer(rSourceBitmap, aSurface); - const tools::Long nDestWidth(basegfx::fround(basegfx::B2DVector(rX - rNull).getLength())); - const tools::Long nDestHeight(basegfx::fround(basegfx::B2DVector(rY - rNull).getLength())); - cairo_surface_t* source(aSurface->getSurface(nDestWidth, nDestHeight)); - - if (!source) - { - SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap case"); - return false; - } - - // MM02 try to access buffered MaskHelper - std::shared_ptr<MaskHelper> aMask; - if (nullptr != pAlphaBitmap) - { - tryToUseMaskBuffer(*pAlphaBitmap, aMask); - } - - // access cairo_surface_t from MaskHelper - cairo_surface_t* mask(nullptr); - if (aMask) - { - mask = aMask->getSurface(nDestWidth, nDestHeight); - } - - if (nullptr != pAlphaBitmap && nullptr == mask) - { - SAL_WARN("vcl.gdi", "unsupported SvpSalGraphics::drawTransformedBitmap case"); - return false; - } - - const Size aSize = rSourceBitmap.GetSize(); - cairo_t* cr = m_rCairoCommon.getCairoContext(false, getAntiAlias()); - m_rCairoCommon.clipRegion(cr); - - // setup the image transformation - // using the rNull,rX,rY points as destinations for the (0,0),(0,Width),(Height,0) source points - const basegfx::B2DVector aXRel = rX - rNull; - const basegfx::B2DVector aYRel = rY - rNull; - cairo_matrix_t matrix; - cairo_matrix_init(&matrix, aXRel.getX() / aSize.Width(), aXRel.getY() / aSize.Width(), - aYRel.getX() / aSize.Height(), aYRel.getY() / aSize.Height(), rNull.getX(), - rNull.getY()); - - cairo_transform(cr, &matrix); - - cairo_rectangle(cr, 0, 0, aSize.Width(), aSize.Height()); - basegfx::B2DRange extents = getClippedFillDamage(cr); - cairo_clip(cr); - - cairo_set_source_surface(cr, source, 0, 0); - if (mask) - cairo_mask_surface(cr, mask, 0, 0); - else - cairo_paint(cr); - - m_rCairoCommon.releaseCairoContext(cr, false, extents); - - return true; + return m_rCairoCommon.drawTransformedBitmap(rNull, rX, rY, rSourceBitmap, pAlphaBitmap, fAlpha, + getAntiAlias()); } bool SvpGraphicsBackend::hasFastDrawTransformedBitmap() const diff --git a/vcl/inc/headless/CairoCommon.hxx b/vcl/inc/headless/CairoCommon.hxx index cd011b2a9eab..6d280d34a955 100644 --- a/vcl/inc/headless/CairoCommon.hxx +++ b/vcl/inc/headless/CairoCommon.hxx @@ -217,6 +217,10 @@ struct VCL_DLLPUBLIC CairoCommon bool drawAlphaBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap, const SalBitmap& rAlphaBitmap, bool bAntiAlias); + bool drawTransformedBitmap(const basegfx::B2DPoint& rNull, const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap, double fAlpha, bool bAntiAlias); + void drawMask(const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor, bool bAntiAlias); diff --git a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx index 87605a067395..53bf309375bc 100644 --- a/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx +++ b/vcl/unx/generic/gdi/X11CairoSalGraphicsImpl.cxx @@ -228,13 +228,14 @@ bool X11CairoSalGraphicsImpl::blendAlphaBitmap(const SalTwoRect&, const SalBitma return false; } -bool X11CairoSalGraphicsImpl::drawTransformedBitmap(const basegfx::B2DPoint&, - const basegfx::B2DPoint&, - const basegfx::B2DPoint&, const SalBitmap&, - const SalBitmap*, double) -{ - // here direct support for transformed bitmaps can be implemented - return false; +bool X11CairoSalGraphicsImpl::drawTransformedBitmap(const basegfx::B2DPoint& rNull, + const basegfx::B2DPoint& rX, + const basegfx::B2DPoint& rY, + const SalBitmap& rSourceBitmap, + const SalBitmap* pAlphaBitmap, double fAlpha) +{ + return mrCairoCommon.drawTransformedBitmap(rNull, rX, rY, rSourceBitmap, pAlphaBitmap, fAlpha, + getAntiAlias()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |