Index: src/core/SkRemote.cpp |
diff --git a/src/core/SkRemote.cpp b/src/core/SkRemote.cpp |
index ae14a47d187b4b28d2b1acfd8913d57638de60ef..20f4c8989061cdd3bb3f1f1b5fea253b1fbf6b2e 100644 |
--- a/src/core/SkRemote.cpp |
+++ b/src/core/SkRemote.cpp |
@@ -61,6 +61,28 @@ namespace SkRemote { |
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // |
+ class LookupScope { |
+ public: |
+ LookupScope(Cache* cache, Encoder* encoder) : fCache(cache), fEncoder(encoder) {} |
+ ~LookupScope() { for (ID id : fToUndefine) { fEncoder->undefine(id); } } |
+ void undefineWhenDone(ID id) { fToUndefine.push_back(id); } |
+ |
+ template <typename T> |
+ ID lookup(const T& val) { |
+ ID id; |
+ if (!fCache->lookup(val, &id, this)) { |
+ fEncoder->define(id, val); |
+ } |
+ return id; |
+ } |
+ |
+ private: |
+ Cache* fCache; |
+ Encoder* fEncoder; |
+ SkSTArray<4, ID> fToUndefine; |
+ }; |
+ |
+ |
Cache* Cache::CreateNeverCache() { |
struct NeverCache final : public Cache { |
NeverCache() |
@@ -164,15 +186,6 @@ namespace SkRemote { |
fCache->cleanup(fEncoder); |
} |
- template <typename T> |
- ID LookupScope::lookup(const T& val) { |
- ID id; |
- if (!fCache->lookup(val, &id, this)) { |
- fEncoder->define(id, val); |
- } |
- return id; |
- } |
- |
void Client::willSave() { fEncoder->save(); } |
void Client::didRestore() { fEncoder->restore(); } |