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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 1971613004: Add isEmpty() query to GrShape and improve comments. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 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/GrShape.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 2016 Google Inc. 2 * Copyright 2016 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 <initializer_list> 8 #include <initializer_list>
9 #include <functional> 9 #include <functional>
10 #include "Test.h" 10 #include "Test.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 make_key(&fAppliedPEThenStrokeKey, fAppliedPEThenStroke); 76 make_key(&fAppliedPEThenStrokeKey, fAppliedPEThenStroke);
77 make_key(&fAppliedFullKey, fAppliedFull); 77 make_key(&fAppliedFullKey, fAppliedFull);
78 78
79 // Applying the path effect and then the stroke should always be the sam e as applying 79 // Applying the path effect and then the stroke should always be the sam e as applying
80 // both in one go. 80 // both in one go.
81 REPORTER_ASSERT(r, fAppliedPEThenStrokeKey == fAppliedFullKey); 81 REPORTER_ASSERT(r, fAppliedPEThenStrokeKey == fAppliedFullKey);
82 SkPath a, b; 82 SkPath a, b;
83 fAppliedPEThenStroke.asPath(&a); 83 fAppliedPEThenStroke.asPath(&a);
84 fAppliedFull.asPath(&b); 84 fAppliedFull.asPath(&b);
85 REPORTER_ASSERT(r, a == b); 85 REPORTER_ASSERT(r, a == b);
86 REPORTER_ASSERT(r, fAppliedFull.isEmpty() == fAppliedPEThenStroke.isEmpt y());
87
88 SkPath path;
89 fBase.asPath(&path);
90 REPORTER_ASSERT(r, path.isEmpty() == fBase.isEmpty());
91 fAppliedPE.asPath(&path);
robertphillips 2016/05/11 21:38:40 Couldn't we have a PE for which this isn't true? I
bsalomon 2016/05/11 21:47:49 This is asserting that after applying the PE the e
92 REPORTER_ASSERT(r, path.isEmpty() == fAppliedPE.isEmpty());
93 fAppliedFull.asPath(&path);
94 REPORTER_ASSERT(r, path.isEmpty() == fAppliedFull.isEmpty());
86 95
87 // Check that the same path is produced when style is applied by GrShape and GrStyle. 96 // Check that the same path is produced when style is applied by GrShape and GrStyle.
88 SkPath preStyle; 97 SkPath preStyle;
89 SkPath postPathEffect; 98 SkPath postPathEffect;
90 SkPath postAllStyle; 99 SkPath postAllStyle;
91 100
92 fBase.asPath(&preStyle); 101 fBase.asPath(&preStyle);
93 SkStrokeRec postPEStrokeRec(SkStrokeRec::kFill_InitStyle); 102 SkStrokeRec postPEStrokeRec(SkStrokeRec::kFill_InitStyle);
94 if (fBase.style().applyPathEffectToPath(&postPathEffect, &postPEStrokeRe c, preStyle, 103 if (fBase.style().applyPathEffectToPath(&postPathEffect, &postPEStrokeRe c, preStyle,
95 scale)) { 104 scale)) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 case kAllDifferent_ComparisonExpecation: 172 case kAllDifferent_ComparisonExpecation:
164 REPORTER_ASSERT(reporter, fBaseKey != that.fBaseKey); 173 REPORTER_ASSERT(reporter, fBaseKey != that.fBaseKey);
165 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey); 174 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey);
166 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); 175 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey);
167 break; 176 break;
168 case kSameUpToPE_ComparisonExpecation: 177 case kSameUpToPE_ComparisonExpecation:
169 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); 178 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey);
170 fBase.asPath(&a); 179 fBase.asPath(&a);
171 that.fBase.asPath(&b); 180 that.fBase.asPath(&b);
172 REPORTER_ASSERT(reporter, a == b); 181 REPORTER_ASSERT(reporter, a == b);
182 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty());
173 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey); 183 REPORTER_ASSERT(reporter, fAppliedPEKey != that.fAppliedPEKey);
174 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); 184 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey);
175 break; 185 break;
176 case kSameUpToStroke_ComparisonExpecation: 186 case kSameUpToStroke_ComparisonExpecation:
177 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); 187 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey);
178 fBase.asPath(&a); 188 fBase.asPath(&a);
179 that.fBase.asPath(&b); 189 that.fBase.asPath(&b);
180 REPORTER_ASSERT(reporter, a == b); 190 REPORTER_ASSERT(reporter, a == b);
191 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty());
181 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); 192 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey);
182 fAppliedPE.asPath(&a); 193 fAppliedPE.asPath(&a);
183 that.fAppliedPE.asPath(&b); 194 that.fAppliedPE.asPath(&b);
184 REPORTER_ASSERT(reporter, a == b); 195 REPORTER_ASSERT(reporter, a == b);
196 REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.is Empty());
185 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey); 197 REPORTER_ASSERT(reporter, fAppliedFullKey != that.fAppliedFullKey);
186 break; 198 break;
187 case kAllSame_ComparisonExpecation: 199 case kAllSame_ComparisonExpecation:
188 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey); 200 REPORTER_ASSERT(reporter, fBaseKey == that.fBaseKey);
189 fBase.asPath(&a); 201 fBase.asPath(&a);
190 that.fBase.asPath(&b); 202 that.fBase.asPath(&b);
191 REPORTER_ASSERT(reporter, a == b); 203 REPORTER_ASSERT(reporter, a == b);
204 REPORTER_ASSERT(reporter, fBase.isEmpty() == that.fBase.isEmpty());
192 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey); 205 REPORTER_ASSERT(reporter, fAppliedPEKey == that.fAppliedPEKey);
193 fAppliedPE.asPath(&a); 206 fAppliedPE.asPath(&a);
194 that.fAppliedPE.asPath(&b); 207 that.fAppliedPE.asPath(&b);
195 REPORTER_ASSERT(reporter, a == b); 208 REPORTER_ASSERT(reporter, a == b);
209 REPORTER_ASSERT(reporter, fAppliedPE.isEmpty() == that.fAppliedPE.is Empty());
196 REPORTER_ASSERT(reporter, fAppliedFullKey == that.fAppliedFullKey); 210 REPORTER_ASSERT(reporter, fAppliedFullKey == that.fAppliedFullKey);
197 fAppliedFull.asPath(&a); 211 fAppliedFull.asPath(&a);
198 that.fAppliedFull.asPath(&b); 212 that.fAppliedFull.asPath(&b);
199 REPORTER_ASSERT(reporter, a == b); 213 REPORTER_ASSERT(reporter, a == b);
214 REPORTER_ASSERT(reporter, fAppliedFull.isEmpty() == that.fAppliedFul l.isEmpty());
200 break; 215 break;
201 } 216 }
202 } 217 }
203 } // namespace 218 } // namespace
204 219
205 static sk_sp<SkPathEffect> make_dash() { 220 static sk_sp<SkPathEffect> make_dash() {
206 static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f }; 221 static const SkScalar kIntervals[] = { 0.25, 3.f, 0.5, 2.f };
207 static const SkScalar kPhase = 0.75; 222 static const SkScalar kPhase = 0.75;
208 return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase ); 223 return SkDashPathEffect::Make(kIntervals, SK_ARRAY_COUNT(kIntervals), kPhase );
209 } 224 }
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 Factory getFactory() const override { return nullptr; } 753 Factory getFactory() const override { return nullptr; }
739 void toString(SkString*) const override {} 754 void toString(SkString*) const override {}
740 private: 755 private:
741 EmptyPathEffect() {} 756 EmptyPathEffect() {}
742 }; 757 };
743 758
744 SkPath emptyPath; 759 SkPath emptyPath;
745 GrShape emptyShape(emptyPath); 760 GrShape emptyShape(emptyPath);
746 Key emptyKey; 761 Key emptyKey;
747 make_key(&emptyKey, emptyShape); 762 make_key(&emptyKey, emptyShape);
763 REPORTER_ASSERT(reporter, emptyShape.isEmpty());
748 764
749 SkPaint pe; 765 SkPaint pe;
750 pe.setPathEffect(EmptyPathEffect::Make()); 766 pe.setPathEffect(EmptyPathEffect::Make());
751 TestCase geoCase(geo, pe, reporter); 767 TestCase geoCase(geo, pe, reporter);
752 REPORTER_ASSERT(reporter, geoCase.appliedFullStyleKey() == emptyKey); 768 REPORTER_ASSERT(reporter, geoCase.appliedFullStyleKey() == emptyKey);
753 REPORTER_ASSERT(reporter, geoCase.appliedPathEffectKey() == emptyKey); 769 REPORTER_ASSERT(reporter, geoCase.appliedPathEffectKey() == emptyKey);
754 REPORTER_ASSERT(reporter, geoCase.appliedPathEffectThenStrokeKey() == emptyK ey); 770 REPORTER_ASSERT(reporter, geoCase.appliedPathEffectThenStrokeKey() == emptyK ey);
771 REPORTER_ASSERT(reporter, geoCase.appliedPathEffectShape().isEmpty());
772 REPORTER_ASSERT(reporter, geoCase.appliedFullStyleShape().isEmpty());
755 773
756 SkPaint peStroke; 774 SkPaint peStroke;
757 peStroke.setPathEffect(EmptyPathEffect::Make()); 775 peStroke.setPathEffect(EmptyPathEffect::Make());
758 peStroke.setStrokeWidth(2.f); 776 peStroke.setStrokeWidth(2.f);
759 peStroke.setStyle(SkPaint::kStroke_Style); 777 peStroke.setStyle(SkPaint::kStroke_Style);
760 TestCase geoPEStrokeCase(geo, peStroke, reporter); 778 TestCase geoPEStrokeCase(geo, peStroke, reporter);
761 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey) ; 779 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey) ;
762 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey ); 780 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey );
763 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() = = emptyKey); 781 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() = = emptyKey);
782 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty() );
783 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty()) ;
764 } 784 }
765 785
766 void test_empty_shape(skiatest::Reporter* reporter) { 786 void test_empty_shape(skiatest::Reporter* reporter) {
767 SkPath emptyPath; 787 SkPath emptyPath;
768 SkPaint fill; 788 SkPaint fill;
769 TestCase fillEmptyCase(emptyPath, fill, reporter); 789 TestCase fillEmptyCase(emptyPath, fill, reporter);
790 REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty());
791 REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty());
792 REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty());
770 793
771 Key emptyKey(fillEmptyCase.baseKey()); 794 Key emptyKey(fillEmptyCase.baseKey());
772 REPORTER_ASSERT(reporter, emptyKey.count()); 795 REPORTER_ASSERT(reporter, emptyKey.count());
773 TestCase::SelfExpectations expectations; 796 TestCase::SelfExpectations expectations;
774 expectations.fStrokeApplies = false; 797 expectations.fStrokeApplies = false;
775 expectations.fPEHasEffect = false; 798 expectations.fPEHasEffect = false;
776 // This will test whether applying style preserves emptiness 799 // This will test whether applying style preserves emptiness
777 fillEmptyCase.testExpectations(reporter, expectations); 800 fillEmptyCase.testExpectations(reporter, expectations);
778 801
779 // Stroking an empty path should have no effect 802 // Stroking an empty path should have no effect
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 } 943 }
921 } 944 }
922 945
923 // Test a volatile empty path. 946 // Test a volatile empty path.
924 test_volatile_path(reporter, SkPath(), true); 947 test_volatile_path(reporter, SkPath(), true);
925 948
926 test_empty_shape(reporter); 949 test_empty_shape(reporter);
927 } 950 }
928 951
929 #endif 952 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrShape.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698