ccpr: Don't use the GrContext id for the path cache id
Currently this is probably safe, but somebody could easily make a
change in the future that adds another path cache to the context and
accidentally introduces tricky bugs.
TBR=brianosman@google.com
Bug: chromium:897510
Bug: chromium:897413
Bug: chromium:897245
Bug: chromium:897507
Change-Id: I6bc40ac671058f78eb290dd775612d99008d32e7
Reviewed-on: https://skia-review.googlesource.com/c/164700
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/ccpr/GrCCPathCache.cpp b/src/gpu/ccpr/GrCCPathCache.cpp
index db85641..6d37b4f 100644
--- a/src/gpu/ccpr/GrCCPathCache.cpp
+++ b/src/gpu/ccpr/GrCCPathCache.cpp
@@ -12,6 +12,16 @@
DECLARE_SKMESSAGEBUS_MESSAGE(sk_sp<GrCCPathCacheEntry>);
+static inline uint32_t next_path_cache_id() {
+ static std::atomic<uint32_t> gNextID(1);
+ for (;;) {
+ uint32_t id = gNextID.fetch_add(+1, std::memory_order_acquire);
+ if (SK_InvalidUniqueID != id) {
+ return id;
+ }
+ }
+}
+
static inline bool SkShouldPostMessageToBus(
const sk_sp<GrCCPathCacheEntry>& entry, uint32_t msgBusUniqueID) {
return entry->pathCacheUniqueID() == msgBusUniqueID;
@@ -20,6 +30,7 @@
// The maximum number of cache entries we allow in our own cache.
static constexpr int kMaxCacheCount = 1 << 16;
+
GrCCPathCache::MaskTransform::MaskTransform(const SkMatrix& m, SkIVector* shift)
: fMatrix2x2{m.getScaleX(), m.getSkewX(), m.getSkewY(), m.getScaleY()} {
SkASSERT(!m.hasPerspective());
@@ -128,6 +139,11 @@
return GrResourceKeyHash(&key.fData[1], key.fData[0]);
}
+
+GrCCPathCache::GrCCPathCache()
+ : fInvalidatedEntriesInbox(next_path_cache_id()) {
+}
+
#ifdef SK_DEBUG
GrCCPathCache::~GrCCPathCache() {
// Ensure the hash table and LRU list are still coherent.
@@ -248,9 +264,8 @@
fCachedAtlasInfo->fNumInvalidatedPathPixels >= fCachedAtlasInfo->fNumPathPixels / 2) {
// Too many invalidated pixels: purge the atlas texture from the resource cache.
// The GrContext and CCPR path cache both share the same unique ID.
- uint32_t contextUniqueID = fPathCacheUniqueID;
SkMessageBus<GrUniqueKeyInvalidatedMessage>::Post(
- GrUniqueKeyInvalidatedMessage(fAtlasKey, contextUniqueID));
+ GrUniqueKeyInvalidatedMessage(fAtlasKey, fCachedAtlasInfo->fContextUniqueID));
fCachedAtlasInfo->fIsPurgedFromResourceCache = true;
}
}