aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-06-20 14:43:23 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-20 20:24:47 +0000
commit3e36ce6e660ad585c58c5cc5591f23a46fcab767 (patch)
tree1a63f02ccef4ba8414997378b5dff225750b44a7 /src
parentb70e3b4831398aff696b9e15ad7e8f581db8aa9d (diff)
Make SkRemoteGlyphCache tests use private glyph cache
Change-Id: If6aa189f3badc7558ab8ecf71ee3d704b275b20f Reviewed-on: https://skia-review.googlesource.com/136225 Commit-Queue: Herb Derby <herb@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkRemoteGlyphCache.cpp14
-rw-r--r--src/core/SkRemoteGlyphCache.h11
-rw-r--r--src/core/SkStrikeCache.cpp129
-rw-r--r--src/core/SkStrikeCache.h19
-rw-r--r--src/core/SkTypeface_remote.cpp7
-rw-r--r--src/core/SkTypeface_remote.h4
6 files changed, 115 insertions, 69 deletions
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index fa4767069f..10b1b41cbd 100644
--- a/src/core/SkRemoteGlyphCache.cpp
+++ b/src/core/SkRemoteGlyphCache.cpp
@@ -734,8 +734,11 @@ private:
sk_sp<DiscardableHandleManager> fManager;
};
-SkStrikeClient::SkStrikeClient(sk_sp<DiscardableHandleManager> discardableManager, bool isLogging)
+SkStrikeClient::SkStrikeClient(sk_sp<DiscardableHandleManager> discardableManager,
+ bool isLogging,
+ SkStrikeCache* strikeCache)
: fDiscardableHandleManager(std::move(discardableManager))
+ , fStrikeCache{strikeCache ? strikeCache : SkStrikeCache::GetGlobalStrikeCache()}
, fIsLogging{isLogging} {}
SkStrikeClient::~SkStrikeClient() = default;
@@ -792,18 +795,19 @@ bool SkStrikeClient::readStrikeData(const volatile void* memory, size_t memorySi
SkAutoDescriptor ad;
auto* client_desc = auto_descriptor_from_desc(sourceAd.getDesc(), tf->uniqueID(), &ad);
- auto strike = SkStrikeCache::FindStrikeExclusive(*client_desc);
+ auto strike = fStrikeCache->findStrikeExclusive(*client_desc);
if (strike == nullptr) {
// Note that we don't need to deserialize the effects since we won't be generating any
// glyphs here anyway, and the desc is still correct since it includes the serialized
// effects.
SkScalerContextEffects effects;
auto scaler = SkStrikeCache::CreateScalerContext(*client_desc, effects, *tf);
- strike = SkStrikeCache::CreateStrikeExclusive(
+ strike = fStrikeCache->createStrikeExclusive(
*client_desc, std::move(scaler), &fontMetrics,
skstd::make_unique<DiscardableStrikePinner>(spec.discardableHandleId,
fDiscardableHandleManager));
- static_cast<SkScalerContextProxy*>(strike->getScalerContext())->initCache(strike.get());
+ auto proxyContext = static_cast<SkScalerContextProxy*>(strike->getScalerContext());
+ proxyContext->initCache(strike.get(), fStrikeCache);
}
size_t glyphImagesCount = 0u;
@@ -865,7 +869,7 @@ sk_sp<SkTypeface> SkStrikeClient::deserializeTypeface(const void* buf, size_t le
WireTypeface wire;
if (len != sizeof(wire)) return nullptr;
memcpy(&wire, buf, sizeof(wire));
- return addTypeface(wire);
+ return this->addTypeface(wire);
}
sk_sp<SkTypeface> SkStrikeClient::addTypeface(const WireTypeface& wire) {
diff --git a/src/core/SkRemoteGlyphCache.h b/src/core/SkRemoteGlyphCache.h
index ac13920772..f09228fd1e 100644
--- a/src/core/SkRemoteGlyphCache.h
+++ b/src/core/SkRemoteGlyphCache.h
@@ -20,7 +20,6 @@
#include "SkMakeUnique.h"
#include "SkNoDrawCanvas.h"
#include "SkRefCnt.h"
-#include "SkRemoteGlyphCache.h"
#include "SkSerialProcs.h"
#include "SkTypeface.h"
@@ -30,6 +29,7 @@ class SkGlyphCache;
struct SkPackedGlyphID;
enum SkScalerContextFlags : uint32_t;
class SkScalerContextRecDescriptor;
+class SkStrikeCache;
class SkTextBlobRunIterator;
class SkTypefaceProxy;
struct WireTypeface;
@@ -212,7 +212,9 @@ public:
virtual void notifyCacheMiss(CacheMissType) {}
};
- SkStrikeClient(sk_sp<DiscardableHandleManager>, bool isLogging = true);
+ SkStrikeClient(sk_sp<DiscardableHandleManager>,
+ bool isLogging = true,
+ SkStrikeCache* strikeCache = nullptr);
~SkStrikeClient();
// Deserializes the typeface previously serialized using the SkStrikeServer. Returns null if the
@@ -223,7 +225,9 @@ public:
// from a server when serializing the ops must be deserialized before the op
// is rasterized.
// Returns false if the data is invalid.
- bool readStrikeData(const volatile void* memory, size_t memorySize);
+ bool readStrikeData(
+ const volatile void* memory,
+ size_t memorySize);
private:
class DiscardableStrikePinner;
@@ -232,6 +236,7 @@ private:
SkTHashMap<SkFontID, sk_sp<SkTypeface>> fRemoteFontIdToTypeface;
sk_sp<DiscardableHandleManager> fDiscardableHandleManager;
+ SkStrikeCache* const fStrikeCache;
const bool fIsLogging;
};
diff --git a/src/core/SkStrikeCache.cpp b/src/core/SkStrikeCache.cpp
index fef46fd36d..5f3a46bd42 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -19,15 +19,6 @@
#include "SkTypefaceCache.h"
#include "SkPaintPriv.h"
-// Returns the shared globals
-static SkStrikeCache& get_globals() {
- static SkOnce once;
- static SkStrikeCache* globals;
-
- once([]{ globals = new SkStrikeCache; });
- return *globals;
-}
-
struct SkStrikeCache::Node {
Node(const SkDescriptor& desc,
std::unique_ptr<SkScalerContext> scaler,
@@ -42,23 +33,35 @@ struct SkStrikeCache::Node {
std::unique_ptr<SkStrikePinner> fPinner;
};
-SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(SkStrikeCache::Node* node) : fNode{node} {}
-SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr() : fNode{nullptr} {}
+SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(
+ SkStrikeCache::Node* node, SkStrikeCache* strikeCache)
+ : fNode{node}
+ , fStrikeCache{strikeCache} {}
+SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr()
+ : fNode{nullptr}
+ , fStrikeCache{nullptr} {}
SkStrikeCache::ExclusiveStrikePtr::ExclusiveStrikePtr(ExclusiveStrikePtr&& o)
- : fNode{o.fNode} {
+ : fNode{o.fNode}, fStrikeCache{o.fStrikeCache} {
o.fNode = nullptr;
+ o.fStrikeCache = nullptr;
}
SkStrikeCache::ExclusiveStrikePtr&
SkStrikeCache::ExclusiveStrikePtr::operator = (ExclusiveStrikePtr&& o) {
- Attach(fNode);
+ if (fNode != nullptr) {
+ fStrikeCache->attachNode(fNode);
+ }
fNode = o.fNode;
+ fStrikeCache = o.fStrikeCache;
o.fNode = nullptr;
+ o.fStrikeCache = nullptr;
return *this;
}
SkStrikeCache::ExclusiveStrikePtr::~ExclusiveStrikePtr() {
- SkStrikeCache::Attach(fNode);
+ if (fNode != nullptr) {
+ fStrikeCache->attachNode(fNode);
+ }
}
SkGlyphCache* SkStrikeCache::ExclusiveStrikePtr::get() const {
return &fNode->fCache;
@@ -84,6 +87,14 @@ bool operator == (decltype(nullptr), const SkStrikeCache::ExclusiveStrikePtr& rh
return nullptr == rhs.fNode;
}
+SkStrikeCache* SkStrikeCache::GetGlobalStrikeCache() {
+ static SkOnce once;
+ static SkStrikeCache* globals;
+
+ once([]{ globals = new SkStrikeCache; });
+ return globals;
+}
+
SkStrikeCache::~SkStrikeCache() {
Node* node = fHead;
while (node) {
@@ -93,22 +104,9 @@ SkStrikeCache::~SkStrikeCache() {
}
}
-void SkStrikeCache::Attach(Node* node) {
- get_globals().attachNode(node);
-}
SkExclusiveStrikePtr SkStrikeCache::FindStrikeExclusive(const SkDescriptor& desc) {
- return get_globals().findStrikeExclusive(desc);
-}
-
-bool SkStrikeCache::DesperationSearchForImage(const SkDescriptor& desc, SkGlyph* glyph,
- SkGlyphCache* targetCache) {
- return get_globals().desperationSearchForImage(desc, glyph, targetCache);
-}
-
-bool SkStrikeCache::DesperationSearchForPath(
- const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path) {
- return get_globals().desperationSearchForPath(desc, glyphID, path);
+ return GetGlobalStrikeCache()->findStrikeExclusive(desc);
}
std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
@@ -131,10 +129,16 @@ std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(
const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
{
- auto cache = FindStrikeExclusive(desc);
+ return GetGlobalStrikeCache()->findOrCreateStrikeExclusive(desc, effects, typeface);
+}
+
+SkExclusiveStrikePtr SkStrikeCache::findOrCreateStrikeExclusive(
+ const SkDescriptor& desc, const SkScalerContextEffects& effects, const SkTypeface& typeface)
+{
+ auto cache = this->findStrikeExclusive(desc);
if (cache == nullptr) {
auto scaler = CreateScalerContext(desc, effects, typeface);
- cache = CreateStrikeExclusive(desc, std::move(scaler));
+ cache = this->createStrikeExclusive(desc, std::move(scaler));
}
return cache;
}
@@ -162,17 +166,23 @@ SkExclusiveStrikePtr SkStrikeCache::FindOrCreateStrikeExclusive(const SkPaint& p
}
void SkStrikeCache::PurgeAll() {
- get_globals().purgeAll();
+ GetGlobalStrikeCache()->purgeAll();
}
void SkStrikeCache::Validate() {
#ifdef SK_DEBUG
- auto visitor = [](const SkGlyphCache& cache) { cache.forceValidate(); };
-
- get_globals().forEachStrike(visitor);
+ GetGlobalStrikeCache()->validate();
#endif
}
+#ifdef SK_DEBUG
+void SkStrikeCache::validate() const {
+ SkAutoExclusive ac(fLock);
+ this->internalValidate();
+}
+#endif
+
+
void SkStrikeCache::Dump() {
SkDebugf("GlyphCache [ used budget ]\n");
SkDebugf(" bytes [ %8zu %8zu ]\n",
@@ -190,7 +200,7 @@ void SkStrikeCache::Dump() {
counter += 1;
};
- get_globals().forEachStrike(visitor);
+ GetGlobalStrikeCache()->forEachStrike(visitor);
}
namespace {
@@ -234,7 +244,7 @@ void SkStrikeCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) {
dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
};
- get_globals().forEachStrike(visitor);
+ GetGlobalStrikeCache()->forEachStrike(visitor);
}
@@ -244,7 +254,7 @@ void SkStrikeCache::attachNode(Node* node) {
}
SkAutoExclusive ac(fLock);
- this->validate();
+ this->internalValidate();
node->fCache.validate();
this->internalAttachToHead(node);
@@ -258,11 +268,11 @@ SkExclusiveStrikePtr SkStrikeCache::findStrikeExclusive(const SkDescriptor& desc
for (node = internalGetHead(); node != nullptr; node = node->fNext) {
if (node->fCache.getDescriptor() == desc) {
this->internalDetachCache(node);
- return SkExclusiveStrikePtr(node);
+ return SkExclusiveStrikePtr(node, this);
}
}
- return SkExclusiveStrikePtr(nullptr);
+ return SkExclusiveStrikePtr();
}
static bool loose_compare(const SkDescriptor& lhs, const SkDescriptor& rhs) {
@@ -354,6 +364,16 @@ SkExclusiveStrikePtr SkStrikeCache::CreateStrikeExclusive(
SkPaint::FontMetrics* maybeMetrics,
std::unique_ptr<SkStrikePinner> pinner)
{
+ return GetGlobalStrikeCache()->createStrikeExclusive(
+ desc, std::move(scaler), maybeMetrics, std::move(pinner));
+}
+
+SkExclusiveStrikePtr SkStrikeCache::createStrikeExclusive(
+ const SkDescriptor& desc,
+ std::unique_ptr<SkScalerContext> scaler,
+ SkPaint::FontMetrics* maybeMetrics,
+ std::unique_ptr<SkStrikePinner> pinner)
+{
SkPaint::FontMetrics fontMetrics;
if (maybeMetrics != nullptr) {
fontMetrics = *maybeMetrics;
@@ -361,7 +381,9 @@ SkExclusiveStrikePtr SkStrikeCache::CreateStrikeExclusive(
scaler->getFontMetrics(&fontMetrics);
}
- return SkExclusiveStrikePtr(new Node(desc, std::move(scaler), fontMetrics, std::move(pinner)));
+ return SkExclusiveStrikePtr(
+ new Node(desc, std::move(scaler), fontMetrics, std::move(pinner)),
+ this);
}
void SkStrikeCache::purgeAll() {
@@ -436,15 +458,13 @@ int SkStrikeCache::setCachePointSizeLimit(int newLimit) {
void SkStrikeCache::forEachStrike(std::function<void(const SkGlyphCache&)> visitor) const {
SkAutoExclusive ac(fLock);
- this->validate();
-
for (Node* node = this->internalGetHead(); node != nullptr; node = node->fNext) {
visitor(node->fCache);
}
}
size_t SkStrikeCache::internalPurge(size_t minBytesNeeded) {
- this->validate();
+ this->internalValidate();
size_t bytesNeeded = 0;
if (fTotalMemoryUsed > fCacheSizeLimit) {
@@ -487,7 +507,7 @@ size_t SkStrikeCache::internalPurge(size_t minBytesNeeded) {
node = prev;
}
- this->validate();
+ this->internalValidate();
#ifdef SPEW_PURGE_STATUS
if (countFreed) {
@@ -534,12 +554,13 @@ void SkStrikeCache::internalDetachCache(Node* node) {
}
#ifdef SK_DEBUG
-void SkStrikeCache::validate() const {
+void SkStrikeCache::internalValidate() const {
size_t computedBytes = 0;
int computedCount = 0;
const Node* node = fHead;
while (node != nullptr) {
+ node->fCache.forceValidate();
computedBytes += node->fCache.getMemoryUsed();
computedCount += 1;
node = node->fNext;
@@ -555,38 +576,38 @@ void SkStrikeCache::validate() const {
////////////////////////////////////////////////////////////////////////////////////////////////////
size_t SkGraphics::GetFontCacheLimit() {
- return get_globals().getCacheSizeLimit();
+ return SkStrikeCache::GetGlobalStrikeCache()->getCacheSizeLimit();
}
size_t SkGraphics::SetFontCacheLimit(size_t bytes) {
- return get_globals().setCacheSizeLimit(bytes);
+ return SkStrikeCache::GetGlobalStrikeCache()->setCacheSizeLimit(bytes);
}
size_t SkGraphics::GetFontCacheUsed() {
- return get_globals().getTotalMemoryUsed();
+ return SkStrikeCache::GetGlobalStrikeCache()->getTotalMemoryUsed();
}
int SkGraphics::GetFontCacheCountLimit() {
- return get_globals().getCacheCountLimit();
+ return SkStrikeCache::GetGlobalStrikeCache()->getCacheCountLimit();
}
int SkGraphics::SetFontCacheCountLimit(int count) {
- return get_globals().setCacheCountLimit(count);
+ return SkStrikeCache::GetGlobalStrikeCache()->setCacheCountLimit(count);
}
int SkGraphics::GetFontCacheCountUsed() {
- return get_globals().getCacheCountUsed();
+ return SkStrikeCache::GetGlobalStrikeCache()->getCacheCountUsed();
}
int SkGraphics::GetFontCachePointSizeLimit() {
- return get_globals().getCachePointSizeLimit();
+ return SkStrikeCache::GetGlobalStrikeCache()->getCachePointSizeLimit();
}
int SkGraphics::SetFontCachePointSizeLimit(int limit) {
- return get_globals().setCachePointSizeLimit(limit);
+ return SkStrikeCache::GetGlobalStrikeCache()->setCachePointSizeLimit(limit);
}
void SkGraphics::PurgeFontCache() {
- get_globals().purgeAll();
+ SkStrikeCache::GetGlobalStrikeCache()->purgeAll();
SkTypefaceCache::PurgeAll();
}
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index 05e3aa4025..a2b3a8a19d 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -47,7 +47,7 @@ public:
class ExclusiveStrikePtr {
public:
- explicit ExclusiveStrikePtr(Node*);
+ explicit ExclusiveStrikePtr(Node*, SkStrikeCache*);
ExclusiveStrikePtr();
ExclusiveStrikePtr(const ExclusiveStrikePtr&) = delete;
ExclusiveStrikePtr& operator = (const ExclusiveStrikePtr&) = delete;
@@ -65,8 +65,10 @@ public:
private:
Node* fNode;
+ SkStrikeCache* fStrikeCache;
};
+ static SkStrikeCache* GetGlobalStrikeCache();
static ExclusiveStrikePtr FindStrikeExclusive(const SkDescriptor&);
@@ -111,6 +113,17 @@ public:
void attachNode(Node* node);
ExclusiveStrikePtr findStrikeExclusive(const SkDescriptor&);
+ ExclusiveStrikePtr findOrCreateStrikeExclusive(
+ const SkDescriptor& desc,
+ const SkScalerContextEffects& effects,
+ const SkTypeface& typeface);
+
+ ExclusiveStrikePtr createStrikeExclusive(
+ const SkDescriptor& desc,
+ std::unique_ptr<SkScalerContext> scaler,
+ SkPaint::FontMetrics* maybeMetrics = nullptr,
+ std::unique_ptr<SkStrikePinner> = nullptr);
+
// Routines to find suitable data when working in a remote cache situation. These are
// suitable as substitutes for similar calls in SkScalerContext.
bool desperationSearchForImage(const SkDescriptor& desc,
@@ -133,13 +146,13 @@ public:
#ifdef SK_DEBUG
void validate() const;
+ void internalValidate() const;
#else
void validate() const {}
+ void internalValidate() const {}
#endif
private:
- static void Attach(Node* node);
-
// The following methods can only be called when mutex is already held.
Node* internalGetHead() const { return fHead; }
Node* internalGetTail() const { return fTail; }
diff --git a/src/core/SkTypeface_remote.cpp b/src/core/SkTypeface_remote.cpp
index 4b10f1e96f..bc6376d8fe 100644
--- a/src/core/SkTypeface_remote.cpp
+++ b/src/core/SkTypeface_remote.cpp
@@ -19,11 +19,12 @@ SkScalerContextProxy::SkScalerContextProxy(sk_sp<SkTypeface> tf,
: SkScalerContext{std::move(tf), effects, desc}
, fDiscardableManager{std::move(manager)} {}
-void SkScalerContextProxy::initCache(SkGlyphCache* cache) {
+void SkScalerContextProxy::initCache(SkGlyphCache* cache, SkStrikeCache* strikeCache) {
SkASSERT(fCache == nullptr);
SkASSERT(cache != nullptr);
fCache = cache;
+ fStrikeCache = strikeCache;
}
unsigned SkScalerContextProxy::generateGlyphCount() {
@@ -57,7 +58,7 @@ void SkScalerContextProxy::generateMetrics(SkGlyph* glyph) {
}
// Now check other caches for a desc mismatch.
- if (SkStrikeCache::DesperationSearchForImage(fCache->getDescriptor(), glyph, fCache)) {
+ if (fStrikeCache->desperationSearchForImage(fCache->getDescriptor(), glyph, fCache)) {
fDiscardableManager->notifyCacheMiss(
SkStrikeClient::CacheMissType::kGlyphMetricsFallback);
return;
@@ -88,7 +89,7 @@ bool SkScalerContextProxy::generatePath(SkGlyphID glyphID, SkPath* path) {
// Since the scaler context is being called, we don't have the needed data. Try to find a
// fallback before failing.
auto desc = SkScalerContext::DescriptorGivenRecAndEffects(this->getRec(), this->getEffects());
- bool foundPath = SkStrikeCache::DesperationSearchForPath(*desc, glyphID, path);
+ bool foundPath = fStrikeCache->desperationSearchForPath(*desc, glyphID, path);
fDiscardableManager->notifyCacheMiss(foundPath
? SkStrikeClient::CacheMissType::kGlyphPathFallback
: SkStrikeClient::CacheMissType::kGlyphPath);
diff --git a/src/core/SkTypeface_remote.h b/src/core/SkTypeface_remote.h
index 88628d13b4..f4d3f73e2b 100644
--- a/src/core/SkTypeface_remote.h
+++ b/src/core/SkTypeface_remote.h
@@ -18,6 +18,7 @@
#include "SkTypeface.h"
class SkTypefaceProxy;
+class SkStrikeCache;
class SkScalerContextProxy : public SkScalerContext {
public:
@@ -26,7 +27,7 @@ public:
const SkDescriptor* desc,
sk_sp<SkStrikeClient::DiscardableHandleManager> manager);
- void initCache(SkGlyphCache*);
+ void initCache(SkGlyphCache*, SkStrikeCache*);
protected:
unsigned generateGlyphCount() override;
@@ -41,6 +42,7 @@ protected:
private:
sk_sp<SkStrikeClient::DiscardableHandleManager> fDiscardableManager;
SkGlyphCache* fCache = nullptr;
+ SkStrikeCache* fStrikeCache = nullptr;
typedef SkScalerContext INHERITED;
};