GLSL editing in Viewer

When in GL backend, adds a "Shaders" section to the debug menu.
"Load" scrapes all of the vertex and fragment shaders being used,
then displays them. They can be edited, and "Save" pushes the
results.

Note: It is trivial to trigger an assert by saving a shader that
doesn't compile. I'd like to make the program builder more robust
in a follow-up CL, to fall back to the "real" SkSL, not draw, or
something along those lines.

Change-Id: I841fe2ee76a3c2eae58b64ef587fcbe25b95cc7e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206905
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/tools/gpu/MemoryCache.h b/tools/gpu/MemoryCache.h
index 119ea8d..1e61994 100644
--- a/tools/gpu/MemoryCache.h
+++ b/tools/gpu/MemoryCache.h
@@ -27,6 +27,10 @@
     MemoryCache() = default;
     MemoryCache(const MemoryCache&) = delete;
     MemoryCache& operator=(const MemoryCache&) = delete;
+    void reset() {
+        fCacheMissCnt = 0;
+        fMap.clear();
+    }
 
     sk_sp<SkData> load(const SkData& key) override;
     void store(const SkData& key, const SkData& data) override;
@@ -35,6 +39,13 @@
 
     void writeShadersToDisk(const char* path, GrBackendApi backend);
 
+    template <typename Fn>
+    void foreach(Fn&& fn) {
+        for (auto it = fMap.begin(); it != fMap.end(); ++it) {
+            fn(it->first.fKey, it->second.fData, it->second.fHitCount);
+        }
+    }
+
 private:
     struct Key {
         Key() = default;