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
115
116enum class PaintMode
117{
118 Over,
119 Xor
120};
121
122typedef void (*damageHandler)(void* handle, sal_Int32 nExtentsX, sal_Int32 nExtentsY,
123 sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight);
124
126{
127 void* handle;
129};
130
132{
136 std::optional<Color> m_oLineColor;
137 std::optional<Color> m_oFillColor;
139 double m_fScale;
140
142 : m_pSurface(nullptr)
143 , m_oLineColor(Color(0x00, 0x00, 0x00))
144 , m_oFillColor(Color(0xFF, 0xFF, 0XFF))
145 , m_ePaintMode(PaintMode::Over)
146 , m_fScale(1.0)
147 {
148 }
149
151
152 cairo_surface_t* getSurface() const { return m_pSurface; }
153
154 sal_uInt16 GetBitCount() const;
155
156 cairo_t* getCairoContext(bool bXorModeAllowed, bool bAntiAlias) const;
157 void releaseCairoContext(cairo_t* cr, bool bXorModeAllowed,
158 const basegfx::B2DRange& rExtents) const;
159
161
162 static void applyColor(cairo_t* cr, Color rColor, double fTransparency = 0.0);
164 static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion);
165
166 void SetXORMode(bool bSet, bool bInvertOnly);
169
170 void drawPixel(const std::optional<Color>& rLineColor, tools::Long nX, tools::Long nY,
171 bool bAntiAlias);
172
174
176 bool bAntiAlias);
177
178 void drawRect(double nX, double nY, double nWidth, double nHeight, bool bAntiAlias);
179
180 void drawPolygon(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
181
182 void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point** pPtAry,
183 bool bAntiAlias);
184
185 bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
186 const basegfx::B2DPolyPolygon&, double fTransparency, bool bAntiAlias);
187
188 void drawPolyLine(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
189
190 bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice,
191 const basegfx::B2DPolygon& rPolyLine, double fTransparency, double fLineWidth,
192 const std::vector<double>* pStroke, basegfx::B2DLineJoin eLineJoin,
193 css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
194 bool bPixelSnapHairline, bool bAntiAlias);
195
197 sal_uInt8 nTransparency, bool bAntiAlias);
198
199 bool drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient,
200 bool bAntiAlias);
201
202 bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, SalGradient const& rGradient,
203 bool bAntiAlias);
204
205 void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source, cairo_operator_t eOp,
206 bool bAntiAlias);
207
208 void copySource(const SalTwoRect& rTR, cairo_surface_t* source, bool bAntiAlias);
209
211 cairo_surface_t* source);
212
213 void copyBitsCairo(const SalTwoRect& rTR, cairo_surface_t* pSourceSurface, bool bAntiAlias);
214
215 void invert(const basegfx::B2DPolygon& rPoly, SalInvert nFlags, bool bAntiAlias);
216
218 SalInvert nFlags, bool bAntiAlias);
219
220 void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags, bool bAntiAlias);
221
222 void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, bool bAntiAlias);
223
224 bool drawAlphaBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap,
225 const SalBitmap& rAlphaBitmap, bool bAntiAlias);
226
228 const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
229 const SalBitmap* pAlphaBitmap, double fAlpha, bool bAntiAlias);
230
231 void drawMask(const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor,
232 bool bAntiAlias);
233
234 std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth,
235 tools::Long nHeight);
236
238
241
242private:
243 void doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, sal_Int32 nExtentsRight,
244 sal_Int32 nExtentsBottom, cairo_surface_t* const surface,
245 sal_Int32 nWidth) const;
246};
247
249{
250private:
252 std::unordered_map<sal_uInt64, cairo_surface_t*> maDownscaled;
253
254 SurfaceHelper(const SurfaceHelper&) = delete;
256
257 cairo_surface_t* implCreateOrReuseDownscale(unsigned long nTargetWidth,
258 unsigned long nTargetHeight);
259
260protected:
261 cairo_surface_t* implGetSurface() const { return pSurface; }
262 void implSetSurface(cairo_surface_t* pNew) { pSurface = pNew; }
263
264 bool isTrivial() const;
265
266public:
267 explicit SurfaceHelper();
269
270 cairo_surface_t* getSurface(unsigned long nTargetWidth = 0,
271 unsigned long nTargetHeight = 0) const;
272};
273
274/* 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
VCL_DLLPUBLIC void Toggle1BitTransparency(const BitmapBuffer &rBuf)
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:162