OLD | NEW |
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 "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
(...skipping 3660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3671 compare_dump(reporter, p, false, true, | 3671 compare_dump(reporter, p, false, true, |
3672 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)
); // 1, 2\n" | 3672 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)
); // 1, 2\n" |
3673 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)
); // 3, 4\n"); | 3673 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)
); // 3, 4\n"); |
3674 p.reset(); | 3674 p.reset(); |
3675 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); | 3675 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); |
3676 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); | 3676 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); |
3677 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n" | 3677 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n" |
3678 "path.lineTo(3, 4);\n"); | 3678 "path.lineTo(3, 4);\n"); |
3679 } | 3679 } |
3680 | 3680 |
| 3681 namespace { |
| 3682 |
| 3683 class ChangeListener : public SkPathRef::GenIDChangeListener { |
| 3684 public: |
| 3685 ChangeListener(bool *changed) : fChanged(changed) { *fChanged = false; } |
| 3686 virtual ~ChangeListener() {} |
| 3687 void onChange() override { |
| 3688 *fChanged = true; |
| 3689 } |
| 3690 private: |
| 3691 bool* fChanged; |
| 3692 }; |
| 3693 |
| 3694 } |
| 3695 |
3681 class PathTest_Private { | 3696 class PathTest_Private { |
3682 public: | 3697 public: |
3683 static void TestPathTo(skiatest::Reporter* reporter) { | 3698 static void TestPathTo(skiatest::Reporter* reporter) { |
3684 SkPath p, q; | 3699 SkPath p, q; |
3685 p.lineTo(4, 4); | 3700 p.lineTo(4, 4); |
3686 p.reversePathTo(q); | 3701 p.reversePathTo(q); |
3687 check_path_is_line(reporter, &p, 4, 4); | 3702 check_path_is_line(reporter, &p, 4, 4); |
3688 q.moveTo(-4, -4); | 3703 q.moveTo(-4, -4); |
3689 p.reversePathTo(q); | 3704 p.reversePathTo(q); |
3690 check_path_is_line(reporter, &p, 4, 4); | 3705 check_path_is_line(reporter, &p, 4, 4); |
3691 q.lineTo(7, 8); | 3706 q.lineTo(7, 8); |
3692 q.conicTo(8, 7, 6, 5, 0.5f); | 3707 q.conicTo(8, 7, 6, 5, 0.5f); |
3693 q.quadTo(6, 7, 8, 6); | 3708 q.quadTo(6, 7, 8, 6); |
3694 q.cubicTo(5, 6, 7, 8, 7, 5); | 3709 q.cubicTo(5, 6, 7, 8, 7, 5); |
3695 q.close(); | 3710 q.close(); |
3696 p.reversePathTo(q); | 3711 p.reversePathTo(q); |
3697 SkRect reverseExpected = {-4, -4, 8, 8}; | 3712 SkRect reverseExpected = {-4, -4, 8, 8}; |
3698 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); | 3713 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
3699 } | 3714 } |
| 3715 |
| 3716 static void TestPathrefListeners(skiatest::Reporter* reporter) { |
| 3717 SkPath p; |
| 3718 |
| 3719 bool changed = false; |
| 3720 p.moveTo(0, 0); |
| 3721 |
| 3722 // Check that listener is notified on moveTo(). |
| 3723 p.pathRef()->addGenIDChangeListener(SkNEW(ChangeListener(&changed))); |
| 3724 REPORTER_ASSERT(reporter, !changed); |
| 3725 p.moveTo(10, 0); |
| 3726 REPORTER_ASSERT(reporter, changed); |
| 3727 |
| 3728 // Check that listener is notified on lineTo(). |
| 3729 p.pathRef()->addGenIDChangeListener(SkNEW(ChangeListener(&changed))); |
| 3730 REPORTER_ASSERT(reporter, !changed); |
| 3731 p.lineTo(20, 0); |
| 3732 REPORTER_ASSERT(reporter, changed); |
| 3733 |
| 3734 // Check that listener is notified on reset(). |
| 3735 p.pathRef()->addGenIDChangeListener(SkNEW(ChangeListener(&changed))); |
| 3736 REPORTER_ASSERT(reporter, !changed); |
| 3737 p.reset(); |
| 3738 REPORTER_ASSERT(reporter, changed); |
| 3739 |
| 3740 p.moveTo(0, 0); |
| 3741 |
| 3742 // Check that listener is notified on rewind(). |
| 3743 p.pathRef()->addGenIDChangeListener(SkNEW(ChangeListener(&changed))); |
| 3744 REPORTER_ASSERT(reporter, !changed); |
| 3745 p.rewind(); |
| 3746 REPORTER_ASSERT(reporter, changed); |
| 3747 |
| 3748 // Check that listener is notified when pathref is deleted. |
| 3749 { |
| 3750 SkPath q; |
| 3751 q.moveTo(10, 10); |
| 3752 q.pathRef()->addGenIDChangeListener(SkNEW(ChangeListener(&changed)))
; |
| 3753 REPORTER_ASSERT(reporter, !changed); |
| 3754 } |
| 3755 // q went out of scope. |
| 3756 REPORTER_ASSERT(reporter, changed); |
| 3757 } |
3700 }; | 3758 }; |
3701 | 3759 |
3702 DEF_TEST(Paths, reporter) { | 3760 DEF_TEST(Paths, reporter) { |
3703 test_path_crbug364224(); | 3761 test_path_crbug364224(); |
3704 | 3762 |
3705 SkTSize<SkScalar>::Make(3,4); | 3763 SkTSize<SkScalar>::Make(3,4); |
3706 | 3764 |
3707 SkPath p, empty; | 3765 SkPath p, empty; |
3708 SkRect bounds, bounds2; | 3766 SkRect bounds, bounds2; |
3709 test_empty(reporter, p); | 3767 test_empty(reporter, p); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3836 test_addPathMode(reporter, false, true); | 3894 test_addPathMode(reporter, false, true); |
3837 test_addPathMode(reporter, true, true); | 3895 test_addPathMode(reporter, true, true); |
3838 test_extendClosedPath(reporter); | 3896 test_extendClosedPath(reporter); |
3839 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); | 3897 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); |
3840 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); | 3898 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); |
3841 test_conicTo_special_case(reporter); | 3899 test_conicTo_special_case(reporter); |
3842 test_get_point(reporter); | 3900 test_get_point(reporter); |
3843 test_contains(reporter); | 3901 test_contains(reporter); |
3844 PathTest_Private::TestPathTo(reporter); | 3902 PathTest_Private::TestPathTo(reporter); |
3845 PathRefTest_Private::TestPathRef(reporter); | 3903 PathRefTest_Private::TestPathRef(reporter); |
| 3904 PathTest_Private::TestPathrefListeners(reporter); |
3846 test_dump(reporter); | 3905 test_dump(reporter); |
3847 test_path_crbug389050(reporter); | 3906 test_path_crbug389050(reporter); |
3848 test_path_crbugskia2820(reporter); | 3907 test_path_crbugskia2820(reporter); |
3849 test_skbug_3469(reporter); | 3908 test_skbug_3469(reporter); |
3850 test_skbug_3239(reporter); | 3909 test_skbug_3239(reporter); |
3851 } | 3910 } |
OLD | NEW |