Make GrSurfaceProxy constructors take arg that determines participation in
GrResourceAllocator.

Removes LazyInstantiationType. All callbacks can be invoked one time (if successful).
Lazy callbacks indicate whether their lifetime should be extended, which is used by
promise image proxy callbacks.

Promise image proxies are no longer deinstantiated at the end of flush and
GrDeinstantiateProxyTracker is removed. They will be instantiated the first time
they are encountered in GrResourceAllocator::addInterval (without actually adding
an interval) and then remain instantiated.

Also removes some "helper" versions of proxy factory functions that took fewer
params. They weren't much used outside of test code and as the total number of params
has grown their relative utility has diminished. We could consider a params struct
or radically simpler helpers that take only a few params if desired.

Change-Id: Ic6b09e7b807b66cb9fcbb7a67ae0f9faf345485f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238216
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 9dd6393..f65ad6f 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -158,7 +158,7 @@
         return nullptr;
     }
 
-    return this->createWrapped(std::move(tex), colorType, origin);
+    return this->createWrapped(std::move(tex), colorType, origin, UseAllocator::kYes);
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createInstantiatedProxy(
@@ -185,12 +185,14 @@
 sk_sp<GrTextureProxy> GrProxyProvider::testingOnly_createWrapped(sk_sp<GrTexture> tex,
                                                                  GrColorType colorType,
                                                                  GrSurfaceOrigin origin) {
-    return this->createWrapped(std::move(tex), colorType, origin);
+    return this->createWrapped(std::move(tex), colorType, origin, UseAllocator::kYes);
 }
 #endif
 
-sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex, GrColorType colorType,
-                                                     GrSurfaceOrigin origin) {
+sk_sp<GrTextureProxy> GrProxyProvider::createWrapped(sk_sp<GrTexture> tex,
+                                                     GrColorType colorType,
+                                                     GrSurfaceOrigin origin,
+                                                     UseAllocator useAllocator) {
 #ifdef SK_DEBUG
     if (tex->getUniqueKey().isValid()) {
         SkASSERT(!this->findProxyByUniqueKey(tex->getUniqueKey(), origin));
@@ -200,16 +202,18 @@
 
     if (tex->asRenderTarget()) {
         GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(tex->backendFormat(), colorType);
-        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin,
-                                                                    texSwizzle, outSwizzle));
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(
+                std::move(tex), origin, texSwizzle, outSwizzle, useAllocator));
     } else {
-        return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
+        return sk_sp<GrTextureProxy>(
+                new GrTextureProxy(std::move(tex), origin, texSwizzle, useAllocator));
     }
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniqueKey& key,
                                                                     GrColorType colorType,
-                                                                    GrSurfaceOrigin origin) {
+                                                                    GrSurfaceOrigin origin,
+                                                                    UseAllocator useAllocator) {
     ASSERT_SINGLE_OWNER
 
     if (this->isAbandoned()) {
@@ -236,7 +240,7 @@
     sk_sp<GrTexture> texture(static_cast<GrSurface*>(resource)->asTexture());
     SkASSERT(texture);
 
-    result = this->createWrapped(std::move(texture), colorType, origin);
+    result = this->createWrapped(std::move(texture), colorType, origin, useAllocator);
     SkASSERT(result->getUniqueKey() == key);
     // createWrapped should've added this for us
     SkASSERT(fUniquelyKeyedProxies.find(key));
@@ -294,12 +298,13 @@
                 SkAssertResult(srcImage->peekPixels(&pixMap));
                 GrMipLevel mipLevel = { pixMap.addr(), pixMap.rowBytes() };
 
-                return LazyInstantiationResult(resourceProvider->createTexture(
+                return LazyCallbackResult(resourceProvider->createTexture(
                         desc, format, GrRenderable::kNo, sampleCnt, budgeted, fit, GrProtected::kNo,
                         ct, mipLevel, GrResourceProvider::Flags::kNoPendingIO));
             },
             format, desc, GrRenderable::kNo, sampleCnt, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
-            GrMipMapsStatus::kNotAllocated, surfaceFlags, fit, budgeted, GrProtected::kNo);
+            GrMipMapsStatus::kNotAllocated, surfaceFlags, fit, budgeted, GrProtected::kNo,
+            UseAllocator::kYes);
 
     if (!proxy) {
         return nullptr;
@@ -321,24 +326,6 @@
     return proxy;
 }
 
-sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxy(const GrBackendFormat& format,
-                                                         const GrSurfaceDesc& desc,
-                                                         GrRenderable renderable,
-                                                         int renderTargetSampleCnt,
-                                                         GrSurfaceOrigin origin,
-                                                         SkBudgeted budgeted,
-                                                         GrProtected isProtected) {
-    ASSERT_SINGLE_OWNER
-
-    if (this->isAbandoned()) {
-        return nullptr;
-    }
-
-    return this->createProxy(format, desc, renderable, renderTargetSampleCnt, origin,
-                             GrMipMapped::kYes, SkBackingFit::kExact, budgeted, isProtected,
-                             GrInternalSurfaceFlags::kNone);
-}
-
 sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
                                                              GrMipMapped mipMapped) {
     ASSERT_SINGLE_OWNER
@@ -421,12 +408,13 @@
                     SkASSERT(texels[i].fPixels);
                 }
 
-                return LazyInstantiationResult(resourceProvider->createTexture(
+                return LazyCallbackResult(resourceProvider->createTexture(
                         desc, format, GrRenderable::kNo, 1, SkBudgeted::kYes, GrProtected::kNo,
                         texels.get(), mipLevelCount));
             },
             format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kYes,
-            GrMipMapsStatus::kValid, SkBackingFit::kExact, SkBudgeted::kYes, GrProtected::kNo);
+            GrMipMapsStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
+            SkBudgeted::kYes, GrProtected::kNo, UseAllocator::kYes);
 
     if (!proxy) {
         return nullptr;
@@ -471,7 +459,8 @@
                                                    SkBackingFit fit,
                                                    SkBudgeted budgeted,
                                                    GrProtected isProtected,
-                                                   GrInternalSurfaceFlags surfaceFlags) {
+                                                   GrInternalSurfaceFlags surfaceFlags,
+                                                   GrSurfaceProxy::UseAllocator useAllocator) {
     const GrCaps* caps = this->caps();
 
     if (caps->isFormatCompressed(format)) {
@@ -515,12 +504,12 @@
         GrSwizzle outSwizzle = caps->getOutputSwizzle(format, colorType);
         return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(
                 *caps, format, copyDesc, renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
-                texSwizzle, outSwizzle, fit, budgeted, isProtected, surfaceFlags));
+                texSwizzle, outSwizzle, fit, budgeted, isProtected, surfaceFlags, useAllocator));
     }
 
-    return sk_sp<GrTextureProxy>(new GrTextureProxy(
-            format, copyDesc, origin, mipMapped, mipMapsStatus, texSwizzle, fit, budgeted,
-            isProtected, surfaceFlags));
+    return sk_sp<GrTextureProxy>(new GrTextureProxy(format, copyDesc, origin, mipMapped,
+                                                    mipMapsStatus, texSwizzle, fit, budgeted,
+                                                    isProtected, surfaceFlags, useAllocator));
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::createCompressedTextureProxy(
@@ -539,14 +528,14 @@
     }
 
     sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
-            [width, height, format, compressionType, budgeted, data]
-            (GrResourceProvider* resourceProvider) {
-                return LazyInstantiationResult(resourceProvider->createCompressedTexture(
+            [width, height, format, compressionType, budgeted,
+             data](GrResourceProvider* resourceProvider) {
+                return LazyCallbackResult(resourceProvider->createCompressedTexture(
                         width, height, format, compressionType, budgeted, data.get()));
             },
             format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo,
-            GrMipMapsStatus::kNotAllocated, SkBackingFit::kExact, SkBudgeted::kYes,
-            GrProtected::kNo);
+            GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
+            SkBudgeted::kYes, GrProtected::kNo, UseAllocator::kYes);
 
     if (!proxy) {
         return nullptr;
@@ -606,7 +595,8 @@
 
     GrSwizzle texSwizzle = caps->getTextureSwizzle(tex->backendFormat(), grColorType);
 
-    return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(tex), origin, texSwizzle));
+    return sk_sp<GrTextureProxy>(
+            new GrTextureProxy(std::move(tex), origin, texSwizzle, UseAllocator::kNo));
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
@@ -656,7 +646,7 @@
     GrSwizzle outSwizzle = caps->getOutputSwizzle(tex->backendFormat(), colorType);
 
     return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(std::move(tex), origin, texSwizzle,
-                                                                outSwizzle));
+                                                                outSwizzle, UseAllocator::kNo));
 }
 
 sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendRenderTarget(
@@ -696,7 +686,7 @@
     GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
 
     return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
-                                                              outSwizzle));
+                                                              outSwizzle, UseAllocator::kNo));
 }
 
 sk_sp<GrSurfaceProxy> GrProxyProvider::wrapBackendTextureAsRenderTarget(
@@ -732,7 +722,7 @@
     GrSwizzle outSwizzle = caps->getOutputSwizzle(rt->backendFormat(), grColorType);
 
     return sk_sp<GrSurfaceProxy>(new GrRenderTargetProxy(std::move(rt), origin, texSwizzle,
-                                                         outSwizzle));
+                                                         outSwizzle, UseAllocator::kNo));
 }
 
 sk_sp<GrRenderTargetProxy> GrProxyProvider::wrapVulkanSecondaryCBAsRenderTarget(
@@ -770,46 +760,9 @@
     }
 
     // All Vulkan surfaces uses top left origins.
-    return sk_sp<GrRenderTargetProxy>(
-            new GrRenderTargetProxy(std::move(rt),
-                                    kTopLeft_GrSurfaceOrigin, texSwizzle, outSwizzle,
-                                    GrRenderTargetProxy::WrapsVkSecondaryCB::kYes));
-}
-
-sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
-                                                       const GrBackendFormat& format,
-                                                       const GrSurfaceDesc& desc,
-                                                       GrRenderable renderable,
-                                                       int renderTargetSampleCnt,
-                                                       GrSurfaceOrigin origin,
-                                                       GrMipMapped mipMapped,
-                                                       GrMipMapsStatus mipMapsStatus,
-                                                       SkBackingFit fit,
-                                                       SkBudgeted budgeted,
-                                                       GrProtected isProtected) {
-    return this->createLazyProxy(std::move(callback), format, desc, renderable,
-                                 renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
-                                 GrInternalSurfaceFlags::kNone, fit, budgeted, isProtected);
-}
-
-sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
-                                                       const GrBackendFormat& format,
-                                                       const GrSurfaceDesc& desc,
-                                                       GrRenderable renderable,
-                                                       int renderTargetSampleCnt,
-                                                       GrSurfaceOrigin origin,
-                                                       GrMipMapped mipMapped,
-                                                       GrMipMapsStatus mipMapsStatus,
-                                                       GrInternalSurfaceFlags surfaceFlags,
-                                                       SkBackingFit fit,
-                                                       SkBudgeted budgeted,
-                                                       GrProtected isProtected) {
-    // For non-ddl draws always make lazy proxy's single use.
-    LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse
-                                                               : LazyInstantiationType::kMultipleUse;
-    return this->createLazyProxy(std::move(callback), format, desc, renderable,
-                                 renderTargetSampleCnt, origin, mipMapped, mipMapsStatus,
-                                 surfaceFlags, fit, budgeted, isProtected, lazyType);
+    return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(
+            std::move(rt), kTopLeft_GrSurfaceOrigin, texSwizzle, outSwizzle, UseAllocator::kNo,
+            GrRenderTargetProxy::WrapsVkSecondaryCB::kYes));
 }
 
 sk_sp<GrTextureProxy> GrProxyProvider::createLazyProxy(LazyInstantiateCallback&& callback,
@@ -824,7 +777,7 @@
                                                        SkBackingFit fit,
                                                        SkBudgeted budgeted,
                                                        GrProtected isProtected,
-                                                       LazyInstantiationType lazyType) {
+                                                       GrSurfaceProxy::UseAllocator useAllocator) {
     SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
              (desc.fWidth > 0 && desc.fHeight > 0));
 
