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/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 618941e..8d59cae 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -21,14 +21,16 @@
                           GrSurfaceOrigin origin,
                           int width, int height, 
                           GrPixelConfig config,
-                          uint32_t uniqueID,
+                          const GrGpuResource::UniqueID& uniqueID,
                           SkBudgeted budgeted) {
     REPORTER_ASSERT(reporter, proxy->origin() == origin);
     REPORTER_ASSERT(reporter, proxy->width() == width);
     REPORTER_ASSERT(reporter, proxy->height() == height);
     REPORTER_ASSERT(reporter, proxy->config() == config);
-    if (SK_InvalidUniqueID != uniqueID) {
-        REPORTER_ASSERT(reporter, proxy->uniqueID() == uniqueID);    
+    if (!uniqueID.isInvalid()) {
+        REPORTER_ASSERT(reporter, proxy->uniqueID().asUInt() == uniqueID.asUInt());
+    } else {
+        REPORTER_ASSERT(reporter, !proxy->uniqueID().isInvalid());
     }
     REPORTER_ASSERT(reporter, proxy->isBudgeted() == budgeted);
 }
@@ -39,20 +41,31 @@
                                GrRenderTargetProxy* rtProxy,
                                int numSamples,
                                SkBackingFit fit,
-                               int expectedMaxWindowRects) {
+                               int expectedMaxWindowRects,
+                               bool wasWrapped) {
     REPORTER_ASSERT(reporter, rtProxy->maxWindowRectangles(caps) == expectedMaxWindowRects);
     REPORTER_ASSERT(reporter, rtProxy->numStencilSamples() == numSamples);
 
+    GrSurfaceProxy::UniqueID idBefore = rtProxy->uniqueID();
     GrRenderTarget* rt = rtProxy->instantiate(provider);
     REPORTER_ASSERT(reporter, rt);
 
+    REPORTER_ASSERT(reporter, rtProxy->uniqueID() == idBefore);
+    if (wasWrapped) {
+        // Wrapped resources share their uniqueID with the wrapping RenderTargetProxy
+        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() == rt->uniqueID().asUInt());
+    } else {
+        // Deferred resources should always have a different ID from their instantiated rendertarget
+        REPORTER_ASSERT(reporter, rtProxy->uniqueID().asUInt() != rt->uniqueID().asUInt());
+    }
+
     REPORTER_ASSERT(reporter, rt->origin() == rtProxy->origin());
     if (SkBackingFit::kExact == fit) {
         REPORTER_ASSERT(reporter, rt->width() == rtProxy->width());
         REPORTER_ASSERT(reporter, rt->height() == rtProxy->height());
     } else {
         REPORTER_ASSERT(reporter, rt->width() >= rtProxy->width());
-        REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());    
+        REPORTER_ASSERT(reporter, rt->height() >= rtProxy->height());
     }
     REPORTER_ASSERT(reporter, rt->config() == rtProxy->config());
 
@@ -68,10 +81,21 @@
 static void check_texture(skiatest::Reporter* reporter,
                           GrTextureProvider* provider,
                           GrTextureProxy* texProxy,
-                          SkBackingFit fit) {
+                          SkBackingFit fit,
+                          bool wasWrapped) {
+    GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
     GrTexture* tex = texProxy->instantiate(provider);
     REPORTER_ASSERT(reporter, tex);
 
+    REPORTER_ASSERT(reporter, texProxy->uniqueID() == idBefore);
+    if (wasWrapped) {
+        // Wrapped resources share their uniqueID with the wrapping TextureProxy
+        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() == tex->uniqueID().asUInt());
+    } else {
+        // Deferred resources should always have a different ID from their instantiated texture
+        REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
+    }
+
     REPORTER_ASSERT(reporter, tex->origin() == texProxy->origin());
     if (SkBackingFit::kExact == fit) {
         REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
@@ -88,6 +112,8 @@
     GrTextureProvider* provider = ctxInfo.grContext()->textureProvider();
     const GrCaps& caps = *ctxInfo.grContext()->caps();
 
+    const GrGpuResource::UniqueID kInvalidResourceID = GrGpuResource::UniqueID::InvalidID();
+
     for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
         for (auto widthHeight : { 100, 128 }) {
             for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
@@ -112,10 +138,10 @@
                                                                                 fit, budgeted));
                                 check_surface(reporter, sProxy.get(), origin,
                                               widthHeight, widthHeight, config,
-                                              SK_InvalidUniqueID, budgeted);
+                                              kInvalidResourceID, budgeted);
                                 check_rendertarget(reporter, caps, provider,
-                                                   sProxy->asRenderTargetProxy(), 
-                                                   numSamples, fit, caps.maxWindowRectangles());
+                                                   sProxy->asRenderTargetProxy(), numSamples,
+                                                   fit, caps.maxWindowRectangles(), false);
                             }
 
                             desc.fFlags = kNone_GrSurfaceFlags;
@@ -127,8 +153,8 @@
                                                                                       budgeted));
                             check_surface(reporter, sProxy.get(), origin,
                                           widthHeight, widthHeight, config,
-                                          SK_InvalidUniqueID, budgeted);
-                            check_texture(reporter, provider, sProxy->asTextureProxy(), fit);
+                                          kInvalidResourceID, budgeted);
+                            check_texture(reporter, provider, sProxy->asTextureProxy(), fit, false);
                         }
                     }
                 }
@@ -175,7 +201,7 @@
                                       kWidthHeight, kWidthHeight, config,
                                       defaultFBO->uniqueID(), SkBudgeted::kNo);
                         check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
-                                           numSamples, SkBackingFit::kExact, 0);
+                                           numSamples, SkBackingFit::kExact, 0, true);
                     }
 
                     sk_sp<GrTexture> tex;
@@ -192,7 +218,7 @@
                                       rt->uniqueID(), budgeted);
                         check_rendertarget(reporter, caps, provider, sProxy->asRenderTargetProxy(),
                                            numSamples, SkBackingFit::kExact,
-                                           caps.maxWindowRectangles());
+                                           caps.maxWindowRectangles(), true);
                     }
 
                     if (!tex) {
@@ -205,7 +231,7 @@
                     check_surface(reporter, sProxy.get(), origin,
                                   kWidthHeight, kWidthHeight, config, tex->uniqueID(), budgeted);
                     check_texture(reporter, provider, sProxy->asTextureProxy(),
-                                  SkBackingFit::kExact);
+                                  SkBackingFit::kExact, true);
                 }
             }
         }