add API to change max pointsize for font cache

Bug: skia:6585
Change-Id: I6df8c439dca0a154e8fbfce6d66c536665dff1d7
Reviewed-on: https://skia-review.googlesource.com/18314
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2017-06-01 14:45:44 -04:00 committed by Skia Commit-Bot
parent c3cbd734f0
commit d5bee5d50c
5 changed files with 66 additions and 12 deletions

View File

@ -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

View File

@ -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;

View File

@ -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();

View File

@ -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.

View File

@ -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;
}
///////////////////////////////////////////////////////////////////////////////