@@ -843,22 +796,52 @@
     GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
     GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
 
-    return sk_sp<GrTextureProxy>((renderable == GrRenderable::kYes)
-            ? new GrTextureRenderTargetProxy(
-                    *this->caps(), std::move(callback), lazyType, format, desc,
-                    renderTargetSampleCnt, origin, mipMapped, mipMapsStatus, texSwizzle, outSwizzle,
-                    fit, budgeted, isProtected, surfaceFlags)
-            : new GrTextureProxy(
-                    std::move(callback), lazyType, format, desc, origin, mipMapped, mipMapsStatus,
-                    texSwizzle, fit, budgeted, isProtected, surfaceFlags));
+    if (renderable == GrRenderable::kYes) {
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(*this->caps(),
+                                                                    std::move(callback),
+                                                                    format,
+                                                                    desc,
+                                                                    renderTargetSampleCnt,
+                                                                    origin,
+                                                                    mipMapped,
+                                                                    mipMapsStatus,
+                                                                    texSwizzle,
+                                                                    outSwizzle,
+                                                                    fit,
+                                                                    budgeted,
+                                                                    isProtected,
+                                                                    surfaceFlags,
+                                                                    useAllocator));
+    } else {
+        return sk_sp<GrTextureProxy>(new GrTextureProxy(std::move(callback),
+                                                        format,
+                                                        desc,
+                                                        origin,
+                                                        mipMapped,
+                                                        mipMapsStatus,
+                                                        texSwizzle,
+                                                        fit,
+                                                        budgeted,
+                                                        isProtected,
+                                                        surfaceFlags,
+                                                        useAllocator));
+    }
 }
 
 sk_sp<GrRenderTargetProxy> GrProxyProvider::createLazyRenderTargetProxy(
-        LazyInstantiateCallback&& callback, const GrBackendFormat& format,
-        const GrSurfaceDesc& desc, int sampleCnt, GrSurfaceOrigin origin,
-        GrInternalSurfaceFlags surfaceFlags, const TextureInfo* textureInfo,
-        GrMipMapsStatus mipMapsStatus, SkBackingFit fit, SkBudgeted budgeted,
-        GrProtected isProtected, bool wrapsVkSecondaryCB) {
+        LazyInstantiateCallback&& callback,
+        const GrBackendFormat& format,
+        const GrSurfaceDesc& desc,
+        int sampleCnt,
+        GrSurfaceOrigin origin,
+        GrInternalSurfaceFlags surfaceFlags,
+        const TextureInfo* textureInfo,
+        GrMipMapsStatus mipMapsStatus,
+        SkBackingFit fit,
+        SkBudgeted budgeted,
+        GrProtected isProtected,
+        bool wrapsVkSecondaryCB,
+        UseAllocator useAllocator) {
     SkASSERT((desc.fWidth <= 0 && desc.fHeight <= 0) ||
              (desc.fWidth > 0 && desc.fHeight > 0));
 
@@ -869,11 +852,6 @@
 
     SkASSERT(validate_backend_format_and_config(this->caps(), format, desc.fConfig));
 
-    using LazyInstantiationType = GrSurfaceProxy::LazyInstantiationType;
-    // For non-ddl draws always make lazy proxy's single use.
-    LazyInstantiationType lazyType = this->renderingDirectly() ? LazyInstantiationType::kSingleUse
-                                                               : LazyInstantiationType::kMultipleUse;
-
     GrColorType colorType = GrPixelConfigToColorType(desc.fConfig);
     GrSwizzle texSwizzle = this->caps()->getTextureSwizzle(format, colorType);
     GrSwizzle outSwizzle = this->caps()->getOutputSwizzle(format, colorType);
@@ -883,9 +861,9 @@
         // actual VkImage to texture from.
         SkASSERT(!wrapsVkSecondaryCB);
         return sk_sp<GrRenderTargetProxy>(new GrTextureRenderTargetProxy(
-                *this->caps(), std::move(callback), lazyType, format, desc, sampleCnt, origin,
+                *this->caps(), std::move(callback), format, desc, sampleCnt, origin,
                 textureInfo->fMipMapped, mipMapsStatus, texSwizzle, outSwizzle, fit, budgeted,
-                isProtected, surfaceFlags));
+                isProtected, surfaceFlags, useAllocator));
     }
 
     GrRenderTargetProxy::WrapsVkSecondaryCB vkSCB =
@@ -893,14 +871,19 @@
                                : GrRenderTargetProxy::WrapsVkSecondaryCB::kNo;
 
     return sk_sp<GrRenderTargetProxy>(new GrRenderTargetProxy(
-            std::move(callback), lazyType, format, desc, sampleCnt, origin, texSwizzle, outSwizzle,
-            fit, budgeted, isProtected, surfaceFlags, vkSCB));
+            std::move(callback), format, desc, sampleCnt, origin, texSwizzle, outSwizzle, fit,
+            budgeted, isProtected, surfaceFlags, useAllocator, vkSCB));
 }
 
-sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy(
-        LazyInstantiateCallback&& callback, const GrBackendFormat& format, GrRenderable renderable,
-        int renderTargetSampleCnt, GrProtected isProtected, GrSurfaceOrigin origin,
-        GrPixelConfig config, const GrCaps& caps) {
+sk_sp<GrTextureProxy> GrProxyProvider::MakeFullyLazyProxy(LazyInstantiateCallback&& callback,
+                                                          const GrBackendFormat& format,
+                                                          GrRenderable renderable,
+                                                          int renderTargetSampleCnt,
+                                                          GrProtected isProtected,
+                                                          GrSurfaceOrigin origin,
+                                                          GrPixelConfig config,
+                                                          const GrCaps& caps,
+                                                          UseAllocator useAllocator) {
     if (!format.isValid()) {
         return nullptr;
     }
@@ -917,16 +900,17 @@
     GrSwizzle texSwizzle = caps.getTextureSwizzle(format, colorType);
     GrSwizzle outSwizzle = caps.getOutputSwizzle(format, colorType);
 
-    return sk_sp<GrTextureProxy>((GrRenderable::kYes == renderable)
-            ? new GrTextureRenderTargetProxy(
-                    caps, std::move(callback), LazyInstantiationType::kSingleUse, format, desc,
-                    renderTargetSampleCnt, origin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated,
-                    texSwizzle, outSwizzle, SkBackingFit::kApprox, SkBudgeted::kYes, isProtected,
-                    surfaceFlags)
-            : new GrTextureProxy(
-                    std::move(callback), LazyInstantiationType::kSingleUse, format, desc, origin,
-                    GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, texSwizzle,
-                    SkBackingFit::kApprox, SkBudgeted::kYes, isProtected, surfaceFlags));
+    if (GrRenderable::kYes == renderable) {
+        return sk_sp<GrTextureProxy>(new GrTextureRenderTargetProxy(
+                caps, std::move(callback), format, desc, renderTargetSampleCnt, origin,
+                GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, texSwizzle, outSwizzle,
+                SkBackingFit::kApprox, SkBudgeted::kYes, isProtected, surfaceFlags, useAllocator));
+    } else {
+        return sk_sp<GrTextureProxy>(new GrTextureProxy(
+                std::move(callback), format, desc, origin, GrMipMapped::kNo,
+                GrMipMapsStatus::kNotAllocated, texSwizzle, SkBackingFit::kApprox, SkBudgeted::kYes,
+                isProtected, surfaceFlags, useAllocator));
+    }
 }
 
 bool GrProxyProvider::IsFunctionallyExact(GrSurfaceProxy* proxy) {