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 #pragma once
21 
22 #include <sal/config.h>
23 
24 #include <X11/Xlib.h>
25 #include <X11/Xutil.h>
26 #include <X11/extensions/Xrender.h>
27 
28 #include <vcl/salgtype.hxx>
29 #include <vcl/vclenum.hxx>
30 
31 #include <unx/saldisp.hxx>
32 #include <salgdi.hxx>
33 #include <salgeom.hxx>
34 #include <sallayout.hxx>
35 #include <vclpluginapi.h>
36 #include <ControlCacheKey.hxx>
37 
38 #include "saltype.h"
39 #include "saldisp.hxx"
40 
41 #include <memory>
42 
43 /* From <X11/Intrinsic.h> */
44 typedef unsigned long Pixel;
45 
46 class SalBitmap;
47 class SalColormap;
48 class SalDisplay;
49 class SalFrame;
51 class X11SalGraphicsImpl;
53 namespace vcl::font
54 {
55 class PhysicalFontCollection;
56 class PhysicalFontFace;
57 }
58 class SalGraphicsImpl;
59 class TextRenderImpl;
60 
61 namespace basegfx {
62  class B2DTrapezoid;
63 }
64 
65 class X11Common
66 {
67 public:
68  Drawable m_hDrawable;
71 
72  X11Common();
73 
75 
76  static void releaseCairoContext(cairo_t* cr);
77 
78  bool SupportsCairo() const;
79 
80  const SalColormap& GetColormap() const { return *m_pColormap; }
81  const SalDisplay* GetDisplay() const { return GetColormap().GetDisplay(); }
82  const SalVisual& GetVisual() const { return GetColormap().GetVisual(); }
83  Display* GetXDisplay() const { return GetColormap().GetXDisplay(); }
84  Pixel GetPixel(Color nColor) const { return GetColormap().GetPixel(nColor); }
85  Drawable GetDrawable() const { return m_hDrawable; }
86 };
87 
89 {
90  friend class X11SalGraphicsImpl;
91  friend class X11CairoTextRender;
92 
93 public:
95  virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override;
96 
97  void Init( SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen );
98  void Init( X11SalVirtualDevice *pVirtualDevice, cairo_surface_t* pPreExistingTarget = nullptr,
99  SalColormap* pColormap = nullptr, bool bDeleteColormap = false );
100  void Init( X11SkiaSalVirtualDevice *pVirtualDevice );
101  void DeInit();
102 
103  virtual SalGraphicsImpl* GetImpl() const override;
105  void SetDrawable(Drawable d, cairo_surface_t* surface, SalX11Screen nXScreen);
106  XRenderPictFormat* GetXRenderFormat() const;
107  void SetXRenderFormat( XRenderPictFormat* pXRenderFormat ) { m_pXRenderFormat = pXRenderFormat; }
108 
109  const SalX11Screen& GetScreenNumber() const { return m_nXScreen; }
110 
111  void Flush();
112 
113  // override all pure virtual methods
114  virtual void GetResolution( sal_Int32& rDPIX, sal_Int32& rDPIY ) override;
115 
116  virtual void SetTextColor( Color nColor ) override;
117  virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
118  virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) override;
119  virtual FontCharMapRef GetFontCharMap() const override;
120  virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override;
121  virtual void GetDevFontList( vcl::font::PhysicalFontCollection* ) override;
122  virtual void ClearDevFontCache() override;
123  virtual bool AddTempDevFont( vcl::font::PhysicalFontCollection*, const OUString& rFileURL, const OUString& rFontName ) override;
124 
125  virtual bool CreateFontSubset(
126  const OUString& rToFile,
128  const sal_GlyphId* pGlyphIDs,
129  const sal_uInt8* pEncoding,
130  sal_Int32* pWidths,
131  int nGlyphs,
132  FontSubsetInfo& rInfo ) override;
133 
134  virtual const void* GetEmbedFontData(const vcl::font::PhysicalFontFace*, tools::Long* pDataLen) override;
135  virtual void FreeEmbedFontData( const void* pData, tools::Long nDataLen ) override;
136 
137  virtual void GetGlyphWidths(
139  bool bVertical,
140  std::vector< sal_Int32 >& rWidths,
141  Ucs2UIntMap& rUnicodeEnc ) override;
142 
143  virtual std::unique_ptr<GenericSalLayout>
144  GetTextLayout(int nFallbackLevel) override;
145  virtual void DrawTextLayout( const GenericSalLayout& ) override;
146 
147  virtual SystemGraphicsData GetGraphicsData() const override;
148 
149 #if ENABLE_CAIRO_CANVAS
150  virtual bool SupportsCairo() const override;
151  virtual cairo::SurfaceSharedPtr CreateSurface(const cairo::CairoSurfaceSharedPtr& rSurface) const override;
152  virtual cairo::SurfaceSharedPtr CreateSurface(const OutputDevice& rRefDevice, int x, int y, int width, int height) const override;
153  virtual cairo::SurfaceSharedPtr CreateBitmapSurface(const OutputDevice& rRefDevice, const BitmapSystemData& rData, const Size& rSize) const override;
154  virtual css::uno::Any GetNativeSurfaceHandle(cairo::SurfaceSharedPtr& rSurface, const basegfx::B2ISize& rSize) const override;
155 
156  void clipRegion(cairo_t* cr);
157 #endif // ENABLE_CAIRO_CANVAS
158 
159  /* use to handle GraphicsExpose/NoExpose after XCopyArea & friends
160  * if pFrame is not NULL, corresponding Paint events are generated
161  * and dispatched to pFrame
162  *
163  * it is imperative to eat up graphics exposes even in case you don't need
164  * them because the next one using XCopyArea can depend on them
165  */
166  void YieldGraphicsExpose();
167 
169  static void releaseCairoContext(cairo_t* cr);
170 
171 
172 private:
173  using SalGraphics::GetPixel;
174  void SetClipRegion( GC pGC, Region pXReg = nullptr ) const;
175  bool GetDitherPixmap ( Color nColor );
176 
177  void freeResources();
178 
179  SalFrame* m_pFrame; // the SalFrame which created this Graphics or NULL
180  SalVirtualDevice* m_pVDev; // the SalVirtualDevice which created this Graphics or NULL
181 
182 
183  std::unique_ptr<SalColormap> m_pDeleteColormap;
184 
186  mutable XRenderPictFormat* m_pXRenderFormat;
188 
189  Region mpClipRegion;
190  Pixmap hBrush_; // Dither
191 
192  bool bWindow_ : 1; // is Window
193  bool bVirDev_ : 1; // is VirDev
194 
195  std::unique_ptr<SalGraphicsImpl> mxImpl;
196  std::unique_ptr<TextRenderImpl> mxTextRenderImpl;
198 
199 public:
200  Drawable GetDrawable() const { return maX11Common.GetDrawable(); }
201  const SalColormap& GetColormap() const { return maX11Common.GetColormap(); }
202  const SalDisplay* GetDisplay() const { return maX11Common.GetDisplay(); }
203  const SalVisual& GetVisual() const { return maX11Common.GetVisual(); }
204  Display* GetXDisplay() const { return maX11Common.GetXDisplay(); }
205  Pixel GetPixel(Color nColor) const { return maX11Common.GetPixel(nColor); }
206 };
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Interface used to share logic on sizing between SalVirtualDevices and SalFrames.
Definition: salgeom.hxx:109
std::unique_ptr< SalGraphicsImpl > mxImpl
Definition: unx/salgdi.h:195
Display * GetXDisplay() const
Definition: unx/salgdi.h:204
virtual SystemGraphicsData GetGraphicsData() const override
void SetXRenderFormat(XRenderPictFormat *pXRenderFormat)
Definition: unx/salgdi.h:107
struct _cairo cairo_t
Definition: CairoCommon.hxx:71
void YieldGraphicsExpose()
const SalVisual & GetVisual() const
Definition: unx/salgdi.h:82
long Long
void freeResources()
void SetDrawable(Drawable d, cairo_surface_t *surface, SalX11Screen nXScreen)
virtual void GetDevFontList(vcl::font::PhysicalFontCollection *) override
std::unique_ptr< TextRenderImpl > mxTextRenderImpl
Definition: unx/salgdi.h:196
X11Common maX11Common
Definition: unx/salgdi.h:197
XID m_aXRenderPicture
Definition: unx/salgdi.h:187
std::unique_ptr< SalColormap > m_pDeleteColormap
Definition: unx/salgdi.h:183
const SalDisplay * GetDisplay() const
Definition: unx/salgdi.h:202
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const override
const SalDisplay * GetDisplay() const
Definition: unx/salgdi.h:81
sal_uInt16 sal_GlyphId
Definition: glyphid.hxx:24
const SalColormap * m_pColormap
Definition: unx/salgdi.h:69
XRenderPictFormat * m_pXRenderFormat
Definition: unx/salgdi.h:186
static void releaseCairoContext(cairo_t *cr)
Display * GetXDisplay() const
Definition: unx/salgdi.h:83
cairo_t * getCairoContext()
Drawable GetDrawable() const
Definition: unx/salgdi.h:85
bool SupportsCairo() const
SalFrame * m_pFrame
Definition: unx/salgdi.h:179
const SalColormap & GetColormap() const
Definition: unx/salgdi.h:201
virtual void clipRegion(cairo_t *cr) override
bool GetDitherPixmap(Color nColor)
std::shared_ptr< Surface > SurfaceSharedPtr
Definition: cairo.hxx:36
virtual FontCharMapRef GetFontCharMap() const override
Drawable GetDrawable() const
Definition: unx/salgdi.h:200
Display * GetXDisplay() const
Definition: saldisp.hxx:395
const SalVisual & GetVisual() const
Definition: unx/salgdi.h:203
Pixmap hBrush_
Definition: unx/salgdi.h:190
virtual void GetGlyphWidths(const vcl::font::PhysicalFontFace *, bool bVertical, std::vector< sal_Int32 > &rWidths, Ucs2UIntMap &rUnicodeEnc) override
static void releaseCairoContext(cairo_t *cr)
virtual SalGraphicsImpl * GetImpl() const override
virtual void GetFontMetric(ImplFontMetricDataRef &, int nFallbackLevel) override
Drawable m_hDrawable
Definition: unx/salgdi.h:68
A PhysicalFontFaceCollection is created by a PhysicalFontCollection and becomes invalid when original...
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:175
virtual void FreeEmbedFontData(const void *pData, tools::Long nDataLen) override
Display
cairo_t * getCairoContext()
std::shared_ptr< cairo_surface_t > CairoSurfaceSharedPtr
Definition: cairo.hxx:34
Pixel GetPixel(Color nColor) const
Definition: unx/salgdi.h:84
virtual void SetFont(LogicalFontInstance *, int nFallbackLevel) override
abstract base class for physical font faces
cairo_surface_t * m_pExternalSurface
Definition: unx/salgdi.h:70
virtual void DrawTextLayout(const GenericSalLayout &) override
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
void SetClipRegion(GC pGC, Region pXReg=nullptr) const
unsigned long Pixel
Definition: saldisp.hxx:48
const SalDisplay * GetDisplay() const
Definition: saldisp.hxx:142
unsigned char sal_uInt8
virtual void ClearDevFontCache() override
A non-visible drawable/buffer (e.g. an X11 Pixmap).
Definition: salvd.hxx:28
virtual void GetResolution(sal_Int32 &rDPIX, sal_Int32 &rDPIY) override
friend class X11SalGraphicsImpl
Definition: unx/salgdi.h:90
Pixel GetPixel(Color nColor) const
virtual bool AddTempDevFont(vcl::font::PhysicalFontCollection *, const OUString &rFileURL, const OUString &rFontName) override
SalGeometryProvider * GetGeometryProvider() const
virtual void SetTextColor(Color nColor) override
Pixel GetPixel(Color nColor) const
Definition: unx/salgdi.h:205
Region mpClipRegion
Definition: unx/salgdi.h:189
Color GetPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
virtual ~X11SalGraphics() COVERITY_NOEXCEPT_FALSE override
SalX11Screen m_nXScreen
Definition: unx/salgdi.h:185
unsigned long Pixel
Definition: unx/salgdi.h:44
const SalColormap & GetColormap() const
Definition: unx/salgdi.h:80
std::map< sal_Ucs, sal_uInt32 > Ucs2UIntMap
Definition: salgdi.hxx:66
virtual const void * GetEmbedFontData(const vcl::font::PhysicalFontFace *, tools::Long *pDataLen) override
void Init(SalFrame *pFrame, Drawable aDrawable, SalX11Screen nXScreen)
const SalVisual & GetVisual() const
Definition: saldisp.hxx:144
virtual std::unique_ptr< GenericSalLayout > GetTextLayout(int nFallbackLevel) override
struct _cairo_surface cairo_surface_t
Definition: CairoCommon.hxx:72
XRenderPictFormat * GetXRenderFormat() const
Implementation class for SalGraphics.
Definition: salgdiimpl.hxx:50
SalVirtualDevice * m_pVDev
Definition: unx/salgdi.h:180
virtual bool CreateFontSubset(const OUString &rToFile, const vcl::font::PhysicalFontFace *, const sal_GlyphId *pGlyphIDs, const sal_uInt8 *pEncoding, sal_Int32 *pWidths, int nGlyphs, FontSubsetInfo &rInfo) override
const SalX11Screen & GetScreenNumber() const
Definition: unx/salgdi.h:109