Work on hiding filter-quality

SkPaintPriv methods are just an internal stopgap

Change-Id: Ibe6e37c5871068d8cd67dc0948961444dfd2b62a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/347041
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/bench/DrawBitmapAABench.cpp b/bench/DrawBitmapAABench.cpp
index 7ba181b..2fc3ccf 100644
--- a/bench/DrawBitmapAABench.cpp
+++ b/bench/DrawBitmapAABench.cpp
@@ -5,11 +5,12 @@
  * found in the LICENSE file.
  */
 #include "bench/Benchmark.h"
-#include "include/core/SkBitmap.h"
 #include "include/core/SkCanvas.h"
+#include "include/core/SkImage.h"
 #include "include/core/SkMatrix.h"
 #include "include/core/SkPaint.h"
 #include "include/core/SkString.h"
+#include "include/core/SkSurface.h"
 
 /**
  * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
@@ -23,8 +24,6 @@
         , fName("draw_bitmap_") {
 
         fPaint.setAntiAlias(doAA);
-        // Most clients use filtering, so let's focus on this for now.
-        fPaint.setFilterQuality(kLow_SkFilterQuality);
         fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
     }
 
@@ -34,14 +33,16 @@
     }
 
     void onDelayedSetup() override {
-        fBitmap.allocN32Pixels(200, 200);
-        fBitmap.eraseARGB(255, 0, 255, 0);
+        auto surf = SkSurface::MakeRasterN32Premul(200, 200);
+        surf->getCanvas()->clear(0xFF00FF00);
+        fImage = surf->makeImageSnapshot();
     }
 
     void onDraw(int loops, SkCanvas* canvas) override {
+        SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
         canvas->concat(fMatrix);
         for (int i = 0; i < loops; i++) {
-            canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
+            canvas->drawImage(fImage.get(), 0, 0, sampling, &fPaint);
         }
     }
 
@@ -49,7 +50,7 @@
     SkPaint  fPaint;
     SkMatrix fMatrix;
     SkString fName;
-    SkBitmap fBitmap;
+    sk_sp<SkImage> fImage;
 
     using INHERITED = Benchmark;
 };
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h
index 9cbb766..6176a02 100644
--- a/include/core/SkPaint.h
+++ b/include/core/SkPaint.h
@@ -192,6 +192,9 @@
     */
     void setDither(bool dither) { fBitfields.fDither = static_cast<unsigned>(dither); }
 
+#ifndef SK_SUPPORT_LEGACY_SETFILTERQUALITY
+private:
+#endif
     /** Returns SkFilterQuality, the image filtering level. A lower setting
         draws faster; a higher setting looks better when the image is scaled.
     */
@@ -199,9 +202,6 @@
         return (SkFilterQuality)fBitfields.fFilterQuality;
     }
 
-#ifndef SK_SUPPORT_LEGACY_SETFILTERQUALITY
-private:
-#endif
     /** Sets SkFilterQuality, the image filtering level. A lower setting
         draws faster; a higher setting looks better when the image is scaled.
         Does not check to see if quality is valid.
diff --git a/modules/sksg/src/SkSGImage.cpp b/modules/sksg/src/SkSGImage.cpp
index 46c161b..8ebdecd 100644
--- a/modules/sksg/src/SkSGImage.cpp
+++ b/modules/sksg/src/SkSGImage.cpp
@@ -9,6 +9,7 @@
 
 #include "include/core/SkCanvas.h"
 #include "include/core/SkImage.h"
+#include "src/core/SkPaintPriv.h"
 
 namespace sksg {
 
@@ -31,7 +32,7 @@
 
     SkPaint paint;
     paint.setAntiAlias(fAntiAlias);
-    paint.setFilterQuality(legacy_quality(fSamplingOptions));
+    SkPaintPriv::SetFQ(&paint, legacy_quality(fSamplingOptions));
 
     sksg::RenderNode::ScopedRenderContext local_ctx(canvas, ctx);
     if (ctx) {
diff --git a/samplecode/SampleFilterQuality.cpp b/samplecode/SampleFilterQuality.cpp
index b0e6f18..adbb0f2 100644
--- a/samplecode/SampleFilterQuality.cpp
+++ b/samplecode/SampleFilterQuality.cpp
@@ -184,7 +184,6 @@
                       SkScalar dx, SkScalar dy) {
         SkPaint paint;
         paint.setAntiAlias(true);
-        paint.setFilterQuality(filter);
 
         SkAutoCanvasRestore acr(canvas, true);
 
@@ -194,7 +193,7 @@
         canvas->scale(fScale, fScale);
         canvas->rotate(fAngle);
         canvas->drawImage(fImage.get(), -SkScalarHalf(fImage->width()), -SkScalarHalf(fImage->height()),
-                          &paint);
+                          SkSamplingOptions(filter), &paint);
 
         if (false) {
             acr.restore();
diff --git a/samplecode/SampleShip.cpp b/samplecode/SampleShip.cpp
index 25853b5..221bbf0 100644
--- a/samplecode/SampleShip.cpp
+++ b/samplecode/SampleShip.cpp
@@ -10,6 +10,7 @@
 #include "include/core/SkRSXform.h"
 #include "include/core/SkSurface.h"
 #include "samplecode/Sample.h"
+#include "src/core/SkPaintPriv.h"
 #include "tools/Resources.h"
 #include "tools/timer/Timer.h"
 
@@ -96,7 +97,7 @@
         }
 
         SkPaint paint;
-        paint.setFilterQuality(kLow_SkFilterQuality);
+        SkPaintPriv::SetFQ(&paint, kLow_SkFilterQuality);
         paint.setColor(SK_ColorWHITE);
 
         SkScalar anchorX = fAtlas->width()*0.5f;
diff --git a/samplecode/SampleThinAA.cpp b/samplecode/SampleThinAA.cpp
index 0a5a25a..08b2b44 100644
--- a/samplecode/SampleThinAA.cpp
+++ b/samplecode/SampleThinAA.cpp
@@ -208,7 +208,6 @@
         // Use medium quality filter to get mipmaps when drawing smaller, or use nearest filtering
         // when upscaling
         SkPaint blit;
-        blit.setFilterQuality(scale > 1.f ? kNone_SkFilterQuality : kMedium_SkFilterQuality);
         if (debugMode) {
             // Makes anything that's > 1/255 alpha fully opaque and sets color to medium green.
             static constexpr float kFilter[] = {
@@ -222,7 +221,12 @@
         }
 
         canvas->scale(scale, scale);
-        canvas->drawImageRect(fLastRendered, SkRect::MakeWH(kTileWidth, kTileHeight), &blit);
+        canvas->drawImageRect(fLastRendered.get(),
+                              SkRect::MakeWH(kTileWidth, kTileHeight),
+                              SkRect::MakeWH(kTileWidth, kTileHeight),
+                              SkSamplingOptions(scale > 1.f ? kNone_SkFilterQuality
+                                                            : kMedium_SkFilterQuality),
+                              &blit);
     }
 
 private:
diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp
index 4efc5e0..41d67f3 100644
--- a/src/core/SkPaint.cpp
+++ b/src/core/SkPaint.cpp
@@ -235,7 +235,7 @@
     packed |= shift_bits(paint.getStrokeCap(),     16, 2);
     packed |= shift_bits(paint.getStrokeJoin(),    18, 2);
     packed |= shift_bits(paint.getStyle(),         20, 2);
-    packed |= shift_bits(paint.getFilterQuality(), 22, 2);
+    packed |= shift_bits(SkPaintPriv::GetFQ(paint), 22, 2);
     packed |= shift_bits(flatFlags,                24, 8);
     return packed;
 }
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 39e4c48..e40bf07 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -222,7 +222,7 @@
     // Convert SkPaint color to 4f format in the destination color space
     SkColor4f origColor = SkColor4fPrepForDst(skPaint.getColor4f(), dstColorInfo);
 
-    GrFPArgs fpArgs(context, matrixProvider, skPaint.getFilterQuality(), &dstColorInfo);
+    GrFPArgs fpArgs(context, matrixProvider, SkPaintPriv::GetFQ(skPaint), &dstColorInfo);
 
     // Setup the initial color considering the shader, the SkPaint color, and the presence or not
     // of per-vertex colors.
@@ -427,7 +427,7 @@
     if (textureIsAlphaOnly) {
         if (const auto* shader = as_SB(paint.getShader())) {
             shaderFP = shader->asFragmentProcessor(
-                    GrFPArgs(context, matrixProvider, paint.getFilterQuality(), &dstColorInfo));
+                    GrFPArgs(context, matrixProvider, SkPaintPriv::GetFQ(paint), &dstColorInfo));
             if (!shaderFP) {
                 return false;
             }
diff --git a/src/shaders/SkBitmapProcShader.cpp b/src/shaders/SkBitmapProcShader.cpp
index 5d0124c..1d7299a 100644
--- a/src/shaders/SkBitmapProcShader.cpp
+++ b/src/shaders/SkBitmapProcShader.cpp
@@ -9,6 +9,7 @@
 
 #include "src/core/SkArenaAlloc.h"
 #include "src/core/SkBitmapProcState.h"
+#include "src/core/SkPaintPriv.h"
 #include "src/core/SkXfermodePriv.h"
 
 class BitmapProcShaderContext : public SkShaderBase::Context {
@@ -86,7 +87,7 @@
 
     SkBitmapProcState* state = alloc->make<SkBitmapProcState>(image, tmx, tmy);
     if (!state->setup(totalInverse, rec.fPaint->getColor(),
-                      SkSamplingOptions(rec.fPaint->getFilterQuality()))) {
+                      SkSamplingOptions(SkPaintPriv::GetFQ(*rec.fPaint)))) {
         return nullptr;
     }
     return alloc->make<BitmapProcShaderContext>(shader, rec, state);
diff --git a/tests/CompressedBackendAllocationTest.cpp b/tests/CompressedBackendAllocationTest.cpp
index 4966eaf..88b81e0 100644
--- a/tests/CompressedBackendAllocationTest.cpp
+++ b/tests/CompressedBackendAllocationTest.cpp
@@ -11,6 +11,7 @@
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkCompressedDataUtils.h"
 #include "src/core/SkMipmap.h"
+#include "src/core/SkPaintPriv.h"
 #include "src/gpu/GrBackendUtils.h"
 #include "src/gpu/GrDirectContextPriv.h"
 #include "src/image/SkImage_Base.h"
@@ -73,7 +74,7 @@
     SkCanvas* canvas = surf->getCanvas();
 
     SkPaint p;
-    p.setFilterQuality(kMedium_SkFilterQuality); // to force mipMapping
+    SkPaintPriv::SetFQ(&p, kMedium_SkFilterQuality); // to force mipMapping
     p.setBlendMode(SkBlendMode::kSrc);
 
     int numMipLevels = 1;
diff --git a/tests/TextureBindingsResetTest.cpp b/tests/TextureBindingsResetTest.cpp
index 8b3a07d..7a017a9 100644
--- a/tests/TextureBindingsResetTest.cpp
+++ b/tests/TextureBindingsResetTest.cpp
@@ -93,9 +93,7 @@
     surf->getCanvas()->clear(SK_ColorBLUE);
     surf->getCanvas()->save();
     surf->getCanvas()->scale(0.25, 0.25);
-    SkPaint paint;
-    paint.setFilterQuality(kHigh_SkFilterQuality);
-    surf->getCanvas()->drawImage(img, 0, 0, &paint);
+    surf->getCanvas()->drawImage(img.get(), 0, 0, SkSamplingOptions({1.0f/3, 1.0f/3}), nullptr);
     surf->getCanvas()->restore();
     surf->flushAndSubmit();
     dContext->resetGLTextureBindings();
diff --git a/tools/debugger/DrawCommand.cpp b/tools/debugger/DrawCommand.cpp
index 1e6e97d..101b791 100644
--- a/tools/debugger/DrawCommand.cpp
+++ b/tools/debugger/DrawCommand.cpp
@@ -24,6 +24,7 @@
 #include "src/core/SkLatticeIter.h"
 #include "src/core/SkMaskFilterBase.h"
 #include "src/core/SkPaintDefaults.h"
+#include "src/core/SkPaintPriv.h"
 #include "src/core/SkReadBuffer.h"
 #include "src/core/SkRectPriv.h"
 #include "src/core/SkTextBlobPriv.h"
@@ -824,7 +825,7 @@
 }
 
 static void apply_paint_filterquality(const SkPaint& paint, SkJSONWriter& writer) {
-    SkFilterQuality quality = paint.getFilterQuality();
+    SkFilterQuality quality = SkPaintPriv::GetFQ(paint);
     switch (quality) {
         case kNone_SkFilterQuality: break;
         case kLow_SkFilterQuality: