aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkStrikeCache.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-04-18 16:02:17 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-19 14:10:05 +0000
commitdce19a76e9ea90a42829cc7d13e23b3507e83bfe (patch)
tree282452d41f07141c96b2030dd4f72627726c0c3a /src/core/SkStrikeCache.h
parent23e4544e9442be38bea9678d66f1c76225eb5bb7 (diff)
Untangle strike cache and glyph cache
The strike cache and the glpyh cache have been friends for a long time. Untangle this twisted relationship. BUG=skia:7515 Change-Id: Ie77393f6923e9886ec90ff7a60a1200e78319937 Reviewed-on: https://skia-review.googlesource.com/122084 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/core/SkStrikeCache.h')
-rw-r--r--src/core/SkStrikeCache.h52
1 files changed, 30 insertions, 22 deletions
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index a72e71f232..a98b508c15 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -11,7 +11,6 @@
#include "SkDescriptor.h"
#include "SkSpinlock.h"
#include "SkTemplates.h"
-#include "SkArenaAlloc.h"
class SkGlyphCache;
class SkTraceMemoryDump;
@@ -30,19 +29,35 @@ class SkTraceMemoryDump;
///////////////////////////////////////////////////////////////////////////////
-class SkGlyphCache;
-
class SkStrikeCache {
+ struct Node;
+
public:
SkStrikeCache() = default;
~SkStrikeCache();
- static void AttachCache(SkGlyphCache* cache);
- using ExclusiveStrikePtr =
- std::unique_ptr<
- SkGlyphCache,
- SkFunctionWrapper<void, SkGlyphCache, SkStrikeCache::AttachCache>>;
+ class ExclusiveStrikePtr {
+ public:
+ explicit ExclusiveStrikePtr(Node*);
+ ExclusiveStrikePtr();
+ ExclusiveStrikePtr(const ExclusiveStrikePtr&) = delete;
+ ExclusiveStrikePtr& operator = (const ExclusiveStrikePtr&) = delete;
+ ExclusiveStrikePtr(ExclusiveStrikePtr&&);
+ ExclusiveStrikePtr& operator = (ExclusiveStrikePtr&&);
+ ~ExclusiveStrikePtr();
+
+ SkGlyphCache* get() const;
+ SkGlyphCache* operator -> () const;
+ SkGlyphCache& operator * () const;
+ explicit operator bool () const;
+ friend bool operator == (const ExclusiveStrikePtr&, const ExclusiveStrikePtr&);
+ friend bool operator == (const ExclusiveStrikePtr&, decltype(nullptr));
+ friend bool operator == (decltype(nullptr), const ExclusiveStrikePtr&);
+
+ private:
+ Node* fNode;
+ };
static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&);
@@ -76,7 +91,7 @@ public:
static void DumpMemoryStatistics(SkTraceMemoryDump* dump);
// call when a glyphcache is available for caching (i.e. not in use)
- void attachCache(SkGlyphCache *cache);
+ void attachNode(Node* node);
ExclusiveStrikePtr findStrikeExclusive(const SkDescriptor&);
void purgeAll(); // does not change budget
@@ -99,20 +114,13 @@ public:
#endif
private:
- friend class SkGlyphCache;
- struct Node {
- Node(const SkDescriptor& desc) : fDesc{desc} {}
- const SkDescriptor& getDescriptor() const {return *fDesc.getDesc(); }
- SkGlyphCache* fNext{nullptr};
- SkGlyphCache* fPrev{nullptr};
- SkAutoDescriptor fDesc;
- };
+ static void Attach(Node* node);
// The following methods can only be called when mutex is already held.
- SkGlyphCache* internalGetHead() const { return fHead; }
- SkGlyphCache* internalGetTail() const;
- void internalDetachCache(SkGlyphCache*);
- void internalAttachCacheToHead(SkGlyphCache*);
+ Node* internalGetHead() const { return fHead; }
+ Node* internalGetTail() const;
+ void internalDetachCache(Node*);
+ void internalAttachToHead(Node*);
// Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
// and attempt to purge caches to match.
@@ -122,7 +130,7 @@ private:
void forEachStrike(std::function<void(const SkGlyphCache&)> visitor) const;
mutable SkSpinlock fLock;
- SkGlyphCache* fHead{nullptr};
+ Node* fHead{nullptr};
size_t fTotalMemoryUsed{0};
size_t fCacheSizeLimit{SK_DEFAULT_FONT_CACHE_LIMIT};
int32_t fCacheCountLimit{SK_DEFAULT_FONT_CACHE_COUNT_LIMIT};