| 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 3697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3708 compare_dump(reporter, p, false, true, | 3708 compare_dump(reporter, p, false, true, |
| 3709 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)
); // 1, 2\n" | 3709 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)
); // 1, 2\n" |
| 3710 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)
); // 3, 4\n"); | 3710 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)
); // 3, 4\n"); |
| 3711 p.reset(); | 3711 p.reset(); |
| 3712 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); | 3712 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); |
| 3713 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); | 3713 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); |
| 3714 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n" | 3714 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n" |
| 3715 "path.lineTo(3, 4);\n"); | 3715 "path.lineTo(3, 4);\n"); |
| 3716 } | 3716 } |
| 3717 | 3717 |
| 3718 namespace { | |
| 3719 | |
| 3720 class ChangeListener : public SkPathRef::GenIDChangeListener { | |
| 3721 public: | |
| 3722 ChangeListener(bool *changed) : fChanged(changed) { *fChanged = false; } | |
| 3723 virtual ~ChangeListener() {} | |
| 3724 void onChange() override { | |
| 3725 *fChanged = true; | |
| 3726 } | |
| 3727 private: | |
| 3728 bool* fChanged; | |
| 3729 }; | |
| 3730 | |
| 3731 } | |
| 3732 | |
| 3733 class PathTest_Private { | 3718 class PathTest_Private { |
| 3734 public: | 3719 public: |
| 3735 static void TestPathTo(skiatest::Reporter* reporter) { | 3720 static void TestPathTo(skiatest::Reporter* reporter) { |
| 3736 SkPath p, q; | 3721 SkPath p, q; |
| 3737 p.lineTo(4, 4); | 3722 p.lineTo(4, 4); |
| 3738 p.reversePathTo(q); | 3723 p.reversePathTo(q); |
| 3739 check_path_is_line(reporter, &p, 4, 4); | 3724 check_path_is_line(reporter, &p, 4, 4); |
| 3740 q.moveTo(-4, -4); | 3725 q.moveTo(-4, -4); |
| 3741 p.reversePathTo(q); | 3726 p.reversePathTo(q); |
| 3742 check_path_is_line(reporter, &p, 4, 4); | 3727 check_path_is_line(reporter, &p, 4, 4); |
| 3743 q.lineTo(7, 8); | 3728 q.lineTo(7, 8); |
| 3744 q.conicTo(8, 7, 6, 5, 0.5f); | 3729 q.conicTo(8, 7, 6, 5, 0.5f); |
| 3745 q.quadTo(6, 7, 8, 6); | 3730 q.quadTo(6, 7, 8, 6); |
| 3746 q.cubicTo(5, 6, 7, 8, 7, 5); | 3731 q.cubicTo(5, 6, 7, 8, 7, 5); |
| 3747 q.close(); | 3732 q.close(); |
| 3748 p.reversePathTo(q); | 3733 p.reversePathTo(q); |
| 3749 SkRect reverseExpected = {-4, -4, 8, 8}; | 3734 SkRect reverseExpected = {-4, -4, 8, 8}; |
| 3750 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); | 3735 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
| 3751 } | 3736 } |
| 3752 | |
| 3753 static void TestPathrefListeners(skiatest::Reporter* reporter) { | |
| 3754 SkPath p; | |
| 3755 | |
| 3756 bool changed = false; | |
| 3757 p.moveTo(0, 0); | |
| 3758 | |
| 3759 // Check that listener is notified on moveTo(). | |
| 3760 | |
| 3761 SkPathPriv::AddGenIDChangeListener(p, SkNEW(ChangeListener(&changed))); | |
| 3762 REPORTER_ASSERT(reporter, !changed); | |
| 3763 p.moveTo(10, 0); | |
| 3764 REPORTER_ASSERT(reporter, changed); | |
| 3765 | |
| 3766 // Check that listener is notified on lineTo(). | |
| 3767 SkPathPriv::AddGenIDChangeListener(p, SkNEW(ChangeListener(&changed))); | |
| 3768 REPORTER_ASSERT(reporter, !changed); | |
| 3769 p.lineTo(20, 0); | |
| 3770 REPORTER_ASSERT(reporter, changed); | |
| 3771 | |
| 3772 // Check that listener is notified on reset(). | |
| 3773 SkPathPriv::AddGenIDChangeListener(p, SkNEW(ChangeListener(&changed))); | |
| 3774 REPORTER_ASSERT(reporter, !changed); | |
| 3775 p.reset(); | |
| 3776 REPORTER_ASSERT(reporter, changed); | |
| 3777 | |
| 3778 p.moveTo(0, 0); | |
| 3779 | |
| 3780 // Check that listener is notified on rewind(). | |
| 3781 SkPathPriv::AddGenIDChangeListener(p, SkNEW(ChangeListener(&changed))); | |
| 3782 REPORTER_ASSERT(reporter, !changed); | |
| 3783 p.rewind(); | |
| 3784 REPORTER_ASSERT(reporter, changed); | |
| 3785 | |
| 3786 // Check that listener is notified when pathref is deleted. | |
| 3787 { | |
| 3788 SkPath q; | |
| 3789 q.moveTo(10, 10); | |
| 3790 SkPathPriv::AddGenIDChangeListener(q, SkNEW(ChangeListener(&changed)
)); | |
| 3791 REPORTER_ASSERT(reporter, !changed); | |
| 3792 } | |
| 3793 // q went out of scope. | |
| 3794 REPORTER_ASSERT(reporter, changed); | |
| 3795 } | |
| 3796 }; | 3737 }; |
| 3797 | 3738 |
| 3798 DEF_TEST(Paths, reporter) { | 3739 DEF_TEST(Paths, reporter) { |
| 3799 test_path_crbug364224(); | 3740 test_path_crbug364224(); |
| 3800 | 3741 |
| 3801 SkTSize<SkScalar>::Make(3,4); | 3742 SkTSize<SkScalar>::Make(3,4); |
| 3802 | 3743 |
| 3803 SkPath p, empty; | 3744 SkPath p, empty; |
| 3804 SkRect bounds, bounds2; | 3745 SkRect bounds, bounds2; |
| 3805 test_empty(reporter, p); | 3746 test_empty(reporter, p); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3932 test_addPathMode(reporter, false, true); | 3873 test_addPathMode(reporter, false, true); |
| 3933 test_addPathMode(reporter, true, true); | 3874 test_addPathMode(reporter, true, true); |
| 3934 test_extendClosedPath(reporter); | 3875 test_extendClosedPath(reporter); |
| 3935 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); | 3876 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); |
| 3936 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); | 3877 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); |
| 3937 test_conicTo_special_case(reporter); | 3878 test_conicTo_special_case(reporter); |
| 3938 test_get_point(reporter); | 3879 test_get_point(reporter); |
| 3939 test_contains(reporter); | 3880 test_contains(reporter); |
| 3940 PathTest_Private::TestPathTo(reporter); | 3881 PathTest_Private::TestPathTo(reporter); |
| 3941 PathRefTest_Private::TestPathRef(reporter); | 3882 PathRefTest_Private::TestPathRef(reporter); |
| 3942 PathTest_Private::TestPathrefListeners(reporter); | |
| 3943 test_dump(reporter); | 3883 test_dump(reporter); |
| 3944 test_path_crbug389050(reporter); | 3884 test_path_crbug389050(reporter); |
| 3945 test_path_crbugskia2820(reporter); | 3885 test_path_crbugskia2820(reporter); |
| 3946 test_skbug_3469(reporter); | 3886 test_skbug_3469(reporter); |
| 3947 test_skbug_3239(reporter); | 3887 test_skbug_3239(reporter); |
| 3948 test_bounds_crbug_513799(reporter); | 3888 test_bounds_crbug_513799(reporter); |
| 3949 } | 3889 } |
| OLD | NEW |