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 FontAttributes;
46 class FontSelectPattern;
47 class SalBitmap;
48 class SalColormap;
49 class SalDisplay;
50 class SalFrame;
51 class X11Pixmap;
53 class X11SalGraphicsImpl;
57 class FreetypeFont;
58 class ImplLayoutArgs;
60 class PhysicalFontFace;
61 class SalGraphicsImpl;
62 class TextRenderImpl;
63 
64 namespace basegfx {
65  class B2DTrapezoid;
66 }
67 
68 class X11SalGraphics final : public SalGraphics
69 {
70  friend class X11SalGraphicsImpl;
72  friend class X11CairoTextRender;
73 
74 public:
76  virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override;
77 
78  void Init( SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen );
79  void Init( X11SalVirtualDevice *pVirtualDevice, SalColormap* pColormap = nullptr, bool bDeleteColormap = false );
80  void Init( X11OpenGLSalVirtualDevice *pVirtualDevice );
81  void Init( X11SkiaSalVirtualDevice *pVirtualDevice );
82  void DeInit();
83 
84  virtual SalGraphicsImpl* GetImpl() const override;
85  inline const SalDisplay* GetDisplay() const;
86  inline Display* GetXDisplay() const;
87  inline const SalVisual& GetVisual() const;
89  Drawable GetDrawable() const { return hDrawable_; }
90  void SetDrawable( Drawable d, SalX11Screen nXScreen );
91  XRenderPictFormat* GetXRenderFormat() const;
92  void SetXRenderFormat( XRenderPictFormat* pXRenderFormat ) { m_pXRenderFormat = pXRenderFormat; }
93  const SalColormap& GetColormap() const { return *m_pColormap; }
94 
96  inline Pixel GetPixel( Color nColor ) const;
97 
98  const SalX11Screen& GetScreenNumber() const { return m_nXScreen; }
99 
100  // override all pure virtual methods
101  virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
102  virtual sal_uInt16 GetBitCount() const override;
103  virtual long GetGraphicsWidth() const override;
104 
105  virtual void ResetClipRegion() override;
106  virtual bool setClipRegion( const vcl::Region& ) override;
107 
108  virtual void SetLineColor() override;
109  virtual void SetLineColor( Color nColor ) override;
110  virtual void SetFillColor() override;
111 
112  virtual void SetFillColor( Color nColor ) override;
113 
114  virtual void SetXORMode( bool bSet, bool ) override;
115 
116  virtual void SetROPLineColor( SalROPColor nROPColor ) override;
117  virtual void SetROPFillColor( SalROPColor nROPColor ) override;
118 
119  virtual void SetTextColor( Color nColor ) override;
120  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
121  virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) override;
122  virtual FontCharMapRef GetFontCharMap() const override;
123  virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override;
124  virtual void GetDevFontList( PhysicalFontCollection* ) override;
125  virtual void ClearDevFontCache() override;
126  virtual bool AddTempDevFont( PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
127 
128  virtual bool CreateFontSubset(
129  const OUString& rToFile,
130  const PhysicalFontFace*,
131  const sal_GlyphId* pGlyphIDs,
132  const sal_uInt8* pEncoding,
133  sal_Int32* pWidths,
134  int nGlyphs,
135  FontSubsetInfo& rInfo ) override;
136 
137  virtual const void* GetEmbedFontData(const PhysicalFontFace*, long* pDataLen) override;
138  virtual void FreeEmbedFontData( const void* pData, long nDataLen ) override;
139 
140  virtual void GetGlyphWidths(
141  const PhysicalFontFace*,
142  bool bVertical,
143  std::vector< sal_Int32 >& rWidths,
144  Ucs2UIntMap& rUnicodeEnc ) override;
145 
146  virtual std::unique_ptr<GenericSalLayout>
147  GetTextLayout(int nFallbackLevel) override;
148  virtual void DrawTextLayout( const GenericSalLayout& ) override;
149 
150  virtual bool supportsOperation( OutDevSupportType ) const override;
151  virtual void drawPixel( long nX, long nY ) override;
152  virtual void drawPixel( long nX, long nY, Color nColor ) override;
153  virtual void drawLine( long nX1, long nY1, long nX2, long nY2 ) override;
154  virtual void drawRect( long nX, long nY, long nWidth, long nHeight ) override;
155  virtual void drawPolyLine( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
156  virtual void drawPolygon( sal_uInt32 nPoints, const SalPoint* pPtAry ) override;
157 
158  virtual void drawPolyPolygon(
159  sal_uInt32 nPoly,
160  const sal_uInt32* pPoints,
161  PCONSTSALPOINT* pPtAry ) override;
162 
163  virtual bool drawPolyPolygon(
164  const basegfx::B2DHomMatrix& rObjectToDevice,
166  double fTransparency) override;
167 
168  virtual bool drawPolyLine(
169  const basegfx::B2DHomMatrix& rObjectToDevice,
170  const basegfx::B2DPolygon&,
171  double fTransparency,
172  double fLineWidth,
173  const std::vector< double >* pStroke, // MM01
175  css::drawing::LineCap,
176  double fMiterMinimumAngle,
177  bool bPixelSnapHairline) override;
178 
179  virtual bool drawGradient( const tools::PolyPolygon&, const Gradient& ) override;
180 
181 #if 1 // TODO: remove these obsolete methods
182  virtual bool drawPolyLineBezier(
183  sal_uInt32 nPoints,
184  const SalPoint* pPtAry,
185  const PolyFlags* pFlgAry ) override;
186 
187  virtual bool drawPolygonBezier(
188  sal_uInt32 nPoints,
189  const SalPoint* pPtAry,
190  const PolyFlags* pFlgAry ) override;
191 
192  virtual bool drawPolyPolygonBezier(
193  sal_uInt32 nPoly,
194  const sal_uInt32* pPoints,
195  const SalPoint* const* pPtAry,
196  const PolyFlags* const* pFlgAry ) override;
197 #endif
198 
199  virtual void copyArea(
200  long nDestX,
201  long nDestY,
202  long nSrcX,
203  long nSrcY,
204  long nSrcWidth,
205  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( long nX, long nY, long nWidth, long nHeight ) override;
227  virtual Color getPixel( long nX, long nY ) override;
228  virtual void invert( long nX, long nY, long nWidth, long nHeight, SalInvert nFlags ) override;
229  virtual void invert( sal_uInt32 nPoints, const SalPoint* pPtAry, SalInvert nFlags ) override;
230 
231  virtual bool drawEPS( long nX, long nY, long nWidth, 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) override;
254 
255  virtual bool drawAlphaRect(
256  long nX, long nY, long nWidth,
257  long nHeight, sal_uInt8 nTransparency ) override;
258 
259  virtual SystemGraphicsData GetGraphicsData() const override;
260 
261 #if ENABLE_CAIRO_CANVAS
262  virtual bool SupportsCairo() const override;
263  virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
264  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
265  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const override;
266  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const basegfx::B2ISize& rSize) const override;
267  virtual SystemFontData GetSysFontData( int nFallbackLevel ) const override;
268 
269  void clipRegion(cairo_t* cr);
270 #endif // ENABLE_CAIRO_CANVAS
271 
272  /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
273  * if pFrame is not NULL, corresponding Paint events are generated
274  * and dispatched to pFrame
275  *
276  * it is imperative to eat up graphics exposes even in case you don't need
277  * them because the next one using XCopyArea can depend on them
278  */
279  void YieldGraphicsExpose();
280 
282  static void releaseCairoContext(cairo_t* cr);
283 
284 
285 private:
287  void SetClipRegion( GC pGC, Region pXReg = nullptr ) const;
288  bool GetDitherPixmap ( Color nColor );
289 
291 
292  void freeResources();
293 
294  SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL
295  SalVirtualDevice* m_pVDev; // the SalVirtualDevice which created this Graphics or NULL
296 
298  std::unique_ptr<SalColormap> m_pDeleteColormap;
299  Drawable hDrawable_; // use
301  mutable XRenderPictFormat* m_pXRenderFormat;
303 
304  Region mpClipRegion;
305 #if ENABLE_CAIRO_CANVAS
306  vcl::Region maClipRegion;
307  Color mnPenColor;
308  Color mnFillColor;
309 #endif // ENABLE_CAIRO_CANVAS
310 
312 
313  Pixmap hBrush_; // Dither
314 
315  bool bWindow_ : 1; // is Window
316  bool bVirDev_ : 1; // is VirDev
317  bool m_bOpenGL : 1;
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 #endif // INCLUDED_VCL_INC_UNX_SALGDI_H
339 
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface used to share logic on sizing between SalVirtualDevices and SalFrames.
Definition: salgeom.hxx:62
std::unique_ptr< SalGraphicsImpl > mxImpl
Definition: unx/salgdi.h:321
virtual SystemGraphicsData GetGraphicsData() const override
void SetXRenderFormat(XRenderPictFormat *pXRenderFormat)
Definition: unx/salgdi.h:92
void SetDrawable(Drawable d, SalX11Screen nXScreen)
SalROPColor
Definition: salgtype.hxx:80
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()
virtual void ResetClipRegion() override
void freeResources()
virtual bool drawPolygonBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry) 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
XID m_aXRenderPicture
Definition: unx/salgdi.h:302
std::unique_ptr< SalColormap > m_pDeleteColormap
Definition: unx/salgdi.h:298
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override
virtual void drawRect(long nX, long nY, long nWidth, long nHeight) override
sal_uInt16 sal_GlyphId
Definition: glyphitem.hxx:26
OutDevSupportType
Definition: vclenum.hxx:198
virtual void SetLineColor() override
Drawable hDrawable_
Definition: unx/salgdi.h:299
virtual bool AddTempDevFont(PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName) override
XRenderPictFormat * m_pXRenderFormat
Definition: unx/salgdi.h:301
virtual bool supportsOperation(OutDevSupportType) const override
virtual bool drawAlphaRect(long nX, long nY, long nWidth, long nHeight, sal_uInt8 nTransparency) override
Render solid rectangle with given transparency.
cairo_t * getCairoContext()
virtual void copyArea(long nDestX, long nDestY, long nSrcX, long nSrcY, long nSrcWidth, long nSrcHeight, bool bWindowInvalidate) override
SalFrame * m_pFrame
Definition: unx/salgdi.h:294
virtual void FreeEmbedFontData(const void *pData, long nDataLen) override
virtual void SetROPLineColor(SalROPColor nROPColor) override
virtual std::shared_ptr< SalBitmap > getBitmap(long nX, long nY, long nWidth, long nHeight) override
const SalColormap & GetColormap() const
Definition: unx/salgdi.h:93
void DrawBitmap(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, const OutputDevice *pOutDev)
virtual void clipRegion(cairo_t *cr) override
bool GetDitherPixmap(Color nColor)
virtual bool drawTransformedBitmap(const basegfx::B2DPoint &rNull, const basegfx::B2DPoint &rX, const basegfx::B2DPoint &rY, const SalBitmap &rSourceBitmap, const SalBitmap *pAlphaBitmap) override
draw transformed bitmap (maybe with alpha) where Null, X, Y define the coordinate system ...
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:89
virtual void invert(long nX, long nY, long nWidth, long nHeight, SalInvert nFlags) override
virtual bool drawPolyLineBezier(sal_uInt32 nPoints, const SalPoint *pPtAry, const PolyFlags *pFlgAry) override
virtual void drawPixel(long nX, long nY) override
virtual void copyBits(const SalTwoRect &rPosAry, SalGraphics *pSrcGraphics) override
Display * GetXDisplay() const
Definition: saldisp.hxx:395
Pixmap hBrush_
Definition: unx/salgdi.h:313
virtual Color getPixel(long nX, long nY) override
static void releaseCairoContext(cairo_t *cr)
virtual SalGraphicsImpl * GetImpl() const override
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel) override
virtual void drawPolygon(sal_uInt32 nPoints, const SalPoint *pPtAry) override
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
virtual void drawLine(long nX1, long nY1, long nX2, long nY2) override
virtual void GetGlyphWidths(const PhysicalFontFace *, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc) override
SalInvert
Definition: salgtype.hxx:84
Display
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
struct _cairo cairo_t
Definition: svpgdi.hxx:70
bool SetClipRegion(const vcl::Region &, const OutputDevice *pOutDev)
Pixel nTextPixel_
Definition: unx/salgdi.h:311
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 DrawTextLayout(const GenericSalLayout &) override
virtual bool drawPolyPolygonBezier(sal_uInt32 nPoly, const sal_uInt32 *pPoints, const SalPoint *const *pPtAry, const PolyFlags *const *pFlgAry) override
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
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:326
Color GetPixel(long nX, long nY, const OutputDevice *pOutDev)
virtual void ClearDevFontCache() override
virtual const void * GetEmbedFontData(const PhysicalFontFace *, long *pDataLen) 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 long GetGraphicsWidth() const 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.
friend class X11SalGraphicsImpl
Definition: unx/salgdi.h:70
Pixel GetPixel(Color nColor) const
SalGeometryProvider * GetGeometryProvider() const
virtual bool drawEPS(long nX, long nY, long nWidth, long nHeight, void *pPtr, sal_uInt32 nSize) override
virtual bool setClipRegion(const vcl::Region &) override
virtual void SetTextColor(Color nColor) override
Region mpClipRegion
Definition: unx/salgdi.h:304
Pixel GetPixel(Color nColor) const
Definition: unx/salgdi.h:335
virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override
SalX11Screen m_nXScreen
Definition: unx/salgdi.h:300
virtual void drawPolyPolygon(sal_uInt32 nPoly, const sal_uInt32 *pPoints, PCONSTSALPOINT *pPtAry) 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:62
void Init(SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen)
const SalVisual & GetVisual() const
Definition: saldisp.hxx:143
virtual void drawPolyLine(sal_uInt32 nPoints, const SalPoint *pPtAry) override
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel) override
XRenderPictFormat * GetXRenderFormat() const
SalVirtualDevice * m_pVDev
Definition: unx/salgdi.h:295
PolyFlags
const SalColormap * m_pColormap
Definition: unx/salgdi.h:297
const SalX11Screen & GetScreenNumber() const
Definition: unx/salgdi.h:98