Add test for proactive proxy-creation failure

This is a follow up to https://skia-review.googlesource.com/c/7828/ (Add more pre-checks to surfaceProxy creation)

BUG=687174

Change-Id: I97385afbdaf1881b806ee37737020564e3f4d444
Reviewed-on: https://skia-review.googlesource.com/7864
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 894c37e..f5a3a2c 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -114,16 +114,15 @@
 
     const GrGpuResource::UniqueID kInvalidResourceID = GrGpuResource::UniqueID::InvalidID();
 
+    int attempt = 0; // useful for debugging
+
     for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin }) {
         for (auto widthHeight : { 100, 128, 1048576 }) {
-            for (auto config : { kAlpha_8_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
+            for (auto config : { kAlpha_8_GrPixelConfig, kRGB_565_GrPixelConfig,
+                                 kETC1_GrPixelConfig, kRGBA_8888_GrPixelConfig }) {
                 for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
                     for (auto budgeted : { SkBudgeted::kYes, SkBudgeted::kNo }) {
-                        for (auto numSamples : { 0, 4}) {
-                            bool renderable = caps.isConfigRenderable(config, numSamples > 0) &&
-                                 numSamples <= caps.maxColorSampleCount();
-                            bool allocable = widthHeight <= caps.maxTextureSize();
-
+                        for (auto numSamples : { 0, 4, 16, 128 }) {
                             GrSurfaceDesc desc;
                             desc.fFlags = kRenderTarget_GrSurfaceFlag;
                             desc.fOrigin = origin;
@@ -132,11 +131,18 @@
                             desc.fConfig = config;
                             desc.fSampleCnt = numSamples;
 
-                            if (renderable) {
+                            {
+                                sk_sp<GrTexture> tex;
+                                if (SkBackingFit::kApprox == fit) {
+                                    tex = sk_ref_sp(provider->createApproxTexture(desc));
+                                } else {
+                                    tex = sk_ref_sp(provider->createTexture(desc, budgeted));
+                                }
+
                                 sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(
                                                                                 caps, desc,
                                                                                 fit, budgeted));
-                                REPORTER_ASSERT(reporter, allocable == SkToBool(sProxy));
+                                REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(sProxy));
                                 if (sProxy) {
                                     REPORTER_ASSERT(reporter, sProxy->asRenderTargetProxy());
                                     // This forces the proxy to compute and cache its
@@ -150,33 +156,44 @@
                                                   widthHeight, widthHeight, config,
                                                   kInvalidResourceID, budgeted);
                                     check_rendertarget(reporter, caps, provider,
-                                                       sProxy->asRenderTargetProxy(), numSamples,
+                                                       sProxy->asRenderTargetProxy(),
+                                                       SkTMin(numSamples, caps.maxSampleCount()),
                                                        fit, caps.maxWindowRectangles(), false);
                                 }
                             }
 
                             desc.fFlags = kNone_GrSurfaceFlags;
-                            desc.fSampleCnt = 0;
 
-                            sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
-                                                                                      desc,
-                                                                                      fit,
-                                                                                      budgeted));
-                            REPORTER_ASSERT(reporter, allocable == SkToBool(sProxy));
-                            if (sProxy) {
-                                // This forces the proxy to compute and cache its pre-instantiation
-                                // size guess. Later, when it is actually instantiated, it checks
-                                // that the instantiated size is <= to the pre-computation.
-                                // If the proxy never computed its pre-instantiation size then the
-                                // check is skipped.
-                                sProxy->gpuMemorySize();
+                            {
+                                sk_sp<GrTexture> tex;
+                                if (SkBackingFit::kApprox == fit) {
+                                    tex = sk_ref_sp(provider->createApproxTexture(desc));
+                                } else {
+                                    tex = sk_ref_sp(provider->createTexture(desc, budgeted));
+                                }
 
-                                check_surface(reporter, sProxy.get(), origin,
-                                              widthHeight, widthHeight, config,
-                                              kInvalidResourceID, budgeted);
-                                check_texture(reporter, provider, sProxy->asTextureProxy(),
-                                              fit, false);
+                                sk_sp<GrSurfaceProxy> sProxy(GrSurfaceProxy::MakeDeferred(caps,
+                                                                                          desc,
+                                                                                          fit,
+                                                                                          budgeted));
+                                REPORTER_ASSERT(reporter, SkToBool(tex) == SkToBool(sProxy));
+                                if (sProxy) {
+                                    // This forces the proxy to compute and cache its pre-instantiation
+                                    // size guess. Later, when it is actually instantiated, it checks
+                                    // that the instantiated size is <= to the pre-computation.
+                                    // If the proxy never computed its pre-instantiation size then the
+                                    // check is skipped.
+                                    sProxy->gpuMemorySize();
+
+                                    check_surface(reporter, sProxy.get(), origin,
+                                                  widthHeight, widthHeight, config,
+                                                  kInvalidResourceID, budgeted);
+                                    check_texture(reporter, provider, sProxy->asTextureProxy(),
+                                                  fit, false);
+                                }
                             }
+
+                            attempt++;
                         }
                     }
                 }