Add explicit UniqueID classes for GrGpuResource & GrSurfaceProxy

This sets the stage for using the Proxy's/RenderTargetContext's ID above the flush and the RenderTarget's/GrGpuResource's below the flush.

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4650

Change-Id: I9f1e6b00c02a0691d90b58c49e1d8c60684884c1
Reviewed-on: https://skia-review.googlesource.com/4650
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/include/private/GrSurfaceProxy.h b/include/private/GrSurfaceProxy.h
index 1e846c5..dd5ece1 100644
--- a/include/private/GrSurfaceProxy.h
+++ b/include/private/GrSurfaceProxy.h
@@ -99,7 +99,44 @@
     int height() const { return fDesc.fHeight; }
     GrPixelConfig config() const { return fDesc.fConfig; }
 
-    uint32_t uniqueID() const { return fUniqueID; }
+    class UniqueID {
+    public:
+        // wrapped
+        explicit UniqueID(const GrGpuResource::UniqueID& id) : fID(id.asUInt()) { }
+        // deferred
+        UniqueID() : fID(GrGpuResource::CreateUniqueID()) { }
+
+        uint32_t asUInt() const { return fID; }
+
+        bool operator==(const UniqueID& other) const {
+            return fID == other.fID;
+        }
+        bool operator!=(const UniqueID& other) const {
+            return !(*this == other);
+        }
+
+        bool isInvalid() const { return SK_InvalidUniqueID == fID; }
+
+    private:
+        const uint32_t fID;
+    };
+
+    /*
+     * The contract for the uniqueID is:
+     *   for wrapped resources:
+     *      the uniqueID will match that of the wrapped resource
+     *
+     *   for deferred resources:
+     *      the uniqueID will be different from the real resource, when it is allocated
+     *      the proxy's uniqueID will not change across the instantiate call
+     *
+     *    the uniqueIDs of the proxies and the resources draw from the same pool
+     *
+     * What this boils down to is that the uniqueID of a proxy can be used to consistently
+     * track/identify a proxy but should never be used to distinguish between
+     * resources and proxies - beware!
+     */
+    UniqueID uniqueID() const { return fUniqueID; }
 
     GrSurface* instantiate(GrTextureProvider* texProvider);
 
@@ -151,9 +188,9 @@
         : fDesc(desc)
         , fFit(fit)
         , fBudgeted(budgeted)
-        , fUniqueID(GrGpuResource::CreateUniqueID())
         , fGpuMemorySize(kInvalidGpuMemorySize)
         , fLastOpList(nullptr) {
+        // Note: this ctor pulls a new uniqueID from the same pool at the GrGpuResources
     }
 
     // Wrapped version
@@ -162,10 +199,10 @@
     virtual ~GrSurfaceProxy();
 
     // For wrapped resources, 'fDesc' will always be filled in from the wrapped resource.
-    const GrSurfaceDesc fDesc;
-    const SkBackingFit  fFit;      // always exact for wrapped resources
-    const SkBudgeted    fBudgeted; // set from the backing resource for wrapped resources
-    const uint32_t      fUniqueID; // set from the backing resource for wrapped resources
+    const GrSurfaceDesc  fDesc;
+    const SkBackingFit   fFit;      // always exact for wrapped resources
+    const SkBudgeted     fBudgeted; // set from the backing resource for wrapped resources
+    const UniqueID       fUniqueID; // set from the backing resource for wrapped resources
 
     static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
     SkDEBUGCODE(size_t getRawGpuMemorySize_debugOnly() const { return fGpuMemorySize; })