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 #ifndef INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
21 #define INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
24 #error This file is not for iOS
27 #include <config_features.h>
29 #include <osl/endian.h>
30 #include <vcl/sysdata.hxx>
31 #include <config_cairo_canvas.h>
34 #include <sallayout.hxx>
35 #include "svpcairotextrender.hxx"
36 #include <impfontmetricdata.hxx>
40 //Using formats that match cairo's formats. For android we patch cairo,
41 //which is internal in that case, to swap the rgb components so that
42 //cairo then matches the OpenGL GL_RGBA format so we can use it there
43 //where we don't have GL_BGRA support.
44 // SVP_24BIT_FORMAT is used to store 24-bit images in 3-byte pixels to conserve memory.
45 #if defined(ANDROID) && !HAVE_FEATURE_ANDROID_LOK
46 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
47 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown)
48 # define SVP_CAIRO_BLUE 1
49 # define SVP_CAIRO_GREEN 2
50 # define SVP_CAIRO_RED 0
51 # define SVP_CAIRO_ALPHA 3
52 #elif defined OSL_BIGENDIAN
53 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcRgb | ScanlineFormat::TopDown)
54 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown)
55 # define SVP_CAIRO_BLUE 3
56 # define SVP_CAIRO_GREEN 2
57 # define SVP_CAIRO_RED 1
58 # define SVP_CAIRO_ALPHA 0
60 # define SVP_24BIT_FORMAT (ScanlineFormat::N24BitTcBgr | ScanlineFormat::TopDown)
61 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown)
62 # define SVP_CAIRO_BLUE 0
63 # define SVP_CAIRO_GREEN 1
64 # define SVP_CAIRO_RED 2
65 # define SVP_CAIRO_ALPHA 3
70 typedef struct _cairo cairo_t
;
71 typedef struct _cairo_surface cairo_surface_t
;
72 typedef struct _cairo_user_data_key cairo_user_data_key_t
;
74 VCL_DLLPUBLIC
void dl_cairo_surface_set_device_scale(cairo_surface_t
*surface
, double x_scale
, double y_scale
);
75 VCL_DLLPUBLIC
void dl_cairo_surface_get_device_scale(cairo_surface_t
*surface
, double *x_scale
, double *y_scale
);
77 enum class PaintMode
{ Over
, Xor
};
79 typedef void (*damageHandler
)(void* handle
,
80 sal_Int32 nExtentsX
, sal_Int32 nExtentsY
,
81 sal_Int32 nExtentsWidth
, sal_Int32 nExtentsHeight
);
83 struct VCL_DLLPUBLIC DamageHandler
86 damageHandler damaged
;
89 class VCL_DLLPUBLIC SvpSalGraphics
: public SalGraphics
91 cairo_surface_t
* m_pSurface
;
92 basegfx::B2IVector m_aFrameSize
;
96 PaintMode m_ePaintMode
;
99 void setSurface(cairo_surface_t
* pSurface
, const basegfx::B2IVector
& rSize
);
100 cairo_surface_t
* getSurface() const { return m_pSurface
; }
101 static cairo_user_data_key_t
* getDamageKey();
103 static void clipRegion(cairo_t
* cr
, const vcl::Region
& rClipRegion
);
105 // need this static version of ::drawPolyLine for usage from
106 // vcl/unx/generic/gdi/salgdi.cxx. It gets wrapped by
107 // ::drawPolyLine with some added parameters (see there)
108 static bool drawPolyLine(
110 basegfx::B2DRange
* pExtents
,
111 const Color
& rLineColor
,
113 const basegfx::B2DHomMatrix
& rObjectToDevice
,
114 const basegfx::B2DPolygon
& rPolyLine
,
115 double fTransparency
,
117 const std::vector
< double >* pStroke
, // MM01
118 basegfx::B2DLineJoin eLineJoin
,
119 css::drawing::LineCap eLineCap
,
120 double fMiterMinimumAngle
,
121 bool bPixelSnapHairline
);
123 void copySource(const SalTwoRect
& rTR
, cairo_surface_t
* source
);
124 void copyWithOperator(const SalTwoRect
& rTR
, cairo_surface_t
* source
,
125 cairo_operator_t eOp
= CAIRO_OPERATOR_SOURCE
);
128 void invert(const basegfx::B2DPolygon
&rPoly
, SalInvert nFlags
);
129 void applyColor(cairo_t
*cr
, Color rColor
, double fTransparency
= 0.0);
132 vcl::Region m_aClipRegion
;
133 SvpCairoTextRender m_aTextRenderImpl
;
136 virtual bool blendBitmap( const SalTwoRect
&, const SalBitmap
& rBitmap
) override
;
137 virtual bool blendAlphaBitmap( const SalTwoRect
&,
138 const SalBitmap
& rSrcBitmap
,
139 const SalBitmap
& rMaskBitmap
,
140 const SalBitmap
& rAlphaBitmap
) override
;
141 virtual bool drawAlphaBitmap( const SalTwoRect
&, const SalBitmap
& rSourceBitmap
, const SalBitmap
& rAlphaBitmap
) override
;
142 virtual bool drawTransformedBitmap(
143 const basegfx::B2DPoint
& rNull
,
144 const basegfx::B2DPoint
& rX
,
145 const basegfx::B2DPoint
& rY
,
146 const SalBitmap
& rSourceBitmap
,
147 const SalBitmap
* pAlphaBitmap
,
148 double fAlpha
) override
;
149 virtual bool hasFastDrawTransformedBitmap() const override
;
150 virtual bool drawAlphaRect( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, sal_uInt8 nTransparency
) override
;
152 cairo_t
* createTmpCompatibleCairoContext() const;
156 virtual ~SvpSalGraphics() override
;
158 virtual SalGraphicsImpl
* GetImpl() const override
{ return nullptr; };
159 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
160 virtual sal_uInt16
GetBitCount() const override
;
161 virtual tools::Long
GetGraphicsWidth() const override
;
163 virtual void ResetClipRegion() override
;
164 virtual bool setClipRegion( const vcl::Region
& ) override
;
166 virtual void SetLineColor() override
;
167 virtual void SetLineColor( Color nColor
) override
;
168 virtual void SetFillColor() override
;
169 virtual void SetFillColor( Color nColor
) override
;
171 virtual void SetXORMode( bool bSet
, bool ) override
;
173 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
174 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
176 virtual void SetTextColor( Color nColor
) override
;
177 virtual void SetFont(LogicalFontInstance
*, int nFallbackLevel
) override
;
178 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) override
;
179 virtual FontCharMapRef
GetFontCharMap() const override
;
180 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const override
;
181 virtual void GetDevFontList( PhysicalFontCollection
* ) override
;
182 virtual void ClearDevFontCache() override
;
183 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) override
;
184 virtual bool CreateFontSubset( const OUString
& rToFile
,
185 const PhysicalFontFace
*,
186 const sal_GlyphId
* pGlyphIds
,
187 const sal_uInt8
* pEncoding
,
190 FontSubsetInfo
& rInfo
192 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, tools::Long
* pDataLen
) override
;
193 virtual void FreeEmbedFontData( const void* pData
, tools::Long nDataLen
) override
;
194 virtual void GetGlyphWidths( const PhysicalFontFace
*,
196 std::vector
< sal_Int32
>& rWidths
,
197 Ucs2UIntMap
& rUnicodeEnc
) override
;
198 virtual std::unique_ptr
<GenericSalLayout
>
199 GetTextLayout(int nFallbackLevel
) override
;
200 virtual void DrawTextLayout( const GenericSalLayout
& ) override
;
201 virtual bool supportsOperation( OutDevSupportType
) const override
;
202 virtual void drawPixel( tools::Long nX
, tools::Long nY
) override
;
203 virtual void drawPixel( tools::Long nX
, tools::Long nY
, Color nColor
) override
;
204 virtual void drawLine( tools::Long nX1
, tools::Long nY1
, tools::Long nX2
, tools::Long nY2
) override
;
205 virtual void drawRect( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
) override
;
207 virtual bool drawPolyPolygon(
208 const basegfx::B2DHomMatrix
& rObjectToDevice
,
209 const basegfx::B2DPolyPolygon
&,
210 double fTransparency
) override
;
212 virtual bool drawPolyLine(
213 const basegfx::B2DHomMatrix
& rObjectToDevice
,
214 const basegfx::B2DPolygon
&,
215 double fTransparency
,
217 const std::vector
< double >* pStroke
, // MM01
218 basegfx::B2DLineJoin
,
219 css::drawing::LineCap
,
220 double fMiterMinimumAngle
,
221 bool bPixelSnapHairline
) override
;
222 virtual void drawPolyLine( sal_uInt32 nPoints
, const Point
* pPtAry
) override
;
223 virtual void drawPolygon( sal_uInt32 nPoints
, const Point
* pPtAry
) override
;
224 virtual void drawPolyPolygon( sal_uInt32 nPoly
,
225 const sal_uInt32
* pPoints
,
226 const Point
** pPtAry
) override
;
227 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
,
229 const PolyFlags
* pFlgAry
) override
;
230 virtual bool drawPolygonBezier( sal_uInt32 nPoints
,
232 const PolyFlags
* pFlgAry
) override
;
233 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
,
234 const sal_uInt32
* pPoints
,
235 const Point
* const* pPtAry
,
236 const PolyFlags
* const* pFlgAry
) override
;
238 virtual bool drawGradient(tools::PolyPolygon
const & rPolyPolygon
, Gradient
const & rGradient
) override
;
240 virtual bool implDrawGradient(basegfx::B2DPolyPolygon
const & rPolyPolygon
, SalGradient
const & rGradient
) override
;
242 virtual void copyArea( tools::Long nDestX
,
246 tools::Long nSrcWidth
,
247 tools::Long nSrcHeight
,
248 bool bWindowInvalidate
) override
;
249 virtual void copyBits( const SalTwoRect
& rPosAry
,
250 SalGraphics
* pSrcGraphics
) override
;
251 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
252 const SalBitmap
& rSalBitmap
) override
;
253 void drawBitmap( const SalTwoRect
& rPosAry
,
254 const BitmapBuffer
* pBuffer
,
255 cairo_operator_t eOp
);
256 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
257 const SalBitmap
& rSalBitmap
,
258 const SalBitmap
& rTransparentBitmap
) override
;
259 virtual void drawMask( const SalTwoRect
& rPosAry
,
260 const SalBitmap
& rSalBitmap
,
261 Color nMaskColor
) override
;
262 virtual std::shared_ptr
<SalBitmap
> getBitmap( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
) override
;
263 virtual Color
getPixel( tools::Long nX
, tools::Long nY
) override
;
264 virtual void invert( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, SalInvert nFlags
) override
;
265 virtual void invert( sal_uInt32 nPoints
, const Point
* pPtAry
, SalInvert nFlags
) override
;
267 virtual bool drawEPS( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, void* pPtr
, sal_uInt32 nSize
) override
;
269 virtual SystemGraphicsData
GetGraphicsData() const override
;
271 virtual OUString
getRenderBackendName() const override
{ return "svp"; }
273 #if ENABLE_CAIRO_CANVAS
274 virtual bool SupportsCairo() const override
;
275 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const override
;
276 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const override
;
277 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const override
;
278 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const override
;
279 #endif // ENABLE_CAIRO_CANVAS
281 cairo_t
* getCairoContext(bool bXorModeAllowed
) const;
282 void releaseCairoContext(cairo_t
* cr
, bool bXorModeAllowed
, const basegfx::B2DRange
& rExtents
) const;
283 static cairo_surface_t
* createCairoSurface(const BitmapBuffer
*pBuffer
);
284 void clipRegion(cairo_t
* cr
);
287 #endif // INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */