Add native caching of uniquely keyed GrTextureProxies (take 2)

TBR=bsalomon@google.com

Change-Id: I590dcdc85fb60706c7eb06277694791dc04c9141
Reviewed-on: https://skia-review.googlesource.com/49543
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrTextureProxyCacheAccess.h b/src/gpu/GrTextureProxyCacheAccess.h
new file mode 100644
index 0000000..79cf845
--- /dev/null
+++ b/src/gpu/GrTextureProxyCacheAccess.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrTextureProxyCacheAccess_DEFINED
+#define GrTextureProxyCacheAccess_DEFINED
+
+#include "GrTextureProxy.h"
+
+/**
+ * This class allows GrResourceCache increased privileged access to GrTextureProxy objects.
+ */
+class GrTextureProxy::CacheAccess {
+private:
+    void setUniqueKey(GrResourceCache* cache, const GrUniqueKey& key) {
+        fTextureProxy->setUniqueKey(cache, key);
+    }
+
+    void clearUniqueKey() {
+        fTextureProxy->clearUniqueKey();
+    }
+
+    explicit CacheAccess(GrTextureProxy* textureProxy) : fTextureProxy(textureProxy) {}
+    CacheAccess(const CacheAccess&) {} // unimpl
+    CacheAccess& operator=(const CacheAccess&); // unimpl
+
+    // No taking addresses of this type.
+    const CacheAccess* operator&() const;
+    CacheAccess* operator&();
+
+    GrTextureProxy* fTextureProxy;
+
+    friend class GrTextureProxy;  // to construct/copy this type.
+    friend class GrResourceCache; // to use this type
+};
+
+inline GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() { return CacheAccess(this); }
+
+inline const GrTextureProxy::CacheAccess GrTextureProxy::cacheAccess() const {
+    return CacheAccess(const_cast<GrTextureProxy*>(this));
+}
+
+#endif