diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-05 14:16:23 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-08 22:29:50 +0200 |
commit | c4c56de1b0e62ec866b519b2b24c5e805f0a86d3 (patch) | |
tree | a8a5b3c67b72804a27fd2f1aea39451691a3fa0c /vcl/inc | |
parent | d865866ec5cf6966757c9f2abd24b18a39f2f924 (diff) |
hold LogicalFontInstance with rtl::Reference
instead of manual reference counting.
Also the releasing of not-currently-in-use LogicalFontInstance objects
from the cache is made less aggressive - we now only flush entries until
we have less than CACHE_SIZE instances, instead of flushing the whole
cache.
Change-Id: Ib235b132776b5f09ae8ae93a933c2eebe5fa9610
Reviewed-on: https://gerrit.libreoffice.org/55384
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/PhysicalFontFace.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/fontinstance.hxx | 9 | ||||
-rw-r--r-- | vcl/inc/fontselect.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/impfontcache.hxx | 20 | ||||
-rw-r--r-- | vcl/inc/quartz/salgdi.h | 6 | ||||
-rw-r--r-- | vcl/inc/sallayout.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/salwtype.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/unx/freetype_glyphcache.hxx | 4 | ||||
-rw-r--r-- | vcl/inc/unx/glyphcache.hxx | 5 | ||||
-rw-r--r-- | vcl/inc/win/salgdi.h | 7 | ||||
-rw-r--r-- | vcl/inc/win/winlayout.hxx | 2 |
11 files changed, 25 insertions, 38 deletions
diff --git a/vcl/inc/PhysicalFontFace.hxx b/vcl/inc/PhysicalFontFace.hxx index 2406b6cf41da..e289345716ca 100644 --- a/vcl/inc/PhysicalFontFace.hxx +++ b/vcl/inc/PhysicalFontFace.hxx @@ -54,7 +54,7 @@ public: class VCL_PLUGIN_PUBLIC PhysicalFontFace : public FontAttributes, public salhelper::SimpleReferenceObject { public: - virtual LogicalFontInstance* CreateFontInstance(const FontSelectPattern&) const; + virtual rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const; virtual rtl::Reference<PhysicalFontFace> Clone() const = 0; int GetHeight() const { return mnHeight; } diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx index 317b7181198d..149bb553c3eb 100644 --- a/vcl/inc/fontinstance.hxx +++ b/vcl/inc/fontinstance.hxx @@ -24,6 +24,7 @@ #include "impfontmetricdata.hxx" #include <rtl/ref.hxx> +#include <salhelper/simplereferenceobject.hxx> #include <unordered_map> #include <memory> @@ -35,7 +36,7 @@ class PhysicalFontFace; // TODO: allow sharing of metrics for related fonts -class VCL_PLUGIN_PUBLIC LogicalFontInstance +class VCL_PLUGIN_PUBLIC LogicalFontInstance : public salhelper::SimpleReferenceObject { // just declaring the factory function doesn't work AKA // friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const; @@ -43,7 +44,7 @@ class VCL_PLUGIN_PUBLIC LogicalFontInstance friend class ImplFontCache; public: // TODO: make data members private - virtual ~LogicalFontInstance(); + virtual ~LogicalFontInstance() override; ImplFontMetricDataRef mxFontMetric; // Font attributes const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol @@ -57,9 +58,6 @@ public: // TODO: make data members private bool GetFallbackForUnicode( sal_UCS4, FontWeight eWeight, OUString* pFontName ) const; void IgnoreFallbackForUnicode( sal_UCS4, FontWeight eWeight, const OUString& rFontName ); - void Acquire(); - void Release(); - inline hb_font_t* GetHbFont(); void SetAverageWidthFactor(double nFactor) { m_nAveWidthFactor = nFactor; } double GetAverageWidthFactor() const { return m_nAveWidthFactor; } @@ -88,7 +86,6 @@ private: typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList; std::unique_ptr<UnicodeFallbackList> mpUnicodeFallbackList; ImplFontCache * mpFontCache; - sal_uInt32 mnRefCount; const FontSelectPattern m_aFontSelData; hb_font_t* m_pHbFont; double m_nAveWidthFactor; diff --git a/vcl/inc/fontselect.hxx b/vcl/inc/fontselect.hxx index 389077270758..efb88ad74ae1 100644 --- a/vcl/inc/fontselect.hxx +++ b/vcl/inc/fontselect.hxx @@ -21,6 +21,7 @@ #define INCLUDED_VCL_INC_FONTSELECT_HXX #include <i18nlangtag/lang.h> +#include <rtl/ref.hxx> #include "fontattributes.hxx" @@ -80,7 +81,7 @@ public: #endif public: // TODO: change to private - LogicalFontInstance* mpFontInstance; // pointer to the resulting FontCache entry + rtl::Reference<LogicalFontInstance> mpFontInstance; // pointer to the resulting FontCache entry void copyAttributes(const FontSelectPatternAttributes &rAttributes); }; diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx index a99283fb300e..6cb05b39d9b3 100644 --- a/vcl/inc/impfontcache.hxx +++ b/vcl/inc/impfontcache.hxx @@ -33,36 +33,24 @@ class PhysicalFontCollection; class ImplFontCache { - // For access to Acquire and Release - friend class LogicalFontInstance; - private: LogicalFontInstance* mpLastHitCacheEntry; ///< keeps the last hit cache entry - int mnRef0Count; ///< number of unreferenced LogicalFontInstances // cache of recently used font instances struct IFSD_Equal { bool operator()( const FontSelectPattern&, const FontSelectPattern& ) const; }; struct IFSD_Hash { size_t operator()( const FontSelectPattern& ) const; }; - typedef std::unordered_map<FontSelectPattern,LogicalFontInstance*,IFSD_Hash,IFSD_Equal > FontInstanceList; + typedef std::unordered_map<FontSelectPattern, rtl::Reference<LogicalFontInstance>, IFSD_Hash, IFSD_Equal> FontInstanceList; FontInstanceList maFontInstanceList; - int CountUnreferencedEntries() const; - bool IsFontInList(const LogicalFontInstance* pFont) const; - - /// Increase the refcount of the given LogicalFontInstance. - void Acquire(LogicalFontInstance*); - /// Decrease the refcount and potentially cleanup the entries with zero refcount from the cache. - void Release(LogicalFontInstance*); - - LogicalFontInstance* GetFontInstance(PhysicalFontCollection const*, FontSelectPattern&); + rtl::Reference<LogicalFontInstance> GetFontInstance(PhysicalFontCollection const*, FontSelectPattern&); public: ImplFontCache(); ~ImplFontCache(); - LogicalFontInstance* GetFontInstance( PhysicalFontCollection const *, + rtl::Reference<LogicalFontInstance> GetFontInstance( PhysicalFontCollection const *, const vcl::Font&, const Size& rPixelSize, float fExactHeight); - LogicalFontInstance* GetGlyphFallbackFont( PhysicalFontCollection const *, FontSelectPattern&, + rtl::Reference<LogicalFontInstance> GetGlyphFallbackFont( PhysicalFontCollection const *, FontSelectPattern&, int nFallbackLevel, OUString& rMissingCodes ); void Invalidate(); diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h index 2f53a44d694e..1dd896058890 100644 --- a/vcl/inc/quartz/salgdi.h +++ b/vcl/inc/quartz/salgdi.h @@ -71,7 +71,7 @@ public: bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const; bool HasChar( sal_uInt32 cChar ) const; - LogicalFontInstance* CreateFontInstance(const FontSelectPattern&) const override; + rtl::Reference<LogicalFontInstance> CreateFontInstance(const FontSelectPattern&) const override; protected: CoreTextFontFace( const CoreTextFontFace& ); @@ -85,7 +85,7 @@ private: class CoreTextStyle : public LogicalFontInstance { - friend LogicalFontInstance* CoreTextFontFace::CreateFontInstance(const FontSelectPattern&) const; + friend rtl::Reference<LogicalFontInstance> CoreTextFontFace::CreateFontInstance(const FontSelectPattern&) const; public: ~CoreTextStyle(); @@ -159,7 +159,7 @@ class AquaSalGraphics : public SalGraphics RGBAColor maFillColor; // Device Font settings - CoreTextStyle* mpTextStyle[MAX_FALLBACK]; + rtl::Reference<CoreTextStyle> mpTextStyle[MAX_FALLBACK]; RGBAColor maTextColor; /// allows text to be rendered without antialiasing bool mbNonAntialiasedText; diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx index 62cda5832906..8daed9a01d09 100644 --- a/vcl/inc/sallayout.hxx +++ b/vcl/inc/sallayout.hxx @@ -352,7 +352,7 @@ private: void ParseFeatures(const OUString& name); - LogicalFontInstance* const mpFont; + rtl::Reference<LogicalFontInstance> const mpFont; css::uno::Reference<css::i18n::XBreakIterator> mxBreak; std::vector<GlyphItem> m_GlyphItems; diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index 34ca43664a25..29cbaf00c3a6 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -21,6 +21,7 @@ #define INCLUDED_VCL_INC_SALWTYPE_HXX #include <i18nlangtag/lang.h> +#include <rtl/ref.hxx> #include <rtl/ustring.hxx> #include <tools/solar.h> @@ -238,7 +239,7 @@ struct SalFrameState struct SalInputContext { - LogicalFontInstance* mpFont; + rtl::Reference<LogicalFontInstance> mpFont; LanguageType meLanguage; InputContextFlags mnOptions; }; diff --git a/vcl/inc/unx/freetype_glyphcache.hxx b/vcl/inc/unx/freetype_glyphcache.hxx index d6b87b7ab7a9..bf00935b15a1 100644 --- a/vcl/inc/unx/freetype_glyphcache.hxx +++ b/vcl/inc/unx/freetype_glyphcache.hxx @@ -114,7 +114,7 @@ private: public: FreetypeFontFace( FreetypeFontInfo*, const FontAttributes& ); - virtual LogicalFontInstance* CreateFontInstance( const FontSelectPattern& ) const override; + virtual rtl::Reference<LogicalFontInstance> CreateFontInstance( const FontSelectPattern& ) const override; virtual rtl::Reference<PhysicalFontFace> Clone() const override { return new FreetypeFontFace( *this ); } virtual sal_IntPtr GetFontId() const override { return mpFreetypeFontInfo->GetFontId(); } }; @@ -122,7 +122,7 @@ public: // a class for cache entries for physical font instances that are based on serverfonts class VCL_DLLPUBLIC FreetypeFontInstance : public LogicalFontInstance { - friend LogicalFontInstance* FreetypeFontFace::CreateFontInstance(const FontSelectPattern&) const; + friend rtl::Reference<LogicalFontInstance> FreetypeFontFace::CreateFontInstance(const FontSelectPattern&) const; FreetypeFont* mpFreetypeFont; diff --git a/vcl/inc/unx/glyphcache.hxx b/vcl/inc/unx/glyphcache.hxx index 5e515db564b5..50d1f071d44f 100644 --- a/vcl/inc/unx/glyphcache.hxx +++ b/vcl/inc/unx/glyphcache.hxx @@ -39,6 +39,7 @@ #include <unordered_map> class FreetypeManager; +class FreetypeFontInstance; class FreetypeFontInfo; class GlyphData; class FontConfigFontOptions; @@ -139,7 +140,7 @@ public: bool GetGlyphOutline(const GlyphItem& rGlyph, basegfx::B2DPolyPolygon&) const; bool GetAntialiasAdvice() const; - LogicalFontInstance* GetFontInstance() const { return mpFontInstance; } + FreetypeFontInstance* GetFontInstance() const { return mpFontInstance.get(); } private: friend class GlyphCache; @@ -161,7 +162,7 @@ private: typedef std::unordered_map<int,GlyphData> GlyphList; mutable GlyphList maGlyphList; - LogicalFontInstance* const mpFontInstance; + rtl::Reference<FreetypeFontInstance> mpFontInstance; // used by GlyphCache for cache LRU algorithm mutable long mnRefCount; diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h index 59190f87e17d..661c47908865 100644 --- a/vcl/inc/win/salgdi.h +++ b/vcl/inc/win/salgdi.h @@ -64,7 +64,7 @@ public: virtual ~WinFontFace() override; virtual rtl::Reference<PhysicalFontFace> Clone() const override; - virtual LogicalFontInstance* CreateFontInstance( const FontSelectPattern& ) const override; + virtual rtl::Reference<LogicalFontInstance> CreateFontInstance( const FontSelectPattern& ) const override; virtual sal_IntPtr GetFontId() const override; void SetFontId( sal_IntPtr nId ) { mnId = nId; } void UpdateFromHDC( HDC ) const; @@ -158,7 +158,8 @@ private: HWND mhWnd; // Window-Handle, when Window-Graphics HFONT mhFonts[ MAX_FALLBACK ]; // Font + Fallbacks - WinFontInstance* mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance + rtl::Reference<WinFontInstance> + mpWinFontEntry[ MAX_FALLBACK ]; // pointer to the most recent font instance float mfFontScale[ MAX_FALLBACK ]; // allows metrics emulation of huge font sizes float mfCurrentFontScale; HRGN mhRegion; // vcl::Region Handle @@ -171,8 +172,6 @@ private: RGNDATA* mpStdClipRgnData; // Cache Standard-ClipRegion-Data int mnPenWidth; // line width - LogicalFontInstance* GetWinFontEntry(int nFallbackLevel); - bool CacheGlyphs(const GenericSalLayout& rLayout); bool DrawCachedGlyphs(const GenericSalLayout& rLayout); diff --git a/vcl/inc/win/winlayout.hxx b/vcl/inc/win/winlayout.hxx index a3229a4010b6..d15b3d124472 100644 --- a/vcl/inc/win/winlayout.hxx +++ b/vcl/inc/win/winlayout.hxx @@ -145,7 +145,7 @@ public: // win32 specific physical font instance class WinFontInstance : public LogicalFontInstance { - friend LogicalFontInstance* WinFontFace::CreateFontInstance(const FontSelectPattern&) const; + friend rtl::Reference<LogicalFontInstance> WinFontFace::CreateFontInstance(const FontSelectPattern&) const; public: virtual ~WinFontInstance() override; |