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 <vcl/salgtype.hxx>
28 #include <vcl/vclenum.hxx>
30 #include <unx/saldisp.hxx>
32 #include <salgeom.hxx>
33 #include <sallayout.hxx>
34 #include <vclpluginapi.h>
35 #include <ControlCacheKey.hxx>
38 #include "saldisp.hxx"
42 /* From <X11/Intrinsic.h> */
43 typedef unsigned long Pixel
;
49 class X11SalVirtualDevice
;
50 class X11SalGraphicsImpl
;
51 class X11SkiaSalVirtualDevice
;
52 class PhysicalFontCollection
;
53 class PhysicalFontFace
;
54 class SalGraphicsImpl
;
61 class X11SalGraphics final
: public SalGraphics
63 friend class X11SalGraphicsImpl
;
64 friend class X11CairoTextRender
;
68 virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override
;
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
);
76 virtual SalGraphicsImpl
* GetImpl() const override
;
77 inline const SalDisplay
* GetDisplay() const;
78 inline Display
* GetXDisplay() const;
79 inline const SalVisual
& GetVisual() const;
80 SalGeometryProvider
* GetGeometryProvider() 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
; }
87 using SalGraphics::GetPixel
;
88 inline Pixel
GetPixel( Color nColor
) const;
90 const SalX11Screen
& GetScreenNumber() const { return m_nXScreen
; }
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
;
99 virtual void ResetClipRegion() override
;
100 virtual bool setClipRegion( const vcl::Region
& ) override
;
102 virtual void SetLineColor() override
;
103 virtual void SetLineColor( Color nColor
) override
;
104 virtual void SetFillColor() override
;
106 virtual void SetFillColor( Color nColor
) override
;
108 virtual void SetXORMode( bool bSet
, bool ) override
;
110 virtual void SetROPLineColor( SalROPColor nROPColor
) override
;
111 virtual void SetROPFillColor( SalROPColor nROPColor
) override
;
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
;
122 virtual bool CreateFontSubset(
123 const OUString
& rToFile
,
124 const PhysicalFontFace
*,
125 const sal_GlyphId
* pGlyphIDs
,
126 const sal_uInt8
* pEncoding
,
129 FontSubsetInfo
& rInfo
) override
;
131 virtual const void* GetEmbedFontData(const PhysicalFontFace
*, tools::Long
* pDataLen
) override
;
132 virtual void FreeEmbedFontData( const void* pData
, tools::Long nDataLen
) override
;
134 virtual void GetGlyphWidths(
135 const PhysicalFontFace
*,
137 std::vector
< sal_Int32
>& rWidths
,
138 Ucs2UIntMap
& rUnicodeEnc
) override
;
140 virtual std::unique_ptr
<GenericSalLayout
>
141 GetTextLayout(int nFallbackLevel
) override
;
142 virtual void DrawTextLayout( const GenericSalLayout
& ) override
;
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
;
152 virtual void drawPolyPolygon(
154 const sal_uInt32
* pPoints
,
155 const Point
** pPtAry
) override
;
157 virtual bool drawPolyPolygon(
158 const basegfx::B2DHomMatrix
& rObjectToDevice
,
159 const basegfx::B2DPolyPolygon
&,
160 double fTransparency
) override
;
162 virtual bool drawPolyLine(
163 const basegfx::B2DHomMatrix
& rObjectToDevice
,
164 const basegfx::B2DPolygon
&,
165 double fTransparency
,
167 const std::vector
< double >* pStroke
, // MM01
168 basegfx::B2DLineJoin
,
169 css::drawing::LineCap
,
170 double fMiterMinimumAngle
,
171 bool bPixelSnapHairline
) override
;
173 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
;
174 virtual bool implDrawGradient(basegfx::B2DPolyPolygon
const & rPolyPolygon
,
175 SalGradient
const & rGradient
) override
;
177 #if 1 // TODO: remove these obsolete methods
178 virtual bool drawPolyLineBezier(
181 const PolyFlags
* pFlgAry
) override
;
183 virtual bool drawPolygonBezier(
186 const PolyFlags
* pFlgAry
) override
;
188 virtual bool drawPolyPolygonBezier(
190 const sal_uInt32
* pPoints
,
191 const Point
* const* pPtAry
,
192 const PolyFlags
* const* pFlgAry
) override
;
195 virtual void copyArea(
200 tools::Long nSrcWidth
,
201 tools::Long nSrcHeight
,
202 bool bWindowInvalidate
) override
;
204 virtual void copyBits(
205 const SalTwoRect
& rPosAry
,
206 SalGraphics
* pSrcGraphics
) override
;
208 virtual void drawBitmap(
209 const SalTwoRect
& rPosAry
,
210 const SalBitmap
& rSalBitmap
) override
;
212 virtual void drawBitmap(
213 const SalTwoRect
& rPosAry
,
214 const SalBitmap
& rSalBitmap
,
215 const SalBitmap
& rMaskBitmap
) override
;
217 virtual void drawMask(
218 const SalTwoRect
& rPosAry
,
219 const SalBitmap
& rSalBitmap
,
220 Color nMaskColor
) override
;
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
;
227 virtual bool drawEPS( tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, void* pPtr
, sal_uInt32 nSize
) override
;
229 virtual bool blendBitmap(
231 const SalBitmap
& rBitmap
) override
;
233 virtual bool blendAlphaBitmap(
235 const SalBitmap
& rSrcBitmap
,
236 const SalBitmap
& rMaskBitmap
,
237 const SalBitmap
& rAlphaBitmap
) override
;
239 virtual bool drawAlphaBitmap(
241 const SalBitmap
& rSourceBitmap
,
242 const SalBitmap
& rAlphaBitmap
) override
;
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
;
252 virtual bool hasFastDrawTransformedBitmap() const override
;
254 virtual bool drawAlphaRect(
255 tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
256 tools::Long nHeight
, sal_uInt8 nTransparency
) override
;
258 virtual SystemGraphicsData
GetGraphicsData() const override
;
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
;
267 void clipRegion(cairo_t
* cr
);
268 #endif // ENABLE_CAIRO_CANVAS
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
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
277 void YieldGraphicsExpose();
279 cairo_t
* getCairoContext();
280 static void releaseCairoContext(cairo_t
* cr
);
284 using SalGraphics::SetClipRegion
;
285 void SetClipRegion( GC pGC
, Region pXReg
= nullptr ) const;
286 bool GetDitherPixmap ( Color nColor
);
288 using SalGraphics::DrawBitmap
;
290 void freeResources();
292 SalFrame
* m_pFrame
; // the SalFrame which created this Graphics or NULL
293 SalVirtualDevice
* m_pVDev
; // the SalVirtualDevice which created this Graphics or NULL
295 const SalColormap
* m_pColormap
;
296 std::unique_ptr
<SalColormap
> m_pDeleteColormap
;
297 Drawable hDrawable_
; // use
298 cairo_surface_t
* m_pExternalSurface
;
299 SalX11Screen m_nXScreen
;
300 mutable XRenderPictFormat
* m_pXRenderFormat
;
301 XID m_aXRenderPicture
;
304 #if ENABLE_CAIRO_CANVAS
305 vcl::Region maClipRegion
;
308 #endif // ENABLE_CAIRO_CANVAS
310 Pixmap hBrush_
; // Dither
312 bool bWindow_
: 1; // is Window
313 bool bVirDev_
: 1; // is VirDev
317 std::unique_ptr
<SalGraphicsImpl
> mxImpl
;
318 std::unique_ptr
<TextRenderImpl
> mxTextRenderImpl
;
322 inline const SalDisplay
*X11SalGraphics::GetDisplay() const
323 { return GetColormap().GetDisplay(); }
325 inline const SalVisual
& X11SalGraphics::GetVisual() const
326 { return GetColormap().GetVisual(); }
328 inline Display
*X11SalGraphics::GetXDisplay() const
329 { return GetColormap().GetXDisplay(); }
331 inline Pixel
X11SalGraphics::GetPixel( Color nColor
) const
332 { return GetColormap().GetPixel( nColor
); }
334 #endif // INCLUDED_VCL_INC_UNX_SALGDI_H
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */