diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2018-06-28 13:42:00 +0200 |
---|---|---|
committer | Katarina Behrens <Katarina.Behrens@cib.de> | 2018-07-03 14:10:49 +0200 |
commit | dc8f347f5fed638f07ef88246950460e3ed284d1 (patch) | |
tree | 7d7ae0d12054f948d138310bf7da8657b68af33f | |
parent | c4a06289ca549290bfd2ba9e16236e430b4c53fe (diff) |
Use cairo's OVER operator to preserve transparency
Change-Id: I1afae266a5308fa0dbf2488777ddb963e99199c7
-rw-r--r-- | vcl/headless/svpgdi.cxx | 29 | ||||
-rw-r--r-- | vcl/inc/headless/svpgdi.hxx | 6 | ||||
-rw-r--r-- | vcl/unx/kde5/KDE5SalGraphics.cxx | 2 |
3 files changed, 25 insertions, 12 deletions
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx index 9163d8cf8133..de1145a6cc7c 100644 --- a/vcl/headless/svpgdi.cxx +++ b/vcl/headless/svpgdi.cxx @@ -35,8 +35,6 @@ #include <basegfx/polygon/b2dpolygon.hxx> #include <basegfx/polygon/b2dpolygontools.hxx> -#include <cairo.h> - #if ENABLE_CAIRO_CANVAS # if defined CAIRO_VERSION && CAIRO_VERSION < CAIRO_VERSION_ENCODE(1, 10, 0) # define CAIRO_OPERATOR_DIFFERENCE (static_cast<cairo_operator_t>(23)) @@ -1134,8 +1132,8 @@ void SvpSalGraphics::copyArea( long nDestX, copyBits(aTR, this); } -static basegfx::B2DRange renderSource(cairo_t* cr, const SalTwoRect& rTR, - cairo_surface_t* source) +static basegfx::B2DRange renderWithOperator(cairo_t* cr, const SalTwoRect& rTR, + cairo_surface_t* source, cairo_operator_t eOperator = CAIRO_OPERATOR_SOURCE) { cairo_rectangle(cr, rTR.mnDestX, rTR.mnDestY, rTR.mnDestWidth, rTR.mnDestHeight); @@ -1160,24 +1158,35 @@ static basegfx::B2DRange renderSource(cairo_t* cr, const SalTwoRect& rTR, cairo_pattern_set_extend(sourcepattern, CAIRO_EXTEND_REPEAT); cairo_pattern_set_filter(sourcepattern, CAIRO_FILTER_NEAREST); } - cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); + cairo_set_operator(cr, eOperator); cairo_paint(cr); cairo_restore(cr); return extents; } -void SvpSalGraphics::copySource( const SalTwoRect& rTR, - cairo_surface_t* source ) +static basegfx::B2DRange renderSource(cairo_t* cr, const SalTwoRect& rTR, + cairo_surface_t* source) +{ + return renderWithOperator(cr, rTR, source, CAIRO_OPERATOR_SOURCE); +} + +void SvpSalGraphics::copyWithOperator( const SalTwoRect& rTR, cairo_surface_t* source, + cairo_operator_t eOp ) { cairo_t* cr = getCairoContext(false); clipRegion(cr); - basegfx::B2DRange extents = renderSource(cr, rTR, source); + basegfx::B2DRange extents = renderWithOperator(cr, rTR, source, eOp); releaseCairoContext(cr, false, extents); } +void SvpSalGraphics::copySource( const SalTwoRect& rTR, cairo_surface_t* source ) +{ + copyWithOperator(rTR, source, CAIRO_OPERATOR_SOURCE); +} + void SvpSalGraphics::copyBits( const SalTwoRect& rTR, SalGraphics* pSrcGraphics ) { @@ -1224,10 +1233,10 @@ void SvpSalGraphics::drawBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceB copySource(rTR, source); } -void SvpSalGraphics::drawBitmap(const SalTwoRect& rTR, BitmapBuffer* pBuffer) +void SvpSalGraphics::drawBitmap(const SalTwoRect& rTR, BitmapBuffer* pBuffer, cairo_operator_t eOp) { cairo_surface_t* source = createCairoSurface( pBuffer ); - copySource(rTR, source); + copyWithOperator(rTR, source, eOp); } void SvpSalGraphics::drawBitmap( const SalTwoRect& rTR, diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx index 860eacec7cbf..6571d21cf89d 100644 --- a/vcl/inc/headless/svpgdi.hxx +++ b/vcl/inc/headless/svpgdi.hxx @@ -24,6 +24,7 @@ #include <vcl/sysdata.hxx> #include <vcl/metric.hxx> #include <config_cairo_canvas.h> +#include <cairo.h> #include <salgdi.hxx> #include <sallayout.hxx> @@ -111,6 +112,8 @@ public: private: void invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags); void copySource(const SalTwoRect& rTR, cairo_surface_t* source); + void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source, + cairo_operator_t eOp = CAIRO_OPERATOR_SOURCE); void setupPolyPolygon(cairo_t* cr, const basegfx::B2DPolyPolygon& rPolyPoly); void applyColor(cairo_t *cr, Color rColor); void drawPolyPolygon(const basegfx::B2DPolyPolygon& rPolyPoly); @@ -225,7 +228,8 @@ public: virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap ) override; void drawBitmap( const SalTwoRect& rPosAry, - BitmapBuffer* pBuffer ); + BitmapBuffer* pBuffer, + cairo_operator_t eOp ); virtual void drawBitmap( const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, const SalBitmap& rTransparentBitmap ) override; diff --git a/vcl/unx/kde5/KDE5SalGraphics.cxx b/vcl/unx/kde5/KDE5SalGraphics.cxx index 6ec1e6e385ea..75e7c8664ab4 100644 --- a/vcl/unx/kde5/KDE5SalGraphics.cxx +++ b/vcl/unx/kde5/KDE5SalGraphics.cxx @@ -622,7 +622,7 @@ bool KDE5SalGraphics::drawNativeControl(ControlType type, ControlPart part, QImage2BitmapBuffer(m_image.get(), pBuffer); SalTwoRect aTR(0, 0, m_image.get()->width(), m_image.get()->height(), rControlRegion.getX(), rControlRegion.getY(), rControlRegion.GetWidth(), rControlRegion.GetHeight()); - drawBitmap(aTR, pBuffer); + drawBitmap(aTR, pBuffer, CAIRO_OPERATOR_OVER); delete localClipRegion; return returnVal; |