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

Side by Side Diff: tests/StrokeTest.cpp

Issue 1130153002: Fix SkStrokeRec == to report true for all fills (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: the testcase had some doubles Created 5 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/GrPath.h ('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 2012 Google Inc. 2 * Copyright 2012 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 "SkPaint.h" 8 #include "SkPaint.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkRect.h" 10 #include "SkRect.h"
11 #include "SkStroke.h" 11 #include "SkStroke.h"
12 #include "SkStrokeRec.h"
12 #include "Test.h" 13 #include "Test.h"
13 14
14 static bool equal(const SkRect& a, const SkRect& b) { 15 static bool equal(const SkRect& a, const SkRect& b) {
15 return SkScalarNearlyEqual(a.left(), b.left()) && 16 return SkScalarNearlyEqual(a.left(), b.left()) &&
16 SkScalarNearlyEqual(a.top(), b.top()) && 17 SkScalarNearlyEqual(a.top(), b.top()) &&
17 SkScalarNearlyEqual(a.right(), b.right()) && 18 SkScalarNearlyEqual(a.right(), b.right()) &&
18 SkScalarNearlyEqual(a.bottom(), b.bottom()); 19 SkScalarNearlyEqual(a.bottom(), b.bottom());
19 } 20 }
20 21
21 static void test_strokecubic(skiatest::Reporter* reporter) { 22 static void test_strokecubic(skiatest::Reporter* reporter) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 REPORTER_ASSERT(reporter, fillPath.isNestedFillRects(nested) == isMiter) ; 78 REPORTER_ASSERT(reporter, fillPath.isNestedFillRects(nested) == isMiter) ;
78 if (isMiter) { 79 if (isMiter) {
79 SkRect inner(r); 80 SkRect inner(r);
80 inner.inset(width/2, width/2); 81 inner.inset(width/2, width/2);
81 REPORTER_ASSERT(reporter, equal(nested[0], outer)); 82 REPORTER_ASSERT(reporter, equal(nested[0], outer));
82 REPORTER_ASSERT(reporter, equal(nested[1], inner)); 83 REPORTER_ASSERT(reporter, equal(nested[1], inner));
83 } 84 }
84 } 85 }
85 } 86 }
86 87
88 static void test_strokerec_equality(skiatest::Reporter* reporter) {
89 {
90 SkStrokeRec s1(SkStrokeRec::kFill_InitStyle);
91 SkStrokeRec s2(SkStrokeRec::kFill_InitStyle);
92 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
93
94 // Test that style mismatch is detected.
95 s2.setHairlineStyle();
96 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
97
98 s1.setHairlineStyle();
99 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
100
101 // ResScale is not part of equality.
102 s1.setResScale(2.1f);
103 s2.setResScale(1.2f);
104 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
105 s1.setFillStyle();
106 s2.setFillStyle();
107 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
108 s1.setStrokeStyle(1.0f, false);
109 s2.setStrokeStyle(1.0f, false);
110 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
111 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
112 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
113 }
114
115 // Stroke parameters on fill or hairline style are not part of equality.
116 {
117 SkStrokeRec s1(SkStrokeRec::kFill_InitStyle);
118 SkStrokeRec s2(SkStrokeRec::kFill_InitStyle);
119 for (int i = 0; i < 2; ++i) {
120 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
121 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f);
122 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
123 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f);
124 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
125 s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f);
126 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
127 s1.setHairlineStyle();
128 s2.setHairlineStyle();
129 }
130 }
131
132 // Stroke parameters on stroke style are part of equality.
133 {
134 SkStrokeRec s1(SkStrokeRec::kFill_InitStyle);
135 SkStrokeRec s2(SkStrokeRec::kFill_InitStyle);
136 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
137 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
138 s1.setStrokeStyle(1.0f, false);
139
140 s2.setStrokeStyle(1.0f, true);
141 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
142
143 s2.setStrokeStyle(2.1f, false);
144 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
145
146 s2.setStrokeStyle(1.0f, false);
147 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
148
149 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f);
150 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
151 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f);
152 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
153 s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f);
154 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
155
156 // Sets fill.
157 s1.setStrokeStyle(0.0f, true);
158 s2.setStrokeStyle(0.0f, true);
159 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
160 }
161 }
162
87 DEF_TEST(Stroke, reporter) { 163 DEF_TEST(Stroke, reporter) {
88 test_strokecubic(reporter); 164 test_strokecubic(reporter);
89 test_strokerect(reporter); 165 test_strokerect(reporter);
166 test_strokerec_equality(reporter);
90 } 167 }
OLDNEW
« no previous file with comments | « src/gpu/GrPath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698