aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-06-21 15:15:50 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-21 19:49:27 +0000
commit5c0c7983bb6371c493561dbc97671e4997f822d5 (patch)
treee8bf690e86f2fb4ed0c55bbf5db929dee2a947ab /src
parentc113e9e23d76a463743d6e5372284fb84b58fd8c (diff)
Use local strike caches to avoid flaky test behavior
The remote glyph cache tests assume that the strike cache will not change during a test. This is not true because other test also mutate the strike cache. This is causing flaky tests. BUG=skia:8091 Change-Id: I397d411f9412006715f6860941dfb05ad54ae1b6 Reviewed-on: https://skia-review.googlesource.com/136741 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Klein <mtklein@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkRemoteGlyphCache.cpp14
-rw-r--r--src/core/SkRemoteGlyphCache.h7
-rw-r--r--src/core/SkStrikeCache.cpp10
-rw-r--r--src/core/SkStrikeCache.h7
-rw-r--r--src/core/SkTypeface_remote.cpp7
-rw-r--r--src/core/SkTypeface_remote.h4
6 files changed, 21 insertions, 28 deletions
diff --git a/src/core/SkRemoteGlyphCache.cpp b/src/core/SkRemoteGlyphCache.cpp
index fa4767069f..774a1eb77c 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::GlobalStrikeCache()}
, 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..157e058331 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
@@ -232,6 +234,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 bac48d8230..94f8c6d8bd 100644
--- a/src/core/SkStrikeCache.cpp
+++ b/src/core/SkStrikeCache.cpp
@@ -111,16 +111,6 @@ SkExclusiveStrikePtr SkStrikeCache::FindStrikeExclusive(const SkDescriptor& desc
return GlobalStrikeCache()->findStrikeExclusive(desc);
}
-bool SkStrikeCache::DesperationSearchForImage(const SkDescriptor& desc, SkGlyph* glyph,
- SkGlyphCache* targetCache) {
- return GlobalStrikeCache()->desperationSearchForImage(desc, glyph, targetCache);
-}
-
-bool SkStrikeCache::DesperationSearchForPath(
- const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path) {
- return GlobalStrikeCache()->desperationSearchForPath(desc, glyphID, path);
-}
-
std::unique_ptr<SkScalerContext> SkStrikeCache::CreateScalerContext(
const SkDescriptor& desc,
const SkScalerContextEffects& effects,
diff --git a/src/core/SkStrikeCache.h b/src/core/SkStrikeCache.h
index 22f1daf9fb..5d88126960 100644
--- a/src/core/SkStrikeCache.h
+++ b/src/core/SkStrikeCache.h
@@ -97,16 +97,9 @@ public:
// Routines to find suitable data when working in a remote cache situation. These are
// suitable as substitutes for similar calls in SkScalerContext.
- static bool DesperationSearchForImage(const SkDescriptor& desc,
- SkGlyph* glyph,
- SkGlyphCache* targetCache);
-
bool desperationSearchForImage(const SkDescriptor& desc,
SkGlyph* glyph,
SkGlyphCache* targetCache);
-
- static bool DesperationSearchForPath(
- const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path);
bool desperationSearchForPath(const SkDescriptor& desc, SkGlyphID glyphID, SkPath* path);
static ExclusiveStrikePtr FindOrCreateStrikeExclusive(
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;
};