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/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index 0e2f908..55fccc0 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -21,53 +21,35 @@
 #include "src/gpu/effects/GrTextureDomain.h"
 #include "src/gpu/effects/GrTextureEffect.h"
 
-GrSurfaceProxyView GrTextureProducer::CopyOnGpu(GrRecordingContext* context,
-                                                GrSurfaceProxyView inputView,
-                                                GrColorType colorType,
-                                                const CopyParams& copyParams,
-                                                bool dstWillRequireMipMaps) {
+GrSurfaceProxyView GrTextureProducer::MakeMipMappedCopy(GrRecordingContext* context,
+                                                        GrSurfaceProxyView inputView,
+                                                        GrColorType colorType) {
     SkASSERT(context);
     SkASSERT(inputView.asTextureProxy());
 
-    const SkRect dstRect = SkRect::Make(copyParams.fDimensions);
-    GrMipMapped mipMapped = dstWillRequireMipMaps ? GrMipMapped::kYes : GrMipMapped::kNo;
-
     GrSurfaceProxy* proxy = inputView.proxy();
-    SkRect localRect = proxy->getBoundsRect();
+    SkRect proxyRect = proxy->getBoundsRect();
 
-    bool resizing = false;
-    if (copyParams.fFilter != GrSamplerState::Filter::kNearest) {
-        resizing = localRect.width() != dstRect.width() || localRect.height() != dstRect.height();
-    }
-
-    if (copyParams.fFilter == GrSamplerState::Filter::kNearest && !resizing &&
-        dstWillRequireMipMaps) {
-        GrSurfaceProxyView view = GrCopyBaseMipMapToTextureProxy(context, proxy, inputView.origin(),
-                                                                 colorType);
-        if (view.proxy()) {
-            return view;
-        }
+    GrSurfaceProxyView view =
+            GrCopyBaseMipMapToTextureProxy(context, proxy, inputView.origin(), colorType);
+    if (view) {
+        return view;
     }
 
     auto copyRTC = GrRenderTargetContext::MakeWithFallback(
-            context, colorType, nullptr, SkBackingFit::kExact, copyParams.fDimensions, 1,
-            mipMapped, proxy->isProtected(), inputView.origin());
+            context, colorType, nullptr, SkBackingFit::kExact, inputView.dimensions(), 1,
+            GrMipMapped::kYes, proxy->isProtected(), inputView.origin());
     if (!copyRTC) {
         return {};
     }
 
-    const auto& caps = *context->priv().caps();
     GrPaint paint;
-
-    GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, copyParams.fFilter);
-    auto boundsRect = SkRect::Make(proxy->dimensions());
-    auto fp = GrTextureEffect::MakeSubset(std::move(inputView), kUnknown_SkAlphaType, SkMatrix::I(),
-                                          sampler, boundsRect, localRect, caps);
+    auto fp = GrTextureEffect::Make(std::move(inputView), kUnknown_SkAlphaType, SkMatrix::I(),
+                                    GrSamplerState::Filter::kNearest);
     paint.addColorFragmentProcessor(std::move(fp));
     paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
 
-    copyRTC->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect,
-                            localRect);
+    copyRTC->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), proxyRect);
     return copyRTC->readSurfaceView();
 }
 
@@ -218,7 +200,7 @@
 }
 
 GrSurfaceProxyView GrTextureProducer::viewForParams(
-        const GrSamplerState::Filter* filterOrNullForBicubic, SkScalar scaleAdjust[2]) {
+        const GrSamplerState::Filter* filterOrNullForBicubic) {
     GrSamplerState sampler; // Default is nearest + clamp
     if (filterOrNullForBicubic) {
         sampler.setFilterMode(*filterOrNullForBicubic);
@@ -230,36 +212,29 @@
             sampler.setWrapModeY(GrSamplerState::WrapMode::kClampToBorder);
         }
     }
-    return this->viewForParams(sampler, scaleAdjust);
+    return this->viewForParams(sampler);
 }
 
-GrSurfaceProxyView GrTextureProducer::viewForParams(GrSamplerState sampler,
-                                                    SkScalar scaleAdjust[2]) {
-    // Check that the caller pre-initialized scaleAdjust
-    SkASSERT(!scaleAdjust || (scaleAdjust[0] == 1 && scaleAdjust[1] == 1));
-
+GrSurfaceProxyView GrTextureProducer::viewForParams(GrSamplerState sampler) {
     const GrCaps* caps = this->context()->priv().caps();
 
     int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height());
     bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount &&
                         caps->mipMapSupport();
 
-    auto result = this->onRefTextureProxyViewForParams(sampler, willBeMipped, scaleAdjust);
+    auto result = this->onRefTextureProxyViewForParams(sampler, willBeMipped);
+    if (!result) {
+        return {};
+    }
+
+    SkASSERT(result.asTextureProxy());
 
     // Check to make sure that if we say the texture willBeMipped that the returned texture has mip
     // maps, unless the config is not copyable.
-    SkASSERT(!result.proxy() || !willBeMipped ||
-             result.asTextureProxy()->mipMapped() == GrMipMapped::kYes ||
+    SkASSERT(!willBeMipped || result.asTextureProxy()->mipMapped() == GrMipMapped::kYes ||
              !caps->isFormatCopyable(result.proxy()->backendFormat()));
 
-    SkASSERT(!result.proxy() || result.asTextureProxy());
-
-    SkDEBUGCODE(bool expectNoScale = (sampler.filter() != GrSamplerState::Filter::kMipMap &&
-                                      !sampler.isRepeated()));
-    // Check that the "no scaling expected" case always returns a proxy of the same size as the
-    // producer.
-    SkASSERT(!result.proxy() || !expectNoScale ||
-             result.proxy()->dimensions() == this->dimensions());
+    SkASSERT(result.proxy()->dimensions() == this->dimensions());
 
     return result;
 }
@@ -270,7 +245,7 @@
                                              : GrSamplerState::Filter::kMipMap;
     GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, filter);
 
-    auto result = this->viewForParams(sampler, nullptr);
+    auto result = this->viewForParams(sampler);
 
 #ifdef SK_DEBUG
     const GrCaps* caps = this->context()->priv().caps();