1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <headless/SvpGraphicsBackend.hxx>
22 #include <sal/log.hxx>
23 #include <basegfx/matrix/b2dhommatrixtools.hxx>
24 #include <basegfx/polygon/b2dpolygontools.hxx>
25 #include <vcl/BitmapTools.hxx>
26 #include <headless/BitmapHelper.hxx>
28 SvpGraphicsBackend::SvpGraphicsBackend(CairoCommon
& rCairoCommon
)
29 : m_rCairoCommon(rCairoCommon
)
33 void SvpGraphicsBackend::Init() {}
35 void SvpGraphicsBackend::freeResources() {}
37 void SvpGraphicsBackend::setClipRegion(const vcl::Region
& i_rClip
)
39 m_rCairoCommon
.m_aClipRegion
= i_rClip
;
42 void SvpGraphicsBackend::ResetClipRegion() { m_rCairoCommon
.m_aClipRegion
.SetNull(); }
44 sal_uInt16
SvpGraphicsBackend::GetBitCount() const { return m_rCairoCommon
.GetBitCount(); }
46 tools::Long
SvpGraphicsBackend::GetGraphicsWidth() const
48 return m_rCairoCommon
.m_pSurface
? m_rCairoCommon
.m_aFrameSize
.getX() : 0;
51 void SvpGraphicsBackend::SetLineColor() { m_rCairoCommon
.m_oLineColor
= std::nullopt
; }
53 void SvpGraphicsBackend::SetLineColor(Color nColor
) { m_rCairoCommon
.m_oLineColor
= nColor
; }
55 void SvpGraphicsBackend::SetFillColor() { m_rCairoCommon
.m_oFillColor
= std::nullopt
; }
57 void SvpGraphicsBackend::SetFillColor(Color nColor
) { m_rCairoCommon
.m_oFillColor
= nColor
; }
59 void SvpGraphicsBackend::SetXORMode(bool bSet
, bool bInvertOnly
)
61 m_rCairoCommon
.SetXORMode(bSet
, bInvertOnly
);
64 void SvpGraphicsBackend::SetROPLineColor(SalROPColor nROPColor
)
66 m_rCairoCommon
.SetROPLineColor(nROPColor
);
69 void SvpGraphicsBackend::SetROPFillColor(SalROPColor nROPColor
)
71 m_rCairoCommon
.SetROPFillColor(nROPColor
);
74 void SvpGraphicsBackend::drawPixel(tools::Long nX
, tools::Long nY
)
76 m_rCairoCommon
.drawPixel(m_rCairoCommon
.m_oLineColor
, nX
, nY
, getAntiAlias());
79 void SvpGraphicsBackend::drawPixel(tools::Long nX
, tools::Long nY
, Color aColor
)
81 m_rCairoCommon
.drawPixel(aColor
, nX
, nY
, getAntiAlias());
84 void SvpGraphicsBackend::drawLine(tools::Long nX1
, tools::Long nY1
, tools::Long nX2
,
87 m_rCairoCommon
.drawLine(nX1
, nY1
, nX2
, nY2
, getAntiAlias());
90 void SvpGraphicsBackend::drawRect(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
93 m_rCairoCommon
.drawRect(nX
, nY
, nWidth
, nHeight
, getAntiAlias());
96 void SvpGraphicsBackend::drawPolyLine(sal_uInt32 nPoints
, const Point
* pPtAry
)
98 m_rCairoCommon
.drawPolyLine(nPoints
, pPtAry
, getAntiAlias());
101 void SvpGraphicsBackend::drawPolygon(sal_uInt32 nPoints
, const Point
* pPtAry
)
103 m_rCairoCommon
.drawPolygon(nPoints
, pPtAry
, getAntiAlias());
106 void SvpGraphicsBackend::drawPolyPolygon(sal_uInt32 nPoly
, const sal_uInt32
* pPointCounts
,
107 const Point
** pPtAry
)
109 m_rCairoCommon
.drawPolyPolygon(nPoly
, pPointCounts
, pPtAry
, getAntiAlias());
112 void SvpGraphicsBackend::drawPolyPolygon(const basegfx::B2DHomMatrix
& rObjectToDevice
,
113 const basegfx::B2DPolyPolygon
& rPolyPolygon
,
114 double fTransparency
)
116 m_rCairoCommon
.drawPolyPolygon(rObjectToDevice
, rPolyPolygon
, fTransparency
, getAntiAlias());
119 bool SvpGraphicsBackend::drawPolyLine(const basegfx::B2DHomMatrix
& rObjectToDevice
,
120 const basegfx::B2DPolygon
& rPolyLine
, double fTransparency
,
121 double fLineWidth
, const std::vector
<double>* pStroke
,
122 basegfx::B2DLineJoin eLineJoin
,
123 css::drawing::LineCap eLineCap
, double fMiterMinimumAngle
,
124 bool bPixelSnapHairline
)
126 return m_rCairoCommon
.drawPolyLine(rObjectToDevice
, rPolyLine
, fTransparency
, fLineWidth
,
127 pStroke
, eLineJoin
, eLineCap
, fMiterMinimumAngle
,
128 bPixelSnapHairline
, getAntiAlias());
131 bool SvpGraphicsBackend::drawPolyLineBezier(sal_uInt32
, const Point
*, const PolyFlags
*)
133 SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyLineBezier case");
137 bool SvpGraphicsBackend::drawPolygonBezier(sal_uInt32
, const Point
*, const PolyFlags
*)
139 SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolygonBezier case");
143 bool SvpGraphicsBackend::drawPolyPolygonBezier(sal_uInt32
, const sal_uInt32
*, const Point
* const*,
144 const PolyFlags
* const*)
146 SAL_INFO("vcl.gdi", "unsupported SvpSalGraphics::drawPolyPolygonBezier case");
150 void SvpGraphicsBackend::copyArea(tools::Long nDestX
, tools::Long nDestY
, tools::Long nSrcX
,
151 tools::Long nSrcY
, tools::Long nSrcWidth
, tools::Long nSrcHeight
,
152 bool /*bWindowInvalidate*/)
154 SalTwoRect
aTR(nSrcX
, nSrcY
, nSrcWidth
, nSrcHeight
, nDestX
, nDestY
, nSrcWidth
, nSrcHeight
);
156 cairo_surface_t
* source
= m_rCairoCommon
.m_pSurface
;
157 m_rCairoCommon
.copyBitsCairo(aTR
, source
, getAntiAlias());
160 void SvpGraphicsBackend::copyBits(const SalTwoRect
& rTR
, SalGraphics
* pSrcGraphics
)
162 cairo_surface_t
* source
= nullptr;
166 SvpGraphicsBackend
* pSrc
= static_cast<SvpGraphicsBackend
*>(pSrcGraphics
->GetImpl());
167 source
= pSrc
->m_rCairoCommon
.m_pSurface
;
171 source
= m_rCairoCommon
.m_pSurface
;
174 m_rCairoCommon
.copyBitsCairo(rTR
, source
, getAntiAlias());
177 void SvpGraphicsBackend::drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
)
179 m_rCairoCommon
.drawBitmap(rPosAry
, rSalBitmap
, getAntiAlias());
182 void SvpGraphicsBackend::drawBitmap(const SalTwoRect
& rPosAry
, const SalBitmap
& rSalBitmap
,
183 const SalBitmap
& rTransparentBitmap
)
185 drawAlphaBitmap(rPosAry
, rSalBitmap
, rTransparentBitmap
);
188 void SvpGraphicsBackend::drawMask(const SalTwoRect
& rTR
, const SalBitmap
& rSalBitmap
,
191 m_rCairoCommon
.drawMask(rTR
, rSalBitmap
, nMaskColor
, getAntiAlias());
194 std::shared_ptr
<SalBitmap
> SvpGraphicsBackend::getBitmap(tools::Long nX
, tools::Long nY
,
195 tools::Long nWidth
, tools::Long nHeight
)
197 return m_rCairoCommon
.getBitmap(nX
, nY
, nWidth
, nHeight
);
200 void SvpGraphicsBackend::drawBitmapBuffer(const SalTwoRect
& rTR
, const BitmapBuffer
* pBuffer
,
201 cairo_operator_t eOp
)
203 cairo_surface_t
* source
= CairoCommon::createCairoSurface(pBuffer
);
204 m_rCairoCommon
.copyWithOperator(rTR
, source
, eOp
, getAntiAlias());
205 cairo_surface_destroy(source
);
208 Color
SvpGraphicsBackend::getPixel(tools::Long nX
, tools::Long nY
)
210 return CairoCommon::getPixel(m_rCairoCommon
.m_pSurface
, nX
, nY
);
213 void SvpGraphicsBackend::invert(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
214 tools::Long nHeight
, SalInvert nFlags
)
216 m_rCairoCommon
.invert(nX
, nY
, nWidth
, nHeight
, nFlags
, getAntiAlias());
219 void SvpGraphicsBackend::invert(sal_uInt32 nPoints
, const Point
* pPtAry
, SalInvert nFlags
)
221 m_rCairoCommon
.invert(nPoints
, pPtAry
, nFlags
, getAntiAlias());
224 bool SvpGraphicsBackend::drawEPS(tools::Long
/*nX*/, tools::Long
/*nY*/, tools::Long
/*nWidth*/,
225 tools::Long
/*nHeight*/, void* /*pPtr*/, sal_uInt32
/*nSize*/)
230 bool SvpGraphicsBackend::blendBitmap(const SalTwoRect
& /*rPosAry*/, const SalBitmap
& /*rBitmap*/)
235 bool SvpGraphicsBackend::blendAlphaBitmap(const SalTwoRect
& /*rPosAry*/,
236 const SalBitmap
& /*rSrcBitmap*/,
237 const SalBitmap
& /*rMaskBitmap*/,
238 const SalBitmap
& /*rAlphaBitmap*/)
243 bool SvpGraphicsBackend::drawAlphaBitmap(const SalTwoRect
& rTR
, const SalBitmap
& rSourceBitmap
,
244 const SalBitmap
& rAlphaBitmap
)
246 return m_rCairoCommon
.drawAlphaBitmap(rTR
, rSourceBitmap
, rAlphaBitmap
, getAntiAlias());
249 bool SvpGraphicsBackend::drawTransformedBitmap(const basegfx::B2DPoint
& rNull
,
250 const basegfx::B2DPoint
& rX
,
251 const basegfx::B2DPoint
& rY
,
252 const SalBitmap
& rSourceBitmap
,
253 const SalBitmap
* pAlphaBitmap
, double fAlpha
)
255 return m_rCairoCommon
.drawTransformedBitmap(rNull
, rX
, rY
, rSourceBitmap
, pAlphaBitmap
, fAlpha
,
259 bool SvpGraphicsBackend::hasFastDrawTransformedBitmap() const
261 return CairoCommon::hasFastDrawTransformedBitmap();
264 bool SvpGraphicsBackend::drawAlphaRect(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
265 tools::Long nHeight
, sal_uInt8 nTransparency
)
267 return m_rCairoCommon
.drawAlphaRect(nX
, nY
, nWidth
, nHeight
, nTransparency
, getAntiAlias());
270 bool SvpGraphicsBackend::drawGradient(const tools::PolyPolygon
& rPolyPolygon
,
271 const Gradient
& rGradient
)
273 return m_rCairoCommon
.drawGradient(rPolyPolygon
, rGradient
, getAntiAlias());
276 bool SvpGraphicsBackend::implDrawGradient(basegfx::B2DPolyPolygon
const& rPolyPolygon
,
277 SalGradient
const& rGradient
)
279 return m_rCairoCommon
.implDrawGradient(rPolyPolygon
, rGradient
, getAntiAlias());
282 bool SvpGraphicsBackend::supportsOperation(OutDevSupportType eType
) const
284 return CairoCommon::supportsOperation(eType
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */