add explicit purgeAll() so we don't get foiled by the min cache-limit
call unref instead of delete on the GrFontScaler
Review URL: https://codereview.appspot.com/6353045
git-svn-id: http://skia.googlecode.com/svn/trunk@4366 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 387b78b..8300d88 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -356,25 +356,6 @@
fAuxProcList = rec;
}
-void SkGlyphCache::removeAuxProc(void (*proc)(void*)) {
- AuxProcRec* rec = fAuxProcList;
- AuxProcRec* prev = NULL;
- while (rec) {
- AuxProcRec* next = rec->fNext;
- if (rec->fProc == proc) {
- if (prev) {
- prev->fNext = next;
- } else {
- fAuxProcList = next;
- }
- SkDELETE(rec);
- return;
- }
- prev = rec;
- rec = next;
- }
-}
-
void SkGlyphCache::invokeAndRemoveAuxProcs() {
AuxProcRec* rec = fAuxProcList;
while (rec) {
@@ -457,6 +438,7 @@
size_t getFontCacheLimit() const { return fFontCacheLimit; }
size_t setFontCacheLimit(size_t limit);
+ void purgeAll(); // does not change budget
// can return NULL
static SkGlyphCache_Globals* FindTLS() {
@@ -486,7 +468,7 @@
if (newLimit < minLimit) {
newLimit = minLimit;
}
-
+
size_t prevLimit = fFontCacheLimit;
fFontCacheLimit = newLimit;
@@ -498,6 +480,11 @@
return prevLimit;
}
+void SkGlyphCache_Globals::purgeAll() {
+ SkAutoMutexAcquire ac(fMutex);
+ SkGlyphCache::InternalFreeCache(this, fTotalMemoryUsed);
+}
+
// Returns the shared globals
static SkGlyphCache_Globals& getSharedGlobals() {
// we leak this, so we don't incur any shutdown cost of the destructor
@@ -731,7 +718,7 @@
}
void SkGraphics::PurgeFontCache() {
- getSharedGlobals().setFontCacheLimit(0);
+ getSharedGlobals().purgeAll();
SkTypefaceCache::PurgeAll();
}
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index f8a23a6..f393416 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -119,9 +119,6 @@
bool getAuxProcData(void (*auxProc)(void*), void** dataPtr) const;
//! Add a proc/data pair to the glyphcache. proc should be non-null
void setAuxProc(void (*auxProc)(void*), void* auxData);
- //! If found, remove the proc/data pair from the glyphcache (does not
- // call the proc)
- void removeAuxProc(void (*auxProc)(void*));
SkScalerContext* getScalerContext() const { return fScalerContext; }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index c033f01..c6f377d 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1673,7 +1673,8 @@
///////////////////////////////////////////////////////////////////////////////
static void GlyphCacheAuxProc(void* data) {
- delete (GrFontScaler*)data;
+ GrFontScaler* scaler = (GrFontScaler*)data;
+ SkSafeUnref(scaler);
}
static GrFontScaler* get_gr_font_scaler(SkGlyphCache* cache) {