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 const basegfx::B2DHomMatrix& rObjectToDevice,
96 basegfx::B2DHomMatrix& rObjectToDeviceInv,
97 sal_uInt32 nIndex);
98
100 const basegfx::B2DHomMatrix& rObjectToDevice, bool bPixelSnap);
101
102VCL_DLLPUBLIC cairo_format_t getCairoFormat(const BitmapBuffer& rBuffer);
103
104VCL_DLLPUBLIC std::unique_ptr<BitmapBuffer>
106
108
109enum class PaintMode
110{
111 Over,
112 Xor
113};
114
115typedef void (*damageHandler)(void* handle, sal_Int32 nExtentsX, sal_Int32 nExtentsY,
116 sal_Int32 nExtentsWidth, sal_Int32 nExtentsHeight);
117
119{
120 void* handle;
122};
123
125{
129 std::optional<Color> m_oLineColor;
130 std::optional<Color> m_oFillColor;
132 double m_fScale;
133
135 : m_pSurface(nullptr)
136 , m_oLineColor(Color(0x00, 0x00, 0x00))
137 , m_oFillColor(Color(0xFF, 0xFF, 0XFF))
138 , m_ePaintMode(PaintMode::Over)
139 , m_fScale(1.0)
140 {
141 }
142
144
145 cairo_surface_t* getSurface() const { return m_pSurface; }
146
147 sal_uInt16 GetBitCount() const;
148
149 cairo_t* getCairoContext(bool bXorModeAllowed, bool bAntiAlias) const;
150 void releaseCairoContext(cairo_t* cr, bool bXorModeAllowed,
151 const basegfx::B2DRange& rExtents) const;
152
154
155 static void applyColor(cairo_t* cr, Color rColor, double fTransparency = 0.0);
157 static void clipRegion(cairo_t* cr, const vcl::Region& rClipRegion);
158
159 void SetXORMode(bool bSet, bool bInvertOnly);
162
163 void drawPixel(const std::optional<Color>& rLineColor, tools::Long nX, tools::Long nY,
164 bool bAntiAlias);
165
167
169 bool bAntiAlias);
170
171 void drawRect(double nX, double nY, double nWidth, double nHeight, bool bAntiAlias);
172
173 void drawPolygon(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
174
175 void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32* pPoints, const Point** pPtAry,
176 bool bAntiAlias);
177
178 bool drawPolyPolygon(const basegfx::B2DHomMatrix& rObjectToDevice,
179 const basegfx::B2DPolyPolygon&, double fTransparency, bool bAntiAlias);
180
181 void drawPolyLine(sal_uInt32 nPoints, const Point* pPtAry, bool bAntiAlias);
182
183 bool drawPolyLine(const basegfx::B2DHomMatrix& rObjectToDevice,
184 const basegfx::B2DPolygon& rPolyLine, double fTransparency, double fLineWidth,
185 const std::vector<double>* pStroke, basegfx::B2DLineJoin eLineJoin,
186 css::drawing::LineCap eLineCap, double fMiterMinimumAngle,
187 bool bPixelSnapHairline, bool bAntiAlias);
188
190 sal_uInt8 nTransparency, bool bAntiAlias);
191
192 bool drawGradient(const tools::PolyPolygon& rPolyPolygon, const Gradient& rGradient,
193 bool bAntiAlias);
194
195 bool implDrawGradient(basegfx::B2DPolyPolygon const& rPolyPolygon, SalGradient const& rGradient,
196 bool bAntiAlias);
197
198 void copyWithOperator(const SalTwoRect& rTR, cairo_surface_t* source, cairo_operator_t eOp,
199 bool bAntiAlias);
200
201 void copySource(const SalTwoRect& rTR, cairo_surface_t* source, bool bAntiAlias);
202
204 cairo_surface_t* source);
205
206 void copyBitsCairo(const SalTwoRect& rTR, cairo_surface_t* pSourceSurface, bool bAntiAlias);
207
208 void invert(const basegfx::B2DPolygon& rPoly, SalInvert nFlags, bool bAntiAlias);
209
211 SalInvert nFlags, bool bAntiAlias);
212
213 void invert(sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags, bool bAntiAlias);
214
215 void drawBitmap(const SalTwoRect& rPosAry, const SalBitmap& rSalBitmap, bool bAntiAlias);
216
217 bool drawAlphaBitmap(const SalTwoRect& rTR, const SalBitmap& rSourceBitmap,
218 const SalBitmap& rAlphaBitmap, bool bAntiAlias);
219
221 const basegfx::B2DPoint& rY, const SalBitmap& rSourceBitmap,
222 const SalBitmap* pAlphaBitmap, double fAlpha, bool bAntiAlias);
223
224 void drawMask(const SalTwoRect& rTR, const SalBitmap& rSalBitmap, Color nMaskColor,
225 bool bAntiAlias);
226
227 std::shared_ptr<SalBitmap> getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth,
228 tools::Long nHeight);
229
231
234
235private:
236 void doXorOnRelease(sal_Int32 nExtentsLeft, sal_Int32 nExtentsTop, sal_Int32 nExtentsRight,
237 sal_Int32 nExtentsBottom, cairo_surface_t* const surface,
238 sal_Int32 nWidth) const;
239};
240
242{
243private:
245 std::unordered_map<sal_uInt64, cairo_surface_t*> maDownscaled;
246
247 SurfaceHelper(const SurfaceHelper&) = delete;
249
250 cairo_surface_t* implCreateOrReuseDownscale(unsigned long nTargetWidth,
251 unsigned long nTargetHeight);
252
253protected:
254 cairo_surface_t* implGetSurface() const { return pSurface; }
255 void implSetSurface(cairo_surface_t* pNew) { pSurface = pNew; }
256
257 bool isTrivial() const;
258
259public:
260 explicit SurfaceHelper();
262
263 cairo_surface_t* getSurface(unsigned long nTargetWidth = 0,
264 unsigned long nTargetHeight = 0) const;
265};
266
267/* 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)
VCL_DLLPUBLIC basegfx::B2DPoint impPixelSnap(const basegfx::B2DPolygon &rPolygon, const basegfx::B2DHomMatrix &rObjectToDevice, basegfx::B2DHomMatrix &rObjectToDeviceInv, sal_uInt32 nIndex)
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
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:68
SalInvert
Definition: salgtype.hxx:72
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:174