summaryrefslogtreecommitdiff
path: root/vcl/inc
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2017-12-28 00:35:23 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2017-12-28 13:04:30 +0100
commitb0203670492d5af7f963e66ef702f36c87b6b694 (patch)
tree2c74d62962df05e3bdfcf2c80633e8e1d00dc9a8 /vcl/inc
parentb6e6c05b11c991757c640a2d46b1d2aa0e50960b (diff)
Try to handle fonts orphaned from cache gracefully
ImplFontCache::Invalidate deletes unused entries (with zero ref count), and keeps other entries, but clears everything (including still used fonts) from its instance list. In the same time, those fonts' mpFontCache pointers kept pointing to this cache object. External clients released font instance by calling its cache's Release method; this itself allows for broken invariants that cache's mnRef0Count is equal to number of unused font instances in its list. Also, those fonts never got released, leaking because ImplFontCache only ever deletes objects in its list. What is worse, sometimes font caches get deleted after invalidation (see OutputDevice::ImplClearFontData). As the instance list of the cache is empty at the point of delete, the cache destructor doesn't delete those fonts that were orphaned at the moment of invalidation (those fonts are still used by some client objects, so deleting them is clearly wrong). But since the font instances still have cache pointer referring the already deleted cache, releasing the instances (by calling deleted cache's Release member function) must lead do some weird results. This patch moves the Acquire/Release to LogicalFontInstance, which now checks if its cache pointer is valid, and if it is, the cache is used to do the work (as before); otherwise, the font handles its lifetime itself, and deletes itself when its reference counter is zero. The cache invalidation clears the cache pointer of the still-used instances. Change-Id: I29811272dda814cbc81f14668d63e385ce772332 Reviewed-on: https://gerrit.libreoffice.org/47111 Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com> Tested-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/inc')
-rw-r--r--vcl/inc/fontinstance.hxx8
-rw-r--r--vcl/inc/impfontcache.hxx13
2 files changed, 14 insertions, 7 deletions
diff --git a/vcl/inc/fontinstance.hxx b/vcl/inc/fontinstance.hxx
index 7595c79036cd..be6df2c0fbad 100644
--- a/vcl/inc/fontinstance.hxx
+++ b/vcl/inc/fontinstance.hxx
@@ -36,17 +36,16 @@ class VCL_PLUGIN_PUBLIC LogicalFontInstance
// just declaring the factory function doesn't work AKA
// friend LogicalFontInstance* PhysicalFontFace::CreateFontInstance(const FontSelectPattern&) const;
friend class PhysicalFontFace;
+ friend class ImplFontCache;
public: // TODO: make data members private
virtual ~LogicalFontInstance();
- ImplFontCache * mpFontCache;
FontSelectPattern maFontSelData; // FontSelectionData
ImplFontMetricDataRef mxFontMetric; // Font attributes
const ConvertChar* mpConversion; // used e.g. for StarBats->StarSymbol
long mnLineHeight;
- sal_uInt32 mnRefCount;
short mnOwnOrientation; // text angle if lower layers don't rotate text themselves
short mnOrientation; // text angle in 3600 system
bool mbInit; // true if maFontMetric member is valid
@@ -55,6 +54,9 @@ 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();
+
protected:
explicit LogicalFontInstance(const FontSelectPattern&);
@@ -64,6 +66,8 @@ private:
// TODO: at least the ones which just differ in orientation, stretching or height
typedef ::std::unordered_map< ::std::pair<sal_UCS4,FontWeight>, OUString > UnicodeFallbackList;
UnicodeFallbackList* mpUnicodeFallbackList;
+ ImplFontCache * mpFontCache;
+ sal_uInt32 mnRefCount;
};
#endif // INCLUDED_VCL_INC_FONTINSTANCE_HXX
diff --git a/vcl/inc/impfontcache.hxx b/vcl/inc/impfontcache.hxx
index eb00009028b1..c5c7a4718d19 100644
--- a/vcl/inc/impfontcache.hxx
+++ b/vcl/inc/impfontcache.hxx
@@ -33,6 +33,8 @@ class PhysicalFontCollection;
class ImplFontCache
{
+ // For access to Acquire and Release
+ friend class LogicalFontInstance;
private:
LogicalFontInstance* mpFirstEntry;
int mnRef0Count; // number of unreferenced LogicalFontInstances
@@ -44,6 +46,12 @@ private:
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*);
public:
ImplFontCache();
@@ -55,11 +63,6 @@ public:
LogicalFontInstance* GetGlyphFallbackFont( PhysicalFontCollection const *, FontSelectPattern&,
int nFallbackLevel, OUString& rMissingCodes );
- /// 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*);
-
void Invalidate();
};