From 840c66c58a149842f2416959f8e8118e9a86b56e Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Mon, 16 Apr 2018 16:42:08 -0400 Subject: Rename SkGlyphCacheGlobals to SkStrikeCache Change-Id: I7773c1fff309bf9416f16fe9908191eeba94eb99 Reviewed-on: https://skia-review.googlesource.com/121356 Reviewed-by: Ben Wagner Commit-Queue: Herb Derby --- bench/SkGlyphCacheBench.cpp | 2 +- gn/core.gni | 2 +- src/core/SkGlyphCache.cpp | 45 ++++++++++---------- src/core/SkGlyphCache.h | 6 +-- src/core/SkGlyphCache_Globals.h | 91 ----------------------------------------- src/core/SkStrikeCache.h | 90 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 118 insertions(+), 118 deletions(-) delete mode 100644 src/core/SkGlyphCache_Globals.h create mode 100644 src/core/SkStrikeCache.h diff --git a/bench/SkGlyphCacheBench.cpp b/bench/SkGlyphCacheBench.cpp index 0cd3ab433f..0333bfe38e 100644 --- a/bench/SkGlyphCacheBench.cpp +++ b/bench/SkGlyphCacheBench.cpp @@ -10,7 +10,7 @@ #include "Benchmark.h" #include "SkCanvas.h" -#include "SkGlyphCache_Globals.h" +#include "SkStrikeCache.h" #include "SkGraphics.h" #include "SkTaskGroup.h" #include "SkTypeface.h" diff --git a/gn/core.gni b/gn/core.gni index 6f019f3f4d..620aa23b05 100644 --- a/gn/core.gni +++ b/gn/core.gni @@ -159,7 +159,6 @@ skia_core_sources = [ "$_src/core/SkGlyph.cpp", "$_src/core/SkGlyphCache.cpp", "$_src/core/SkGlyphCache.h", - "$_src/core/SkGlyphCache_Globals.h", "$_src/core/SkGpuBlurUtils.h", "$_src/core/SkGpuBlurUtils.cpp", "$_src/core/SkGraphics.cpp", @@ -295,6 +294,7 @@ skia_core_sources = [ "$_src/core/SkSpriteBlitter.h", "$_src/core/SkStream.cpp", "$_src/core/SkStreamPriv.h", + "$_src/core/SkStrikeCache.h", "$_src/core/SkString.cpp", "$_src/core/SkStringUtils.cpp", "$_src/core/SkStroke.h", diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp index 057f4d731e..11b9728b77 100644 --- a/src/core/SkGlyphCache.cpp +++ b/src/core/SkGlyphCache.cpp @@ -8,6 +8,7 @@ #include "SkGlyphCache.h" #include "SkGraphics.h" +#include "SkMutex.h" #include "SkOnce.h" #include "SkPaintPriv.h" #include "SkPath.h" @@ -24,11 +25,11 @@ const char gGlyphCacheDumpName[] = "skia/sk_glyph_cache"; } // namespace // Returns the shared globals -static SkGlyphCache_Globals& get_globals() { +static SkStrikeCache& get_globals() { static SkOnce once; - static SkGlyphCache_Globals* globals; + static SkStrikeCache* globals; - once([]{ globals = new SkGlyphCache_Globals; }); + once([]{ globals = new SkStrikeCache; }); return *globals; } @@ -414,22 +415,22 @@ void SkGlyphCache::dump() const { /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -size_t SkGlyphCache_Globals::getTotalMemoryUsed() const { +size_t SkStrikeCache::getTotalMemoryUsed() const { SkAutoExclusive ac(fLock); return fTotalMemoryUsed; } -int SkGlyphCache_Globals::getCacheCountUsed() const { +int SkStrikeCache::getCacheCountUsed() const { SkAutoExclusive ac(fLock); return fCacheCount; } -int SkGlyphCache_Globals::getCacheCountLimit() const { +int SkStrikeCache::getCacheCountLimit() const { SkAutoExclusive ac(fLock); return fCacheCountLimit; } -size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) { +size_t SkStrikeCache::setCacheSizeLimit(size_t newLimit) { static const size_t minLimit = 256 * 1024; if (newLimit < minLimit) { newLimit = minLimit; @@ -443,12 +444,12 @@ size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) { return prevLimit; } -size_t SkGlyphCache_Globals::getCacheSizeLimit() const { +size_t SkStrikeCache::getCacheSizeLimit() const { SkAutoExclusive ac(fLock); return fCacheSizeLimit; } -int SkGlyphCache_Globals::setCacheCountLimit(int newCount) { +int SkStrikeCache::setCacheCountLimit(int newCount) { if (newCount < 0) { newCount = 0; } @@ -461,12 +462,12 @@ int SkGlyphCache_Globals::setCacheCountLimit(int newCount) { return prevCount; } -int SkGlyphCache_Globals::getCachePointSizeLimit() const { +int SkStrikeCache::getCachePointSizeLimit() const { SkAutoExclusive ac(fLock); return fPointSizeLimit; } -int SkGlyphCache_Globals::setCachePointSizeLimit(int newLimit) { +int SkStrikeCache::setCachePointSizeLimit(int newLimit) { if (newLimit < 0) { newLimit = 0; } @@ -478,13 +479,13 @@ int SkGlyphCache_Globals::setCachePointSizeLimit(int newLimit) { return prevLimit; } -void SkGlyphCache_Globals::purgeAll() { +void SkStrikeCache::purgeAll() { SkAutoExclusive ac(fLock); this->internalPurge(fTotalMemoryUsed); } SkExclusiveStrikePtr SkGlyphCache::FindStrikeExclusive(const SkDescriptor& desc) { - SkGlyphCache_Globals& globals = get_globals(); + SkStrikeCache& globals = get_globals(); SkGlyphCache* cache; SkAutoExclusive ac(globals.fLock); @@ -559,7 +560,7 @@ SkExclusiveStrikePtr SkGlyphCache::CreateStrikeExclusive( } void SkGlyphCache::ForEachStrike(std::function visitor) { - SkGlyphCache_Globals& globals = get_globals(); + SkStrikeCache& globals = get_globals(); SkAutoExclusive ac(globals.fLock); SkGlyphCache* cache; @@ -632,7 +633,7 @@ void SkGlyphCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { /////////////////////////////////////////////////////////////////////////////// -SkGlyphCache_Globals::~SkGlyphCache_Globals() { +SkStrikeCache::~SkStrikeCache() { SkGlyphCache* cache = fHead; while (cache) { SkGlyphCache* next = cache->fNext; @@ -641,7 +642,7 @@ SkGlyphCache_Globals::~SkGlyphCache_Globals() { } } -void SkGlyphCache_Globals::AttachCache(SkGlyphCache* cache) { +void SkStrikeCache::AttachCache(SkGlyphCache* cache) { if (cache == nullptr) { return; } @@ -651,7 +652,7 @@ void SkGlyphCache_Globals::AttachCache(SkGlyphCache* cache) { } -void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { +void SkStrikeCache::attachCacheToHead(SkGlyphCache* cache) { SkAutoExclusive ac(fLock); this->validate(); @@ -661,7 +662,7 @@ void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) { this->internalPurge(); } -SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { +SkGlyphCache* SkStrikeCache::internalGetTail() const { SkGlyphCache* cache = fHead; if (cache) { while (cache->fNext) { @@ -671,7 +672,7 @@ SkGlyphCache* SkGlyphCache_Globals::internalGetTail() const { return cache; } -size_t SkGlyphCache_Globals::internalPurge(size_t minBytesNeeded) { +size_t SkStrikeCache::internalPurge(size_t minBytesNeeded) { this->validate(); size_t bytesNeeded = 0; @@ -725,7 +726,7 @@ size_t SkGlyphCache_Globals::internalPurge(size_t minBytesNeeded) { return bytesFreed; } -void SkGlyphCache_Globals::internalAttachCacheToHead(SkGlyphCache* cache) { +void SkStrikeCache::internalAttachCacheToHead(SkGlyphCache* cache) { SkASSERT(nullptr == cache->fPrev && nullptr == cache->fNext); if (fHead) { fHead->fPrev = cache; @@ -737,7 +738,7 @@ void SkGlyphCache_Globals::internalAttachCacheToHead(SkGlyphCache* cache) { fTotalMemoryUsed += cache->fMemoryUsed; } -void SkGlyphCache_Globals::internalDetachCache(SkGlyphCache* cache) { +void SkStrikeCache::internalDetachCache(SkGlyphCache* cache) { SkASSERT(fCacheCount > 0); fCacheCount -= 1; fTotalMemoryUsed -= cache->fMemoryUsed; @@ -770,7 +771,7 @@ void SkGlyphCache::validate() const { #endif } -void SkGlyphCache_Globals::validate() const { +void SkStrikeCache::validate() const { size_t computedBytes = 0; int computedCount = 0; diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h index 8bb10bb55f..3143656659 100644 --- a/src/core/SkGlyphCache.h +++ b/src/core/SkGlyphCache.h @@ -10,7 +10,7 @@ #include "SkArenaAlloc.h" #include "SkDescriptor.h" #include "SkGlyph.h" -#include "SkGlyphCache_Globals.h" +#include "SkStrikeCache.h" #include "SkPaint.h" #include "SkTHash.h" #include "SkScalerContext.h" @@ -22,7 +22,7 @@ class SkTraceMemoryDump; class SkGlyphCache; using SkExclusiveStrikePtr = std::unique_ptr< SkGlyphCache, - SkFunctionWrapper>; + SkFunctionWrapper>; /** \class SkGlyphCache @@ -191,7 +191,7 @@ public: }; private: - friend class SkGlyphCache_Globals; + friend class SkStrikeCache; enum MetricsType { kNothing_MetricsType, diff --git a/src/core/SkGlyphCache_Globals.h b/src/core/SkGlyphCache_Globals.h deleted file mode 100644 index de37bbb7e8..0000000000 --- a/src/core/SkGlyphCache_Globals.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * 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 SkGlyphCache_Globals_DEFINED -#define SkGlyphCache_Globals_DEFINED - -#include "SkMutex.h" -#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 SkGlyphCache_Globals { -public: - SkGlyphCache_Globals() { - 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; - } - - ~SkGlyphCache_Globals(); - - 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 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 -- cgit v1.2.3