Move GrPipelineBuilder into GrRenderTargetContext::addLegacyDrawOp

This makes the legacy code use GrProcessorSet::Analysis in the same manner as the non-GrLegacyMeshDrawOps which enables changes to how analysis works.

Change-Id: I8171e285ac8930beb3ac33cd3c4ee88f217b9e40
Reviewed-on: https://skia-review.googlesource.com/11205
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index e36db07..f48162c 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -19,10 +19,6 @@
 #include "ops/GrOp.h"
 
 void GrPipeline::init(const InitArgs& args) {
-    if (args.fAnalysis) {
-        SkASSERT(args.fAnalysis->outputColor() == args.fInputColor);
-        SkASSERT(args.fAnalysis->outputCoverage() == args.fInputCoverage);
-    }
     SkASSERT(args.fRenderTarget);
 
     fRenderTarget.reset(args.fRenderTarget);
@@ -62,12 +58,12 @@
         const GrXPFactory* xpFactory = args.fProcessors->xpFactory();
         if (xpFactory) {
             xferProcessor.reset(xpFactory->createXferProcessor(
-                    args.fInputColor, args.fInputCoverage, hasMixedSamples, *args.fCaps));
+                    args.fXPInputColor, args.fXPInputCoverage, hasMixedSamples, *args.fCaps));
             SkASSERT(xferProcessor);
         } else {
             // This may return nullptr in the common case of src-over implemented using hw blending.
             xferProcessor.reset(GrPorterDuffXPFactory::CreateSrcOverXferProcessor(
-                    *args.fCaps, args.fInputColor, args.fInputCoverage, hasMixedSamples));
+                    *args.fCaps, args.fXPInputColor, args.fXPInputCoverage, hasMixedSamples));
         }
         fXferProcessor.reset(xferProcessor.get());
     }
@@ -76,25 +72,9 @@
         fDstTextureOffset = args.fDstTexture.offset();
     }
 
-    // This is for the legacy GrPipeline creation in GrLegacyMeshDrawOp where analysis does not
-    // eliminate fragment processors from GrProcessorSet.
-    int colorFPsToEliminate = 0;
-    if (args.fAnalysis) {
-        GrColor overrideColor = GrColor_ILLEGAL;
-        colorFPsToEliminate =
-                args.fAnalysis->getInputColorOverrideAndColorProcessorEliminationCount(
-                        &overrideColor);
-        colorFPsToEliminate = SkTMax(colorFPsToEliminate, 0);
-        if (args.fAnalysis->isInputColorIgnored()) {
-            // No need to have an override color if it isn't even going to be used.
-            overrideColor = GrColor_ILLEGAL;
-            colorFPsToEliminate = args.fProcessors->numColorFragmentProcessors();
-        }
-    }
-
     // Copy GrFragmentProcessors from GrPipelineBuilder to Pipeline, possibly removing some of the
     // color fragment processors.
-    fNumColorProcessors = args.fProcessors->numColorFragmentProcessors() - colorFPsToEliminate;
+    fNumColorProcessors = args.fProcessors->numColorFragmentProcessors();
     int numTotalProcessors =
             fNumColorProcessors + args.fProcessors->numCoverageFragmentProcessors();
     if (args.fAppliedClip && args.fAppliedClip->clipCoverageFragmentProcessor()) {
@@ -102,8 +82,7 @@
     }
     fFragmentProcessors.reset(numTotalProcessors);
     int currFPIdx = 0;
