From d40da64fcdecde1a2909cc42ca41eac6315bb162 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Thu, 20 Oct 2011 13:18:37 +0000 Subject: add typefacecache to be purged in SkGraphics::Term() git-svn-id: http://skia.googlecode.com/svn/trunk@2504 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkGraphics.cpp | 2 ++ src/core/SkTypefaceCache.cpp | 9 +++++++++ src/core/SkTypefaceCache.h | 8 ++++++++ 3 files changed, 19 insertions(+) diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp index 8102aca8ee..2da0856d86 100644 --- a/src/core/SkGraphics.cpp +++ b/src/core/SkGraphics.cpp @@ -108,9 +108,11 @@ void SkGraphics::Init() { /////////////////////////////////////////////////////////////////////////////// #include "SkGlyphCache.h" +#include "SkTypefaceCache.h" void SkGraphics::Term() { SkGraphics::SetFontCacheUsed(0); + SkTypefaceCache::PurgeAll(); SkGlobals::Term(); } diff --git a/src/core/SkTypefaceCache.cpp b/src/core/SkTypefaceCache.cpp index fc013cd149..8d86005473 100644 --- a/src/core/SkTypefaceCache.cpp +++ b/src/core/SkTypefaceCache.cpp @@ -66,6 +66,11 @@ void SkTypefaceCache::purge(int numToPurge) { } } +void SkTypefaceCache::purgeAll() { + this->purge(fArray.count()); + fArray.reset(); +} + /////////////////////////////////////////////////////////////////////////////// SkTypefaceCache& SkTypefaceCache::Get() { @@ -95,6 +100,10 @@ SkTypeface* SkTypefaceCache::FindByProc(FindProc proc, void* ctx) { return Get().findByProc(proc, ctx); } +void SkTypefaceCache::PurgeAll() { + Get().purgeAll(); +} + /////////////////////////////////////////////////////////////////////////////// #ifdef SK_DEBUG diff --git a/src/core/SkTypefaceCache.h b/src/core/SkTypefaceCache.h index ce351e5fc4..b788d21e4a 100644 --- a/src/core/SkTypefaceCache.h +++ b/src/core/SkTypefaceCache.h @@ -52,6 +52,13 @@ public: */ static SkTypeface* FindByProc(FindProc proc, void* ctx); + /** + * This will unref all of the typefaces in the cache. Normally this is + * handled automatically as needed. This function is exposed for clients + * that explicitly want to purge the entire cache (e.g. to look for leaks). + */ + static void PurgeAll(); + /** * Debugging only: dumps the status of the typefaces in the cache */ @@ -64,6 +71,7 @@ private: SkTypeface* findByID(SkFontID findID) const; SkTypeface* findByProc(FindProc proc, void* ctx) const; void purge(int count); + void purgeAll(); struct Rec { SkTypeface* fFace; -- cgit v1.2.3