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