diff --git a/include/core/SkGraphics.h b/include/core/SkGraphics.h index 4b62e55efc..1c97f0c291 100644 --- a/include/core/SkGraphics.h +++ b/include/core/SkGraphics.h @@ -72,6 +72,30 @@ public: */ static int SetFontCacheCountLimit(int count); + /* + * Returns the maximum point size for text that may be cached. + * + * Sizes above this will be drawn directly from the font's outline. + * Setting this to a large value may speed up drawing larger text (repeatedly), + * but could cause the cache to purge other sizes more often. + * + * This value is a hint to the font engine, and the actual limit may be different due to + * implementation specific details. + */ + static int GetFontCachePointSizeLimit(); + + /* + * Set the maximum point size for text that may be cached, returning the previous value. + * + * Sizes above this will be drawn directly from the font's outline. + * Setting this to a large value may speed up drawing larger text (repeatedly), + * but could cause the cache to purge other sizes more often. + * + * This value is a hint to the font engine, and the actual limit may be different due to + * implementation specific details. + */ + static int SetFontCachePointSizeLimit(int maxPointSize); + /** * For debugging purposes, this will attempt to purge the font cache. It * does not change the limit, but will cause subsequent font measures and diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 3a10c872aa..5b2283aa19 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -1110,13 +1110,6 @@ private: * need not match per-se. */ kCanonicalTextSizeForPaths = 64, - - /* - * Above this size (taking into account CTM and textSize), we never use - * the cache for bits or metrics (we might overflow), so we just ask - * for a caononical size and post-transform that. - */ - kMaxSizeForGlyphCache = 256, }; static bool TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM); @@ -1126,11 +1119,7 @@ private: // have change it to kCanonicalTextSizeForPaths. SkScalar setupForAsPaths(); - static SkScalar MaxCacheSize2() { - static const SkScalar kMaxSize = SkIntToScalar(kMaxSizeForGlyphCache); - static const SkScalar kMag2Max = kMaxSize * kMaxSize; - return kMag2Max; - } + static SkScalar MaxCacheSize2(); friend class SkAutoGlyphCache; friend class SkAutoGlyphCacheNoGamma; diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index d5efc0e672..6a54f928ca 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -448,6 +448,23 @@ int SkGlyphCache_Globals::setCacheCountLimit(int newCount) { return prevCount; } +int SkGlyphCache_Globals::getCachePointSizeLimit() const { + SkAutoExclusive ac(fLock); + return fPointSizeLimit; +} + +int SkGlyphCache_Globals::setCachePointSizeLimit(int newLimit) { + if (newLimit < 0) { + newLimit = 0; + } + + SkAutoExclusive ac(fLock); + + int prevLimit = fPointSizeLimit; + fPointSizeLimit = newLimit; + return prevLimit; +} + void SkGlyphCache_Globals::purgeAll() { SkAutoExclusive ac(fLock); this->internalPurge(fTotalMemoryUsed); @@ -775,6 +792,14 @@ int SkGraphics::GetFontCacheCountUsed() { return get_globals().getCacheCountUsed(); } +int SkGraphics::GetFontCachePointSizeLimit() { + return get_globals().getCachePointSizeLimit(); +} + +int SkGraphics::SetFontCachePointSizeLimit(int limit) { + return get_globals().setCachePointSizeLimit(limit); +} + void SkGraphics::PurgeFontCache() { get_globals().purgeAll(); SkTypefaceCache::PurgeAll(); diff --git a/src/core/SkGlyphCache_Globals.h b/src/core/SkGlyphCache_Globals.h index 4d7fe22d80..a1e0ac04e2 100644 --- a/src/core/SkGlyphCache_Globals.h +++ b/src/core/SkGlyphCache_Globals.h @@ -21,6 +21,10 @@ #define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024) #endif +#ifndef SK_DEFAULT_FONT_CACHE_POINT_SIZE_LIMIT + #define SK_DEFAULT_FONT_CACHE_POINT_SIZE_LIMIT 256 +#endif + /////////////////////////////////////////////////////////////////////////////// class SkGlyphCache_Globals { @@ -31,6 +35,7 @@ public: fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT; fCacheCount = 0; fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT; + fPointSizeLimit = SK_DEFAULT_FONT_CACHE_POINT_SIZE_LIMIT; } ~SkGlyphCache_Globals() { @@ -62,6 +67,9 @@ public: size_t getCacheSizeLimit() const; size_t setCacheSizeLimit(size_t limit); + int getCachePointSizeLimit() const; + int setCachePointSizeLimit(int limit); + void purgeAll(); // does not change budget // call when a glyphcache is available for caching (i.e. not in use) @@ -77,6 +85,7 @@ private: size_t fCacheSizeLimit; int32_t fCacheCountLimit; int32_t fCacheCount; + int32_t fPointSizeLimit; // Checkout budgets, modulated by the specified min-bytes-needed-to-purge, // and attempt to purge caches to match. diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index 2d3eb1822b..78754957cf 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -12,6 +12,7 @@ #include "SkData.h" #include "SkDraw.h" #include "SkFontDescriptor.h" +#include "SkGraphics.h" #include "SkGlyphCache.h" #include "SkImageFilter.h" #include "SkMaskFilter.h" @@ -392,6 +393,12 @@ bool SkPaint::TooBigToUseCache(const SkMatrix& ctm, const SkMatrix& textM) { return tooBig(matrix, MaxCacheSize2()); } +SkScalar SkPaint::MaxCacheSize2() { + // we have a self-imposed maximum, just for memory-usage sanity + const int limit = SkMin32(SkGraphics::GetFontCachePointSizeLimit(), 1024); + const SkScalar maxSize = SkIntToScalar(limit); + return maxSize * maxSize; +} ///////////////////////////////////////////////////////////////////////////////