-    for (int i = colorFPsToEliminate; i < args.fProcessors->numColorFragmentProcessors();
-         ++i, ++currFPIdx) {
+    for (int i = 0; i < args.fProcessors->numColorFragmentProcessors(); ++i, ++currFPIdx) {
         const GrFragmentProcessor* fp = args.fProcessors->colorFragmentProcessor(i);
         fFragmentProcessors[currFPIdx].reset(fp);
     }
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index d7a4f4e..02a14af 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -57,10 +57,8 @@
         uint32_t fFlags = 0;
         GrDrawFace fDrawFace = GrDrawFace::kBoth;
         const GrProcessorSet* fProcessors = nullptr;
-        GrProcessorAnalysisColor fInputColor;
-        GrProcessorAnalysisCoverage fInputCoverage = GrProcessorAnalysisCoverage::kNone;
-        // This is only used for GrLegacyMeshDrawOp's pipeline creation system.
-        const GrProcessorSet::Analysis* fAnalysis = nullptr;
+        GrProcessorAnalysisColor fXPInputColor;
+        GrProcessorAnalysisCoverage fXPInputCoverage = GrProcessorAnalysisCoverage::kNone;
         const GrUserStencilSettings* fUserStencil = &GrUserStencilSettings::kUnused;
         const GrAppliedClip* fAppliedClip = nullptr;
         GrRenderTarget* fRenderTarget = nullptr;
diff --git a/src/gpu/GrPipelineBuilder.h b/src/gpu/GrPipelineBuilder.h
index 7451b65..94e07e6 100644
--- a/src/gpu/GrPipelineBuilder.h
+++ b/src/gpu/GrPipelineBuilder.h
@@ -63,6 +63,14 @@
 
     const GrProcessorSet& processors() const { return fProcessors; }
 
+    void analyzeAndEliminateFragmentProcessors(GrProcessorSet::Analysis* analysis,
+                                               const GrProcessorAnalysisColor& colorInput,
+                                               const GrProcessorAnalysisCoverage coverageInput,
+                                               const GrAppliedClip* clip, const GrCaps& caps) {
+        fProcessors.analyzeAndEliminateFragmentProcessors(analysis, colorInput, coverageInput, clip,
+                                                          caps);
+    }
+
     /// @}
 
 
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index f4c4410..af17e5b 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -516,7 +516,7 @@
                 if (ss) {
                     pipelineBuilder.setUserStencil(ss);
                 }
-                this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+                this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
                 return true;
             }
         }
@@ -639,7 +639,7 @@
         if (op) {
             GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
             pipelineBuilder.setSnapVerticesToPixelCenters(snapToPixelCenters);
-            this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+            this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
             return;
         }
     }
@@ -814,7 +814,7 @@
         std::unique_ptr<GrLegacyMeshDrawOp> op = GrAAFillRectOp::MakeWithLocalRect(
                 paint.getColor(), viewMatrix, croppedRect, croppedLocalRect);
         GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-        this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
         return;
     }
 
@@ -870,7 +870,7 @@
         std::unique_ptr<GrLegacyMeshDrawOp> op =
                 GrAAFillRectOp::Make(paint.getColor(), viewMatrix, localMatrix, croppedRect);
         GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-        this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
         return;
     }
 
@@ -920,7 +920,7 @@
         return;
     }
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 void GrRenderTargetContext::drawVertices(const GrClip& clip,
@@ -941,7 +941,7 @@
         return;
     }
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -963,7 +963,7 @@
     std::unique_ptr<GrLegacyMeshDrawOp> op =
             GrDrawAtlasOp::Make(paint.getColor(), viewMatrix, spriteCount, xform, texRect, colors);
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -1023,7 +1023,7 @@
                                              shaderCaps);
         if (op) {
             GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-            this->addLegacyMeshDrawOp(pipelineBuilder, *clip, std::move(op));
+            this->addLegacyMeshDrawOp(std::move(pipelineBuilder), *clip, std::move(op));
             return;
         }
     }
@@ -1061,7 +1061,7 @@
             paint.getColor(), viewMatrix, rrect, blurRadius, stroke, shaderCaps);
     if (op) {
         GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-        this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
         return;
     }
 }
@@ -1202,7 +1202,7 @@
 
     std::unique_ptr<GrLegacyMeshDrawOp> op = GrRegionOp::Make(paint.getColor(), viewMatrix, region);
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 void GrRenderTargetContext::drawOval(const GrClip& clip,
@@ -1243,7 +1243,7 @@
                 GrOvalOpFactory::MakeOvalOp(paint.getColor(), viewMatrix, oval, stroke, shaderCaps);
         if (op) {
             GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-            this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+            this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
             return;
         }
     }
@@ -1283,7 +1283,7 @@
                                                                             shaderCaps);
         if (op) {
             GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-            this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+            this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
             return;
         }
     }
@@ -1311,7 +1311,7 @@
             paint.getColor(), viewMatrix, imageWidth, imageHeight, std::move(iter), dst);
 
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 void GrRenderTargetContext::prepareForExternalIO() {
@@ -1339,7 +1339,7 @@
     if (ss) {
         pipelineBuilder.setUserStencil(ss);
     }
-    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 // Can 'path' be drawn as a pair of filled nested rectangles?
@@ -1419,7 +1419,7 @@
                         GrRectOpFactory::MakeAAFillNestedRects(paint.getColor(), viewMatrix, rects);
                 if (op) {
                     GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-                    this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+                    this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
                 }
                 return;
             }
@@ -1433,7 +1433,7 @@
                     paint.getColor(), viewMatrix, ovalRect, style.strokeRec(), shaderCaps);
             if (op) {
                 GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
-                this->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+                this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
                 return;
             }
         }
@@ -1676,7 +1676,7 @@
     return this->getOpList()->addOp(std::move(op), this, std::move(appliedClip), dstTexture);
 }
 
-uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(const GrPipelineBuilder& pipelineBuilder,
+uint32_t GrRenderTargetContext::addLegacyMeshDrawOp(GrPipelineBuilder&& pipelineBuilder,
                                                     const GrClip& clip,
                                                     std::unique_ptr<GrLegacyMeshDrawOp> op) {
     ASSERT_SINGLE_OWNER
@@ -1711,16 +1711,15 @@
     }
 
     GrProcessorSet::Analysis analysis;
-    op->analyzeProcessors(&analysis, pipelineBuilder.processors(), &appliedClip, *this->caps());
+    op->analyzeProcessors(&analysis, &pipelineBuilder, &appliedClip, *this->caps());
 
     GrPipeline::InitArgs args;
     pipelineBuilder.getPipelineInitArgs(&args);
     args.fAppliedClip = &appliedClip;
     args.fRenderTarget = rt;
     args.fCaps = this->caps();
-    args.fAnalysis = &analysis;
-    args.fInputColor = analysis.outputColor();
-    args.fInputCoverage = analysis.outputCoverage();
+    args.fXPInputColor = analysis.outputColor();
+    args.fXPInputCoverage = analysis.outputCoverage();
 
     if (analysis.requiresDstTexture()) {
         this->setupDstTexture(rt, clip, bounds, &args.fDstTexture);
@@ -1728,7 +1727,7 @@
             return SK_InvalidUniqueID;
         }
     }
-    op->initPipeline(args);
+    op->initPipeline(args, analysis);
     // TODO: We need to add pipeline dependencies on textures, etc before recording this op.
     op->setClippedBounds(bounds);
     return this->getOpList()->addOp(std::move(op), this);
diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h
index edec4de..fe32faf 100644
--- a/src/gpu/GrRenderTargetContext.h
+++ b/src/gpu/GrRenderTargetContext.h
@@ -466,7 +466,7 @@
     // the op list. They return the id of the opList to which the op was added, or 0, if it was
     // dropped (e.g., due to clipping).
     uint32_t addDrawOp(const GrClip&, std::unique_ptr<GrDrawOp>);
-    uint32_t addLegacyMeshDrawOp(const GrPipelineBuilder&, const GrClip&,
+    uint32_t addLegacyMeshDrawOp(GrPipelineBuilder&&, const GrClip&,
                                  std::unique_ptr<GrLegacyMeshDrawOp>);
 
     // Makes a copy of the dst if it is necessary for the draw and returns the texture that should
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index fb06ab4..2068734 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -180,5 +180,5 @@
             GrSamplerParams::kNone_FilterMode));
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
     pipelineBuilder.setUserStencil(&userStencilSettings);
-    renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 25004e1..0e7cecd 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -81,7 +81,7 @@
 
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
     pipelineBuilder.setUserStencil(&userStencilSettings);
-    renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+    renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
 }
 
 void GrSoftwarePathRenderer::DrawAroundInvPath(GrRenderTargetContext* renderTargetContext,
diff --git a/src/gpu/instanced/InstancedRendering.cpp b/src/gpu/instanced/InstancedRendering.cpp
index 4abaef6..9b6e576 100644
--- a/src/gpu/instanced/InstancedRendering.cpp
+++ b/src/gpu/instanced/InstancedRendering.cpp
@@ -482,8 +482,8 @@
 
     GrPipeline pipeline;
     GrPipeline::InitArgs args;
-    args.fInputColor = fAnalysisColor;
-    args.fInputCoverage = coverage;
+    args.fXPInputColor = fAnalysisColor;
+    args.fXPInputCoverage = coverage;
     args.fAppliedClip = clip;
     args.fCaps = &state->caps();
     args.fProcessors = &fProcessors;
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index 5c52fef..efc6622 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -979,7 +979,8 @@
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
+                                                   std::move(op));
 
     return true;
 
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index c789aa8..274e308 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -950,7 +950,8 @@
             args.fPaint.getColor(), *args.fViewMatrix, path, args.fShape->style(), devClipBounds);
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
+                                                   std::move(op));
     return true;
 }
 
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index 8768c1e..2a5464c 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -343,7 +343,8 @@
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
+                                                   std::move(op));
 
     return true;
 }
diff --git a/src/gpu/ops/GrDashLinePathRenderer.cpp b/src/gpu/ops/GrDashLinePathRenderer.cpp
index eda8906..cafe247 100644
--- a/src/gpu/ops/GrDashLinePathRenderer.cpp
+++ b/src/gpu/ops/GrDashLinePathRenderer.cpp
@@ -55,6 +55,7 @@
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(
+            std::move(pipelineBuilder), *args.fClip, std::move(op));
     return true;
 }
diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp
index 73c1f10..762084c 100644
--- a/src/gpu/ops/GrDefaultPathRenderer.cpp
+++ b/src/gpu/ops/GrDefaultPathRenderer.cpp
@@ -554,7 +554,8 @@
             GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
             pipelineBuilder.setDrawFace(drawFace[p]);
             pipelineBuilder.setUserStencil(passes[p]);
-            renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+            renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip,
+                                                     std::move(op));
         } else {
             std::unique_ptr<GrLegacyMeshDrawOp> op =
                     DefaultPathOp::Make(paint.getColor(), path, srcSpaceTol, newCoverage,
@@ -567,7 +568,8 @@
             GrPipelineBuilder pipelineBuilder(std::move(passPaint), aaType);
             pipelineBuilder.setDrawFace(drawFace[p]);
             pipelineBuilder.setUserStencil(passes[p]);
-            renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+            renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip,
+                                                     std::move(op));
         }
     }
     return true;
diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp
index 81a2de0..1c68fdf 100644
--- a/src/gpu/ops/GrDrawPathOp.cpp
+++ b/src/gpu/ops/GrDrawPathOp.cpp
@@ -46,8 +46,8 @@
     args.fRenderTarget = state.drawOpArgs().fRenderTarget;
     args.fCaps = &state.caps();
     args.fDstTexture = state.drawOpArgs().fDstTexture;
-    args.fInputColor = analysis.outputColor();
-    args.fInputCoverage = analysis.outputCoverage();
+    args.fXPInputColor = analysis.outputColor();
+    args.fXPInputCoverage = analysis.outputCoverage();
 
     return pipeline->init(args);
 }
diff --git a/src/gpu/ops/GrMSAAPathRenderer.cpp b/src/gpu/ops/GrMSAAPathRenderer.cpp
index 227c540..8e32006 100644
--- a/src/gpu/ops/GrMSAAPathRenderer.cpp
+++ b/src/gpu/ops/GrMSAAPathRenderer.cpp
@@ -640,7 +640,7 @@
         }
         GrPipelineBuilder pipelineBuilder(std::move(firstPassPaint), aaType);
         pipelineBuilder.setUserStencil(passes[0]);
-        renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
     }
 
     if (passes[1]) {
@@ -669,7 +669,7 @@
         GrPipelineBuilder pipelineBuilder(std::move(paint), aaType);
         pipelineBuilder.setUserStencil(passes[1]);
 
-        renderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        renderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
     }
     return true;
 }
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index 8daa62b..41d3848 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -12,6 +12,7 @@
 #include "GrGeometryProcessor.h"
 #include "GrMesh.h"
 #include "GrPendingProgramElement.h"
+#include "GrPipelineBuilder.h"
 
 #include "SkTLList.h"
 
@@ -101,18 +102,19 @@
      * initial color and coverage from this op's geometry processor.
      */
     void analyzeProcessors(GrProcessorSet::Analysis* analysis,
-                           const GrProcessorSet& processors,
+                           GrPipelineBuilder* pipelineBuilder,
                            const GrAppliedClip* appliedClip,
                            const GrCaps& caps) const {
         GrProcessorAnalysisColor inputColor;
         GrProcessorAnalysisCoverage inputCoverage;
         this->getProcessorAnalysisInputs(&inputColor, &inputCoverage);
-        analysis->init(inputColor, inputCoverage, processors, appliedClip, caps);
+        pipelineBuilder->analyzeAndEliminateFragmentProcessors(analysis, inputColor, inputCoverage,
+                                                               appliedClip, caps);
     }
 
-    void initPipeline(const GrPipeline::InitArgs& args) {
+    void initPipeline(const GrPipeline::InitArgs& args, const GrProcessorSet::Analysis& analysis) {
         fPipeline.init(args);
-        this->applyPipelineOptimizations(PipelineOptimizations(*args.fAnalysis));
+        this->applyPipelineOptimizations(PipelineOptimizations(analysis));
     }
 
     /**
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index ef70bc5..0986a09 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -766,7 +766,8 @@
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
 
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
+                                                   std::move(op));
 
     return true;
 }
diff --git a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
index ea07644..a4e32ac 100644
--- a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
+++ b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
@@ -141,7 +141,7 @@
             GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), coverAAType);
             pipelineBuilder.setUserStencil(&kInvertedCoverPass);
 
-            args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip,
+            args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
                                                            std::move(coverOp));
         }
     } else {
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index eda39c2..059d831 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -369,7 +369,8 @@
                                      GrAAType::kCoverage == args.fAAType);
     GrPipelineBuilder pipelineBuilder(std::move(args.fPaint), args.fAAType);
     pipelineBuilder.setUserStencil(args.fUserStencilSettings);
-    args.fRenderTargetContext->addLegacyMeshDrawOp(pipelineBuilder, *args.fClip, std::move(op));
+    args.fRenderTargetContext->addLegacyMeshDrawOp(std::move(pipelineBuilder), *args.fClip,
+                                                   std::move(op));
     return true;
 }
 
diff --git a/src/gpu/text/GrAtlasTextBlob.cpp b/src/gpu/text/GrAtlasTextBlob.cpp
index e8eeb0c..d3aa7e4 100644
--- a/src/gpu/text/GrAtlasTextBlob.cpp
+++ b/src/gpu/text/GrAtlasTextBlob.cpp
@@ -310,7 +310,7 @@
                              distanceAdjustTable, rtc->isGammaCorrect(), cache));
         GrPipelineBuilder pipelineBuilder(std::move(grPaint), GrAAType::kNone);
 
-        rtc->addLegacyMeshDrawOp(pipelineBuilder, clip, std::move(op));
+        rtc->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op));
     }
 }