Make GrPathRenderer only support fills for path stenciling
authorbsalomon <bsalomon@google.com>
Thu, 5 May 2016 16:26:21 +0000 (09:26 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 5 May 2016 16:26:22 +0000 (09:26 -0700)
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1950893002

Review-Url: https://codereview.chromium.org/1950893002

13 files changed:
src/gpu/GrClipMaskManager.cpp
src/gpu/GrPathRenderer.h
src/gpu/GrPathRendererChain.cpp
src/gpu/GrSoftwarePathRenderer.h
src/gpu/batches/GrAADistanceFieldPathRenderer.h
src/gpu/batches/GrDashLinePathRenderer.h
src/gpu/batches/GrDefaultPathRenderer.cpp
src/gpu/batches/GrDefaultPathRenderer.h
src/gpu/batches/GrMSAAPathRenderer.cpp
src/gpu/batches/GrMSAAPathRenderer.h
src/gpu/batches/GrStencilAndCoverPathRenderer.cpp
src/gpu/batches/GrStencilAndCoverPathRenderer.h
src/gpu/batches/GrTessellatingPathRenderer.h

index 3548963..3988e67 100644 (file)
@@ -865,7 +865,6 @@ bool GrClipMaskManager::createStencilClipMask(GrRenderTarget* rt,
                             args.fPipelineBuilder = &pipelineBuilder;
                             args.fViewMatrix = &viewMatrix;
                             args.fPath = &clipPath;
-                            args.fStroke = &stroke;
                             pr->stencilPath(args);
                         }
                     }
index 051e007..1072f69 100644 (file)
@@ -57,14 +57,13 @@ public:
 
     /**
      * This function is to get the stencil support for a particular path. The path's fill must
-     * not be an inverse type.
+     * not be an inverse type. The path will always be filled and not stroked.
      *
      * @param path      the path that will be drawn
-     * @param stroke    the stroke information (width, join, cap).
      */
-    StencilSupport getStencilSupport(const SkPath& path, const GrStrokeInfo& stroke) const {
+    StencilSupport getStencilSupport(const SkPath& path) const {
         SkASSERT(!path.isInverseFillType());
-        return this->onGetStencilSupport(path, stroke);
+        return this->onGetStencilSupport(path);
     }
 
     /** Args to canDrawPath()
@@ -161,9 +160,11 @@ public:
         canArgs.fIsStencilBufferMSAA =
                           args.fPipelineBuilder->getRenderTarget()->isStencilBufferMultisampled();
         SkASSERT(this->canDrawPath(canArgs));
-        SkASSERT(args.fPipelineBuilder->getStencil().isDisabled() ||
-                 kNoRestriction_StencilSupport == this->getStencilSupport(*args.fPath,
-                                                                          *args.fStroke));
+        if (!args.fPipelineBuilder->getStencil().isDisabled()) {
+            SkASSERT(kNoRestriction_StencilSupport == this->getStencilSupport(*args.fPath));
+            SkASSERT(!args.fStroke->isDashed());
+            SkASSERT(args.fStroke->isFillStyle());
+        }
 #endif
         return this->onDrawPath(args);
     }
@@ -175,7 +176,6 @@ public:
      * fPipelineBuilder       The pipeline builder.
      * fViewMatrix            Matrix applied to the path.
      * fPath                  The path to draw.
-     * fStroke                The stroke information (width, join, cap)
      */
     struct StencilPathArgs {
         GrDrawTarget*       fTarget;
@@ -183,7 +183,6 @@ public:
         GrPipelineBuilder*  fPipelineBuilder;
         const SkMatrix*     fViewMatrix;
         const SkPath*       fPath;
-        const GrStrokeInfo* fStroke;
 
         void validate() const {
             SkASSERT(fTarget);
@@ -191,7 +190,6 @@ public:
             SkASSERT(fPipelineBuilder);
             SkASSERT(fViewMatrix);
             SkASSERT(fPath);
-            SkASSERT(fStroke);
             SkASSERT(!fPath->isEmpty());
         }
     };
@@ -203,7 +201,7 @@ public:
      */
     void stencilPath(const StencilPathArgs& args) {
         SkDEBUGCODE(args.validate();)
-        SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPath, *args.fStroke));
+        SkASSERT(kNoSupport_StencilSupport != this->getStencilSupport(*args.fPath));
 
         this->onStencilPath(args);
     }
@@ -246,7 +244,7 @@ private:
     /**
      * Subclass overrides if it has any limitations of stenciling support.
      */
-    virtual StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const {
+    virtual StencilSupport onGetStencilSupport(const SkPath&) const {
         return kNoRestriction_StencilSupport;
     }
 
@@ -281,7 +279,7 @@ private:
         drawArgs.fColor = 0xFFFFFFFF;
         drawArgs.fViewMatrix = args.fViewMatrix;
         drawArgs.fPath = args.fPath;
-        drawArgs.fStroke = args.fStroke;
+        drawArgs.fStroke = &GrStrokeInfo::FillInfo();
         drawArgs.fAntiAlias = false;
         drawArgs.fGammaCorrect = false;
         this->drawPath(drawArgs);
index e19a134..c9e21ad 100644 (file)
@@ -60,9 +60,10 @@ GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) {
     return pr;
 }
 
-GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
-                                                     DrawType drawType,
-                                                     GrPathRenderer::StencilSupport* stencilSupport) {
+GrPathRenderer* GrPathRendererChain::getPathRenderer(
+        const GrPathRenderer::CanDrawPathArgs& args,
+        DrawType drawType,
+        GrPathRenderer::StencilSupport* stencilSupport) {
     GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport <
                      GrPathRenderer::kStencilOnly_StencilSupport);
     GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport <
@@ -76,12 +77,18 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDr
     } else {
         minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport;
     }
+    if (minStencilSupport != GrPathRenderer::kNoSupport_StencilSupport) {
+        // We don't support (and shouldn't need) stenciling of non-fill paths.
+        if (!args.fStroke->isFillStyle() || args.fStroke->isDashed()) {
+            return nullptr;
+        }
+    }
 
     for (int i = 0; i < fChain.count(); ++i) {
         if (fChain[i]->canDrawPath(args)) {
             if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) {
                 GrPathRenderer::StencilSupport support =
-                                        fChain[i]->getStencilSupport(*args.fPath, *args.fStroke);
+                                        fChain[i]->getStencilSupport(*args.fPath);
                 if (support < minStencilSupport) {
                     continue;
                 } else if (stencilSupport) {
index 8b2f2d7..5789119 100644 (file)
@@ -22,7 +22,7 @@ public:
         : fContext(context) {
     }
 private:
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
+    StencilSupport onGetStencilSupport(const SkPath&) const override {
         return GrPathRenderer::kNoSupport_StencilSupport;
     }
 
index 200d315..099d0c7 100755 (executable)
@@ -23,7 +23,7 @@ public:
     virtual ~GrAADistanceFieldPathRenderer();
 
 private:
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
+    StencilSupport onGetStencilSupport(const SkPath&) const override {
         return GrPathRenderer::kNoSupport_StencilSupport;
     }
 
index af8324d..e25f882 100644 (file)
@@ -14,7 +14,7 @@ class GrDashLinePathRenderer : public GrPathRenderer {
 private:
     bool onCanDrawPath(const CanDrawPathArgs&) const override;
 
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
+    StencilSupport onGetStencilSupport(const SkPath&) const override {
         return kNoSupport_StencilSupport;
     }
 
index 708bcd7..1de0bf7 100644 (file)
@@ -46,8 +46,8 @@ static inline bool single_pass_path(const SkPath& path, const SkStrokeRec& strok
 }
 
 GrPathRenderer::StencilSupport
-GrDefaultPathRenderer::onGetStencilSupport(const SkPath& path, const GrStrokeInfo& stroke) const {
-    if (single_pass_path(path, stroke)) {
+GrDefaultPathRenderer::onGetStencilSupport(const SkPath& path) const {
+    if (single_pass_path(path, SkStrokeRec(SkStrokeRec::kFill_InitStyle))) {
         return GrPathRenderer::kNoRestriction_StencilSupport;
     } else {
         return GrPathRenderer::kStencilOnly_StencilSupport;
@@ -618,7 +618,7 @@ void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
     SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType());
     SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType());
     this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *args.fViewMatrix,
-                           *args.fPath, *args.fStroke, true);
+                           *args.fPath, GrStrokeInfo::FillInfo(), true);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
index 9973c2b..8156462 100644 (file)
@@ -22,7 +22,7 @@ public:
 
 private:
 
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override;
+    StencilSupport onGetStencilSupport(const SkPath&) const override;
 
     bool onCanDrawPath(const CanDrawPathArgs&) const override;
 
index 9889528..a9ba06c 100644 (file)
@@ -37,8 +37,8 @@ static inline bool single_pass_path(const SkPath& path, const SkStrokeRec& strok
 }
 
 GrPathRenderer::StencilSupport
-GrMSAAPathRenderer::onGetStencilSupport(const SkPath& path, const GrStrokeInfo& stroke) const {
-    if (single_pass_path(path, stroke)) {
+GrMSAAPathRenderer::onGetStencilSupport(const SkPath& path) const {
+    if (single_pass_path(path, SkStrokeRec(SkStrokeRec::kFill_InitStyle))) {
         return GrPathRenderer::kNoRestriction_StencilSupport;
     } else {
         return GrPathRenderer::kStencilOnly_StencilSupport;
@@ -739,7 +739,7 @@ void GrMSAAPathRenderer::onStencilPath(const StencilPathArgs& args) {
     SkASSERT(SkPath::kInverseEvenOdd_FillType != args.fPath->getFillType());
     SkASSERT(SkPath::kInverseWinding_FillType != args.fPath->getFillType());
     this->internalDrawPath(args.fTarget, args.fPipelineBuilder, GrColor_WHITE, *args.fViewMatrix,
-                           *args.fPath, *args.fStroke, true);
+                           *args.fPath, GrStrokeInfo::FillInfo(), true);
 }
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
index 0ffd280..a355360 100644 (file)
@@ -13,7 +13,7 @@
 
 class SK_API GrMSAAPathRenderer : public GrPathRenderer {
 private:
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override;
+    StencilSupport onGetStencilSupport(const SkPath&) const override;
 
     bool onCanDrawPath(const CanDrawPathArgs&) const override;
 
index 4aaea84..6933efe 100644 (file)
@@ -66,7 +66,7 @@ void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) {
     GR_AUDIT_TRAIL_AUTO_FRAME(args.fTarget->getAuditTrail(),
                               "GrStencilAndCoverPathRenderer::onStencilPath");
     SkASSERT(!args.fPath->isInverseFillType());
-    SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, *args.fStroke));
+    SkAutoTUnref<GrPath> p(get_gr_path(fResourceProvider, *args.fPath, GrStrokeInfo::FillInfo()));
     args.fTarget->stencilPath(*args.fPipelineBuilder, *args.fViewMatrix, p, p->getFillType());
 }
 
index 8fec6c6..cec8126 100644 (file)
@@ -24,7 +24,7 @@ public:
 
 
 private:
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
+    StencilSupport onGetStencilSupport(const SkPath&) const override {
         return GrPathRenderer::kStencilOnly_StencilSupport;
     }
 
index 7598ceb..f1faa60 100644 (file)
@@ -21,7 +21,7 @@ public:
 private:
     bool onCanDrawPath(const CanDrawPathArgs& ) const override;
 
-    StencilSupport onGetStencilSupport(const SkPath&, const GrStrokeInfo&) const override {
+    StencilSupport onGetStencilSupport(const SkPath&) const override {
         return GrPathRenderer::kNoSupport_StencilSupport;
     }