LibreOffice Module vcl (master)  1
unx/salgdi.h
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 #ifndef INCLUDED_VCL_INC_UNX_SALGDI_H
21 #define INCLUDED_VCL_INC_UNX_SALGDI_H
22 
23 #include <X11/Xlib.h>
24 #include <X11/Xutil.h>
25 #include <X11/extensions/Xrender.h>
26 
27 #include <vcl/salgtype.hxx>
28 #include <vcl/vclenum.hxx>
29 
30 #include <unx/saldisp.hxx>
31 #include <salgdi.hxx>
32 #include <salgeom.hxx>
33 #include <sallayout.hxx>
34 #include <vclpluginapi.h>
35 #include <ControlCacheKey.hxx>
36 
37 #include "saltype.h"
38 #include "saldisp.hxx"
39 
40 #include <memory>
41 
42 /* From <X11/Intrinsic.h> */
43 typedef unsigned long Pixel;
44 
45 class SalBitmap;
46 class SalColormap;
47 class SalDisplay;
48 class SalFrame;
50 class X11SalGraphicsImpl;
53 class PhysicalFontFace;
54 class SalGraphicsImpl;
55 class TextRenderImpl;
56 
57 namespace basegfx {
58  class B2DTrapezoid;
59 }
60 
61 class X11SalGraphics final : public SalGraphics
62 {
63  friend class X11SalGraphicsImpl;
64  friend class X11CairoTextRender;
65 
66 public:
68  virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override;
69 
70  void Init( SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen );
71  void Init( X11SalVirtualDevice *pVirtualDevice, cairo_surface_t* pPreExistingTarget = nullptr,
72  SalColormap* pColormap = nullptr, bool bDeleteColormap = false );
73  void Init( X11SkiaSalVirtualDevice *pVirtualDevice );
74  void DeInit();
75 
76  virtual SalGraphicsImpl* GetImpl() const override;
77  inline const SalDisplay* GetDisplay() const;
78  inline Display* GetXDisplay() const;
79  inline const SalVisual& GetVisual() const;
81  Drawable GetDrawable() const { return hDrawable_; }
82  void SetDrawable(Drawable d, cairo_surface_t* surface, SalX11Screen nXScreen);
83  XRenderPictFormat* GetXRenderFormat() const;
84  void SetXRenderFormat( XRenderPictFormat* pXRenderFormat ) { m_pXRenderFormat = pXRenderFormat; }
85  const SalColormap& GetColormap() const { return *m_pColormap; }
86 
88  inline Pixel GetPixel( Color nColor ) const;
89 
90  const SalX11Screen& GetScreenNumber() const { return m_nXScreen; }
91 
92  void Flush();
93 
94  // override all pure virtual methods
95  virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
96  virtual sal_uInt16 GetBitCount() const override;
97  virtual tools::Long GetGraphicsWidth() const override;
98 
99  virtual void ResetClipRegion() override;
100  virtual bool setClipRegion( const vcl::Region& ) override;
101 
102  virtual void SetLineColor() override;
103  virtual void SetLineColor( Color nColor ) override;
104  virtual void SetFillColor() override;
105 
106  virtual void SetFillColor( Color nColor ) override;
107 
108  virtual void SetXORMode( bool bSet, bool ) override;
109 
110  virtual void SetROPLineColor( SalROPColor nROPColor ) override;
111  virtual void SetROPFillColor( SalROPColor nROPColor ) override;
112 
113  virtual void SetTextColor( Color nColor ) override;
114  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
115  virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) override;
116  virtual FontCharMapRef GetFontCharMap() const override;
117  virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override;
118  virtual void GetDevFontList( PhysicalFontCollection* ) override;
119  virtual void ClearDevFontCache() override;
120  virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
121 
122  virtual bool CreateFontSubset(
123  const OUString& rToFile,
124  const PhysicalFontFace*,
125  const sal_GlyphId* pGlyphIDs,
126  const sal_uInt8* pEncoding,
127  sal_Int32* pWidths,
128  int nGlyphs,
129  FontSubsetInfo& rInfo ) override;
130 
131  virtual const void* GetEmbedFontData(const PhysicalFontFace*, tools::Long* pDataLen) override;
132  virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override;
133 
134  virtual void GetGlyphWidths(
135  const PhysicalFontFace*,
136  bool bVertical,
137  std::vector< sal_Int32 >& rWidths,
138  Ucs2UIntMap& rUnicodeEnc ) override;
139 
140  virtual std::unique_ptr<GenericSalLayout>
141  GetTextLayout(int nFallbackLevel) override;
142  virtual void DrawTextLayout( const GenericSalLayout& ) override;
143 
144  virtual bool supportsOperation( OutDevSupportType ) const override;
145  virtual void drawPixel( tools::Long nX, tools::Long nY ) override;
146  virtual void drawPixel( tools::Long nX, tools::Long nY, Color nColor ) override;
147  virtual void drawLine( tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2 ) override;
148  virtual void drawRect( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
149  virtual void drawPolyLine( sal_uInt32 nPoints, const Point* pPtAry ) override;
150  virtual void drawPolygon( sal_uInt32 nPoints, const Point* pPtAry ) override;
151 
152  virtual void drawPolyPolygon(
153  sal_uInt32 nPoly,
154  const sal_uInt32* pPoints,
155  const Point** pPtAry ) override;
156 
157  virtual bool drawPolyPolygon(
158  const basegfx::B2DHomMatrix& rObjectToDevice,
160  double fTransparency) override;
161 
162  virtual bool drawPolyLine(
163  const basegfx::B2DHomMatrix& rObjectToDevice,
164  const basegfx::B2DPolygon&,
165  double fTransparency,
166  double fLineWidth,
167  const std::vector< double >* pStroke, // MM01
169  css::drawing::LineCap,
170  double fMiterMinimumAngle,
171  bool bPixelSnapHairline) override;
172 
173  virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) override;
174  virtual bool implDrawGradient(basegfx::B2DPolyPolygon const & rPolyPolygon,
175  SalGradient const & rGradient) override;
176 
177 #if 1 // TODO: remove these obsolete methods
178  virtual bool drawPolyLineBezier(
179  sal_uInt32 nPoints,
180  const Point* pPtAry,
181  const PolyFlags* pFlgAry ) override;
182 
183  virtual bool drawPolygonBezier(
184  sal_uInt32 nPoints,
185  const Point* pPtAry,
186  const PolyFlags* pFlgAry ) override;
187 
188  virtual bool drawPolyPolygonBezier(
189  sal_uInt32 nPoly,
190  const sal_uInt32* pPoints,
191  const Point* const* pPtAry,
192  const PolyFlags* const* pFlgAry ) override;
193 #endif
194 
195  virtual void copyArea(
196  tools::Long nDestX,
197  tools::Long nDestY,
198  tools::Long nSrcX,
199  tools::Long nSrcY,
200  tools::Long nSrcWidth,
201  tools::Long nSrcHeight,
202  bool bWindowInvalidate ) override;
203 
204  virtual void copyBits(
205  const SalTwoRect& rPosAry,
206  SalGraphics* pSrcGraphics ) override;
207 
208  virtual void drawBitmap(
209  const SalTwoRect& rPosAry,
210  const SalBitmap& rSalBitmap ) override;
211 
212  virtual void drawBitmap(
213  const SalTwoRect& rPosAry,
214  const SalBitmap& rSalBitmap,
215  const SalBitmap& rMaskBitmap ) override;
216 
217  virtual void drawMask(
218  const SalTwoRect& rPosAry,
219  const SalBitmap& rSalBitmap,
220  Color nMaskColor ) override;
221 
222  virtual std::shared_ptr<SalBitmap> getBitmap( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight ) override;
223  virtual Color getPixel( tools::Long nX, tools::Long nY ) override;
224  virtual void invert( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags ) override;
225  virtual void invert( sal_uInt32 nPoints, const Point* pPtAry, SalInvert nFlags ) override;
226 
227  virtual bool drawEPS( tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, void* pPtr, sal_uInt32 nSize ) override;
228 
229  virtual bool blendBitmap(
230  const SalTwoRect&,
231  const SalBitmap& rBitmap ) override;
232 
233  virtual bool blendAlphaBitmap(
234  const SalTwoRect&,
235  const SalBitmap& rSrcBitmap,
236  const SalBitmap& rMaskBitmap,
237  const SalBitmap& rAlphaBitmap ) override;
238 
239  virtual bool drawAlphaBitmap(
240  const SalTwoRect&,
241  const SalBitmap& rSourceBitmap,
242  const SalBitmap& rAlphaBitmap ) override;
243 
244  virtual bool drawTransformedBitmap(
245  const basegfx::B2DPoint& rNull,
246  const basegfx::B2DPoint& rX,
247  const basegfx::B2DPoint& rY,
248  const SalBitmap& rSourceBitmap,
249  const SalBitmap* pAlphaBitmap,
250  double fAlpha) override;
251 
252  virtual bool hasFastDrawTransformedBitmap() const override;
253 
254  virtual bool drawAlphaRect(
255  tools::Long nX, tools::Long nY, tools::Long nWidth,
256  tools::Long nHeight, sal_uInt8 nTransparency ) override;
257 
258  virtual SystemGraphicsData GetGraphicsData() const override;
259 
260 #if ENABLE_CAIRO_CANVAS
261  virtual bool SupportsCairo() const override;
262  virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
263  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
264  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const override;
265  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const basegfx::B2ISize& rSize) const override;
266 
267  void clipRegion(cairo_t* cr);
268 #endif // ENABLE_CAIRO_CANVAS
269 
270  /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
271  * if pFrame is not NULL, corresponding Paint events are generated
272  * and dispatched to pFrame
273  *
274  * it is imperative to eat up graphics exposes even in case you don't need
275  * them because the next one using XCopyArea can depend on them
276  */
277  void YieldGraphicsExpose();
278 
280  static void releaseCairoContext(cairo_t* cr);
281 
282 
283 private:
285  void SetClipRegion( GC pGC, Region pXReg = nullptr ) const;
286  bool GetDitherPixmap ( Color nColor );
287 
289 
290  void freeResources();
291 
292  SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL
293  SalVirtualDevice* m_pVDev; // the SalVirtualDevice which created this Graphics or NULL
294 
296  std::unique_ptr<SalColormap> m_pDeleteColormap;
297  Drawable hDrawable_; // use
300  mutable XRenderPictFormat* m_pXRenderFormat;
302 
303  Region mpClipRegion;
304 #if ENABLE_CAIRO_CANVAS
305  vcl::Region maClipRegion;
306  Color mnPenColor;
307  Color mnFillColor;
308 #endif // ENABLE_CAIRO_CANVAS
309 
310  Pixmap hBrush_; // Dither
311 
312  bool bWindow_ : 1; // is Window
313  bool bVirDev_ : 1; // is VirDev
314  bool m_bSkia : 1;
315 
316 private:
317  std::unique_ptr<SalGraphicsImpl> mxImpl;
318  std::unique_ptr<TextRenderImpl> mxTextRenderImpl;
319 
320 };
321 
323 { return GetColormap().GetDisplay(); }
324 
326 { return GetColormap().GetVisual(); }
327 
329 { return GetColormap().GetXDisplay(); }
330 
331 inline Pixel X11SalGraphics::GetPixel( Color nColor ) const
332 { return GetColormap().GetPixel( nColor ); }
333 
334 #endif // INCLUDED_VCL_INC_UNX_SALGDI_H
335 
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface used to share logic on sizing between SalVirtualDevices and SalFrames.
Definition: salgeom.hxx:63
std::unique_ptr< SalGraphicsImpl > mxImpl
Definition: unx/salgdi.h:317
bool SetClipRegion(const vcl::Region &, const OutputDevice &rOutDev)
virtual void drawRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override
virtual SystemGraphicsData GetGraphicsData() const override
void SetXRenderFormat(XRenderPictFormat *pXRenderFormat)
Definition: unx/salgdi.h:84
SalROPColor
Definition: salgtype.hxx:71
const SalVisual & GetVisual() const
Definition: unx/salgdi.h:325
Display * GetXDisplay() const
Definition: unx/salgdi.h:328
virtual void SetXORMode(bool bSet, bool) override
void YieldGraphicsExpose()
long Long
virtual void ResetClipRegion() override
void freeResources()
void SetDrawable(Drawable d, cairo_surface_t *surface, SalX11Screen nXScreen)
virtual bool blendBitmap(const SalTwoRect &, const SalBitmap &rBitmap) override
Blend the bitmap with the current buffer.
std::unique_ptr< TextRenderImpl > mxTextRenderImpl
Definition: unx/salgdi.h:318
virtual void drawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap) override
virtual sal_uInt16 GetBitCount() const override
virtual bool hasFastDrawTransformedBitmap() const override
Used e.g.
XID m_aXRenderPicture
Definition: unx/salgdi.h:301
std::unique_ptr< SalColormap > m_pDeleteColormap
Definition: unx/salgdi.h:296
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
OutDevSupportType
Definition: vclenum.hxx:196
virtual void SetLineColor() override
Drawable hDrawable_
Definition: unx/salgdi.h:297
virtual bool AddTempDevFont(PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName) override
XRenderPictFormat * m_pXRenderFormat
Definition: unx/salgdi.h:300
virtual bool supportsOperation(OutDevSupportType) const override
cairo_t * getCairoContext()
void DrawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, const OutputDevice &rOutDev)
SalFrame * m_pFrame
Definition: unx/salgdi.h:292
virtual Color getPixel(tools::Long nX, tools::Long nY) override
virtual void SetROPLineColor(SalROPColor nROPColor) override
const SalColormap & GetColormap() const
Definition: unx/salgdi.h:85
virtual void clipRegion(cairo_t *cr) override
bool GetDitherPixmap(Color nColor)
abstract base class for physical font faces
std::shared_ptr< Surface > SurfaceSharedPtr
Definition: cairo.hxx:36
virtual FontCharMapRef GetFontCharMap() const override
virtual void drawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor) override
Drawable GetDrawable() const
Definition: unx/salgdi.h:81
virtual void copyArea(tools::Long nDestX, tools::Long nDestY, tools::Long nSrcX, tools::Long nSrcY, tools::Long nSrcWidth, tools::Long nSrcHeight, bool bWindowInvalidate) override
virtual bool implDrawGradient(basegfx::B2DPolyPolygon const &rPolyPolygon, SalGradient const &rGradient) override
virtual const void * GetEmbedFontData(const PhysicalFontFace *, tools::Long *pDataLen) override
virtual void copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcGraphics) override
Display * GetXDisplay() const
Definition: saldisp.hxx:394
Pixmap hBrush_
Definition: unx/salgdi.h:310
virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point *const *pPtAry, const PolyFlags *const *pFlgAry) override
static void releaseCairoContext(cairo_t *cr)
virtual SalGraphicsImpl * GetImpl() const override
virtual std::shared_ptr< SalBitmap > getBitmap(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight) override
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel) override
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:303
virtual bool drawEPS(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, void *pPtr, sal_uInt32 nSize) override
virtual void GetGlyphWidths(const PhysicalFontFace *, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc) override
SalInvert
Definition: salgtype.hxx:75
virtual void FreeEmbedFontData(const void *pData, tools::Long nDataLen) override
Display
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
virtual tools::Long GetGraphicsWidth() const override
struct _cairo cairo_t
Definition: svpgdi.hxx:70
virtual void SetFillColor() override
virtual void SetFont(LogicalFontInstance *, int nFallbackLevel) override
virtual bool drawAlphaBitmap(const SalTwoRect &, const SalBitmap &rSourceBitmap, const SalBitmap &rAlphaBitmap) override
Render bitmap with alpha channel.
virtual void invert(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, SalInvert nFlags) override
virtual void DrawTextLayout(const GenericSalLayout &) override
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
virtual void drawPolyLine(sal_uInt32 nPoints, const Point *pPtAry) override
virtual bool drawAlphaRect(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, sal_uInt8 nTransparency) override
Render solid rectangle with given transparency.
virtual bool drawGradient(const tools::PolyPolygon &, const Gradient &) override
void SetClipRegion(GC pGC, Region pXReg=nullptr) const
unsigned long Pixel
Definition: saldisp.hxx:26
const SalDisplay * GetDisplay() const
Definition: saldisp.hxx:141
unsigned char sal_uInt8
virtual void GetDevFontList(PhysicalFontCollection *) override
const SalDisplay * GetDisplay() const
Definition: unx/salgdi.h:322
virtual void ClearDevFontCache() override
A non-visible drawable/buffer (e.g. an X11 Pixmap).
Definition: salvd.hxx:28
virtual bool CreateFontSubset(const OUString &rToFile, const PhysicalFontFace *, const sal_GlyphId *pGlyphIDs, const sal_uInt8 *pEncoding, sal_Int32 *pWidths, int nGlyphs, FontSubsetInfo &rInfo) override
virtual void GetResolution(sal_Int32 &rDPIX, sal_Int32 &rDPIY) override
virtual bool blendAlphaBitmap(const SalTwoRect &, const SalBitmap &rSrcBitmap, const SalBitmap &rMaskBitmap, const SalBitmap &rAlphaBitmap) override
Draw the bitmap by blending using the mask and alpha channel.
virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const Point **pPtAry) override
friend class X11SalGraphicsImpl
Definition: unx/salgdi.h:63
Pixel GetPixel(Color nColor) const
SalGeometryProvider * GetGeometryProvider() const
virtual bool setClipRegion(const vcl::Region &) override
virtual void SetTextColor(Color nColor) override
Region mpClipRegion
Definition: unx/salgdi.h:303
Pixel GetPixel(Color nColor) const
Definition: unx/salgdi.h:331
Color GetPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override
SalX11Screen m_nXScreen
Definition: unx/salgdi.h:299
virtual bool drawPolygonBezier(sal_uInt32 nPoints, const Point *pPtAry, const PolyFlags *pFlgAry) override
unsigned long Pixel
Definition: unx/salgdi.h:43
virtual void SetROPFillColor(SalROPColor nROPColor) override
std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap
Definition: salgdi.hxx:64
void Init(SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen)
virtual void drawLine(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2) override
const SalVisual & GetVisual() const
Definition: saldisp.hxx:143
virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const Point *pPtAry, const PolyFlags *pFlgAry) override
struct _cairo_surface cairo_surface_t
Definition: svpgdi.hxx:71
virtual void drawPolygon(sal_uInt32 nPoints, const Point *pPtAry) override
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel) override
XRenderPictFormat * GetXRenderFormat() const
virtual void drawPixel(tools::Long nX, tools::Long nY) override
virtual bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap, double fAlpha) override
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
cairo_surface_t * m_pExternalSurface
Definition: unx/salgdi.h:298
SalVirtualDevice * m_pVDev
Definition: unx/salgdi.h:293
PolyFlags
const SalColormap * m_pColormap
Definition: unx/salgdi.h:295
const SalX11Screen & GetScreenNumber() const
Definition: unx/salgdi.h:90