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( SalColor nSalColor
) 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( SalColor nSalColor
) override
;
108 virtual void SetFillColor() override
;
110 virtual void SetFillColor( SalColor nSalColor
) 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( SalColor nSalColor
) override
;
118 virtual void SetFont( 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 SalLayout
* GetTextLayout( ImplLayoutArgs
&, int nFallbackLevel
) override
;
147 virtual void DrawTextLayout( const CommonSalLayout
& ) override
;
149 virtual bool supportsOperation( OutDevSupportType
) const override
;
150 virtual void drawPixel( long nX
, long nY
) override
;
151 virtual void drawPixel( long nX
, long nY
, SalColor nSalColor
) override
;
152 virtual void drawLine( long nX1
, long nY1
, long nX2
, long nY2
) override
;
153 virtual void drawRect( long nX
, long nY
, long nWidth
, long nHeight
) override
;
154 virtual void drawPolyLine( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
155 virtual void drawPolygon( sal_uInt32 nPoints
, const SalPoint
* pPtAry
) override
;
157 virtual void drawPolyPolygon(
159 const sal_uInt32
* pPoints
,
160 PCONSTSALPOINT
* pPtAry
) override
;
162 virtual bool drawPolyPolygon( const basegfx::B2DPolyPolygon
&, double fTransparency
) override
;
164 virtual bool drawPolyLine(
165 const basegfx::B2DPolygon
&,
166 double fTransparency
,
167 const basegfx::B2DVector
& rLineWidth
,
168 basegfx::B2DLineJoin
,
169 css::drawing::LineCap
,
170 double fMiterMinimumAngle
) override
;
172 virtual bool drawGradient( const tools::PolyPolygon
&, const Gradient
& ) override
;
174 #if 1 // TODO: remove these obsolete methods
175 virtual bool drawPolyLineBezier(
177 const SalPoint
* pPtAry
,
178 const PolyFlags
* pFlgAry
) override
;
180 virtual bool drawPolygonBezier(
182 const SalPoint
* pPtAry
,
183 const PolyFlags
* pFlgAry
) override
;
185 virtual bool drawPolyPolygonBezier(
187 const sal_uInt32
* pPoints
,
188 const SalPoint
* const* pPtAry
,
189 const PolyFlags
* const* pFlgAry
) override
;
192 virtual void copyArea(
199 bool bWindowInvalidate
) override
;
201 virtual void copyBits(
202 const SalTwoRect
& rPosAry
,
203 SalGraphics
* pSrcGraphics
) override
;
205 virtual void drawBitmap(
206 const SalTwoRect
& rPosAry
,
207 const SalBitmap
& rSalBitmap
) override
;
209 virtual void drawBitmap(
210 const SalTwoRect
& rPosAry
,
211 const SalBitmap
& rSalBitmap
,
212 const SalBitmap
& rMaskBitmap
) override
;
214 virtual void drawMask(
215 const SalTwoRect
& rPosAry
,
216 const SalBitmap
& rSalBitmap
,
217 SalColor nMaskColor
) override
;
219 virtual SalBitmap
* getBitmap( long nX
, long nY
, long nWidth
, long nHeight
) override
;
220 virtual SalColor
getPixel( long nX
, long nY
) override
;
221 virtual void invert( long nX
, long nY
, long nWidth
, long nHeight
, SalInvert nFlags
) override
;
222 virtual void invert( sal_uInt32 nPoints
, const SalPoint
* pPtAry
, SalInvert nFlags
) override
;
224 virtual bool drawEPS( long nX
, long nY
, long nWidth
, long nHeight
, void* pPtr
, sal_uIntPtr nSize
) override
;
226 virtual bool blendBitmap(
228 const SalBitmap
& rBitmap
) override
;
230 virtual bool blendAlphaBitmap(
232 const SalBitmap
& rSrcBitmap
,
233 const SalBitmap
& rMaskBitmap
,
234 const SalBitmap
& rAlphaBitmap
) override
;
236 virtual bool drawAlphaBitmap(
238 const SalBitmap
& rSourceBitmap
,
239 const SalBitmap
& rAlphaBitmap
) override
;
241 virtual bool drawTransformedBitmap(
242 const basegfx::B2DPoint
& rNull
,
243 const basegfx::B2DPoint
& rX
,
244 const basegfx::B2DPoint
& rY
,
245 const SalBitmap
& rSourceBitmap
,
246 const SalBitmap
* pAlphaBitmap
) override
;
248 virtual bool drawAlphaRect(
249 long nX
, long nY
, long nWidth
,
250 long nHeight
, sal_uInt8 nTransparency
) override
;
252 virtual SystemGraphicsData
GetGraphicsData() const override
;
254 #if ENABLE_CAIRO_CANVAS
255 virtual bool SupportsCairo() const override
;
256 virtual cairo::SurfaceSharedPtr
CreateSurface(const cairo::CairoSurfaceSharedPtr
& rSurface
) const override
;
257 virtual cairo::SurfaceSharedPtr
CreateSurface(const OutputDevice
& rRefDevice
, int x
, int y
, int width
, int height
) const override
;
258 virtual cairo::SurfaceSharedPtr
CreateBitmapSurface(const OutputDevice
& rRefDevice
, const BitmapSystemData
& rData
, const Size
& rSize
) const override
;
259 virtual css::uno::Any
GetNativeSurfaceHandle(cairo::SurfaceSharedPtr
& rSurface
, const basegfx::B2ISize
& rSize
) const override
;
260 virtual SystemFontData
GetSysFontData( int nFallbackLevel
) const override
;
262 void clipRegion(cairo_t
* cr
);
263 #endif // ENABLE_CAIRO_CANVAS
265 bool TryRenderCachedNativeControl(ControlCacheKey
& aControlCacheKey
,
268 bool RenderAndCacheNativeControl(X11Pixmap
* pPixmap
, X11Pixmap
* pMask
, int nX
, int nY
,
269 ControlCacheKey
& aControlCacheKey
);
271 // fill a pixmap from a screen region
272 void FillPixmapFromScreen( X11Pixmap
* pPixmap
, int nX
, int nY
);
274 // render a pixmap to the screen
275 bool RenderPixmapToScreen( X11Pixmap
* pPixmap
, X11Pixmap
* pMask
, int nX
, int nY
);
278 /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
279 * if pFrame is not NULL, corresponding Paint events are generated
280 * and dispatched to pFrame
282 * it is imperative to eat up graphics exposes even in case you don't need
283 * them because the next one using XCopyArea can depend on them
285 void YieldGraphicsExpose();
287 cairo_t
* getCairoContext();
288 static void releaseCairoContext(cairo_t
* cr
);
291 // do XCopyArea or XGet/PutImage depending on screen numbers
292 // signature is like XCopyArea with screen numbers added
293 static void CopyScreenArea(
295 Drawable aSrc
, SalX11Screen nXScreenSrc
, int nSrcDepth
,
296 Drawable aDest
, SalX11Screen nXScreenDest
, int nDestDepth
,
298 int src_x
, int src_y
,
299 unsigned int w
, unsigned int h
,
300 int dest_x
, int dest_y
);
302 static void releaseGlyphPeer();
305 using SalGraphics::SetClipRegion
;
306 void SetClipRegion( GC pGC
, Region pXReg
= nullptr ) const;
307 bool GetDitherPixmap ( SalColor nSalColor
);
309 using SalGraphics::DrawBitmap
;
313 void freeResources();
316 SalFrame
* m_pFrame
; // the SalFrame which created this Graphics or NULL
317 SalVirtualDevice
* m_pVDev
; // the SalVirtualDevice which created this Graphics or NULL
319 const SalColormap
* m_pColormap
;
320 SalColormap
* m_pDeleteColormap
;
321 Drawable hDrawable_
; // use
322 SalX11Screen m_nXScreen
;
323 mutable XRenderPictFormat
* m_pXRenderFormat
;
324 XID m_aXRenderPicture
;
327 #if ENABLE_CAIRO_CANVAS
328 vcl::Region maClipRegion
;
330 SalColor mnFillColor
;
331 #endif // ENABLE_CAIRO_CANVAS
333 GC pFontGC_
; // Font attributes
336 Pixmap hBrush_
; // Dither
338 bool bWindow_
: 1; // is Window
339 bool bPrinter_
: 1; // is Printer
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( SalColor nSalColor
) const
360 { return GetColormap().GetPixel( nSalColor
); }
362 #endif // INCLUDED_VCL_INC_UNX_SALGDI_H
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */