Pass samplingoptions to GrArgs

Also, add control over kMedium mapping

Seems like a loss that GrInterpret throws away the cubic coefficients...

A step towards https://skia-review.googlesource.com/c/skia/+/347022

Bug: skia:11105, skia:7650
Change-Id: I2564c29b0eeffd4df92c0baa78e2c04f6348d7d7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347636
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 438f734..c6b7bbe 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -427,7 +427,7 @@
                                   GrQuadAAFlags aaFlags,
                                   SkCanvas::SrcRectConstraint constraint,
                                   GrSamplerState sampler,
-                                  bool doBicubic) {
+                                  SkCubicResampler cubic) {
     const SkMatrix& ctm(matrixProvider.localToDevice());
     if (sampler.wrapModeX() == GrSamplerState::WrapMode::kClamp &&
         sampler.wrapModeY() == GrSamplerState::WrapMode::kClamp && !producer->isPlanar() &&
@@ -480,7 +480,8 @@
     bool coordsAllInsideSrcRect = aaFlags == GrQuadAAFlags::kNone && !mf;
 
     // Check for optimization to drop the src rect constraint when using linear filtering.
-    if (!doBicubic && sampler.filter() == GrSamplerState::Filter::kLinear && restrictToSubset &&
+    if (!GrValidCubicResampler(cubic) &&
+        sampler.filter() == GrSamplerState::Filter::kLinear && restrictToSubset &&
         sampler.mipmapped() == GrMipmapped::kNo && coordsAllInsideSrcRect &&
         !producer->isPlanar()) {
         SkMatrix combinedMatrix;
@@ -501,10 +502,10 @@
     const SkRect* subset = restrictToSubset       ? &src : nullptr;
     const SkRect* domain = coordsAllInsideSrcRect ? &src : nullptr;
     std::unique_ptr<GrFragmentProcessor> fp;
-    if (doBicubic) {
+    if (GrValidCubicResampler(cubic)) {
         fp = producer->createBicubicFragmentProcessor(textureMatrix, subset, domain,
                                                       sampler.wrapModeX(), sampler.wrapModeY(),
-                                                      GrBicubicEffect::gMitchell);
+                                                      cubic);
     } else {
         fp = producer->createFragmentProcessor(textureMatrix, subset, domain, sampler);
     }
@@ -573,7 +574,8 @@
                        GrAA aa,
                        SkCanvas::SrcRectConstraint constraint,
                        GrSamplerState sampler,
-                       bool doBicubic) {
+                       SkCubicResampler cubic) {
+    const bool doBicubic = GrValidCubicResampler(cubic);
     SkRect clippedSrcRect = SkRect::Make(clippedSrcIRect);
 
     int nx = bitmap.width() / tileSize;
@@ -650,7 +652,7 @@
                 offsetSrcToDst.preTranslate(offset.fX, offset.fY);
                 draw_texture_producer(context, rtc, clip, matrixProvider, paint, &tileProducer,
                                       tileR, rectToDraw, nullptr, offsetSrcToDst, aa, aaFlags,
-                                      constraint, sampler, doBicubic);
+                                      constraint, sampler, cubic);
             }
         }
     }
@@ -685,13 +687,16 @@
     SkOverrideDeviceMatrixProvider matrixProvider(this->asMatrixProvider(), localToDevice);
     draw_texture_producer(fContext.get(), fSurfaceDrawContext.get(), this->clip(), matrixProvider,
                           paint, &texture, src, dst, nullptr, srcToDst, aa, aaFlags,
-                          SkCanvas::kStrict_SrcRectConstraint, sampler, false);
+                          SkCanvas::kStrict_SrcRectConstraint, sampler, kInvalidCubicResampler);
 }
 
 void SkGpuDevice::drawImageQuad(const SkImage* image, const SkRect* srcRect, const SkRect* dstRect,
                                 const SkPoint dstClip[4], GrAA aa, GrQuadAAFlags aaFlags,
                                 const SkMatrix* preViewMatrix, const SkPaint& paint,
                                 SkCanvas::SrcRectConstraint constraint) {
+    // TODO: pass in sampling directly
+    SkSamplingOptions sampling(paint.getFilterQuality(), SkSamplingOptions::kMedium_asMipmapLinear);
+
     SkRect src;
     SkRect dst;
     SkMatrix srcToDst;
@@ -715,7 +720,7 @@
     const SkMatrix& ctm(matrixProvider.localToDevice());
 
     bool sharpenMM = fContext->priv().options().fSharpenMipmappedTextures;
-    auto [fm, mm, bicubic] = GrInterpretFilterQuality(image->dimensions(), paint.getFilterQuality(),
+    auto [fm, mm, cubic] = GrInterpretSamplingOptions(image->dimensions(), sampling,
                                                       ctm, srcToDst, sharpenMM,
                                                       /*allowFilterQualityReduction=*/true);
 
@@ -728,7 +733,7 @@
         GrYUVAImageTextureMaker maker(fContext.get(), image);
         draw_texture_producer(fContext.get(), fSurfaceDrawContext.get(), clip, matrixProvider,
                               paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
-                              {wrapMode, fm, mm}, bicubic);
+                              {wrapMode, fm, mm}, cubic);
         return;
     }
 
@@ -749,7 +754,7 @@
         GrTextureAdjuster adjuster(fContext.get(), std::move(view), colorInfo, pinnedUniqueID);
         draw_texture_producer(fContext.get(), fSurfaceDrawContext.get(), clip, matrixProvider,
                               paint, &adjuster, src, dst, dstClip, srcToDst, aa, aaFlags,
-                              constraint, {wrapMode, fm, mm}, bicubic);
+                              constraint, {wrapMode, fm, mm}, cubic);
         return;
     }
 
@@ -759,7 +764,7 @@
         SkASSERT(!image->isTextureBacked());
 
         int tileFilterPad;
-        if (bicubic) {
+        if (GrValidCubicResampler(cubic)) {
             tileFilterPad = GrBicubicEffect::kFilterTexelPad;
         } else if (GrSamplerState::Filter::kNearest == fm) {
             tileFilterPad = 0;
@@ -779,7 +784,7 @@
                 // This is the funnel for all paths that draw tiled bitmaps/images.
                 draw_tiled_bitmap(fContext.get(), fSurfaceDrawContext.get(), clip, bm, tileSize,
                                   matrixProvider, srcToDst, src, clippedSubset, paint, aa,
-                                  constraint, {wrapMode, fm, mm}, bicubic);
+                                  constraint, {wrapMode, fm, mm}, cubic);
                 return;
             }
         }
@@ -791,7 +796,7 @@
         GrImageTextureMaker maker(fContext.get(), image, GrImageTexGenPolicy::kDraw);
         draw_texture_producer(fContext.get(), fSurfaceDrawContext.get(), clip, matrixProvider,
                               paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
-                              {wrapMode, fm, mm}, bicubic);
+                              {wrapMode, fm, mm}, cubic);
         return;
     }
 
@@ -800,7 +805,7 @@
         GrBitmapTextureMaker maker(fContext.get(), bm, GrImageTexGenPolicy::kDraw);
         draw_texture_producer(fContext.get(), fSurfaceDrawContext.get(), clip, matrixProvider,
                               paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
-                              {wrapMode, fm, mm}, bicubic);
+                              {wrapMode, fm, mm}, cubic);
     }
 
     // Otherwise don't know how to draw it