LibreOffice Module vcl (master) 1
CairoCommon.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <sal/config.h>
23#include <config_features.h>
24
25#include <cairo.h>
26
27#include <vcl/dllapi.h>
28#include <vcl/region.hxx>
29#include <vcl/salgtype.hxx>
30#include <vcl/vclenum.hxx>
31#include <vcl/BitmapBuffer.hxx>
32
33#include <com/sun/star/drawing/LineCap.hpp>
34
41
42#include <optional>
43#include <unordered_map>
44
45typedef struct _cairo cairo_t;
46typedef struct _cairo_surface cairo_surface_t;
47typedef struct _cairo_user_data_key cairo_user_data_key_t;
48
49class Gradient;
50class SalBitmap;
51struct SalGradient;
52
54 double y_scale);
56 double* y_scale);
57
63
65{
66private:
67 // the path data itself
68 cairo_path_t* mpCairoPath;
69
70 // all other values the path data is based on and
71 // need to be compared with to check for data validity
74 std::vector<double> maStroke;
75
76public:
77 SystemDependentData_CairoPath(size_t nSizeMeasure, cairo_t* cr, bool bNoJoin, bool bAntiAlias,
78 const std::vector<double>* pStroke); // MM01
80
81 // read access
82 cairo_path_t* getCairoPath() { return mpCairoPath; }
83 bool getNoJoin() const { return mbNoJoin; }
84 bool getAntiAlias() const { return mbAntiAlias; }
85 const std::vector<double>& getStroke() const { return maStroke; }
86
87 virtual sal_Int64 estimateUsageInBytes() const override;
88};
89
91 const basegfx::B2DHomMatrix& rObjectToDevice, bool bPixelSnap,
92 bool bPixelSnapHairline);
93
95{
96public:
98 const basegfx::B2DHomMatrix& rObjectToDevice,
99 basegfx::B2DHomMatrix& rObjectToDeviceInv, sal_uInt32 nIndex);
100
101private:
102 basegfx::B2DPoint maPrevPoint, maCurrPoint, maNextPoint;
103 basegfx::B2ITuple maPrevTuple, maCurrTuple, maNextTuple;
104};
105
107 const basegfx::B2DHomMatrix& rObjectToDevice, bool bPixelSnap);
108
109VCL_DLLPUBLIC cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer);
110
111VCL_DLLPUBLIC std::unique_ptr<BitmapBuffer>
113
114enum class PaintMode
115{
116 Over,
117 Xor
118};
119
120typedef void (*damageHandler)(void* handle, sal_Int32 nExtentsX, sal_Int32 nExtentsY,
121 sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight);
122
124{
125 void* handle;
127};
128
130{
134 std::optional<Color> m_oLineColor;
135 std::optional<Color> m_oFillColor;
137 double m_fScale;
138
140 : m_pSurface(nullptr)
141 , m_oLineColor(Color(0x00, 0x00, 0x00))
142 , m_oFillColor(Color(0xFF, 0xFF, 0XFF))
143 , m_ePaintMode(PaintMode::Over)
144 , m_fScale(1.0)
145 {
146 }
147
149
150 cairo_surface_t* getSurface() const { return m_pSurface; }
151
152 sal_uInt16 GetBitCount() const;
153
154 cairo_t* getCairoContext(bool bXorModeAllowed, bool bAntiAlias) const;
155 void releaseCairoContext(cairo_t* cr, bool bXorModeAllowed,
156 const basegfx::B2DRange& rExtents) const;
157
159
160 static void applyColor(cairo_t* cr, Color rColor, double fTransparency = 0.0);
162 static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion);
163
164 void SetXORMode(bool bSet, bool bInvertOnly);
167
168 void drawPixel(const std::optional<Color>& rLineColor, tools::Long nX, tools::Long nY,
169 bool bAntiAlias);
170
172
174 bool bAntiAlias);
175
176 void drawRect(double nX, double nY, double nWidth, double nHeight, bool bAntiAlias);
177
178 void drawPolygon(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
179
180 void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point** pPtAry,
181 bool bAntiAlias);
182
183 bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
184 const basegfx::B2DPolyPolygon&, double fTransparency, bool bAntiAlias);
185
186 void drawPolyLine(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
187
188 bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice,
189 const basegfx::B2DPolygon& rPolyLine, double fTransparency, double fLineWidth,
190 const std::vector<double>* pStroke, basegfx::B2DLineJoin eLineJoin,
191 css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
192 bool bPixelSnapHairline, bool bAntiAlias);
193
195 sal_uInt8 nTransparency, bool bAntiAlias);
196
197 bool drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient,
198 bool bAntiAlias);
199
200 bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, SalGradient const& rGradient,
201 bool bAntiAlias);
202
203 void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source, cairo_operator_t eOp,
204 bool bAntiAlias);
205
206 void copySource(const SalTwoRect& rTR, cairo_surface_t* source, bool bAntiAlias);
207
209 cairo_surface_t* source);
210
211 void copyBitsCairo(const SalTwoRect& rTR, cairo_surface_t* pSourceSurface, bool bAntiAlias);
212
213 void invert(const basegfx::B2DPolygon& rPoly, SalInvert nFlags, bool bAntiAlias);
214
216 SalInvert nFlags, bool bAntiAlias);
217
218 void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags, bool bAntiAlias);
219
220 void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, bool bAntiAlias);
221
222 bool drawAlphaBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap,
223 const SalBitmap& rAlphaBitmap, bool bAntiAlias);
224
226 const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
227 const SalBitmap* pAlphaBitmap, double fAlpha, bool bAntiAlias);
228
229 void drawMask(const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor,
230 bool bAntiAlias);
231
232 std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth,
233 tools::Long nHeight);
234
236
239
240private:
241 void doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, sal_Int32 nExtentsRight,
242 sal_Int32 nExtentsBottom, cairo_surface_t* const surface,
243 sal_Int32 nWidth) const;
244};
245
247{
248private:
250 std::unordered_map<sal_uInt64, cairo_surface_t*> maDownscaled;
251
252 SurfaceHelper(const SurfaceHelper&) = delete;
254
255 cairo_surface_t* implCreateOrReuseDownscale(unsigned long nTargetWidth,
256 unsigned long nTargetHeight);
257
258protected:
259 cairo_surface_t* implGetSurface() const { return pSurface; }
260 void implSetSurface(cairo_surface_t* pNew) { pSurface = pNew; }
261
262 bool isTrivial() const;
263
264public:
265 explicit SurfaceHelper();
267
268 cairo_surface_t* getSurface(unsigned long nTargetWidth = 0,
269 unsigned long nTargetHeight = 0) const;
270};
271
272/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VCL_DLLPUBLIC cairo_format_t getCairoFormat(const BitmapBuffer &rBuffer)
struct _cairo_surface cairo_surface_t
Definition: CairoCommon.hxx:46
struct _cairo cairo_t
Definition: CairoCommon.hxx:45
VCL_DLLPUBLIC basegfx::B2DRange getFillDamage(cairo_t *cr)
void(* damageHandler)(void *handle, sal_Int32 nExtentsX, sal_Int32 nExtentsY, sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight)
VCL_DLLPUBLIC basegfx::B2DRange getClipBox(cairo_t *cr)
VCL_DLLPUBLIC basegfx::B2DRange getClippedFillDamage(cairo_t *cr)
VCL_DLLPUBLIC std::unique_ptr< BitmapBuffer > FastConvert24BitRgbTo32BitCairo(const BitmapBuffer *pSrc)
VCL_DLLPUBLIC void dl_cairo_surface_get_device_scale(cairo_surface_t *surface, double *x_scale, double *y_scale)
VCL_DLLPUBLIC size_t AddPolygonToPath(cairo_t *cr, const basegfx::B2DPolygon &rPolygon, const basegfx::B2DHomMatrix &rObjectToDevice, bool bPixelSnap, bool bPixelSnapHairline)
struct _cairo_user_data_key cairo_user_data_key_t
Definition: CairoCommon.hxx:47
VCL_DLLPUBLIC basegfx::B2DRange getStrokeDamage(cairo_t *cr)
VCL_DLLPUBLIC void add_polygon_path(cairo_t *cr, const basegfx::B2DPolyPolygon &rPolyPolygon, const basegfx::B2DHomMatrix &rObjectToDevice, bool bPixelSnap)
VCL_DLLPUBLIC void dl_cairo_surface_set_device_scale(cairo_surface_t *surface, double x_scale, double y_scale)
VCL_DLLPUBLIC basegfx::B2DRange getClippedStrokeDamage(cairo_t *cr)
PaintMode
basegfx::B2DPoint maCurrPoint
basegfx::B2ITuple maCurrTuple
basegfx::B2DPoint snap(const basegfx::B2DPolygon &rPolygon, const basegfx::B2DHomMatrix &rObjectToDevice, basegfx::B2DHomMatrix &rObjectToDeviceInv, sal_uInt32 nIndex)
cairo_surface_t * implGetSurface() const
cairo_surface_t * getSurface(unsigned long nTargetWidth=0, unsigned long nTargetHeight=0) const
cairo_surface_t * pSurface
SurfaceHelper & operator=(const SurfaceHelper &)=delete
std::unordered_map< sal_uInt64, cairo_surface_t * > maDownscaled
bool isTrivial() const
SurfaceHelper(const SurfaceHelper &)=delete
cairo_surface_t * implCreateOrReuseDownscale(unsigned long nTargetWidth, unsigned long nTargetHeight)
void implSetSurface(cairo_surface_t *pNew)
std::vector< double > maStroke
Definition: CairoCommon.hxx:74
cairo_path_t * getCairoPath()
Definition: CairoCommon.hxx:82
const std::vector< double > & getStroke() const
Definition: CairoCommon.hxx:85
SystemDependentData_CairoPath(size_t nSizeMeasure, cairo_t *cr, bool bNoJoin, bool bAntiAlias, const std::vector< double > *pStroke)
virtual ~SystemDependentData_CairoPath() override
virtual sal_Int64 estimateUsageInBytes() const override
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
SalROPColor
Definition: salgtype.hxx:69
SalInvert
Definition: salgtype.hxx:73
static bool supportsOperation(OutDevSupportType eType)
void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point **pPtAry, bool bAntiAlias)
void clipRegion(cairo_t *cr)
void drawRect(double nX, double nY, double nWidth, double nHeight, bool bAntiAlias)
static void clipRegion(cairo_t *cr, const vcl::Region &rClipRegion)
double m_fScale
void copyBitsCairo(const SalTwoRect &rTR, cairo_surface_t *pSourceSurface, bool bAntiAlias)
void doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, sal_Int32 nExtentsRight, sal_Int32 nExtentsBottom, cairo_surface_t *const surface, sal_Int32 nWidth) const
void drawPolyLine(sal_uInt32 nPoints, const Point *pPtAry, bool bAntiAlias)
std::shared_ptr< SalBitmap > getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight)
bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency, bool bAntiAlias)
bool drawGradient(const tools::PolyPolygon &rPolyPolygon, const Gradient &rGradient, bool bAntiAlias)
void copyWithOperator(const SalTwoRect &rTR, cairo_surface_t *source, cairo_operator_t eOp, bool bAntiAlias)
static cairo_surface_t * createCairoSurface(const BitmapBuffer *pBuffer)
bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap, double fAlpha, bool bAntiAlias)
cairo_surface_t * getSurface() const
vcl::Region m_aClipRegion
void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2, bool bAntiAlias)
static bool hasFastDrawTransformedBitmap()
cairo_t * createTmpCompatibleCairoContext() const
bool drawPolyLine(const basegfx::B2DHomMatrix &rObjectToDevice, const basegfx::B2DPolygon &rPolyLine, double fTransparency, double fLineWidth, const std::vector< double > *pStroke, basegfx::B2DLineJoin eLineJoin, css::drawing::LineCap eLineCap, double fMiterMinimumAngle, bool bPixelSnapHairline, bool bAntiAlias)
cairo_t * getCairoContext(bool bXorModeAllowed, bool bAntiAlias) const
bool drawAlphaBitmap(const SalTwoRect &rTR, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap, bool bAntiAlias)
void copySource(const SalTwoRect &rTR, cairo_surface_t *source, bool bAntiAlias)
void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags, bool bAntiAlias)
cairo_surface_t * m_pSurface
void SetROPLineColor(SalROPColor nROPColor)
basegfx::B2IVector m_aFrameSize
void drawMask(const SalTwoRect &rTR, const SalBitmap &rSalBitmap, Color nMaskColor, bool bAntiAlias)
void invert(const basegfx::B2DPolygon &rPoly, SalInvert nFlags, bool bAntiAlias)
void invert(sal_uInt32 nPoints, const Point *pPtAry, SalInvert nFlags, bool bAntiAlias)
void releaseCairoContext(cairo_t *cr, bool bXorModeAllowed, const basegfx::B2DRange &rExtents) const
static cairo_user_data_key_t * getDamageKey()
bool drawPolyPolygon(const basegfx::B2DHomMatrix &rObjectToDevice, const basegfx::B2DPolyPolygon &, double fTransparency, bool bAntiAlias)
sal_uInt16 GetBitCount() const
void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, bool bAntiAlias)
void SetXORMode(bool bSet, bool bInvertOnly)
bool implDrawGradient(basegfx::B2DPolyPolygon const &rPolyPolygon, SalGradient const &rGradient, bool bAntiAlias)
std::optional< Color > m_oFillColor
void drawPolygon(sal_uInt32 nPoints, const Point *pPtAry, bool bAntiAlias)
static void applyColor(cairo_t *cr, Color rColor, double fTransparency=0.0)
void SetROPFillColor(SalROPColor nROPColor)
static basegfx::B2DRange renderSource(cairo_t *cr, const SalTwoRect &rTR, cairo_surface_t *source)
PaintMode m_ePaintMode
std::optional< Color > m_oLineColor
void drawPixel(const std::optional< Color > &rLineColor, tools::Long nX, tools::Long nY, bool bAntiAlias)
static Color getPixel(cairo_surface_t *pSurface, tools::Long nX, tools::Long nY)
damageHandler damaged
unsigned char sal_uInt8
OutDevSupportType
Definition: vclenum.hxx:163