Make GrSurfaceProxy derive from GrNonAtomicRef and remove GrIORefProxy.

Also, expose GrNonAtomicRef's ref count. Since it's non-atomic and not
thread-safe it seems fine.

Change-Id: I5cf48e60d32094354955b2614cfeebbb4c1ecf2a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238059
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrNonAtomicRef.h b/src/gpu/GrNonAtomicRef.h
index d60c978..db7eea2 100644
--- a/src/gpu/GrNonAtomicRef.h
+++ b/src/gpu/GrNonAtomicRef.h
@@ -31,6 +31,10 @@
 
     bool unique() const { return 1 == fRefCnt; }
 
+    // We allow this getter because this type is not thread-safe, meaning only one thread should
+    // have ownership and be manipulating the ref count or querying this.
+    int refCnt() const { return fRefCnt; }
+
     void ref() const {
         // Once the ref cnt reaches zero it should never be ref'ed again.
         SkASSERT(fRefCnt > 0);
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 734b227..9dd6393 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -104,7 +104,7 @@
 
     GrTextureProxy* proxy = fUniquelyKeyedProxies.find(key);
     if (proxy) {
-        SkASSERT(proxy->getProxyRefCnt() >= 1);
+        SkASSERT(proxy->refCnt() >= 1);
         SkASSERT(proxy->origin() == origin);
         return sk_ref_sp(proxy);
     }
diff --git a/src/gpu/GrRenderTargetProxy.h b/src/gpu/GrRenderTargetProxy.h
index 2759a3d..3371850 100644
--- a/src/gpu/GrRenderTargetProxy.h
+++ b/src/gpu/GrRenderTargetProxy.h
@@ -135,10 +135,6 @@
     // about what we're doing).
     char               fDummyPadding[10];
 
-    // For wrapped render targets the actual GrRenderTarget is stored in the GrIORefProxy class.
-    // For deferred proxies that pointer is filled in when we need to instantiate the
-    // deferred resource.
-
     typedef GrSurfaceProxy INHERITED;
 };
 
diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp
index ecc9a42..1e27c77 100644
--- a/src/gpu/GrResourceAllocator.cpp
+++ b/src/gpu/GrResourceAllocator.cpp
@@ -44,10 +44,10 @@
             continue;
         }
 
-        if (cur->uses() >= cur->proxy()->priv().getProxyRefCnt()) {
+        if (cur->uses() >= cur->proxy()->refCnt()) {
             // All the refs on the proxy are known to the resource allocator thus no one
             // should be holding onto it outside of Ganesh.
-            SkASSERT(cur->uses() == cur->proxy()->priv().getProxyRefCnt());
+            SkASSERT(cur->uses() == cur->proxy()->refCnt());
             cur->markAsRecyclable();
         }
     }
diff --git a/src/gpu/GrSurfaceProxy.h b/src/gpu/GrSurfaceProxy.h
index 5b0297d..673e10e 100644
--- a/src/gpu/GrSurfaceProxy.h
+++ b/src/gpu/GrSurfaceProxy.h
@@ -14,6 +14,7 @@
 #include "include/gpu/GrSurface.h"
 #include "include/gpu/GrTexture.h"
 #include "include/private/SkNoncopyable.h"
+#include "src/gpu/GrNonAtomicRef.h"
 #include "src/gpu/GrSwizzle.h"
 
 class GrCaps;
@@ -27,40 +28,10 @@
 class GrSurfaceProxyPriv;
 class GrTextureProxy;
 
-// This is basically SkRefCntBase except Ganesh uses internalGetProxyRefCnt for more than asserts.
-class GrIORefProxy : public SkNoncopyable {
+class GrSurfaceProxy : public GrNonAtomicRef<GrSurfaceProxy> {
 public:
-    GrIORefProxy() : fRefCnt(1) {}
+    virtual ~GrSurfaceProxy();
 
-    virtual ~GrIORefProxy() {}
-
-    bool unique() const {
-        SkASSERT(fRefCnt > 0);
-        return 1 == fRefCnt;
-    }
-
-    void ref() const {
-        SkASSERT(fRefCnt > 0);
-        ++fRefCnt;
-    }
-
-    void unref() const {
-        SkASSERT(fRefCnt > 0);
-        --fRefCnt;
-        if (0 == fRefCnt) {
-            delete this;
-        }
-    }
-
-protected:
-    int32_t internalGetProxyRefCnt() const { return fRefCnt; }
-
-private:
-    mutable int32_t fRefCnt;
-};
-
-class GrSurfaceProxy : public GrIORefProxy {
-public:
     /**
      * Some lazy proxy callbacks want to set their own (or no key) on the GrSurfaces they return.
      * Others want the GrSurface's key to be kept in sync with the proxy's key. This enum controls
@@ -352,16 +323,12 @@
     GrSurfaceProxy(sk_sp<GrSurface>, GrSurfaceOrigin, const GrSwizzle& textureSwizzle,
                    SkBackingFit);
 
-    ~GrSurfaceProxy() override;
-
     friend class GrSurfaceProxyPriv;
 
     // Methods made available via GrSurfaceProxyPriv
     bool ignoredByResourceAllocator() const { return fIgnoredByResourceAllocator; }
     void setIgnoredByResourceAllocator() { fIgnoredByResourceAllocator = true; }
 
-    int32_t getProxyRefCnt() const { return this->internalGetProxyRefCnt(); }
-
     void computeScratchKey(GrScratchKey*) const;
 
     virtual sk_sp<GrSurface> createSurface(GrResourceProvider*) const = 0;
@@ -447,8 +414,6 @@
     // and the GrRenderTask of a destination surface to which this one is being drawn or copied.
     // This pointer is unreffed. GrRenderTasks own a ref on their surface proxies.
     GrRenderTask*          fLastRenderTask;
-
-    typedef GrIORefProxy INHERITED;
 };
 
 #endif
diff --git a/src/gpu/GrSurfaceProxyPriv.h b/src/gpu/GrSurfaceProxyPriv.h
index 41aa04e..2c65e83 100644
--- a/src/gpu/GrSurfaceProxyPriv.h
+++ b/src/gpu/GrSurfaceProxyPriv.h
@@ -17,8 +17,6 @@
     data members or virtual methods. */
 class GrSurfaceProxyPriv {
 public:
-    int32_t getProxyRefCnt() const { return fProxy->getProxyRefCnt(); }
-
     void computeScratchKey(GrScratchKey* key) const { return fProxy->computeScratchKey(key); }
 
     // Create a GrSurface-derived class that meets the requirements (i.e, desc, renderability)
diff --git a/src/gpu/GrTextureProxy.h b/src/gpu/GrTextureProxy.h
index 5870510..42e5af0 100644
--- a/src/gpu/GrTextureProxy.h
+++ b/src/gpu/GrTextureProxy.h
@@ -173,10 +173,6 @@
 
     SkDEBUGCODE(void onValidateSurface(const GrSurface*) override;)
 
-    // For wrapped proxies the GrTexture pointer is stored in GrIORefProxy.
-    // For deferred proxies that pointer will be filled in when we need to instantiate
-    // the deferred resource
-
     typedef GrSurfaceProxy INHERITED;
 };