Have GrTextureProducer return views instead of proxies.

Bug: skia:9556
Change-Id: Ieedb9c48914c637278203d4d462c19b2d85b27d4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268396
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index f518714..0fb2e05 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -39,21 +39,26 @@
     }
 }
 
-sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeMipped,
-                                                                    AllowedTexGenType onlyIfFast) {
+GrSurfaceProxyView GrBitmapTextureMaker::refOriginalTextureProxyView(bool willBeMipped,
+                                                                     AllowedTexGenType onlyIfFast) {
     if (AllowedTexGenType::kCheap == onlyIfFast) {
-        return nullptr;
+        return {};
     }
 
     GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider();
     sk_sp<GrTextureProxy> proxy;
+    GrSwizzle swizzle;
 
     if (fOriginalKey.isValid()) {
         auto colorType = SkColorTypeToGrColorType(fBitmap.colorType());
         proxy = proxyProvider->findOrCreateProxyByUniqueKey(fOriginalKey, colorType,
                                                             kTopLeft_GrSurfaceOrigin);
-        if (proxy && (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped())) {
-            return proxy;
+        if (proxy) {
+            swizzle = this->context()->priv().caps()->getReadSwizzle(proxy->backendFormat(),
+                                                                     this->colorType());
+            if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
+                return GrSurfaceProxyView(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
+            }
         }
     }
 
@@ -63,7 +68,7 @@
             SkBitmap copy8888;
             if (!copy8888.tryAllocPixels(fBitmap.info().makeColorType(kRGBA_8888_SkColorType)) ||
                 !fBitmap.readPixels(copy8888.pixmap())) {
-                return nullptr;
+                return {};
             }
             copy8888.setImmutable();
             proxy = proxyProvider->createProxyFromBitmap(
@@ -73,51 +78,50 @@
                     fBitmap, willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo, fFit);
         }
         if (proxy) {
+            swizzle = this->context()->priv().caps()->getReadSwizzle(proxy->backendFormat(),
+                                                                     this->colorType());
+            SkASSERT(!willBeMipped || GrMipMapped::kYes == proxy->mipMapped());
+            SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
             if (fOriginalKey.isValid()) {
                 proxyProvider->assignUniqueKeyToProxy(fOriginalKey, proxy.get());
+                GrInstallBitmapUniqueKeyInvalidator(
+                        fOriginalKey, proxyProvider->contextID(), fBitmap.pixelRef());
             }
-            if (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped()) {
-                SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
-                if (fOriginalKey.isValid()) {
-                    GrInstallBitmapUniqueKeyInvalidator(
-                            fOriginalKey, proxyProvider->contextID(), fBitmap.pixelRef());
-                }
-                return proxy;
-            }
+            return GrSurfaceProxyView(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
         }
     }
 
     if (proxy) {
         SkASSERT(willBeMipped);
         SkASSERT(GrMipMapped::kNo == proxy->mipMapped());
-        // We need a mipped proxy, but we either found a proxy earlier that wasn't mipped or
-        // generated a non mipped proxy. Thus we generate a new mipped surface and copy the original
-        // proxy into the base layer. We will then let the gpu generate the rest of the mips.
+        SkASSERT(fOriginalKey.isValid());
+        // We need a mipped proxy, but we found a proxy earlier that wasn't mipped. Thus we generate
+        // a new mipped surface and copy the original proxy into the base layer. We will then let
+        // the gpu generate the rest of the mips.
         GrColorType srcColorType = SkColorTypeToGrColorType(fBitmap.colorType());
-        if (auto mippedProxy = GrCopyBaseMipMapToTextureProxy(this->context(), proxy.get(),
-                                                              kTopLeft_GrSurfaceOrigin,
-                                                              srcColorType)) {
-            if (fOriginalKey.isValid()) {
-                // In this case we are stealing the key from the original proxy which should only
-                // happen when we have just generated mipmaps for an originally unmipped
-                // proxy/texture. This means that all future uses of the key will access the
-                // mipmapped version. The texture backing the unmipped version will remain in the
-                // resource cache until the last texture proxy referencing it is deleted at which
-                // time it too will be deleted or recycled.
-                SkASSERT(proxy->getUniqueKey() == fOriginalKey);
-                proxyProvider->removeUniqueKeyFromProxy(proxy.get());
-                proxyProvider->assignUniqueKeyToProxy(fOriginalKey, mippedProxy.get());
-                GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, proxyProvider->contextID(),
-                                                    fBitmap.pixelRef());
-            }
-            return mippedProxy;
+        auto mippedView = GrCopyBaseMipMapToTextureProxy(this->context(), proxy.get(),
+                                                         kTopLeft_GrSurfaceOrigin, srcColorType);
+        if (auto mippedProxy = mippedView.asTextureProxy()) {
+            // In this case we are stealing the key from the original proxy which should only happen
+            // when we have just generated mipmaps for an originally unmipped proxy/texture. This
+            // means that all future uses of the key will access the mipmapped version. The texture
+            // backing the unmipped version will remain in the resource cache until the last texture
+            // proxy referencing it is deleted at which time it too will be deleted or recycled.
+            SkASSERT(proxy->getUniqueKey() == fOriginalKey);
+            SkASSERT(mippedView.origin() == kTopLeft_GrSurfaceOrigin);
+            SkASSERT(mippedView.swizzle() == swizzle);
+            proxyProvider->removeUniqueKeyFromProxy(proxy.get());
+            proxyProvider->assignUniqueKeyToProxy(fOriginalKey, mippedProxy);
+            GrInstallBitmapUniqueKeyInvalidator(fOriginalKey, proxyProvider->contextID(),
+                                                fBitmap.pixelRef());
+            return mippedView;
         }
         // We failed to make a mipped proxy with the base copied into it. This could have
         // been from failure to make the proxy or failure to do the copy. Thus we will fall
         // back to just using the non mipped proxy; See skbug.com/7094.
-        return proxy;
+        return GrSurfaceProxyView(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
     }
-    return nullptr;
+    return {};
 }
 
 void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) {