fix the error that path is inversed for stroke and strokeAndFill styles.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Sun, 4 May 2014 03:43:20 +0000 (03:43 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Sun, 4 May 2014 03:43:20 +0000 (03:43 +0000)
However, because hairline stroke + fill = fill (see src/core/SkStrokeRec.cpp), strokeAndFill will be thought as fill style when paint.getStrokeWidth() <= 0, this edge case can be inverse-filled.

BUG=skia:2222
R=bsalomon@google.com, reed@google.com

Author: yunchao.he@intel.com

Review URL: https://codereview.chromium.org/183683010

git-svn-id: http://skia.googlecode.com/svn/trunk@14561 2bbb7eff-a529-9590-31e7-b0007b416f81

expectations/gm/ignored-tests.txt
src/core/SkCanvas.cpp
src/core/SkDraw.cpp
src/core/SkStroke.cpp
src/gpu/GrStencilAndCoverPathRenderer.cpp

index 8a4dcc97e129a5b93c0e91ee077a30f975328915..d059490eddbd8a8c264dc163ffee28a024d81c0c 100644 (file)
 # This change removes an API that this GM was testing. If/when it lands and sticks,
 # I will likely just delete the GM.
 canvas-layer-state
+
+# yunchao: https://codereview.chromium.org/183683010/
+# This change fixed the error that path is inversed for Stroke and StrokeAndFill
+# styles. These GM cases need to be rebaselined:
+inverse_paths
+degeneratesegments
+quadclosepath
+quadpath
+lineclosepath
+linepath
+cubicclosepath
+cubicpath
+emptypath
index 6c0fc884e1a53472f3a3681df8537c69dc283c6a..34559795e4c81f9f16532cc600172908f6a285d6 100644 (file)
@@ -2076,7 +2076,7 @@ void SkCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
 
     const SkRect& r = path.getBounds();
     if (r.width() <= 0 && r.height() <= 0) {
-        if (path.isInverseFillType()) {
+        if (path.isInverseFillType() && SkPaint::kFill_Style == paint.getStyle()) {
             this->internalDrawPaint(paint);
         }
         return;
index c4f5f74eefb93ea0ca539e28b079d4e4125c4149..ee2e1125ea2003603cd8e95073d5e0c963e7e2dd 100644 (file)
@@ -1119,6 +1119,13 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
 
     SkAutoBlitterChoose blitter(*fBitmap, *fMatrix, *paint, drawCoverage);
 
+    // make sure the path will not be inverse-stroked. hairlineStroke + fill = fill,
+    // they can be inverse-filled.
+    if (devPathPtr->isInverseFillType() && (SkPaint::kStroke_Style == paint->getStyle() ||
+            (SkPaint::kStrokeAndFill_Style == paint->getStyle() && paint->getStrokeWidth() > 0))) {
+        devPathPtr->toggleInverseFillType();
+    }
+
     if (paint->getMaskFilter()) {
         SkPaint::Style style = doFill ? SkPaint::kFill_Style :
             SkPaint::kStroke_Style;
index b138c326bab497c96429ed1d111ff57954c8ab0d..7d8d707752e942982ce51f01af4e7eebe256249b 100644 (file)
@@ -562,8 +562,9 @@ void SkStroke::strokePath(const SkPath& src, SkPath* dst) const {
         SkPath::Direction dir;
         if (src.isRect(&isClosed, &dir) && isClosed) {
             this->strokeRect(src.getBounds(), dst, dir);
-            // our answer should preserve the inverseness of the src
-            if (src.isInverseFillType()) {
+            // our answer should preserve the inverseness of the src, but the
+            // rect should not be inverse-stroked.
+            if (src.isInverseFillType() && fWidth < 0) {
                 SkASSERT(!dst->isInverseFillType());
                 dst->toggleInverseFillType();
             }
@@ -646,8 +647,9 @@ DONE:
 #endif
     }
 
-    // our answer should preserve the inverseness of the src
-    if (src.isInverseFillType()) {
+    // our answer should preserve the inverseness of the src, but the path
+    // should not be inverse-stroked.
+    if (src.isInverseFillType() && fWidth < 0) {
         SkASSERT(!dst->isInverseFillType());
         dst->toggleInverseFillType();
     }
index 273c01b8618cec3cfdd4c47aade162c035785d2c..ad6192ae3b11068d38491be30b80e4cfeecac67c 100644 (file)
@@ -71,7 +71,7 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const SkPath& path,
 
     SkAutoTUnref<GrPath> p(fGpu->getContext()->createPath(path, stroke));
 
-    if (path.isInverseFillType()) {
+    if (path.isInverseFillType() && SkStrokeRec::kFill_Style == stroke.getStyle()) {
         GR_STATIC_CONST_SAME_STENCIL(kInvertedStencilPass,
             kZero_StencilOp,
             kZero_StencilOp,