Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: tests/EmptyPathTest.cpp

Issue 183683010: fix the error that path is inversed for stroke and strokeAndFill styles (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update unittest EmptyPath accordingly Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrStencilAndCoverPathRenderer.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "Test.h" 10 #include "Test.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 ERRORF(reporter, "%s style[%d] cap[%d] join[%d] antialias[%d]" 48 ERRORF(reporter, "%s style[%d] cap[%d] join[%d] antialias[%d]"
49 " filltype[%d] ptcount[%d]", str, paint.getStyle(), 49 " filltype[%d] ptcount[%d]", str, paint.getStyle(),
50 paint.getStrokeCap(), paint.getStrokeJoin(), 50 paint.getStrokeCap(), paint.getStrokeJoin(),
51 paint.isAntiAlias(), path.getFillType(), path.countPoints()); 51 paint.isAntiAlias(), path.getFillType(), path.countPoints());
52 // uncomment this if you want to step in to see the failure 52 // uncomment this if you want to step in to see the failure
53 // canvas.drawPath(path, p); 53 // canvas.drawPath(path, p);
54 } 54 }
55 } 55 }
56 56
57 static void iter_paint(skiatest::Reporter* reporter, const SkPath& path, bool sh ouldDraw) { 57 static void iter_paint(skiatest::Reporter* reporter, const SkPath& path) {
58 static const SkPaint::Cap gCaps[] = { 58 static const SkPaint::Cap gCaps[] = {
59 SkPaint::kButt_Cap, 59 SkPaint::kButt_Cap,
60 SkPaint::kRound_Cap, 60 SkPaint::kRound_Cap,
61 SkPaint::kSquare_Cap 61 SkPaint::kSquare_Cap
62 }; 62 };
63 static const SkPaint::Join gJoins[] = { 63 static const SkPaint::Join gJoins[] = {
64 SkPaint::kMiter_Join, 64 SkPaint::kMiter_Join,
65 SkPaint::kRound_Join, 65 SkPaint::kRound_Join,
66 SkPaint::kBevel_Join 66 SkPaint::kBevel_Join
67 }; 67 };
68 static const SkPaint::Style gStyles[] = { 68 static const SkPaint::Style gStyles[] = {
69 SkPaint::kFill_Style, 69 SkPaint::kFill_Style,
70 SkPaint::kStroke_Style, 70 SkPaint::kStroke_Style,
71 SkPaint::kStrokeAndFill_Style 71 SkPaint::kStrokeAndFill_Style
72 }; 72 };
73 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) { 73 for (size_t cap = 0; cap < SK_ARRAY_COUNT(gCaps); ++cap) {
74 for (size_t join = 0; join < SK_ARRAY_COUNT(gJoins); ++join) { 74 for (size_t join = 0; join < SK_ARRAY_COUNT(gJoins); ++join) {
75 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) { 75 for (size_t style = 0; style < SK_ARRAY_COUNT(gStyles); ++style) {
76 SkPaint paint; 76 SkPaint paint;
77 paint.setStrokeWidth(SkIntToScalar(10)); 77 paint.setStrokeWidth(SkIntToScalar(10));
78 78
79 paint.setStrokeCap(gCaps[cap]); 79 paint.setStrokeCap(gCaps[cap]);
80 paint.setStrokeJoin(gJoins[join]); 80 paint.setStrokeJoin(gJoins[join]);
81 paint.setStyle(gStyles[style]); 81 paint.setStyle(gStyles[style]);
82 82
83 bool shouldDraw = path.isInverseFillType() &&
84 SkPaint::kFill_Style == paint.getStyle();
83 paint.setAntiAlias(false); 85 paint.setAntiAlias(false);
84 drawAndTest(reporter, path, paint, shouldDraw); 86 drawAndTest(reporter, path, paint, shouldDraw);
85 paint.setAntiAlias(true); 87 paint.setAntiAlias(true);
86 drawAndTest(reporter, path, paint, shouldDraw); 88 drawAndTest(reporter, path, paint, shouldDraw);
87 } 89 }
88 } 90 }
89 } 91 }
90 } 92 }
91 93
92 #define CX (SkIntToScalar(DIMENSION) / 2) 94 #define CX (SkIntToScalar(DIMENSION) / 2)
93 #define CY (SkIntToScalar(DIMENSION) / 2) 95 #define CY (SkIntToScalar(DIMENSION) / 2)
94 96
95 static void make_empty(SkPath*) {} 97 static void make_empty(SkPath*) {}
96 static void make_M(SkPath* path) { path->moveTo(CX, CY); } 98 static void make_M(SkPath* path) { path->moveTo(CX, CY); }
97 static void make_MM(SkPath* path) { path->moveTo(CX, CY); path->moveTo(CX, CY); } 99 static void make_MM(SkPath* path) { path->moveTo(CX, CY); path->moveTo(CX, CY); }
98 static void make_MZM(SkPath* path) { path->moveTo(CX, CY); path->close(); path-> moveTo(CX, CY); } 100 static void make_MZM(SkPath* path) { path->moveTo(CX, CY); path->close(); path-> moveTo(CX, CY); }
99 static void make_L(SkPath* path) { path->moveTo(CX, CY); path->lineTo(CX, CY); } 101 static void make_L(SkPath* path) { path->moveTo(CX, CY); path->lineTo(CX, CY); }
100 static void make_Q(SkPath* path) { path->moveTo(CX, CY); path->quadTo(CX, CY, CX , CY); } 102 static void make_Q(SkPath* path) { path->moveTo(CX, CY); path->quadTo(CX, CY, CX , CY); }
101 static void make_C(SkPath* path) { path->moveTo(CX, CY); path->cubicTo(CX, CY, C X, CY, CX, CY); } 103 static void make_C(SkPath* path) { path->moveTo(CX, CY); path->cubicTo(CX, CY, C X, CY, CX, CY); }
102 104
103 /* Two invariants are tested: How does an empty/degenerate path draw? 105 /* Two invariants are tested: How does an empty/degenerate path draw?
104 * - if the path is drawn inverse, it should draw everywhere 106 * - if the path is drawn inverse, it should draw everywhere for fill style,
107 * but draw nowhere for other styles.
105 * - if the path is drawn non-inverse, it should draw nowhere 108 * - if the path is drawn non-inverse, it should draw nowhere
106 * 109 *
107 * Things to iterate on: 110 * Things to iterate on:
108 * - path (empty, degenerate line/quad/cubic w/ and w/o close 111 * - path (empty, degenerate line/quad/cubic w/ and w/o close
109 * - paint style 112 * - paint style
110 * - path filltype 113 * - path filltype
111 * - path stroke variants (e.g. caps, joins, width) 114 * - path stroke variants (e.g. caps, joins, width)
112 */ 115 */
113 static void test_emptydrawing(skiatest::Reporter* reporter) { 116 static void test_emptydrawing(skiatest::Reporter* reporter) {
114 static void (*gMakeProc[])(SkPath*) = { 117 static void (*gMakeProc[])(SkPath*) = {
115 make_empty, make_M, make_MM, make_MZM, make_L, make_Q, make_C 118 make_empty, make_M, make_MM, make_MZM, make_L, make_Q, make_C
116 }; 119 };
117 static SkPath::FillType gFills[] = { 120 static SkPath::FillType gFills[] = {
118 SkPath::kWinding_FillType, 121 SkPath::kWinding_FillType,
119 SkPath::kEvenOdd_FillType, 122 SkPath::kEvenOdd_FillType,
120 SkPath::kInverseWinding_FillType, 123 SkPath::kInverseWinding_FillType,
121 SkPath::kInverseEvenOdd_FillType 124 SkPath::kInverseEvenOdd_FillType
122 }; 125 };
123 for (int doClose = 0; doClose < 2; ++doClose) { 126 for (int doClose = 0; doClose < 2; ++doClose) {
124 for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProc); ++i) { 127 for (size_t i = 0; i < SK_ARRAY_COUNT(gMakeProc); ++i) {
125 SkPath path; 128 SkPath path;
126 gMakeProc[i](&path); 129 gMakeProc[i](&path);
127 if (doClose) { 130 if (doClose) {
128 path.close(); 131 path.close();
129 } 132 }
130 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) { 133 for (size_t fill = 0; fill < SK_ARRAY_COUNT(gFills); ++fill) {
131 path.setFillType(gFills[fill]); 134 path.setFillType(gFills[fill]);
132 bool shouldDraw = path.isInverseFillType(); 135 iter_paint(reporter, path);
133 iter_paint(reporter, path, shouldDraw);
134 } 136 }
135 } 137 }
136 } 138 }
137 } 139 }
138 140
139 DEF_TEST(EmptyPath, reporter) { 141 DEF_TEST(EmptyPath, reporter) {
140 test_emptydrawing(reporter); 142 test_emptydrawing(reporter);
141 } 143 }
OLDNEW
« no previous file with comments | « src/gpu/GrStencilAndCoverPathRenderer.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698