aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-04-17 15:00:40 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-17 20:15:11 +0000
commitf155f81b8dacc2a779bce57b7f056c2831c7267d (patch)
treebd73477c433a60a88adaa035c57a0d0d06f16461 /src/core
parenteed61283770799292615aede81934f4e794621b7 (diff)
Move node information to SkStrikeCache
Move all the information for handling nodes into SkStrikeCache. Having all the cache organization in SkStrikeCache will localize all the Chrome pinning machinery to this class. BUG=skia:7515 Change-Id: I5bc5488ddfe1806d62927d13148af36dac08eae9 Reviewed-on: https://skia-review.googlesource.com/121888 Reviewed-by: Ben Wagner <bungeman@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkGlyphCache.cpp38
-rw-r--r--src/core/SkGlyphCache.h18
-rw-r--r--src/core/SkRemoteGlyphCache.cpp4
-rw-r--r--src/core/SkStrikeCache.cpp33
-rw-r--r--src/core/SkStrikeCache.h23
5 files changed, 60 insertions, 56 deletions
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index 58f0eb355a..5327d1accb 100644
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -19,7 +19,7 @@ SkGlyphCache::SkGlyphCache(
const SkDescriptor& desc,
std::unique_ptr<SkScalerContext> scaler,
const SkPaint::FontMetrics& fontMetrics)
- : fDesc{desc.copy()}
+ : Node{desc}
, fScalerContext{std::move(scaler)}
, fFontMetrics(fontMetrics)
{
@@ -391,30 +391,13 @@ SkExclusiveStrikePtr SkGlyphCache::FindStrikeExclusive(const SkDescriptor& desc)
return SkStrikeCache::FindStrikeExclusive(desc);
}
-std::unique_ptr<SkScalerContext> SkGlyphCache::CreateScalerContext(
- const SkDescriptor& desc,
- const SkScalerContextEffects& effects,
- const SkTypeface& typeface) {
- auto scaler = typeface.createScalerContext(effects, &desc, true /* can fail */);
-
- // Check if we can create a scaler-context before creating the glyphcache.
- // If not, we may have exhausted OS/font resources, so try purging the
- // cache once and try again
- // pass true the first time, to notice if the scalercontext failed,
- if (scaler == nullptr) {
- SkStrikeCache::PurgeAll();
- scaler = typeface.createScalerContext(effects, &desc, false /* must succeed */);
- }
- return scaler;
-}
-
SkExclusiveStrikePtr SkGlyphCache::FindOrCreateStrikeExclusive(
const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
{
auto cache = SkGlyphCache::FindStrikeExclusive(desc);
if (cache == nullptr) {
- auto scaler = CreateScalerContext(desc, effects, typeface);
- cache = SkGlyphCache::CreateStrikeExclusive(desc, std::move(scaler));
+ auto scaler = SkStrikeCache::CreateScalerContext(desc, effects, typeface);
+ cache = SkStrikeCache::CreateStrikeExclusive(desc, std::move(scaler));
}
return cache;
}
@@ -436,21 +419,6 @@ SkExclusiveStrikePtr SkGlyphCache::FindOrCreateStrikeExclusive(
return FindOrCreateStrikeExclusive(*desc, effects, *tf);
}
-SkExclusiveStrikePtr SkGlyphCache::CreateStrikeExclusive(
- const SkDescriptor& desc,
- std::unique_ptr<SkScalerContext> scaler,
- SkPaint::FontMetrics* maybeMetrics)
-{
- SkPaint::FontMetrics fontMetrics;
- if (maybeMetrics != nullptr) {
- fontMetrics = *maybeMetrics;
- } else {
- scaler->getFontMetrics(&fontMetrics);
- }
-
- return SkExclusiveStrikePtr(new SkGlyphCache(desc, std::move(scaler), fontMetrics));
-}
-
#ifdef SK_DEBUG
void SkGlyphCache::validate() const {
diff --git a/src/core/SkGlyphCache.h b/src/core/SkGlyphCache.h
index 2896be58e0..7d31bf9181 100644
--- a/src/core/SkGlyphCache.h
+++ b/src/core/SkGlyphCache.h
@@ -19,7 +19,6 @@
class SkTraceMemoryDump;
-
/** \class SkGlyphCache
This class represents a strike: a specific combination of typeface, size, matrix, etc., and
@@ -33,7 +32,7 @@ class SkTraceMemoryDump;
The Find*Exclusive() method returns SkExclusiveStrikePtr, which releases exclusive ownership
when they go out of scope.
*/
-class SkGlyphCache {
+class SkGlyphCache : private SkStrikeCache::Node<SkGlyphCache> {
public:
/** Return true if glyph is cached. */
bool isGlyphCached(SkGlyphID glyphID, SkFixed x, SkFixed y) const;
@@ -107,7 +106,7 @@ public:
return fFontMetrics;
}
- const SkDescriptor& getDescriptor() const { return *fDesc; }
+ using Node::getDescriptor;
SkMask::Format getMaskFormat() const {
return fScalerContext->getMaskFormat();
@@ -122,11 +121,6 @@ public:
void dump() const;
- static std::unique_ptr<SkScalerContext> CreateScalerContext(
- const SkDescriptor& desc,
- const SkScalerContextEffects& effects,
- const SkTypeface& typeface);
-
SkScalerContext* getScalerContext() const { return fScalerContext.get(); }
static SkExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor& desc);
@@ -147,11 +141,6 @@ public:
paint, nullptr, SkScalerContextFlags::kFakeGammaAndBoostContrast, nullptr);
}
- static SkExclusiveStrikePtr CreateStrikeExclusive(
- const SkDescriptor& desc,
- std::unique_ptr<SkScalerContext> scaler,
- SkPaint::FontMetrics* maybeMetrics = nullptr);
-
#ifdef SK_DEBUG
void validate() const;
#else
@@ -230,9 +219,6 @@ private:
static const SkGlyph::Intercept* MatchBounds(const SkGlyph* glyph,
const SkScalar bounds[2]);
- SkGlyphCache* fNext{nullptr};
- SkGlyphCache* fPrev{nullptr};
- const std::unique_ptr<SkDescriptor> fDesc;
const std::unique_ptr<SkScalerContext> fScalerContext;
SkPaint::FontMetrics fFontMetrics;
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index c0ee42cfa3..9252589461 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -482,8 +482,8 @@ static void update_caches_from_strikes_data(SkStrikeClient *client,
SkScalerContextEffects effects;
auto strike = SkGlyphCache::FindStrikeExclusive(*desc);
if (strike == nullptr) {
- auto scaler = SkGlyphCache::CreateScalerContext(*desc, effects, *tf);
- strike = SkGlyphCache::CreateStrikeExclusive(*desc, std::move(scaler), fontMetrics);
+ auto scaler = SkStrikeCache::CreateScalerContext(*desc, effects, *tf);
+ strike = SkStrikeCache::CreateStrikeExclusive(*desc, std::move(scaler), fontMetrics);
}
for (int j = 0; j < spec->glyphCount; j++) {
auto glyph = deserializer->read<SkGlyph>();
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index 386be1ce9f..8d0b8326d3 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -44,6 +44,23 @@ SkExclusiveStrikePtr SkStrikeCache::FindStrikeExclusive(const SkDescriptor& desc
return get_globals().findStrikeExclusive(desc);
}
+std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
+ const SkDescriptor& desc,
+ const SkScalerContextEffects& effects,
+ const SkTypeface& typeface) {
+ auto scaler = typeface.createScalerContext(effects, &desc, true /* can fail */);
+
+ // Check if we can create a scaler-context before creating the glyphcache.
+ // If not, we may have exhausted OS/font resources, so try purging the
+ // cache once and try again
+ // pass true the first time, to notice if the scalercontext failed,
+ if (scaler == nullptr) {
+ PurgeAll();
+ scaler = typeface.createScalerContext(effects, &desc, false /* must succeed */);
+ }
+ return scaler;
+}
+
void SkStrikeCache::PurgeAll() {
get_globals().purgeAll();
}
@@ -131,7 +148,7 @@ SkExclusiveStrikePtr SkStrikeCache::findStrikeExclusive(const SkDescriptor& desc
SkAutoExclusive ac(fLock);
for (cache = internalGetHead(); cache != nullptr; cache = cache->fNext) {
- if (*cache->fDesc == desc) {
+ if (cache->getDescriptor() == desc) {
this->internalDetachCache(cache);
return SkExclusiveStrikePtr(cache);
}
@@ -348,3 +365,17 @@ void SkGraphics::PurgeFontCache() {
SkTypefaceCache::PurgeAll();
}
+SkExclusiveStrikePtr SkStrikeCache::CreateStrikeExclusive(
+ const SkDescriptor& desc,
+ std::unique_ptr<SkScalerContext> scaler,
+ SkPaint::FontMetrics* maybeMetrics)
+{
+ SkPaint::FontMetrics fontMetrics;
+ if (maybeMetrics != nullptr) {
+ fontMetrics = *maybeMetrics;
+ } else {
+ scaler->getFontMetrics(&fontMetrics);
+ }
+
+ return SkExclusiveStrikePtr(new SkGlyphCache(desc, move(scaler), fontMetrics));
+} \ No newline at end of file
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index eaf360b361..6d5dd3b7bd 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -11,6 +11,7 @@
#include "SkDescriptor.h"
#include "SkSpinlock.h"
#include "SkTemplates.h"
+#include "SkArenaAlloc.h"
class SkGlyphCache;
class SkTraceMemoryDump;
@@ -38,12 +39,21 @@ public:
static void AttachCache(SkGlyphCache* cache);
- using ExclusiveStrikePtr = std::unique_ptr<
+ using ExclusiveStrikePtr =
+ std::unique_ptr<
SkGlyphCache,
SkFunctionWrapper<void, SkGlyphCache, SkStrikeCache::AttachCache>>;
static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&);
+ static std::unique_ptr<SkScalerContext> CreateScalerContext(
+ const SkDescriptor&, const SkScalerContextEffects&, const SkTypeface&);
+
+ static ExclusiveStrikePtr CreateStrikeExclusive(
+ const SkDescriptor& desc,
+ std::unique_ptr<SkScalerContext> scaler,
+ SkPaint::FontMetrics* maybeMetrics = nullptr);
+
static void PurgeAll();
static void Dump();
@@ -69,7 +79,6 @@ public:
int getCachePointSizeLimit() const;
int setCachePointSizeLimit(int limit);
-
#ifdef SK_DEBUG
void validate() const;
#else
@@ -77,6 +86,16 @@ public:
#endif
private:
+ friend class SkGlyphCache;
+ template <typename T>
+ struct Node {
+ Node(const SkDescriptor& desc) : fDesc{desc} {}
+ const SkDescriptor& getDescriptor() const {return *fDesc.getDesc(); }
+ T* fNext{nullptr};
+ T* fPrev{nullptr};
+ SkAutoDescriptor fDesc;
+ };
+
// The following methods can only be called when mutex is already held.
SkGlyphCache* internalGetHead() const { return fHead; }
SkGlyphCache* internalGetTail() const;