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
23 #include <osl/endian.h>
24 #include <vcl/sysdata.hxx>
25 #include <vcl/metric.hxx>
26 #include <config_cairo_canvas.h>
29 #include "sallayout.hxx"
30 #include "svpcairotextrender.hxx"
31 #include "impfontmetricdata.hxx"
34 #define SvpSalGraphics AquaSalGraphics
37 //Using formats that match cairo's formats. For android we patch cairo,
38 //which is internal in that case, to swap the rgb components so that
39 //cairo then matches the OpenGL GL_RGBA format so we can use it there
40 //where we don't have GL_BGRA support.
42 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcRgba | ScanlineFormat::TopDown)
43 # define SVP_CAIRO_BLUE 1
44 # define SVP_CAIRO_GREEN 2
45 # define SVP_CAIRO_RED 0
46 # define SVP_CAIRO_ALPHA 3
47 #elif defined OSL_BIGENDIAN
48 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcArgb | ScanlineFormat::TopDown)
49 # define SVP_CAIRO_BLUE 3
50 # define SVP_CAIRO_GREEN 2
51 # define SVP_CAIRO_RED 1
52 # define SVP_CAIRO_ALPHA 0
54 # define SVP_CAIRO_FORMAT (ScanlineFormat::N32BitTcBgra | ScanlineFormat::TopDown)
55 # define SVP_CAIRO_BLUE 0
56 # define SVP_CAIRO_GREEN 1
57 # define SVP_CAIRO_RED 2
58 # define SVP_CAIRO_ALPHA 3
64 typedef struct _cairo cairo_t
;
65 typedef struct _cairo_surface cairo_surface_t
;
66 typedef struct _cairo_user_data_key cairo_user_data_key_t
;
68 enum class PaintMode
{ Over
, Xor
};
70 typedef void (*damageHandler
)(void* handle
,
71 sal_Int32 nExtentsX
, sal_Int32 nExtentsY
,
72 sal_Int32 nExtentsWidth
, sal_Int32 nExtentsHeight
);
74 struct VCL_DLLPUBLIC DamageHandler
77 damageHandler damaged
;
80 class VCL_DLLPUBLIC SvpSalGraphics
: public SalGraphics
82 cairo_surface_t
* m_pSurface
;
83 basegfx::B2IVector m_aFrameSize
;
85 SalColor m_aLineColor
;
86 SalColor m_aFillColor
;
87 PaintMode m_ePaintMode
;
90 static GlyphCache
& getPlatformGlyphCache();
91 void setSurface(cairo_surface_t
* pSurface
, const basegfx::B2IVector
& rSize
);
92 static cairo_user_data_key_t
* getDamageKey();
95 void invert(const basegfx::B2DPolygon
&rPoly
, SalInvert nFlags
);
96 void copySource(const SalTwoRect
& rTR
, cairo_surface_t
* source
);
97 void setupPolyPolygon(cairo_t
* cr
, const basegfx::B2DPolyPolygon
& rPolyPoly
);
98 void applyColor(cairo_t
*cr
, SalColor rColor
);
99 void drawPolyPolygon(const basegfx::B2DPolyPolygon
& rPolyPoly
);
101 vcl::Region m_aClipRegion
;
102 SvpCairoTextRender m_aTextRenderImpl
;
105 virtual bool blendBitmap( const SalTwoRect
&, const SalBitmap
& rBitmap
) override
;
106 virtual bool blendAlphaBitmap( const SalTwoRect
&,
107 const SalBitmap
& rSrcBitmap
,
108 const SalBitmap
& rMaskBitmap
,
109 const SalBitmap
& rAlphaBitmap
) override
;
110 virtual bool drawAlphaBitmap( const SalTwoRect
&, const SalBitmap
& rSourceBitmap
, const SalBitmap
& rAlphaBitmap
) override
;
111 virtual bool drawTransformedBitmap(
112 const basegfx::B2DPoint
& rNull
,
113 const basegfx::B2DPoint
& rX
,
114 const basegfx::B2DPoint
& rY
,
115 const SalBitmap
& rSourceBitmap
,
116 const SalBitmap
* pAlphaBitmap
) override
;
117 virtual bool drawAlphaRect( long nX
, long nY
, long nWidth
, long nHeight
, sal_uInt8 nTransparency
) override
;
119 cairo_t
* createTmpCompatibleCairoContext() const;
123 virtual ~SvpSalGraphics() override
;
125 virtual SalGraphicsImpl
* GetImpl() const override
{ return nullptr; };
126 virtual void GetResolution( sal_Int32
& rDPIX
, sal_Int32
& rDPIY
) override
;
127 virtual sal_uInt16
GetBitCount() const override
;
128 virtual long GetGraphicsWidth() const override
;
130 virtual void ResetClipRegion() override
;
131 virtual bool setClipRegion( const vcl::Region
& ) override
;
133 virtual void SetLineColor() override
;
134 virtual void SetLineColor( SalColor nSalColor
) override
;
135 virtual void SetFillColor() override
;
136 virtual void SetFillColor( SalColor nSalColor
) override
;
138 virtual void SetXORMode( bool bSet
) override
;
140 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
141 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
143 virtual void SetTextColor( SalColor nSalColor
) override
;
144 virtual void SetFont( FontSelectPattern
*, int nFallbackLevel
) override
;
145 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) override
;
146 virtual const FontCharMapRef
GetFontCharMap() const override
;
147 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const override
;
148 virtual void GetDevFontList( PhysicalFontCollection
* ) override
;
149 virtual void ClearDevFontCache() override
;
150 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) override
;
151 virtual bool CreateFontSubset( const OUString
& rToFile
,
152 const PhysicalFontFace
*,
153 const sal_GlyphId
* pGlyphIds
,
154 const sal_uInt8
* pEncoding
,
157 FontSubsetInfo
& rInfo
159 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, long* pDataLen
) override
;
160 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) override
;
161 virtual void GetGlyphWidths( const PhysicalFontFace
*,
163 std::vector
< sal_Int32
>& rWidths
,
164 Ucs2UIntMap
& rUnicodeEnc
) override
;
165 virtual bool GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) override
;
166 virtual bool GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) override
;
167 virtual SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) override
;
168 virtual void DrawTextLayout( const CommonSalLayout
& ) override
;
169 virtual bool supportsOperation( OutDevSupportType
) const override
;
170 virtual void drawPixel( long nX
, long nY
) override
;
171 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) override
;
172 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) override
;
173 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) override
;
174 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
175 virtual bool drawPolyLine( const basegfx::B2DPolygon
&,
176 double fTransparency
,
177 const basegfx::B2DVector
& rLineWidths
,
178 basegfx::B2DLineJoin
,
179 css::drawing::LineCap
,
180 double fMiterMinimumAngle
) override
;
181 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
182 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
183 virtual void drawPolyPolygon( sal_uInt32 nPoly
,
184 const sal_uInt32
* pPoints
,
185 PCONSTSALPOINT
* pPtAry
) override
;
186 virtual bool drawPolyLineBezier( sal_uInt32 nPoints
,
187 const SalPoint
* pPtAry
,
188 const PolyFlags
* pFlgAry
) override
;
189 virtual bool drawPolygonBezier( sal_uInt32 nPoints
,
190 const SalPoint
* pPtAry
,
191 const PolyFlags
* pFlgAry
) override
;
192 virtual bool drawPolyPolygonBezier( sal_uInt32 nPoly
,
193 const sal_uInt32
* pPoints
,
194 const SalPoint
* const* pPtAry
,
195 const PolyFlags
* const* pFlgAry
) override
;
196 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
{ return false; };
198 virtual void copyArea( long nDestX
,
204 bool bWindowInvalidate
) override
;
205 virtual void copyBits( const SalTwoRect
& rPosAry
,
206 SalGraphics
* pSrcGraphics
) override
;
207 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
208 const SalBitmap
& rSalBitmap
) override
;
209 virtual void drawBitmap( const SalTwoRect
& rPosAry
,
210 const SalBitmap
& rSalBitmap
,
211 const SalBitmap
& rTransparentBitmap
) override
;
212 virtual void drawMask( const SalTwoRect
& rPosAry
,
213 const SalBitmap
& rSalBitmap
,
214 SalColor nMaskColor
) override
;
215 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) override
;
216 virtual SalColor
getPixel( long nX
, long nY
) override
;
217 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) override
;
218 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) override
;
220 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uLong nSize
) override
;
222 virtual SystemGraphicsData
GetGraphicsData() const override
;
224 #if ENABLE_CAIRO_CANVAS
225 virtual bool SupportsCairo() const override
;
226 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const override
;
227 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const override
;
228 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const override
;
229 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const override
;
230 virtual SystemFontData
GetSysFontData( int nFallbacklevel
) const override
;
231 #endif // ENABLE_CAIRO_CANVAS
233 cairo_t
* getCairoContext(bool bXorModeAllowed
) const;
234 void releaseCairoContext(cairo_t
* cr
, bool bXorModeAllowed
, const basegfx::B2DRange
& rExtents
) const;
235 static cairo_surface_t
* createCairoSurface(const BitmapBuffer
*pBuffer
);
236 double getScale() const { return m_fScale
; }
237 void clipRegion(cairo_t
* cr
);
242 #endif // INCLUDED_VCL_INC_HEADLESS_SVPGDI_HXX
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */