Index: src/core/SkTypefaceCache.cpp |
diff --git a/src/core/SkTypefaceCache.cpp b/src/core/SkTypefaceCache.cpp |
index faf39788edb3374c5c8cddf48e1d34290a6f831c..05a7a8eb5f3beb187447952c9ea1b3bd8a9a98e1 100644 |
--- a/src/core/SkTypefaceCache.cpp |
+++ b/src/core/SkTypefaceCache.cpp |
@@ -15,46 +15,29 @@ |
SkTypefaceCache::SkTypefaceCache() {} |
-SkTypefaceCache::~SkTypefaceCache() { |
- const Rec* curr = fArray.begin(); |
- const Rec* stop = fArray.end(); |
- while (curr < stop) { |
- curr->fFace->unref(); |
- curr += 1; |
- } |
-} |
- |
-void SkTypefaceCache::add(SkTypeface* face, const SkFontStyle& requestedStyle) { |
- if (fArray.count() >= TYPEFACE_CACHE_LIMIT) { |
+void SkTypefaceCache::add(SkTypeface* face) { |
+ if (fTypefaces.count() >= TYPEFACE_CACHE_LIMIT) { |
this->purge(TYPEFACE_CACHE_LIMIT >> 2); |
} |
- Rec* rec = fArray.append(); |
- rec->fFace = SkRef(face); |
- rec->fRequestedStyle = requestedStyle; |
+ fTypefaces.emplace_back(SkRef(face)); |
} |
SkTypeface* SkTypefaceCache::findByProcAndRef(FindProc proc, void* ctx) const { |
- const Rec* curr = fArray.begin(); |
- const Rec* stop = fArray.end(); |
- while (curr < stop) { |
- SkTypeface* currFace = curr->fFace; |
- if (proc(currFace, curr->fRequestedStyle, ctx)) { |
- return SkRef(currFace); |
+ for (const sk_sp<SkTypeface>& typeface : fTypefaces) { |
+ if (proc(typeface.get(), ctx)) { |
+ return SkRef(typeface.get()); |
} |
- curr += 1; |
} |
return nullptr; |
} |
void SkTypefaceCache::purge(int numToPurge) { |
- int count = fArray.count(); |
+ int count = fTypefaces.count(); |
int i = 0; |
while (i < count) { |
- SkTypeface* face = fArray[i].fFace; |
- if (face->unique()) { |
- face->unref(); |
- fArray.remove(i); |
+ if (fTypefaces[i]->unique()) { |
+ fTypefaces.removeShuffle(i); |
--count; |
if (--numToPurge == 0) { |
return; |
@@ -66,7 +49,7 @@ void SkTypefaceCache::purge(int numToPurge) { |
} |
void SkTypefaceCache::purgeAll() { |
- this->purge(fArray.count()); |
+ this->purge(fTypefaces.count()); |
} |
/////////////////////////////////////////////////////////////////////////////// |
@@ -83,15 +66,14 @@ SkFontID SkTypefaceCache::NewFontID() { |
SK_DECLARE_STATIC_MUTEX(gMutex); |
-void SkTypefaceCache::Add(SkTypeface* face, const SkFontStyle& requestedStyle) { |
+void SkTypefaceCache::Add(SkTypeface* face) { |
SkAutoMutexAcquire ama(gMutex); |
- Get().add(face, requestedStyle); |
+ Get().add(face); |
} |
SkTypeface* SkTypefaceCache::FindByProcAndRef(FindProc proc, void* ctx) { |
SkAutoMutexAcquire ama(gMutex); |
- SkTypeface* typeface = Get().findByProcAndRef(proc, ctx); |
- return typeface; |
+ return Get().findByProcAndRef(proc, ctx); |
} |
void SkTypefaceCache::PurgeAll() { |
@@ -102,16 +84,19 @@ void SkTypefaceCache::PurgeAll() { |
/////////////////////////////////////////////////////////////////////////////// |
#ifdef SK_DEBUG |
-static bool DumpProc(SkTypeface* face, const SkFontStyle& s, void* ctx) { |
- SkDebugf("SkTypefaceCache: face %p fontID %d weight %d width %d style %d refcnt %d\n", |
- face, face->uniqueID(), s.weight(), s.width(), s.slant(), face->getRefCnt()); |
+static bool DumpProc(SkTypeface* face, void* ctx) { |
+ SkString n; |
+ face->getFamilyName(&n); |
+ SkFontStyle s = face->fontStyle(); |
+ SkFontID id = face->uniqueID(); |
+ SkDebugf("SkTypefaceCache: face %p fontID %d weight %d width %d style %d refcnt %d name %s\n", |
+ face, id, s.weight(), s.width(), s.slant(), face->getRefCnt(), n.c_str()); |
return false; |
} |
#endif |
void SkTypefaceCache::Dump() { |
#ifdef SK_DEBUG |
- SkAutoMutexAcquire ama(gMutex); |
(void)Get().findByProcAndRef(DumpProc, nullptr); |
#endif |
} |