diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-05 10:25:43 +0000 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-06 12:06:30 +0200 |
commit | 8fdb37119f6db7f7fa5af1644e15347f17e5968e (patch) | |
tree | a45d779da39ae6b3e24519b3cb55fa12260bf0ec /vcl/inc/unx | |
parent | ede39d78282484650796456327a35a879a475cef (diff) |
Add GlyphCache instance to GenericUnixSalData
This gets rid of some statics and drops some duplicate code:
- the X11 based GlyphCache => gone
- the svp version of the GlyphCache => gone
- the "normal" GlyphCache
- the PrintFontManager
And while at it move the implementation into its own file
gendata.cxx.
Change-Id: I9063139c9482f5f37285505f389cf5f32c02426b
Reviewed-on: https://gerrit.libreoffice.org/61454
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/inc/unx')
-rw-r--r-- | vcl/inc/unx/gendata.hxx | 73 | ||||
-rw-r--r-- | vcl/inc/unx/glyphcache.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/unx/x11/xrender_peer.hxx | 166 |
3 files changed, 217 insertions, 24 deletions
diff --git a/vcl/inc/unx/gendata.hxx b/vcl/inc/unx/gendata.hxx index c2ac8b1b6fa4..12824fb8bc69 100644 --- a/vcl/inc/unx/gendata.hxx +++ b/vcl/inc/unx/gendata.hxx @@ -16,59 +16,86 @@ #include <memory> +class GlyphCache; class SalGenericDisplay; -namespace psp { class PrintFontManager; } +namespace psp +{ +class PrintFontManager; +} -enum GenericUnixSalDataType { SAL_DATA_GTK, SAL_DATA_GTK3, - SAL_DATA_KDE4, SAL_DATA_KDE5, - SAL_DATA_UNX, SAL_DATA_SVP, - SAL_DATA_ANDROID, SAL_DATA_IOS, - SAL_DATA_HEADLESS, SAL_DATA_QT5 }; +enum GenericUnixSalDataType +{ + SAL_DATA_GTK, + SAL_DATA_GTK3, + SAL_DATA_KDE4, + SAL_DATA_KDE5, + SAL_DATA_UNX, + SAL_DATA_SVP, + SAL_DATA_ANDROID, + SAL_DATA_IOS, + SAL_DATA_HEADLESS, + SAL_DATA_QT5 +}; class VCL_DLLPUBLIC GenericUnixSalData : public SalData { - protected: +private: GenericUnixSalDataType const m_eType; - SalGenericDisplay *m_pDisplay; + SalGenericDisplay* m_pDisplay; // cached hostname to avoid slow lookup - OUString m_aHostname; + OUString m_aHostname; // for transient storage of unicode strings eg. 'u123' by input methods - OUString m_aUnicodeEntry; + OUString m_aUnicodeEntry; - friend class psp::PrintFontManager; + std::unique_ptr<GlyphCache> m_pGlyphCache; std::unique_ptr<psp::PrintFontManager> m_pPrintFontManager; - public: - GenericUnixSalData(GenericUnixSalDataType const t, SalInstance *const pInstance); + void InitGlyphCache(); + void InitPrintFontManager(); + +public: + GenericUnixSalData(GenericUnixSalDataType const t, SalInstance* const pInstance); virtual ~GenericUnixSalData() override; virtual void Dispose() {} - SalGenericDisplay *GetDisplay() const { return m_pDisplay; } - void SetDisplay( SalGenericDisplay *pDisp ) { m_pDisplay = pDisp; } + SalGenericDisplay* GetDisplay() const { return m_pDisplay; } + void SetDisplay(SalGenericDisplay* pDisp) { m_pDisplay = pDisp; } const OUString& GetHostname() { if (m_aHostname.isEmpty()) - osl_getLocalHostname( &m_aHostname.pData ); + osl_getLocalHostname(&m_aHostname.pData); return m_aHostname; } - OUString &GetUnicodeCommand() + + OUString& GetUnicodeCommand() { return m_aUnicodeEntry; } + + GenericUnixSalDataType GetType() const { return m_eType; } + + GlyphCache* GetGlyphCache() { - return m_aUnicodeEntry; + if (!m_pGlyphCache) + InitGlyphCache(); + return m_pGlyphCache.get(); } - GenericUnixSalDataType GetType() const + + psp::PrintFontManager* GetPrintFontManager() { - return m_eType; + if (!m_pPrintFontManager) + InitPrintFontManager(); + // PrintFontManager needs the GlyphCache + assert(m_pGlyphCache.get()); + return m_pPrintFontManager.get(); } // Mostly useful for remote protocol backends virtual void ErrorTrapPush() = 0; - virtual bool ErrorTrapPop( bool bIgnoreError = true ) = 0; // true on error + virtual bool ErrorTrapPop(bool bIgnoreError = true) = 0; // true on error }; -inline GenericUnixSalData * GetGenericUnixSalData() +inline GenericUnixSalData* GetGenericUnixSalData() { - return static_cast<GenericUnixSalData *>(ImplGetSVData()->mpSalData); + return static_cast<GenericUnixSalData*>(ImplGetSVData()->mpSalData); } #endif diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx index 561029b67bbd..446acc2944af 100644 --- a/vcl/inc/unx/glyphcache.hxx +++ b/vcl/inc/unx/glyphcache.hxx @@ -50,7 +50,7 @@ class SvpGcpHelper; namespace basegfx { class B2DPolyPolygon; } namespace vcl { struct FontCapabilities; } -class VCL_DLLPUBLIC GlyphCache +class VCL_DLLPUBLIC GlyphCache final { public: explicit GlyphCache(); diff --git a/vcl/inc/unx/x11/xrender_peer.hxx b/vcl/inc/unx/x11/xrender_peer.hxx new file mode 100644 index 000000000000..05312bfcb3e5 --- /dev/null +++ b/vcl/inc/unx/x11/xrender_peer.hxx @@ -0,0 +1,166 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX +#define INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +struct _XTrap; // on some older systems this is not declared within Xrender.h +#include <X11/extensions/Xrender.h> + +#include <vcl/salgtype.hxx> +#include <osl/module.h> + + +class XRenderPeer +{ +public: + static XRenderPeer& GetInstance(); + +private: + XRenderPeer(); + void InitRenderLib(); + + Display* const mpDisplay; + XRenderPictFormat* mpStandardFormatA8; + +public: + XRenderPictFormat* GetStandardFormatA8() const; + XRenderPictFormat* FindStandardFormat(int nFormat) const; + + // the methods below are thin wrappers for the XRENDER API + XRenderPictFormat* FindVisualFormat( Visual const * ) const; + Picture CreatePicture( Drawable, const XRenderPictFormat*, + unsigned long nDrawable, const XRenderPictureAttributes* ) const; + void ChangePicture( Picture, unsigned long nValueMask, + const XRenderPictureAttributes* ) const; + void SetPictureClipRegion( Picture, Region ) const; + void CompositePicture( int nOp, Picture aSrc, Picture aMask, Picture aDst, + int nXSrc, int nYSrc, + int nXDst, int nYDst, unsigned nWidth, unsigned nHeight ) const; + void FreePicture( Picture ) const; + + void FillRectangle( int nOp, Picture aDst, const XRenderColor*, + int nX, int nY, unsigned nW, unsigned nH ) const; + void CompositeTrapezoids( int nOp, Picture aSrc, Picture aDst, + const XRenderPictFormat*, int nXSrc, int nYSrc, + const XTrapezoid*, int nCount ) const; + void CompositeTriangles( int nOp, Picture aSrc, Picture aDst, + const XRenderPictFormat*, int nXSrc, int nYSrc, + const XTriangle*, int nCount ) const; +}; + +inline XRenderPictFormat* XRenderPeer::GetStandardFormatA8() const +{ + return mpStandardFormatA8; +} + +inline XRenderPictFormat* XRenderPeer::FindStandardFormat(int nFormat) const +{ + return XRenderFindStandardFormat(mpDisplay, nFormat); +} + +inline XRenderPictFormat* XRenderPeer::FindVisualFormat( Visual const * pVisual ) const +{ + return XRenderFindVisualFormat ( mpDisplay, pVisual ); +} + +inline Picture XRenderPeer::CreatePicture( Drawable aDrawable, + const XRenderPictFormat* pVisFormat, unsigned long nValueMask, + const XRenderPictureAttributes* pRenderAttr ) const +{ + return XRenderCreatePicture( mpDisplay, aDrawable, pVisFormat, + nValueMask, pRenderAttr ); +} + +inline void XRenderPeer::ChangePicture( Picture aPicture, + unsigned long nValueMask, const XRenderPictureAttributes* pRenderAttr ) const +{ + XRenderChangePicture( mpDisplay, aPicture, nValueMask, pRenderAttr ); +} + +inline void XRenderPeer::SetPictureClipRegion( Picture aPicture, + Region aXlibRegion ) const +{ + XRenderSetPictureClipRegion( mpDisplay, aPicture, aXlibRegion ); +} + +inline void XRenderPeer::CompositePicture( int nXRenderOp, + Picture aSrcPic, Picture aMaskPic, Picture aDstPic, + int nSrcX, int nSrcY, int nDstX, int nDstY, + unsigned nWidth, unsigned nHeight ) const +{ + XRenderComposite( mpDisplay, nXRenderOp, aSrcPic, aMaskPic, aDstPic, + nSrcX, nSrcY, 0/*nMaskX*/, 0/*nMaskY*/, nDstX, nDstY, nWidth, nHeight ); +} + +inline void XRenderPeer::FreePicture( Picture aPicture ) const +{ + XRenderFreePicture( mpDisplay, aPicture ); +} + +inline void XRenderPeer::FillRectangle( int a, Picture b, const XRenderColor* c, + int d, int e, unsigned int f, unsigned int g) const +{ + XRenderFillRectangle( mpDisplay, a, b, c, d, e, f, g ); +} + +inline void XRenderPeer::CompositeTrapezoids( int nOp, + Picture aSrc, Picture aDst, const XRenderPictFormat* pXRPF, + int nXSrc, int nYSrc, const XTrapezoid* pXT, int nCount ) const +{ + XRenderCompositeTrapezoids( mpDisplay, nOp, aSrc, aDst, pXRPF, + nXSrc, nYSrc, pXT, nCount ); +} + +inline void XRenderPeer::CompositeTriangles( int nOp, + Picture aSrc, Picture aDst, const XRenderPictFormat* pXRPF, + int nXSrc, int nYSrc, const XTriangle* pXT, int nCount ) const +{ + XRenderCompositeTriangles( mpDisplay, nOp, aSrc, aDst, pXRPF, + nXSrc, nYSrc, pXT, nCount ); +} + +inline XRenderColor GetXRenderColor( Color rColor, double fTransparency ) +{ + XRenderColor aRetVal; + // convert the Color + aRetVal.red = rColor.GetRed(); aRetVal.red |= (aRetVal.red << 8); + aRetVal.green = rColor.GetGreen(); aRetVal.green |= (aRetVal.green << 8); + aRetVal.blue = rColor.GetBlue(); aRetVal.blue |= (aRetVal.blue << 8); + + // handle transparency + aRetVal.alpha = 0xFFFF; // default to opaque + if( fTransparency != 0 ) + { + const double fAlpha = 1.0 - fTransparency; + aRetVal.alpha = static_cast<sal_uInt16>(fAlpha * 0xFFFF + 0.5); + // xrender wants pre-multiplied colors + aRetVal.red = static_cast<sal_uInt16>(fAlpha * aRetVal.red + 0.5); + aRetVal.green = static_cast<sal_uInt16>(fAlpha * aRetVal.green + 0.5); + aRetVal.blue = static_cast<sal_uInt16>(fAlpha * aRetVal.blue + 0.5); + } + + return aRetVal; +} + +#endif // INCLUDED_VCL_UNX_X11_XRENDER_PEER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |