Make GrClipMaskManager stateless and push GrPipelineBuilder construction downstack

This will be followed up with a CL to remove the GrRenderTarget from the GrPipelineBuilder.

Split out of:
https://codereview.chromium.org/1988923002/ (Declassify GrClipMaskManager and Remove GrRenderTarget and GrDrawTarget from GrPipelineBuilder)

GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2035823002

Review-Url: https://codereview.chromium.org/2035823002
diff --git a/src/gpu/batches/GrMSAAPathRenderer.cpp b/src/gpu/batches/GrMSAAPathRenderer.cpp
index 2072175..887c527 100644
--- a/src/gpu/batches/GrMSAAPathRenderer.cpp
+++ b/src/gpu/batches/GrMSAAPathRenderer.cpp
@@ -7,7 +7,9 @@
 
 #include "GrMSAAPathRenderer.h"
 
+#include "GrAuditTrail.h"
 #include "GrBatchFlushState.h"
+#include "GrClip.h"
 #include "GrDefaultGeoProcFactory.h"
 #include "GrPathStencilSettings.h"
 #include "GrPathUtils.h"
@@ -566,19 +568,14 @@
     typedef GrVertexBatch INHERITED;
 };
 
-bool GrMSAAPathRenderer::internalDrawPath(GrDrawTarget* target,
-                                          GrPipelineBuilder* pipelineBuilder,
+bool GrMSAAPathRenderer::internalDrawPath(GrDrawContext* drawContext,
+                                          const GrPaint& paint,
+                                          const GrUserStencilSettings* userStencilSettings,
                                           const GrClip& clip,
                                           GrColor color,
                                           const SkMatrix& viewMatrix,
                                           const SkPath& path,
                                           bool stencilOnly) {
-
-    const GrXPFactory* xpFactory = pipelineBuilder->getXPFactory();
-    SkAutoTUnref<const GrXPFactory> backupXPFactory(SkSafeRef(xpFactory));
-    // face culling doesn't make sense here
-    SkASSERT(GrPipelineBuilder::kBoth_DrawFace == pipelineBuilder->getDrawFace());
-
     int                          passCount = 0;
     const GrUserStencilSettings* passes[3];
     GrPipelineBuilder::DrawFace  drawFace[3];
@@ -643,21 +640,13 @@
     }
 
     SkRect devBounds;
-    GetPathDevBounds(path, pipelineBuilder->getRenderTarget(), viewMatrix, &devBounds);
+    GetPathDevBounds(path, drawContext->width(), drawContext->height(), viewMatrix, &devBounds);
 
     for (int p = 0; p < passCount; ++p) {
-        pipelineBuilder->setDrawFace(drawFace[p]);
-        if (passes[p]) {
-            pipelineBuilder->setUserStencil(passes[p]);
-        }
-
         if (lastPassIsBounds && (p == passCount-1)) {
-            // Reset the XP Factory on pipelineBuilder
-            pipelineBuilder->setXPFactory(backupXPFactory);
             SkRect bounds;
             SkMatrix localMatrix = SkMatrix::I();
             if (reverse) {
-                SkASSERT(pipelineBuilder->getRenderTarget());
                 // draw over the dev bounds (which will be the whole dst surface for inv fill).
                 bounds = devBounds;
                 SkMatrix vmi;
@@ -677,12 +666,18 @@
             SkAutoTUnref<GrDrawBatch> batch(
                     GrRectBatchFactory::CreateNonAAFill(color, viewM, bounds, nullptr,
                                                         &localMatrix));
-            target->drawBatch(*pipelineBuilder, clip, batch);
-        } else {
-            if (passCount > 1) {
-                pipelineBuilder->setDisableColorXPFactory();
+
+            GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMultisampled());
+            pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
+            pipelineBuilder.setDrawFace(drawFace[p]);
+            if (passes[p]) {
+                pipelineBuilder.setUserStencil(passes[p]);
+            } else {
+                pipelineBuilder.setUserStencil(userStencilSettings);
             }
 
+            drawContext->drawBatch(pipelineBuilder, clip, batch);
+        } else {
             MSAAPathBatch::Geometry geometry;
             geometry.fColor = color;
             geometry.fPath = path;
@@ -690,12 +685,23 @@
 
             SkAutoTUnref<MSAAPathBatch> batch(MSAAPathBatch::Create(geometry, viewMatrix, 
                                                                     devBounds));
-            if (batch->isValid()) {
-                target->drawBatch(*pipelineBuilder, clip, batch);
-            }
-            else {
+            if (!batch->isValid()) {
                 return false;
             }
+
+            GrPipelineBuilder pipelineBuilder(paint, drawContext->isUnifiedMultisampled());
+            pipelineBuilder.setRenderTarget(drawContext->accessRenderTarget());
+            pipelineBuilder.setDrawFace(drawFace[p]);
+            if (passes[p]) {
+                pipelineBuilder.setUserStencil(passes[p]);
+            } else {
+                pipelineBuilder.setUserStencil(userStencilSettings);
+            }
+            if (passCount > 1) {
+                pipelineBuilder.setDisableColorXPFactory();
+            }
+
+            drawContext->drawBatch(pipelineBuilder, clip, batch);
         }
     }
     return true;
@@ -711,7 +717,8 @@
 }
 
 bool GrMSAAPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(), "GrMSAAPathRenderer::onDrawPath");
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(),
+                              "GrMSAAPathRenderer::onDrawPath");
     SkPath tmpPath;
     const SkPath* path;
     if (args.fStyle->applies()) {
@@ -727,8 +734,9 @@
     } else {
         path = args.fPath;
     }
-    return this->internalDrawPath(args.fTarget,
-                                  args.fPipelineBuilder,
+    return this->internalDrawPath(args.fDrawContext,
+                                  *args.fPaint,
+                                  args.fUserStencilSettings,
                                   *args.fClip,
                                   args.fColor,
                                   *args.fViewMatrix,
@@ -737,11 +745,23 @@
 }
 
 void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),"GrMSAAPathRenderer::onStencilPath");
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fDrawContext->auditTrail(),
+                              "GrMSAAPathRenderer::onStencilPath");
     SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType());
     SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType());
-    this->internalDrawPath(args.fTarget, args.fPipelineBuilder, *args.fClip, GrColor_WHITE,
-                           *args.fViewMatrix, *args.fPath, true);
+
+    GrPaint paint;
+    paint.setXPFactory(GrDisableColorXPFactory::Create());
+    paint.setAntiAlias(args.fIsAA);
+
+    this->internalDrawPath(args.fDrawContext,
+                           paint,
+                           &GrUserStencilSettings::kUnused,
+                           *args.fClip,
+                           GrColor_WHITE,
+                           *args.fViewMatrix,
+                           *args.fPath,
+                           true);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////