Draw dmsaa textures with GrFillRRectOp

With the new drawing API in Ganesh it should be relatively
straightforward to chain FPs with different textures.

Bug: skia:11396
Change-Id: I57cde39a2c00c79ea8b9b907c0ee8a034f977a14
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386616
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index 5ad0b48..5f8c49b 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -49,6 +49,7 @@
 #include "src/gpu/GrTracing.h"
 #include "src/gpu/SkGr.h"
 #include "src/gpu/effects/GrBicubicEffect.h"
+#include "src/gpu/effects/GrBlendFragmentProcessor.h"
 #include "src/gpu/effects/GrRRectEffect.h"
 #include "src/gpu/geometry/GrQuad.h"
 #include "src/gpu/geometry/GrQuadUtils.h"
@@ -614,6 +615,52 @@
     // All other optimization levels were completely handled inside attempt(), so no extra op needed
 }
 
+void GrSurfaceDrawContext::drawTexture(const GrClip* clip,
+                                       GrSurfaceProxyView view,
+                                       SkAlphaType srcAlphaType,
+                                       GrSamplerState::Filter filter,
+                                       GrSamplerState::MipmapMode mm,
+                                       SkBlendMode blendMode,
+                                       const SkPMColor4f& color,
+                                       const SkRect& srcRect,
+                                       const SkRect& dstRect,
+                                       GrAA aa,
+                                       GrQuadAAFlags edgeAA,
+                                       SkCanvas::SrcRectConstraint constraint,
+                                       const SkMatrix& viewMatrix,
+                                       sk_sp<GrColorSpaceXform> colorSpaceXform) {
+    // If we are using dmsaa then go through GrFillRRectOp (via fillRectToRect).
+    if (fContext->priv().alwaysAntialias() && aa == GrAA::kYes) {
+        GrPaint paint;
+        paint.setColor4f(color);
+        std::unique_ptr<GrFragmentProcessor> fp;
+        if (constraint == SkCanvas::kStrict_SrcRectConstraint) {
+            fp = GrTextureEffect::MakeSubset(view, srcAlphaType, SkMatrix::I(),
+                                             GrSamplerState(filter, mm), srcRect,
+                                             *this->caps());
+        } else {
+            fp = GrTextureEffect::Make(view, srcAlphaType, SkMatrix::I(), filter, mm);
+        }
+        if (colorSpaceXform) {
+            fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform));
+        }
+        fp = GrBlendFragmentProcessor::Make(std::move(fp), nullptr, SkBlendMode::kModulate);
+        paint.setColorFragmentProcessor(std::move(fp));
+        if (blendMode != SkBlendMode::kSrcOver) {
+            paint.setXPFactory(SkBlendMode_AsXPFactory(blendMode));
+        }
+        this->fillRectToRect(clip, std::move(paint), GrAA::kYes, viewMatrix, dstRect, srcRect);
+        return;
+    }
+
+    const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint ?
+            &srcRect : nullptr;
+    DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA};
+
+    this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(colorSpaceXform), filter,
+                           mm, color, blendMode, aa, &quad, subset);
+}
+
 void GrSurfaceDrawContext::drawTexturedQuad(const GrClip* clip,
                                             GrSurfaceProxyView proxyView,
                                             SkAlphaType srcAlphaType,
diff --git a/src/gpu/GrSurfaceDrawContext.h b/src/gpu/GrSurfaceDrawContext.h
index f394093..56dd22c 100644
--- a/src/gpu/GrSurfaceDrawContext.h
+++ b/src/gpu/GrSurfaceDrawContext.h
@@ -250,27 +250,20 @@
      * specifies the rectangle to draw in local coords which will be transformed by 'viewMatrix' to
      * device space.
      */
-    void drawTexture(const GrClip* clip,
-                     GrSurfaceProxyView view,
-                     SkAlphaType srcAlphaType,
-                     GrSamplerState::Filter filter,
-                     GrSamplerState::MipmapMode mm,
-                     SkBlendMode mode,
-                     const SkPMColor4f& color,
+    void drawTexture(const GrClip*,
+                     GrSurfaceProxyView,
+                     SkAlphaType,
+                     GrSamplerState::Filter,
+                     GrSamplerState::MipmapMode,
+                     SkBlendMode,
+                     const SkPMColor4f&,
                      const SkRect& srcRect,
                      const SkRect& dstRect,
-                     GrAA aa,
-                     GrQuadAAFlags edgeAA,
-                     SkCanvas::SrcRectConstraint constraint,
-                     const SkMatrix& viewMatrix,
-                     sk_sp<GrColorSpaceXform> texXform) {
-        const SkRect* subset = constraint == SkCanvas::kStrict_SrcRectConstraint ?
-                &srcRect : nullptr;
-        DrawQuad quad{GrQuad::MakeFromRect(dstRect, viewMatrix), GrQuad(srcRect), edgeAA};
-
-        this->drawTexturedQuad(clip, std::move(view), srcAlphaType, std::move(texXform), filter, mm,
-                               color, mode, aa, &quad, subset);
-    }
+                     GrAA,
+                     GrQuadAAFlags,
+                     SkCanvas::SrcRectConstraint,
+                     const SkMatrix&,
+                     sk_sp<GrColorSpaceXform>);
 
     /**
      * Variant of drawTexture that instead draws the texture applied to 'dstQuad' transformed by