1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_UNX_SALGDI_H
21 #define INCLUDED_VCL_INC_UNX_SALGDI_H
24 #include <X11/Xutil.h>
25 #include <X11/extensions/Xrender.h>
27 #include <tools/fract.hxx>
29 #include <vcl/salgtype.hxx>
30 #include <vcl/vclenum.hxx>
31 #include <vcl/metric.hxx>
34 #include <salgeom.hxx>
35 #include <sallayout.hxx>
36 #include <vclpluginapi.h>
37 #include <ControlCacheKey.hxx>
42 /* From <X11/Intrinsic.h> */
43 typedef unsigned long Pixel
;
46 class FontSelectPattern
;
52 class X11SalVirtualDevice
;
53 class X11SalGraphicsImpl
;
54 class X11OpenGLSalGraphicsImpl
;
55 class X11OpenGLSalVirtualDevice
;
58 class PhysicalFontCollection
;
59 class PhysicalFontFace
;
60 class SalGraphicsImpl
;
67 class VCLPLUG_GEN_PUBLIC X11SalGraphics
: public SalGraphics
69 friend class X11SalGraphicsImpl
;
70 friend class X11OpenGLSalGraphicsImpl
;
71 friend class X11CairoTextRender
;
75 virtual ~X11SalGraphics() override
;
77 void Init( SalFrame
*pFrame
, Drawable aDrawable
, SalX11Screen nXScreen
);
78 void Init( X11SalVirtualDevice
*pVirtualDevice
, SalColormap
* pColormap
= nullptr, bool bDeleteColormap
= false );
79 void Init( X11OpenGLSalVirtualDevice
*pVirtualDevice
);
82 virtual SalGraphicsImpl
* GetImpl() const override
;
83 inline const SalDisplay
* GetDisplay() const;
84 inline Display
* GetXDisplay() const;
85 inline const SalVisual
& GetVisual() const;
86 SalGeometryProvider
* GetGeometryProvider() const;
87 Drawable
GetDrawable() const { return hDrawable_
; }
88 void SetDrawable( Drawable d
, SalX11Screen nXScreen
);
89 XRenderPictFormat
* GetXRenderFormat() const;
90 void SetXRenderFormat( XRenderPictFormat
* pXRenderFormat
) { m_pXRenderFormat
= pXRenderFormat
; }
91 const SalColormap
& GetColormap() const { return *m_pColormap
; }
93 using SalGraphics::GetPixel
;
94 inline Pixel
GetPixel( Color nColor
) const;
96 const SalX11Screen
& GetScreenNumber() const { return m_nXScreen
; }
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 long GetGraphicsWidth() const override
;
103 virtual void ResetClipRegion() override
;
104 virtual bool setClipRegion( const vcl::Region
& ) override
;
106 virtual void SetLineColor() override
;
107 virtual void SetLineColor( Color nColor
) override
;
108 virtual void SetFillColor() override
;
110 virtual void SetFillColor( Color nColor
) override
;
112 virtual void SetXORMode( bool bSet
) override
;
114 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
115 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
117 virtual void SetTextColor( Color nColor
) override
;
118 virtual void SetFont( const FontSelectPattern
*, int nFallbackLevel
) override
;
119 virtual void GetFontMetric( ImplFontMetricDataRef
&, int nFallbackLevel
) override
;
120 virtual const FontCharMapRef
GetFontCharMap() const override
;
121 virtual bool GetFontCapabilities(vcl::FontCapabilities
&rFontCapabilities
) const override
;
122 virtual void GetDevFontList( PhysicalFontCollection
* ) override
;
123 virtual void ClearDevFontCache() override
;
124 virtual bool AddTempDevFont( PhysicalFontCollection
*, const OUString
& rFileURL
, const OUString
& rFontName
) override
;
126 virtual bool CreateFontSubset(
127 const OUString
& rToFile
,
128 const PhysicalFontFace
*,
129 const sal_GlyphId
* pGlyphIDs
,
130 const sal_uInt8
* pEncoding
,
133 FontSubsetInfo
& rInfo
) override
;
135 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, long* pDataLen
) override
;
136 virtual void FreeEmbedFontData( const void* pData
, long nDataLen
) override
;
138 virtual void GetGlyphWidths(
139 const PhysicalFontFace
*,
141 std::vector
< sal_Int32
>& rWidths
,
142 Ucs2UIntMap
& rUnicodeEnc
) override
;
144 virtual bool GetGlyphBoundRect(const GlyphItem
&, tools::Rectangle
&) override
;
145 virtual bool GetGlyphOutline(const GlyphItem
&, basegfx::B2DPolyPolygon
&) override
;
146 virtual std::unique_ptr
<SalLayout
>
147 GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) override
;
148 virtual void DrawTextLayout( const GenericSalLayout
& ) override
;
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
;
158 virtual void drawPolyPolygon(
160 const sal_uInt32
* pPoints
,
161 PCONSTSALPOINT
* pPtAry
) override
;
163 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
165 virtual bool drawPolyLine(
166 const basegfx::B2DPolygon
&,
167 double fTransparency
,
168 const basegfx::B2DVector
& rLineWidth
,
169 basegfx::B2DLineJoin
,
170 css::drawing::LineCap
,
171 double fMiterMinimumAngle
) override
;
173 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
;
175 #if 1 // TODO: remove these obsolete methods
176 virtual bool drawPolyLineBezier(
178 const SalPoint
* pPtAry
,
179 const PolyFlags
* pFlgAry
) override
;
181 virtual bool drawPolygonBezier(
183 const SalPoint
* pPtAry
,
184 const PolyFlags
* pFlgAry
) override
;
186 virtual bool drawPolyPolygonBezier(
188 const sal_uInt32
* pPoints
,
189 const SalPoint
* const* pPtAry
,
190 const PolyFlags
* const* pFlgAry
) override
;
193 virtual void copyArea(
200 bool bWindowInvalidate
) override
;
202 virtual void copyBits(
203 const SalTwoRect
& rPosAry
,
204 SalGraphics
* pSrcGraphics
) override
;
206 virtual void drawBitmap(
207 const SalTwoRect
& rPosAry
,
208 const SalBitmap
& rSalBitmap
) override
;
210 virtual void drawBitmap(
211 const SalTwoRect
& rPosAry
,
212 const SalBitmap
& rSalBitmap
,
213 const SalBitmap
& rMaskBitmap
) override
;
215 virtual void drawMask(
216 const SalTwoRect
& rPosAry
,
217 const SalBitmap
& rSalBitmap
,
218 Color nMaskColor
) override
;
220 virtual 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
;
225 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uIntPtr nSize
) override
;
227 virtual bool blendBitmap(
229 const SalBitmap
& rBitmap
) override
;
231 virtual bool blendAlphaBitmap(
233 const SalBitmap
& rSrcBitmap
,
234 const SalBitmap
& rMaskBitmap
,
235 const SalBitmap
& rAlphaBitmap
) override
;
237 virtual bool drawAlphaBitmap(
239 const SalBitmap
& rSourceBitmap
,
240 const SalBitmap
& rAlphaBitmap
) override
;
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
;
249 virtual bool drawAlphaRect(
250 long nX
, long nY
, long nWidth
,
251 long nHeight
, sal_uInt8 nTransparency
) override
;
253 virtual SystemGraphicsData
GetGraphicsData() const override
;
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
;
263 void clipRegion(cairo_t
* cr
);
264 #endif // ENABLE_CAIRO_CANVAS
266 bool TryRenderCachedNativeControl(ControlCacheKey
& aControlCacheKey
,
269 bool RenderAndCacheNativeControl(X11Pixmap
* pPixmap
, X11Pixmap
* pMask
, int nX
, int nY
,
270 ControlCacheKey
& aControlCacheKey
);
272 // fill a pixmap from a screen region
273 void FillPixmapFromScreen( X11Pixmap
* pPixmap
, int nX
, int nY
);
275 // render a pixmap to the screen
276 bool RenderPixmapToScreen( X11Pixmap
* pPixmap
, X11Pixmap
* pMask
, int nX
, int nY
);
279 /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
280 * if pFrame is not NULL, corresponding Paint events are generated
281 * and dispatched to pFrame
283 * it is imperative to eat up graphics exposes even in case you don't need
284 * them because the next one using XCopyArea can depend on them
286 void YieldGraphicsExpose();
288 cairo_t
* getCairoContext();
289 static void releaseCairoContext(cairo_t
* cr
);
292 // do XCopyArea or XGet/PutImage depending on screen numbers
293 // signature is like XCopyArea with screen numbers added
294 static void CopyScreenArea(
296 Drawable aSrc
, SalX11Screen nXScreenSrc
, int nSrcDepth
,
297 Drawable aDest
, SalX11Screen nXScreenDest
, int nDestDepth
,
299 int src_x
, int src_y
,
300 unsigned int w
, unsigned int h
,
301 int dest_x
, int dest_y
);
303 static void releaseGlyphPeer();
306 using SalGraphics::SetClipRegion
;
307 void SetClipRegion( GC pGC
, Region pXReg
= nullptr ) const;
308 bool GetDitherPixmap ( Color nColor
);
310 using SalGraphics::DrawBitmap
;
314 void freeResources();
317 SalFrame
* m_pFrame
; // the SalFrame which created this Graphics or NULL
318 SalVirtualDevice
* m_pVDev
; // the SalVirtualDevice which created this Graphics or NULL
320 const SalColormap
* m_pColormap
;
321 std::unique_ptr
<SalColormap
> m_pDeleteColormap
;
322 Drawable hDrawable_
; // use
323 SalX11Screen m_nXScreen
;
324 mutable XRenderPictFormat
* m_pXRenderFormat
;
325 XID m_aXRenderPicture
;
328 #if ENABLE_CAIRO_CANVAS
329 vcl::Region maClipRegion
;
332 #endif // ENABLE_CAIRO_CANVAS
334 GC pFontGC_
; // Font attributes
337 Pixmap hBrush_
; // Dither
339 bool bWindow_
: 1; // is Window
340 bool bVirDev_
: 1; // is VirDev
341 bool bFontGC_
: 1; // is Font GC valid
345 std::unique_ptr
<SalGraphicsImpl
> mxImpl
;
346 std::unique_ptr
<TextRenderImpl
> mxTextRenderImpl
;
350 inline const SalDisplay
*X11SalGraphics::GetDisplay() const
351 { return GetColormap().GetDisplay(); }
353 inline const SalVisual
& X11SalGraphics::GetVisual() const
354 { return GetColormap().GetVisual(); }
356 inline Display
*X11SalGraphics::GetXDisplay() const
357 { return GetColormap().GetXDisplay(); }
359 inline Pixel
X11SalGraphics::GetPixel( Color nColor
) const
360 { return GetColormap().GetPixel( nColor
); }
362 #endif // INCLUDED_VCL_INC_UNX_SALGDI_H
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */