Remove most modifiers of processors on GrPipelineBuilder
authorBrian Salomon <bsalomon@google.com>
Fri, 13 Jan 2017 17:11:36 +0000 (12:11 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 13 Jan 2017 20:08:16 +0000 (20:08 +0000)
Change-Id: I2fc12a97d694e5c0d86c9a4e0818a058905c8cf0
Reviewed-on: https://skia-review.googlesource.com/6993
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
include/gpu/GrPaint.h
src/gpu/GrPipelineBuilder.h
src/gpu/GrSWMaskHelper.cpp
src/gpu/ops/GrDefaultPathRenderer.cpp
src/gpu/ops/GrMSAAPathRenderer.cpp

index 0f3b525..6897679 100644 (file)
@@ -199,7 +199,8 @@ public:
         }
     }
 
-    operator GrPaint&&() { return std::move(*fPaint); }
+    operator GrPaint&&() && { return std::move(*fPaint); }
+    GrPaint& paint() { return *fPaint; }
 
 private:
     SkTLazy<GrPaint> fStorage;
index 15af681..66459ae 100644 (file)
@@ -61,41 +61,6 @@ public:
         return fCoverageFragmentProcessors[idx].get();
     }
 
-    void addColorFragmentProcessor(sk_sp<GrFragmentProcessor> processor) {
-        SkASSERT(processor);
-        fColorFragmentProcessors.push_back(std::move(processor));
-    }
-
-    void addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor> processor) {
-        SkASSERT(processor);
-        fCoverageFragmentProcessors.push_back(std::move(processor));
-    }
-
-    /**
-     * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
-     */
-    void addColorTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
-        this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix));
-    }
-
-    void addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
-        this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix));
-    }
-
-    void addColorTextureProcessor(GrTexture* texture,
-                                  const SkMatrix& matrix,
-                                  const GrSamplerParams& params) {
-        this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix,
-                                                                    params));
-    }
-
-    void addCoverageTextureProcessor(GrTexture* texture,
-                                     const SkMatrix& matrix,
-                                     const GrSamplerParams& params) {
-        this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix,
-                                                                       params));
-    }
-
     /**
      * When this object is destroyed it will remove any color/coverage FPs from the pipeline builder
      * that were added after its constructor.
@@ -140,18 +105,6 @@ public:
     /// @name Blending
     ////
 
-    /**
-     * Installs a GrXPFactory. This object controls how src color, fractional pixel coverage,
-     * and the dst color are blended.
-     */
-    void setXPFactory(const GrXPFactory* xpFactory) { fXPFactory = xpFactory; }
-
-    /**
-     * Sets a GrXPFactory that disables color writes to the destination. This is useful when
-     * rendering to the stencil buffer.
-     */
-    void setDisableColorXPFactory() { fXPFactory = GrDisableColorXPFactory::Get(); }
-
     const GrXPFactory* getXPFactory() const { return fXPFactory; }
 
     /**
@@ -288,6 +241,13 @@ public:
     bool usePLSDstRead(const GrDrawOp*) const;
 
 private:
+    // This exists solely for AutoRestoreFragmentProcessor, which itself exists solely to install
+    // an applied clip's FP. This will be removed soon.
+    void addCoverageFragmentProcessor(sk_sp<GrFragmentProcessor> processor) {
+        SkASSERT(processor);
+        fCoverageFragmentProcessors.push_back(std::move(processor));
+    }
+
     // Some of the auto restore objects assume that no effects are removed during their lifetime.
     // This is used to assert that this condition holds.
     SkDEBUGCODE(mutable int fBlockEffectRemovalCnt;)
index f85bbe6..240f9f9 100644 (file)
@@ -183,12 +183,9 @@ void GrSWMaskHelper::DrawToTargetWithShapeMask(GrTexture* texture,
     maskMatrix.preConcat(viewMatrix);
     std::unique_ptr<GrDrawOp> op = GrRectOpFactory::MakeNonAAFill(paint.getColor(), SkMatrix::I(),
                                                                   dstRect, nullptr, &invert);
+    paint.addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(
+            texture, nullptr, maskMatrix, GrSamplerParams::kNone_FilterMode));
     GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone);
     pipelineBuilder.setUserStencil(&userStencilSettings);
-    pipelineBuilder.addCoverageFragmentProcessor(
-                         GrSimpleTextureEffect::Make(texture,
-                                                     nullptr,
-                                                     maskMatrix,
-                                                     GrSamplerParams::kNone_FilterMode));
     renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
 }
index 270dc09..e76ded3 100644 (file)
@@ -557,14 +557,15 @@ bool GrDefaultPathRenderer::internalDrawPath(GrRenderTargetContext* renderTarget
         } else {
             std::unique_ptr<GrDrawOp> op =
                     DefaultPathOp::Make(paint.getColor(), path, srcSpaceTol, newCoverage,
-
                                         viewMatrix, isHairline, devBounds);
-            GrPipelineBuilder pipelineBuilder(GrPaint::MoveOrNew(paint, lastPassIsBounds), aaType);
+            bool stencilPass = stencilOnly || passCount > 1;
+            GrPaint::MoveOrNew passPaint(paint, stencilPass);
+            if (stencilPass) {
+                passPaint.paint().setXPFactory(GrDisableColorXPFactory::Get());
+            }
+            GrPipelineBuilder pipelineBuilder(std::move(passPaint), aaType);
             pipelineBuilder.setDrawFace(drawFace[p]);
             pipelineBuilder.setUserStencil(passes[p]);
-            if (passCount > 1) {
-                pipelineBuilder.setDisableColorXPFactory();
-            }
             renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
         }
     }
index 5c1c110..26fdf5d 100644 (file)
@@ -613,20 +613,25 @@ bool GrMSAAPathRenderer::internalDrawPath(GrRenderTargetContext* renderTargetCon
     SkRect devBounds;
     GetPathDevBounds(path, renderTargetContext->width(), renderTargetContext->height(), viewMatrix,
                      &devBounds);
-    SkASSERT(passes[0]);
 
-    std::unique_ptr<GrDrawOp> op = MSAAPathOp::Make(paint.getColor(), path, viewMatrix, devBounds);
-    if (!op) {
-        return false;
-    }
-    // If we have a cover pass then we ignore the paint in the first pass and apply it in the
-    // second.
-    GrPipelineBuilder pipelineBuilder(GrPaint::MoveOrNew(paint, passes[1]), aaType);
-    pipelineBuilder.setUserStencil(passes[0]);
-    if (passes[1]) {
-        pipelineBuilder.setDisableColorXPFactory();
+    SkASSERT(passes[0]);
+    {  // First pass
+        std::unique_ptr<GrDrawOp> op =
+                MSAAPathOp::Make(paint.getColor(), path, viewMatrix, devBounds);
+        if (!op) {
+            return false;
+        }
+        bool firstPassIsStencil = stencilOnly || passes[1];
+        // If we have a cover pass then we ignore the paint in the first pass and apply it in the
+        // second.
+        GrPaint::MoveOrNew firstPassPaint(paint, firstPassIsStencil);
+        if (firstPassIsStencil) {
+            firstPassPaint.paint().setXPFactory(GrDisableColorXPFactory::Get());
+        }
+        GrPipelineBuilder pipelineBuilder(std::move(firstPassPaint), aaType);
+        pipelineBuilder.setUserStencil(passes[0]);
+        renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
     }
-    renderTargetContext->addDrawOp(pipelineBuilder, clip, std::move(op));
 
     if (passes[1]) {
         SkRect bounds;