OLD | NEW |
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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 hairline.setStrokeWidth(0.f); | 256 hairline.setStrokeWidth(0.f); |
257 TestCase hairlineCase(geo, hairline, reporter); | 257 TestCase hairlineCase(geo, hairline, reporter); |
258 // Since hairline style doesn't change the SkPath data, it is keyed identica
lly to fill. | 258 // Since hairline style doesn't change the SkPath data, it is keyed identica
lly to fill. |
259 hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpeca
tion); | 259 hairlineCase.compare(reporter, fillCase, TestCase::kAllSame_ComparisonExpeca
tion); |
260 REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline(
)); | 260 REPORTER_ASSERT(reporter, hairlineCase.baseShape().style().isSimpleHairline(
)); |
261 REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSim
pleHairline()); | 261 REPORTER_ASSERT(reporter, hairlineCase.appliedFullStyleShape().style().isSim
pleHairline()); |
262 REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSi
mpleHairline()); | 262 REPORTER_ASSERT(reporter, hairlineCase.appliedPathEffectShape().style().isSi
mpleHairline()); |
263 } | 263 } |
264 | 264 |
265 template <typename GEO, typename T> | 265 template <typename GEO, typename T> |
266 static void test_stroke_param(skiatest::Reporter* reporter, const GEO& geo, | 266 static void test_stroke_param_impl(skiatest::Reporter* reporter, const GEO& geo, |
267 std::function<void(SkPaint*, T)> setter, T a, T b)
{ | 267 std::function<void(SkPaint*, T)> setter, T a,
T b, |
268 // Set the stroke width so that we don't get hairline. However, call the fun
ction second so that | 268 bool paramAffectsStroke, |
269 // it can override. | 269 bool paramAffectsDashAndStroke) { |
| 270 // Set the stroke width so that we don't get hairline. However, call the set
ter afterward so |
| 271 // that it can override the stroke width. |
270 SkPaint strokeA; | 272 SkPaint strokeA; |
271 strokeA.setStyle(SkPaint::kStroke_Style); | 273 strokeA.setStyle(SkPaint::kStroke_Style); |
272 strokeA.setStrokeWidth(2.f); | 274 strokeA.setStrokeWidth(2.f); |
273 setter(&strokeA, a); | 275 setter(&strokeA, a); |
274 SkPaint strokeB; | 276 SkPaint strokeB; |
275 strokeB.setStyle(SkPaint::kStroke_Style); | 277 strokeB.setStyle(SkPaint::kStroke_Style); |
276 strokeB.setStrokeWidth(2.f); | 278 strokeB.setStrokeWidth(2.f); |
277 setter(&strokeB, b); | 279 setter(&strokeB, b); |
278 | 280 |
279 TestCase strokeACase(geo, strokeA, reporter); | 281 TestCase strokeACase(geo, strokeA, reporter); |
280 TestCase strokeBCase(geo, strokeB, reporter); | 282 TestCase strokeBCase(geo, strokeB, reporter); |
281 strokeACase.compare(reporter, strokeBCase, TestCase::kSameUpToStroke_Compari
sonExpecation); | 283 if (paramAffectsStroke) { |
| 284 strokeACase.compare(reporter, strokeBCase, TestCase::kSameUpToStroke_Com
parisonExpecation); |
| 285 } else { |
| 286 strokeACase.compare(reporter, strokeBCase, TestCase::kAllSame_Comparison
Expecation); |
| 287 } |
282 | 288 |
283 // Make sure stroking params don't affect fill style. | 289 // Make sure stroking params don't affect fill style. |
284 SkPaint fillA = strokeA, fillB = strokeB; | 290 SkPaint fillA = strokeA, fillB = strokeB; |
285 fillA.setStyle(SkPaint::kFill_Style); | 291 fillA.setStyle(SkPaint::kFill_Style); |
286 fillB.setStyle(SkPaint::kFill_Style); | 292 fillB.setStyle(SkPaint::kFill_Style); |
287 TestCase fillACase(geo, fillA, reporter); | 293 TestCase fillACase(geo, fillA, reporter); |
288 TestCase fillBCase(geo, fillB, reporter); | 294 TestCase fillBCase(geo, fillB, reporter); |
289 fillACase.compare(reporter, fillBCase, TestCase::kAllSame_ComparisonExpecati
on); | 295 fillACase.compare(reporter, fillBCase, TestCase::kAllSame_ComparisonExpecati
on); |
290 | 296 |
291 // Make sure just applying the dash but not stroke gives the same key for bo
th stroking | 297 // Make sure just applying the dash but not stroke gives the same key for bo
th stroking |
292 // variations. | 298 // variations. |
293 SkPaint dashA = strokeA, dashB = strokeB; | 299 SkPaint dashA = strokeA, dashB = strokeB; |
294 dashA.setPathEffect(make_dash()); | 300 dashA.setPathEffect(make_dash()); |
295 dashB.setPathEffect(make_dash()); | 301 dashB.setPathEffect(make_dash()); |
296 TestCase dashACase(geo, dashA, reporter); | 302 TestCase dashACase(geo, dashA, reporter); |
297 TestCase dashBCase(geo, dashB, reporter); | 303 TestCase dashBCase(geo, dashB, reporter); |
298 dashACase.compare(reporter, dashBCase, TestCase::kSameUpToStroke_ComparisonE
xpecation); | 304 if (paramAffectsDashAndStroke) { |
| 305 dashACase.compare(reporter, dashBCase, TestCase::kSameUpToStroke_Compari
sonExpecation); |
| 306 } else { |
| 307 dashACase.compare(reporter, dashBCase, TestCase::kAllSame_ComparisonExpe
cation); |
| 308 } |
299 } | 309 } |
300 | 310 |
| 311 template <typename GEO, typename T> |
| 312 static void test_stroke_param(skiatest::Reporter* reporter, const GEO& geo, |
| 313 std::function<void(SkPaint*, T)> setter, T a, T b)
{ |
| 314 test_stroke_param_impl(reporter, geo, setter, a, b, true, true); |
| 315 }; |
| 316 |
| 317 template <typename GEO> |
| 318 static void test_stroke_cap(skiatest::Reporter* reporter, const GEO& geo) { |
| 319 GrShape shape(geo, GrStyle(SkStrokeRec::kHairline_InitStyle)); |
| 320 // The cap should only affect shapes that may be open. |
| 321 bool affectsStroke = !shape.knownToBeClosed(); |
| 322 // Dashing adds ends that need caps. |
| 323 bool affectsDashAndStroke = true; |
| 324 test_stroke_param_impl<GEO, SkPaint::Cap>( |
| 325 reporter, |
| 326 geo, |
| 327 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, |
| 328 SkPaint::kButt_Cap, SkPaint::kRound_Cap, |
| 329 affectsStroke, |
| 330 affectsDashAndStroke); |
| 331 }; |
| 332 |
301 template <typename GEO> | 333 template <typename GEO> |
302 static void test_miter_limit(skiatest::Reporter* reporter, const GEO& geo) { | 334 static void test_miter_limit(skiatest::Reporter* reporter, const GEO& geo) { |
303 // Miter limit should only matter when stroking with miter joins. It shouldn
't affect other | 335 auto setMiterJoinAndLimit = [](SkPaint* p, SkScalar miter) { |
304 // joins or fills. | 336 p->setStrokeJoin(SkPaint::kMiter_Join); |
305 SkPaint miterA; | 337 p->setStrokeMiter(miter); |
306 miterA.setStyle(SkPaint::kStroke_Style); | 338 }; |
307 miterA.setStrokeWidth(2.f); | |
308 miterA.setStrokeJoin(SkPaint::kMiter_Join); | |
309 miterA.setStrokeMiter(0.5f); | |
310 SkPaint miterB = miterA; | |
311 miterA.setStrokeMiter(0.6f); | |
312 | 339 |
313 TestCase miterACase(geo, miterA, reporter); | 340 auto setOtherJoinAndLimit = [](SkPaint* p, SkScalar miter) { |
314 TestCase miterBCase(geo, miterB, reporter); | 341 p->setStrokeJoin(SkPaint::kRound_Join); |
315 miterACase.compare(reporter, miterBCase, TestCase::kSameUpToStroke_Compariso
nExpecation); | 342 p->setStrokeMiter(miter); |
| 343 }; |
316 | 344 |
317 SkPaint noMiterA = miterA, noMiterB = miterB; | 345 // The miter limit should affect stroked and dashed-stroked cases when the j
oin type is |
318 noMiterA.setStrokeJoin(SkPaint::kRound_Join); | 346 // miter. |
319 noMiterB.setStrokeJoin(SkPaint::kRound_Join); | 347 test_stroke_param_impl<GEO, SkScalar>( |
320 TestCase noMiterACase(geo, noMiterA, reporter); | 348 reporter, |
321 TestCase noMiterBCase(geo, noMiterB, reporter); | 349 geo, |
322 noMiterACase.compare(reporter, noMiterBCase, TestCase::kAllSame_ComparisonEx
pecation); | 350 setMiterJoinAndLimit, |
| 351 0.5f, 0.75f, |
| 352 true, |
| 353 true); |
323 | 354 |
324 SkPaint fillA = miterA, fillB = miterB; | 355 // The miter limit should not affect stroked and dashed-stroked cases when t
he join type is |
325 fillA.setStyle(SkPaint::kFill_Style); | 356 // not miter. |
326 fillB.setStyle(SkPaint::kFill_Style); | 357 test_stroke_param_impl<GEO, SkScalar>( |
327 TestCase fillACase(geo, fillA, reporter); | 358 reporter, |
328 TestCase fillBCase(geo, fillB, reporter); | 359 geo, |
329 fillACase.compare(reporter, fillBCase, TestCase::kAllSame_ComparisonExpecati
on); | 360 setOtherJoinAndLimit, |
| 361 0.5f, 0.75f, |
| 362 false, |
| 363 false); |
330 } | 364 } |
331 | 365 |
332 template<typename GEO> | 366 template<typename GEO> |
333 static void test_dash_fill(skiatest::Reporter* reporter, const GEO& geo) { | 367 static void test_dash_fill(skiatest::Reporter* reporter, const GEO& geo) { |
334 // A dash with no stroke should have no effect | 368 // A dash with no stroke should have no effect |
335 using DashFactoryFn = sk_sp<SkPathEffect>(*)(); | 369 using DashFactoryFn = sk_sp<SkPathEffect>(*)(); |
336 for (DashFactoryFn md : {&make_dash, &make_null_dash}) { | 370 for (DashFactoryFn md : {&make_dash, &make_null_dash}) { |
337 SkPaint dashFill; | 371 SkPaint dashFill; |
338 dashFill.setPathEffect((*md)()); | 372 dashFill.setPathEffect((*md)()); |
339 TestCase dashFillCase(geo, dashFill, reporter); | 373 TestCase dashFillCase(geo, dashFill, reporter); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), | 687 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), |
654 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4)}) { | 688 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4)}) { |
655 test_basic(reporter, rr); | 689 test_basic(reporter, rr); |
656 test_dash_fill(reporter, rr); | 690 test_dash_fill(reporter, rr); |
657 test_null_dash(reporter, rr); | 691 test_null_dash(reporter, rr); |
658 // Test modifying various stroke params. | 692 // Test modifying various stroke params. |
659 test_stroke_param<SkRRect, SkScalar>( | 693 test_stroke_param<SkRRect, SkScalar>( |
660 reporter, rr, | 694 reporter, rr, |
661 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, | 695 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, |
662 SkIntToScalar(2), SkIntToScalar(4)); | 696 SkIntToScalar(2), SkIntToScalar(4)); |
663 test_stroke_param<SkRRect, SkPaint::Cap>( | |
664 reporter, rr, | |
665 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, | |
666 SkPaint::kButt_Cap, SkPaint::kRound_Cap); | |
667 test_stroke_param<SkRRect, SkPaint::Join>( | 697 test_stroke_param<SkRRect, SkPaint::Join>( |
668 reporter, rr, | 698 reporter, rr, |
669 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);
}, | 699 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);
}, |
670 SkPaint::kMiter_Join, SkPaint::kRound_Join); | 700 SkPaint::kMiter_Join, SkPaint::kRound_Join); |
| 701 test_stroke_cap(reporter, rr); |
671 test_miter_limit(reporter, rr); | 702 test_miter_limit(reporter, rr); |
672 test_path_effect_makes_rrect(reporter, rr); | 703 test_path_effect_makes_rrect(reporter, rr); |
673 test_unknown_path_effect(reporter, rr); | 704 test_unknown_path_effect(reporter, rr); |
674 test_path_effect_makes_empty_shape(reporter, rr); | 705 test_path_effect_makes_empty_shape(reporter, rr); |
675 test_make_hairline_path_effect(reporter, rr, true); | 706 test_make_hairline_path_effect(reporter, rr, true); |
676 } | 707 } |
677 | 708 |
678 struct TestPath { | 709 struct TestPath { |
679 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const
SkRRect& rrect) | 710 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const
SkRRect& rrect) |
680 : fPath(path) | 711 : fPath(path) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 test_path_effect_makes_rrect(reporter, path); | 749 test_path_effect_makes_rrect(reporter, path); |
719 } | 750 } |
720 // This test uses a stroking paint, hence use of fIsRRectForStroke | 751 // This test uses a stroking paint, hence use of fIsRRectForStroke |
721 test_volatile_path(reporter, path, testPath.fIsRRectForStroke); | 752 test_volatile_path(reporter, path, testPath.fIsRRectForStroke); |
722 test_dash_fill(reporter, path); | 753 test_dash_fill(reporter, path); |
723 // Test modifying various stroke params. | 754 // Test modifying various stroke params. |
724 test_stroke_param<SkPath, SkScalar>( | 755 test_stroke_param<SkPath, SkScalar>( |
725 reporter, path, | 756 reporter, path, |
726 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, | 757 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, |
727 SkIntToScalar(2), SkIntToScalar(4)); | 758 SkIntToScalar(2), SkIntToScalar(4)); |
728 test_stroke_param<SkPath, SkPaint::Cap>( | |
729 reporter, path, | |
730 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, | |
731 SkPaint::kButt_Cap, SkPaint::kRound_Cap); | |
732 test_stroke_param<SkPath, SkPaint::Join>( | 759 test_stroke_param<SkPath, SkPaint::Join>( |
733 reporter, path, | 760 reporter, path, |
734 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, | 761 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, |
735 SkPaint::kMiter_Join, SkPaint::kRound_Join); | 762 SkPaint::kMiter_Join, SkPaint::kRound_Join); |
| 763 test_stroke_cap(reporter, path); |
736 test_miter_limit(reporter, path); | 764 test_miter_limit(reporter, path); |
737 test_unknown_path_effect(reporter, path); | 765 test_unknown_path_effect(reporter, path); |
738 test_path_effect_makes_empty_shape(reporter, path); | 766 test_path_effect_makes_empty_shape(reporter, path); |
739 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok
e); | 767 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok
e); |
740 | 768 |
741 SkPaint fillPaint; | 769 SkPaint fillPaint; |
742 TestCase fillPathCase(path, fillPaint, reporter); | 770 TestCase fillPathCase(path, fillPaint, reporter); |
743 SkRRect rrect; | 771 SkRRect rrect; |
744 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == | 772 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == |
745 fillPathCase.baseShape().asRRect(&rrect)); | 773 fillPathCase.baseShape().asRRect(&rrect)); |
(...skipping 17 matching lines...) Expand all Loading... |
763 } | 791 } |
764 } | 792 } |
765 | 793 |
766 // Test a volatile empty path. | 794 // Test a volatile empty path. |
767 test_volatile_path(reporter, SkPath(), true); | 795 test_volatile_path(reporter, SkPath(), true); |
768 | 796 |
769 test_empty_shape(reporter); | 797 test_empty_shape(reporter); |
770 } | 798 } |
771 | 799 |
772 #endif | 800 #endif |
OLD | NEW |