| 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" |
| 11 #include "SkParsePath.h" | 11 #include "SkParsePath.h" |
| 12 #include "SkPathPriv.h" | 12 #include "SkPathPriv.h" |
| 13 #include "SkPathEffect.h" | 13 #include "SkPathEffect.h" |
| 14 #include "SkRRect.h" | 14 #include "SkRRect.h" |
| 15 #include "SkRandom.h" | 15 #include "SkRandom.h" |
| 16 #include "SkReader32.h" | 16 #include "SkReader32.h" |
| 17 #include "SkSize.h" | 17 #include "SkSize.h" |
| 18 #include "SkStream.h" | 18 #include "SkStream.h" |
| 19 #include "SkSurface.h" | 19 #include "SkSurface.h" |
| 20 #include "SkTypes.h" | 20 #include "SkTypes.h" |
| 21 #include "SkWriter32.h" | 21 #include "SkWriter32.h" |
| 22 #include "Test.h" | 22 #include "Test.h" |
| 23 | 23 |
| 24 #include "SkPathIter.h" |
| 25 |
| 26 static void test_2_iters(const SkPath& path) { |
| 27 SkPath::RawIter iter0(path); |
| 28 SkPathIter iter1(path); |
| 29 |
| 30 SkPoint pts[4]; |
| 31 SkPath::Verb verb; |
| 32 while ((verb = iter0.next(pts)) != SkPath::kDone_Verb) { |
| 33 SkASSERT(iter1.next()); |
| 34 SkASSERT(!iter1.done()); |
| 35 SkASSERT(iter1.currVerb() == (SkPathVerb)verb); |
| 36 int n = 0; |
| 37 switch (verb) { |
| 38 case SkPath::kMove_Verb: n = 1; break; |
| 39 case SkPath::kLine_Verb: n = 2; break; |
| 40 case SkPath::kQuad_Verb: n = 3; break; |
| 41 case SkPath::kConic_Verb: n = 3; break; |
| 42 case SkPath::kCubic_Verb: n = 4; break; |
| 43 case SkPath::kClose_Verb: n = 0; break; |
| 44 default: |
| 45 SkASSERT(!"unexpected"); |
| 46 } |
| 47 for (int i = 0; i < n; ++i) { |
| 48 SkASSERT(pts[i] == iter1.currPts()[i]); |
| 49 } |
| 50 } |
| 51 SkASSERT(iter1.done()); |
| 52 SkDebugf("test_2_iters\n"); |
| 53 } |
| 54 |
| 24 static void set_radii(SkVector radii[4], int index, float rad) { | 55 static void set_radii(SkVector radii[4], int index, float rad) { |
| 25 sk_bzero(radii, sizeof(SkVector) * 4); | 56 sk_bzero(radii, sizeof(SkVector) * 4); |
| 26 radii[index].set(rad, rad); | 57 radii[index].set(rad, rad); |
| 27 } | 58 } |
| 28 | 59 |
| 29 static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds, | 60 static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds, |
| 30 const SkVector radii[4]) { | 61 const SkVector radii[4]) { |
| 31 SkRRect rrect; | 62 SkRRect rrect; |
| 32 rrect.setRectRadii(bounds, radii); | 63 rrect.setRectRadii(bounds, radii); |
| 33 REPORTER_ASSERT(reporter, bounds == rrect.rect()); | 64 REPORTER_ASSERT(reporter, bounds == rrect.rect()); |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 | 849 |
| 819 // assert that we always | 850 // assert that we always |
| 820 // start with a moveTo | 851 // start with a moveTo |
| 821 // only have 1 moveTo | 852 // only have 1 moveTo |
| 822 // only have Lines after that | 853 // only have Lines after that |
| 823 // end with a single close | 854 // end with a single close |
| 824 // only have (at most) 1 close | 855 // only have (at most) 1 close |
| 825 // | 856 // |
| 826 static void test_poly(skiatest::Reporter* reporter, const SkPath& path, | 857 static void test_poly(skiatest::Reporter* reporter, const SkPath& path, |
| 827 const SkPoint srcPts[], bool expectClose) { | 858 const SkPoint srcPts[], bool expectClose) { |
| 859 test_2_iters(path); |
| 828 SkPath::RawIter iter(path); | 860 SkPath::RawIter iter(path); |
| 829 SkPoint pts[4]; | 861 SkPoint pts[4]; |
| 830 | 862 |
| 831 bool firstTime = true; | 863 bool firstTime = true; |
| 832 bool foundClose = false; | 864 bool foundClose = false; |
| 833 for (;;) { | 865 for (;;) { |
| 834 switch (iter.next(pts)) { | 866 switch (iter.next(pts)) { |
| 835 case SkPath::kMove_Verb: | 867 case SkPath::kMove_Verb: |
| 836 REPORTER_ASSERT(reporter, firstTime); | 868 REPORTER_ASSERT(reporter, firstTime); |
| 837 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]); | 869 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 rec.setStrokeStyle(0, true); | 935 rec.setStrokeStyle(0, true); |
| 904 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle()); | 936 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle()); |
| 905 } | 937 } |
| 906 | 938 |
| 907 // Set this for paths that don't have a consistent direction such as a bowtie. | 939 // Set this for paths that don't have a consistent direction such as a bowtie. |
| 908 // (cheapComputeDirection is not expected to catch these.) | 940 // (cheapComputeDirection is not expected to catch these.) |
| 909 const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDi
rection>(-1); | 941 const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDi
rection>(-1); |
| 910 | 942 |
| 911 static void check_direction(skiatest::Reporter* reporter, const SkPath& path, | 943 static void check_direction(skiatest::Reporter* reporter, const SkPath& path, |
| 912 SkPathPriv::FirstDirection expected) { | 944 SkPathPriv::FirstDirection expected) { |
| 945 test_2_iters(path); |
| 913 if (expected == kDontCheckDir) { | 946 if (expected == kDontCheckDir) { |
| 914 return; | 947 return; |
| 915 } | 948 } |
| 916 SkPath copy(path); // we make a copy so that we don't cache the result on th
e passed in path. | 949 SkPath copy(path); // we make a copy so that we don't cache the result on th
e passed in path. |
| 917 | 950 |
| 918 SkPathPriv::FirstDirection dir; | 951 SkPathPriv::FirstDirection dir; |
| 919 if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) { | 952 if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) { |
| 920 REPORTER_ASSERT(reporter, dir == expected); | 953 REPORTER_ASSERT(reporter, dir == expected); |
| 921 } else { | 954 } else { |
| 922 REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expecte
d); | 955 REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expecte
d); |
| (...skipping 3017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3940 PathTest_Private::TestPathTo(reporter); | 3973 PathTest_Private::TestPathTo(reporter); |
| 3941 PathRefTest_Private::TestPathRef(reporter); | 3974 PathRefTest_Private::TestPathRef(reporter); |
| 3942 PathTest_Private::TestPathrefListeners(reporter); | 3975 PathTest_Private::TestPathrefListeners(reporter); |
| 3943 test_dump(reporter); | 3976 test_dump(reporter); |
| 3944 test_path_crbug389050(reporter); | 3977 test_path_crbug389050(reporter); |
| 3945 test_path_crbugskia2820(reporter); | 3978 test_path_crbugskia2820(reporter); |
| 3946 test_skbug_3469(reporter); | 3979 test_skbug_3469(reporter); |
| 3947 test_skbug_3239(reporter); | 3980 test_skbug_3239(reporter); |
| 3948 test_bounds_crbug_513799(reporter); | 3981 test_bounds_crbug_513799(reporter); |
| 3949 } | 3982 } |
| OLD | NEW |