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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 1923403003: Add tests for volatile paths to GrShapeTest (Closed) Base URL: https://chromium.googlesource.com/skia.git@emptyshape
Patch Set: cleanup 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 | « no previous file | 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 peStroke.setStrokeWidth(2.f); 442 peStroke.setStrokeWidth(2.f);
443 peStroke.setStyle(SkPaint::kStroke_Style); 443 peStroke.setStyle(SkPaint::kStroke_Style);
444 TestCase geoPEStrokeCase(geo, peStroke); 444 TestCase geoPEStrokeCase(geo, peStroke);
445 TestCase::SelfExpectations expectations; 445 TestCase::SelfExpectations expectations;
446 expectations.fPEHasEffect = true; 446 expectations.fPEHasEffect = true;
447 expectations.fPEHasValidKey = false; 447 expectations.fPEHasValidKey = false;
448 expectations.fStrokeApplies = true; 448 expectations.fStrokeApplies = true;
449 geoPEStrokeCase.testExpectations(reporter, expectations); 449 geoPEStrokeCase.testExpectations(reporter, expectations);
450 } 450 }
451 451
452 /**
453 * isNonPath indicates whether the initial shape made from the path is expected to be recognized
454 * as a simpler shape type (e.g. rrect)
455 */
456 void test_volatile_path(skiatest::Reporter* reporter, const SkPath& path,
457 bool isNonPath) {
458 SkPath vPath(path);
459 vPath.setIsVolatile(true);
460
461 SkPaint dashAndStroke;
462 dashAndStroke.setPathEffect(make_dash());
463 dashAndStroke.setStrokeWidth(2.f);
464 dashAndStroke.setStyle(SkPaint::kStroke_Style);
465 TestCase volatileCase(vPath, dashAndStroke);
466 // We expect a shape made from a volatile path to have a key iff the shape i s recognized
467 // as a specialized geometry.
468 if (isNonPath) {
469 REPORTER_ASSERT(reporter, SkToBool(volatileCase.baseKey().count()));
470 // In this case all the keys should be identical to the non-volatile cas e.
471 TestCase nonVolatileCase(path, dashAndStroke);
472 volatileCase.compare(reporter, nonVolatileCase, TestCase::kAllSame_Compa risonExpecation);
473 } else {
474 // None of the keys should be valid.
475 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.baseKey().count()));
476 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectKey(). count()));
477 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedFullStyleKey().c ount()));
478 REPORTER_ASSERT(reporter, !SkToBool(volatileCase.appliedPathEffectThenSt rokeKey().count()));
479 }
480 }
481
452 template <typename GEO> 482 template <typename GEO>
453 void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& geo) { 483 void test_path_effect_makes_empty_shape(skiatest::Reporter* reporter, const GEO& geo) {
454 /** 484 /**
455 * This path effect returns an empty path. 485 * This path effect returns an empty path.
456 */ 486 */
457 class EmptyPathEffect : SkPathEffect { 487 class EmptyPathEffect : SkPathEffect {
458 public: 488 public:
459 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*, 489 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
460 const SkRect* cullR) const override { 490 const SkRect* cullR) const override {
461 dst->reset(); 491 dst->reset();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 for (auto testPath : paths) { 617 for (auto testPath : paths) {
588 const SkPath& path = testPath.fPath; 618 const SkPath& path = testPath.fPath;
589 // These tests all assume that the original GrShape for fill and stroke will be the same. 619 // These tests all assume that the original GrShape for fill and stroke will be the same.
590 // However, that is not the case in special cases (e.g. a unclosed rect becomes a RRect 620 // However, that is not the case in special cases (e.g. a unclosed rect becomes a RRect
591 // GrShape with a fill style but becomes a Path GrShape when stroked). 621 // GrShape with a fill style but becomes a Path GrShape when stroked).
592 if (testPath.fIsRRectForFill == testPath.fIsRRectForStroke) { 622 if (testPath.fIsRRectForFill == testPath.fIsRRectForStroke) {
593 test_basic(reporter, path); 623 test_basic(reporter, path);
594 test_null_dash(reporter, path); 624 test_null_dash(reporter, path);
595 test_path_effect_makes_rrect(reporter, path); 625 test_path_effect_makes_rrect(reporter, path);
596 } 626 }
627 // This test uses a stroking paint, hence use of fIsRRectForStroke
628 test_volatile_path(reporter, path, testPath.fIsRRectForStroke);
597 test_dash_fill(reporter, path); 629 test_dash_fill(reporter, path);
598 // Test modifying various stroke params. 630 // Test modifying various stroke params.
599 test_stroke_param<SkPath, SkScalar>( 631 test_stroke_param<SkPath, SkScalar>(
600 reporter, path, 632 reporter, path,
601 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, 633 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
602 SkIntToScalar(2), SkIntToScalar(4)); 634 SkIntToScalar(2), SkIntToScalar(4));
603 test_stroke_param<SkPath, SkPaint::Cap>( 635 test_stroke_param<SkPath, SkPaint::Cap>(
604 reporter, path, 636 reporter, path,
605 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);}, 637 [](SkPaint* p, SkPaint::Cap c) { p->setStrokeCap(c);},
606 SkPaint::kButt_Cap, SkPaint::kRound_Cap); 638 SkPaint::kButt_Cap, SkPaint::kRound_Cap);
(...skipping 23 matching lines...) Expand all
630 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke == 662 REPORTER_ASSERT(reporter, testPath.fIsRRectForStroke ==
631 strokePathCase.baseShape().asRRect(&rrect)); 663 strokePathCase.baseShape().asRRect(&rrect));
632 if (testPath.fIsRRectForStroke) { 664 if (testPath.fIsRRectForStroke) {
633 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); 665 REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
634 TestCase strokeRRectCase(rrect, strokePaint); 666 TestCase strokeRRectCase(rrect, strokePaint);
635 strokePathCase.compare(reporter, strokeRRectCase, 667 strokePathCase.compare(reporter, strokeRRectCase,
636 TestCase::kAllSame_ComparisonExpecation); 668 TestCase::kAllSame_ComparisonExpecation);
637 } 669 }
638 } 670 }
639 671
672 // Test a volatile empty path.
673 test_volatile_path(reporter, SkPath(), true);
674
640 test_empty_shape(reporter); 675 test_empty_shape(reporter);
641 } 676 }
642 677
643 #endif 678 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698