Revert "Revert "Remove copies for wrap modes in GrTextureProducer.""

This reverts commit bf5cb0f539e7b7485bda9c1377f663d6c444d2f4.

Change-Id: I0dd15d03c42c5dc2c09ba81b6bc16d582f9093f6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272928
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp
index 17200f2..d9e89c2 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -14,102 +14,66 @@
 #include "src/gpu/GrRecordingContextPriv.h"
 
 GrSurfaceProxyView GrTextureMaker::onRefTextureProxyViewForParams(GrSamplerState params,
-                                                                  bool willBeMipped,
-                                                                  SkScalar scaleAdjust[2]) {
+                                                                  bool willBeMipped) {
     if (this->width() > this->context()->priv().caps()->maxTextureSize() ||
         this->height() > this->context()->priv().caps()->maxTextureSize()) {
         return {};
     }
 
-    CopyParams copyParams;
-
     GrSurfaceProxyView original = this->refOriginalTextureProxyView(willBeMipped,
                                                                     AllowedTexGenType::kCheap);
-    bool needsCopyForMipsOnly = false;
-    if (original.proxy()) {
-        GrTextureProxy* texProxy = original.asTextureProxy();
-        SkASSERT(texProxy);
-        if (!params.isRepeated() ||
-            !GrGpu::IsACopyNeededForRepeatWrapMode(this->context()->priv().caps(), texProxy,
-                                                   texProxy->dimensions(), params.filter(),
-                                                   &copyParams, scaleAdjust)) {
-            needsCopyForMipsOnly = GrGpu::IsACopyNeededForMips(this->context()->priv().caps(),
-                                                               texProxy, params.filter(),
-                                                               &copyParams);
-            if (!needsCopyForMipsOnly) {
-                return original;
-            }
-        }
-    } else {
-        if (!params.isRepeated() ||
-            !GrGpu::IsACopyNeededForRepeatWrapMode(this->context()->priv().caps(), nullptr,
-                                                   this->dimensions(), params.filter(), &copyParams,
-                                                   scaleAdjust)) {
-            return this->refOriginalTextureProxyView(willBeMipped, AllowedTexGenType::kAny);
-        }
+    if (!original) {
+        return this->refOriginalTextureProxyView(willBeMipped, AllowedTexGenType::kAny);
+    }
+
+    GrTextureProxy* texProxy = original.asTextureProxy();
+    if (!GrGpu::IsACopyNeededForMips(this->context()->priv().caps(), texProxy, params.filter())) {
+        return original;
     }
 
     GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider();
 
     GrSurfaceOrigin origOrigin = original.proxy() ? original.origin() : kTopLeft_GrSurfaceOrigin;
-    GrUniqueKey copyKey;
-    this->makeCopyKey(copyParams, &copyKey);
-    GrSurfaceProxyView cachedView;
-    if (copyKey.isValid()) {
-        auto cachedProxy = proxyProvider->findOrCreateProxyByUniqueKey(copyKey, this->colorType());
+    GrUniqueKey mipMappedKey;
+    this->makeMipMappedKey(&mipMappedKey);
+    if (mipMappedKey.isValid()) {
+        auto cachedProxy =
+                proxyProvider->findOrCreateProxyByUniqueKey(mipMappedKey, this->colorType());
         if (cachedProxy) {
-            GrMipMapped mipped = cachedProxy->mipMapped();
-            // TODO: Once we no longer use CopyOnGpu which can fallback to arbitrary formats and
-            // colorTypes, we can use the swizzle of the originalView.
+            SkASSERT(cachedProxy->mipMapped() == GrMipMapped::kYes);
+            // TODO: Once we no longer use MakeMipMappedCopy which can fallback to arbitrary formats
+            // and colorTypes, we can use the swizzle of the originalView.
             GrSwizzle swizzle = cachedProxy->textureSwizzleDoNotUse();
-            cachedView = GrSurfaceProxyView(std::move(cachedProxy), origOrigin, swizzle);
-            if (!willBeMipped || GrMipMapped::kYes == mipped) {
-                return cachedView;
-            }
+            return GrSurfaceProxyView(std::move(cachedProxy), origOrigin, swizzle);
         }
     }
 
     GrSurfaceProxyView source;
-    if (original.proxy()) {
+    if (original) {
         source = std::move(original);
-    } else if (cachedView.proxy()) {
-        source = cachedView;
     } else {
         // Since we will be copying this texture there is no reason to make it mipped
         source = this->refOriginalTextureProxyView(false, AllowedTexGenType::kAny);
+        if (!source) {
+            return {};
+        }
     }
 
-    if (!source.proxy()) {
-        return {};
-    }
     SkASSERT(source.asTextureProxy());
 
-    GrSurfaceProxyView result =
-            CopyOnGpu(this->context(), source, this->colorType(), copyParams, willBeMipped);
+    GrSurfaceProxyView result = MakeMipMappedCopy(this->context(), source, this->colorType());
 
-    if (!result.proxy()) {
+    if (!result) {
         // If we were unable to make a copy and we only needed a copy for mips, then we will return
         // the source texture here and require that the GPU backend is able to fall back to using
         // bilerp if mips are required.
-        if (needsCopyForMipsOnly) {
-            return source;
-        }
-        return {};
+        return source;
     }
 
-    if (copyKey.isValid()) {
+    if (mipMappedKey.isValid()) {
         SkASSERT(result.origin() == origOrigin);
-        if (cachedView.proxy()) {
-            SkASSERT(GrMipMapped::kYes == result.asTextureProxy()->mipMapped() &&
-                     GrMipMapped::kNo == cachedView.asTextureProxy()->mipMapped());
-            // If we had a cachedProxy, that means there already is a proxy in the cache which
-            // matches the key, but it does not have mip levels and we require them. Thus we must
-            // remove the unique key from that proxy.
-            SkASSERT(cachedView.asTextureProxy()->getUniqueKey() == copyKey);
-            proxyProvider->removeUniqueKeyFromProxy(cachedView.asTextureProxy());
-        }
-        proxyProvider->assignUniqueKeyToProxy(copyKey, result.asTextureProxy());
-        this->didCacheCopy(copyKey, proxyProvider->contextID());
+        proxyProvider->assignUniqueKeyToProxy(mipMappedKey, result.asTextureProxy());
+        this->didCacheMipMappedCopy(mipMappedKey, proxyProvider->contextID());
     }
     return result;
 }
@@ -132,13 +96,10 @@
         fmForDetermineDomain = &kBilerp;
     }
 
-    SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
-    GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic, scaleAdjust);
-    if (!view.proxy()) {
+    GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic);
+    if (!view) {
         return nullptr;
     }
-    SkMatrix adjustedMatrix = textureMatrix;
-    adjustedMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
 
     SkRect domain;
     DomainMode domainMode =
@@ -146,5 +107,5 @@
                             view.proxy(), fmForDetermineDomain, &domain);
     SkASSERT(kTightCopy_DomainMode != domainMode);
     return this->createFragmentProcessorForDomainAndFilter(
-            std::move(view), adjustedMatrix, domainMode, domain, filterOrNullForBicubic);
+            std::move(view), textureMatrix, domainMode, domain, filterOrNullForBicubic);
 }