diff options
Diffstat (limited to 'src/core/SkStrikeCache.h')
-rw-r--r-- | src/core/SkStrikeCache.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h new file mode 100644 index 0000000000..5efbdc9f01 --- /dev/null +++ b/src/core/SkStrikeCache.h @@ -0,0 +1,90 @@ +/* + * Copyright 2010 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkStrikeCache_DEFINED +#define SkStrikeCache_DEFINED + +#include "SkSpinlock.h" + +class SkGlyphCache; + +#ifndef SK_DEFAULT_FONT_CACHE_COUNT_LIMIT + #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 +#endif + +#ifndef SK_DEFAULT_FONT_CACHE_LIMIT + #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 SkStrikeCache { +public: + SkStrikeCache() { + fHead = nullptr; + fTotalMemoryUsed = 0; + fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT; + fCacheCount = 0; + fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT; + fPointSizeLimit = SK_DEFAULT_FONT_CACHE_POINT_SIZE_LIMIT; + } + + ~SkStrikeCache(); + + static void AttachCache(SkGlyphCache* cache); + + mutable SkSpinlock fLock; + + SkGlyphCache* internalGetHead() const { return fHead; } + SkGlyphCache* internalGetTail() const; + + size_t getTotalMemoryUsed() const; + int getCacheCountUsed() const; + +#ifdef SK_DEBUG + void validate() const; +#else + void validate() const {} +#endif + + int getCacheCountLimit() const; + int setCacheCountLimit(int limit); + + 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) + void attachCacheToHead(SkGlyphCache*); + + // can only be called when the mutex is already held + void internalDetachCache(SkGlyphCache*); + void internalAttachCacheToHead(SkGlyphCache*); + +private: + SkGlyphCache* fHead; + size_t fTotalMemoryUsed; + 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. + // Returns number of bytes freed. + size_t internalPurge(size_t minBytesNeeded = 0); +}; + +#endif // SkStrikeCache_DEFINED |