#define TYPEFACE_CACHE_LIMIT 1024
+#if defined(USE_SK_MISMATCH_CACHE)
+#define MISMATCH_FONT_CACHE_LIMIT 64
+#endif
+
SkTypefaceCache::SkTypefaceCache() {}
void SkTypefaceCache::add(sk_sp<SkTypeface> face) {
this->purge(fTypefaces.count());
}
+#if defined(USE_SK_MISMATCH_CACHE)
+void SkTypefaceCache::addMismatch(const char* requestedFamily) {
+ if (fMismatches.count() >= MISMATCH_FONT_CACHE_LIMIT) {
+ this->purgeMismatch(MISMATCH_FONT_CACHE_LIMIT >> 2);
+ }
+
+ fMismatches.emplace_back(SkString(requestedFamily));
+}
+
+bool SkTypefaceCache::findMismatch(const char* requestedFamily) {
+ for (const SkString& mismatch : fMismatches) {
+ if (mismatch.equals(requestedFamily)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void SkTypefaceCache::purgeMismatch(int numToPurge) {
+ int count = fMismatches.count();
+ int i = 0;
+ while (i < count) {
+ fMismatches.removeShuffle(i);
+ --count;
+ if (--numToPurge == 0) {
+ return;
+ }
+ }
+}
+#endif
+
///////////////////////////////////////////////////////////////////////////////
SkTypefaceCache& SkTypefaceCache::Get() {
#include "include/core/SkTypeface.h"
#include "include/private/SkTArray.h"
+#include "build/build_config.h"
+
+#if BUILDFLAG(IS_EFL)
+#define USE_SK_MISMATCH_CACHE
+#endif
+
class SkTypefaceCache {
public:
SkTypefaceCache();
*/
sk_sp<SkTypeface> findByProcAndRef(FindProc proc, void* ctx) const;
+#if defined(USE_SK_MISMATCH_CACHE)
+ void addMismatch(const char*);
+ bool findMismatch(const char*);
+ void purgeMismatch(int numToPurge);
+#endif
+
/**
* This will unref all of the typefaces in the cache for which the cache
* is the only owner. Normally this is handled automatically as needed.
void purge(int count);
SkTArray<sk_sp<SkTypeface>> fTypefaces;
+
+#if defined(USE_SK_MISMATCH_CACHE)
+ SkTArray<SkString> fMismatches;
+#endif
};
#endif
return sk_sp<SkTypeface>(face);
}
+#if defined(USE_SK_MISMATCH_CACHE)
+ if (fTFCache.findMismatch(requestedFamilyName)) {
+ return nullptr;
+ }
+#endif
+
SkFontConfigInterface::FontIdentity identity;
SkString outFamilyName;
SkFontStyle outStyle;
if (!fFCI->matchFamilyName(requestedFamilyName, requestedStyle,
&identity, &outFamilyName, &outStyle))
{
+#if defined(USE_SK_MISMATCH_CACHE)
+ fTFCache.addMismatch(requestedFamilyName);
+#endif
return nullptr;
}