summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2015-08-31 15:37:22 +0200
committerMichael Stahl <mstahl@redhat.com>2015-08-31 14:25:47 +0000
commit44377b911f9e19e43f14e390b69db4055f423b6a (patch)
tree0e9fab7a7f6bf8bf4d753e69fd9f4a926ad1b590
parent6489557740fd3cae0d8ff559b3c760b3f26eec0b (diff)
vcl: Improve management of mnRef0Count.
Follow-up to 34700400247e378e074ce4164ab2809edb092201; this fixes sw_ww8export unit test on Windows. Change-Id: Ic0c3228efb59a182e1562b73117418cd8b5e6017 Reviewed-on: https://gerrit.libreoffice.org/18175 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--vcl/inc/outdev.h7
-rw-r--r--vcl/source/outdev/font.cxx15
-rw-r--r--vcl/win/source/gdi/winlayout.cxx3
3 files changed, 20 insertions, 5 deletions
diff --git a/vcl/inc/outdev.h b/vcl/inc/outdev.h
index 7d4479825667..f40d5bd04209 100644
--- a/vcl/inc/outdev.h
+++ b/vcl/inc/outdev.h
@@ -157,7 +157,12 @@ public:
ImplFontEntry* GetFontEntry( PhysicalFontCollection*, FontSelectPattern& );
ImplFontEntry* GetGlyphFallbackFont( PhysicalFontCollection*, FontSelectPattern&,
int nFallbackLevel, OUString& rMissingCodes );
- void Release( ImplFontEntry* );
+
+ /// Increase the refcount of the given ImplFontEntry.
+ void Acquire(ImplFontEntry*);
+ /// Decrease the refcount and potentially cleanup the entries with zero refcount from the cache.
+ void Release(ImplFontEntry*);
+
void Invalidate();
};
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 355e8afbe2e2..eb98b2c2a184 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1316,8 +1316,7 @@ ImplFontEntry* ImplFontCache::GetFontEntry( PhysicalFontCollection* pFontList,
if( pEntry ) // cache hit => use existing font instance
{
// increase the font instance's reference count
- if( !pEntry->mnRefCount++ )
- --mnRef0Count;
+ Acquire(pEntry);
}
if (!pEntry && pFontData)// still no cache hit => create a new font instance
@@ -1390,7 +1389,15 @@ ImplFontEntry* ImplFontCache::GetGlyphFallbackFont( PhysicalFontCollection* pFon
return pFallbackFont;
}
-void ImplFontCache::Release( ImplFontEntry* pEntry )
+void ImplFontCache::Acquire(ImplFontEntry* pEntry)
+{
+ assert(pEntry->m_pFontCache == this);
+
+ if (0 == pEntry->mnRefCount++)
+ --mnRef0Count;
+}
+
+void ImplFontCache::Release(ImplFontEntry* pEntry)
{
static const int FONTCACHE_MAX = 50;
@@ -1401,6 +1408,8 @@ void ImplFontCache::Release( ImplFontEntry* pEntry )
if (++mnRef0Count < FONTCACHE_MAX)
return;
+ assert(CountUnreferencedEntries() == mnRef0Count);
+
// remove unused entries from font instance cache
FontInstanceList::iterator it_next = maFontInstanceList.begin();
while( it_next != maFontInstanceList.end() )
diff --git a/vcl/win/source/gdi/winlayout.cxx b/vcl/win/source/gdi/winlayout.cxx
index f26272499c7d..4718a8dc38f6 100644
--- a/vcl/win/source/gdi/winlayout.cxx
+++ b/vcl/win/source/gdi/winlayout.cxx
@@ -455,7 +455,8 @@ WinLayout::WinLayout(HDC hDC, const ImplWinFontData& rWFD, ImplWinFontEntry& rWF
mrWinFontEntry(rWFE),
mbUseOpenGL(bUseOpenGL)
{
- ++mrWinFontEntry.mnRefCount; // keep it alive
+ // keep mrWinFontEntry alive
+ mrWinFontEntry.m_pFontCache->Acquire(&mrWinFontEntry);
}
WinLayout::~WinLayout()