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