Revert "Revert "Assert that all GrCaps colortype/format -> swizzle queries are legal.""

This reverts commit ef4d3794a2ddffa877065aa66869c02bb582a479.

Fix for finding cached textures that were made with fallback color types.

Change-Id: Ic5b67801f9275f6a1cbe8373b8cce382f3cedfe7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280607
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp
index 8c3a0f2..ec6c648 100644
--- a/src/gpu/GrClipStackClip.cpp
+++ b/src/gpu/GrClipStackClip.cpp
@@ -352,6 +352,12 @@
     SkDEBUGFAIL("Gen ID was not found in stack.");
 }
 
+static constexpr auto kMaskOrigin = kTopLeft_GrSurfaceOrigin;
+
+static GrSurfaceProxyView find_mask(GrProxyProvider* provider, const GrUniqueKey& key) {
+    return provider->findCachedProxyWithColorTypeFallback(key, kMaskOrigin, GrColorType::kAlpha_8);
+}
+
 GrSurfaceProxyView GrClipStackClip::createAlphaClipMask(GrRecordingContext* context,
                                                         const GrReducedClip& reducedClip) const {
     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
@@ -359,16 +365,14 @@
     create_clip_mask_key(reducedClip.maskGenID(), reducedClip.scissor(),
                          reducedClip.numAnalyticFPs(), &key);
 
-    if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
-        GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
-                                                                   GrColorType::kAlpha_8);
-        return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
+    if (auto cachedView = find_mask(context->priv().proxyProvider(), key)) {
+        return cachedView;
     }
 
     auto rtc = GrRenderTargetContext::MakeWithFallback(
             context, GrColorType::kAlpha_8, nullptr, SkBackingFit::kApprox,
             {reducedClip.width(), reducedClip.height()}, 1, GrMipMapped::kNo, GrProtected::kNo,
-            kTopLeft_GrSurfaceOrigin);
+            kMaskOrigin);
     if (!rtc) {
         return {};
     }
@@ -382,7 +386,7 @@
         return {};
     }
 
-    SkASSERT(result.origin() == kTopLeft_GrSurfaceOrigin);
+    SkASSERT(result.origin() == kMaskOrigin);
     proxyProvider->assignUniqueKeyToProxy(key, result.asTextureProxy());
     add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
 
@@ -471,12 +475,9 @@
                          reducedClip.numAnalyticFPs(), &key);
 
     GrProxyProvider* proxyProvider = context->priv().proxyProvider();
-    const GrCaps* caps = context->priv().caps();
 
-    if (sk_sp<GrTextureProxy> proxy = proxyProvider->findOrCreateProxyByUniqueKey(key)) {
-        GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
-                                                                   GrColorType::kAlpha_8);
-        return {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
+    if (auto cachedView = find_mask(proxyProvider, key)) {
+        return cachedView;
     }
 
     // The mask texture may be larger than necessary. We round out the clip bounds and pin the top
@@ -490,6 +491,7 @@
 
     GrSurfaceProxyView view;
     if (taskGroup && renderTargetContext) {
+        const GrCaps* caps = context->priv().caps();
         // Create our texture proxy
         GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kAlpha_8,
                                                                GrRenderable::kNo);
@@ -525,7 +527,7 @@
         taskGroup->add(std::move(drawAndUploadMask));
         proxy->texPriv().setDeferredUploader(std::move(uploader));
 
-        view = {std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle};
+        view = {std::move(proxy), kMaskOrigin, swizzle};
     } else {
         GrSWMaskHelper helper;
         if (!helper.init(maskSpaceIBounds)) {
@@ -539,7 +541,7 @@
     }
 
     SkASSERT(view);
-    SkASSERT(view.origin() == kTopLeft_GrSurfaceOrigin);
+    SkASSERT(view.origin() == kMaskOrigin);
     proxyProvider->assignUniqueKeyToProxy(key, view.asTextureProxy());
     add_invalidate_on_pop_message(context, *fStack, reducedClip.maskGenID(), key);
     return view;