Roll external/skia e5d7107f6..f4c057af0 (1 commits)

https://skia.googlesource.com/skia.git/+log/e5d7107f6..f4c057af0

2019-04-29 jvanverth@google.com Clean out stale shadow vertices from the SkResourceCache

The AutoRoll server is located here: https://autoroll-internal.skia.org/r/android-next-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC'd on the roll, and stop the roller if necessary.

Test: Presubmit checks will test this change.
Exempt-From-Owner-Approval: The autoroll bot does not require owner approval.

Bug: 130757982
Merged-In: I48b225a2801844e1265ac2181eb02fcf2cd71c39
Change-Id: If8838e268b1267115c6f35f3021b6c4805c714cc
diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp
index 4cc8398..df167d3 100644
--- a/src/utils/SkShadowUtils.cpp
+++ b/src/utils/SkShadowUtils.cpp
@@ -14,6 +14,7 @@
 #include "SkDrawShadowInfo.h"
 #include "SkMaskFilter.h"
 #include "SkPath.h"
+#include "SkPathPriv.h"
 #include "SkRandom.h"
 #include "SkRasterPipeline.h"
 #include "SkResourceCache.h"
@@ -379,6 +380,31 @@
 // This creates a domain of keys in SkResourceCache used by this file.
 static void* kNamespace;
 
+// When the SkPathRef genID changes, invalidate a corresponding GrResource described by key.
+class ShadowInvalidator : public SkPathRef::GenIDChangeListener {
+public:
+    ShadowInvalidator(const SkResourceCache::Key& key) {
+        fKey.reset(new uint8_t[key.size()]);
+        memcpy(fKey.get(), &key, key.size());
+    }
+
+private:
+    const SkResourceCache::Key& getKey() const {
+        return *reinterpret_cast<SkResourceCache::Key*>(fKey.get());
+    }
+
+    // always purge
+    static bool FindVisitor(const SkResourceCache::Rec&, void*) {
+        return false;
+    }
+
+    void onChange() override {
+        SkResourceCache::Find(this->getKey(), ShadowInvalidator::FindVisitor, nullptr);
+    }
+
+    std::unique_ptr<uint8_t[]> fKey;
+};
+
 /**
  * Draws a shadow to 'canvas'. The vertices used to draw the shadow are created by 'factory' unless
  * they are first found in SkResourceCache.
@@ -420,6 +446,7 @@
                 return false;
             }
             auto rec = new CachedTessellationsRec(*key, std::move(tessellations));
+            SkPathPriv::AddGenIDChangeListener(path.path(), sk_make_sp<ShadowInvalidator>(*key));
             SkResourceCache::Add(rec);
         } else {
             vertices = factory.makeVertices(path.path(), path.viewMatrix(),