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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 2044793002: Make GrShape use the original path when path effect fails. (Closed) Base URL: https://skia.googlesource.com/skia.git@segments
Patch Set: update commnet Created 4 years, 6 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 | « src/gpu/GrShape.cpp ('k') | 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 874 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 peStroke.setStrokeWidth(2.f); 885 peStroke.setStrokeWidth(2.f);
886 peStroke.setStyle(SkPaint::kStroke_Style); 886 peStroke.setStyle(SkPaint::kStroke_Style);
887 TestCase geoPEStrokeCase(geo, peStroke, reporter); 887 TestCase geoPEStrokeCase(geo, peStroke, reporter);
888 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey) ; 888 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleKey() == emptyKey) ;
889 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey ); 889 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectKey() == emptyKey );
890 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() = = emptyKey); 890 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectThenStrokeKey() = = emptyKey);
891 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty() ); 891 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedPathEffectShape().isEmpty() );
892 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty()) ; 892 REPORTER_ASSERT(reporter, geoPEStrokeCase.appliedFullStyleShape().isEmpty()) ;
893 } 893 }
894 894
895 template <typename GEO>
896 void test_path_effect_fails(skiatest::Reporter* reporter, const GEO& geo) {
897 /**
898 * This path effect returns an empty path.
899 */
900 class FailurePathEffect : SkPathEffect {
901 public:
902 bool filterPath(SkPath* dst, const SkPath& src, SkStrokeRec*,
903 const SkRect* cullR) const override {
904 return false;
905 }
906 void computeFastBounds(SkRect* dst, const SkRect& src) const override {
907 *dst = src;
908 }
909 static sk_sp<SkPathEffect> Make() { return sk_sp<SkPathEffect>(new Failu rePathEffect); }
910 Factory getFactory() const override { return nullptr; }
911 void toString(SkString*) const override {}
912 private:
913 FailurePathEffect() {}
914 };
915
916 SkPaint fill;
917 TestCase fillCase(geo, fill, reporter);
918
919 SkPaint pe;
920 pe.setPathEffect(FailurePathEffect::Make());
921 TestCase peCase(geo, pe, reporter);
922
923 SkPaint stroke;
924 stroke.setStrokeWidth(2.f);
925 stroke.setStyle(SkPaint::kStroke_Style);
926 TestCase strokeCase(geo, stroke, reporter);
927
928 SkPaint peStroke = stroke;
929 peStroke.setPathEffect(FailurePathEffect::Make());
930 TestCase peStrokeCase(geo, peStroke, reporter);
931
932 // In general the path effect failure can cause some of the TestCase::compar e() tests to fail
933 // for at least two reasons: 1) We will initially treat the shape as unkeyab le because of the
934 // path effect, but then when the path effect fails we can key it. 2) GrShap e will change its
935 // mind about whether a unclosed rect is actually rect. The path effect init ially bars us from
936 // closing it but after the effect fails we can (for the fill+pe case). This causes different
937 // routes through GrShape to have equivalent but different representations o f the path (closed
938 // or not) but that fill the same.
939 SkPath a;
940 SkPath b;
941 fillCase.appliedPathEffectShape().asPath(&a);
942 peCase.appliedPathEffectShape().asPath(&b);
943 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
944
945 fillCase.appliedFullStyleShape().asPath(&a);
946 peCase.appliedFullStyleShape().asPath(&b);
947 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
948
949 strokeCase.appliedPathEffectShape().asPath(&a);
950 peStrokeCase.appliedPathEffectShape().asPath(&b);
951 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
952
953 strokeCase.appliedFullStyleShape().asPath(&a);
954 peStrokeCase.appliedFullStyleShape().asPath(&b);
955 REPORTER_ASSERT(reporter, paths_fill_same(a, b));
956 }
957
895 void test_empty_shape(skiatest::Reporter* reporter) { 958 void test_empty_shape(skiatest::Reporter* reporter) {
896 SkPath emptyPath; 959 SkPath emptyPath;
897 SkPaint fill; 960 SkPaint fill;
898 TestCase fillEmptyCase(emptyPath, fill, reporter); 961 TestCase fillEmptyCase(emptyPath, fill, reporter);
899 REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty()); 962 REPORTER_ASSERT(reporter, fillEmptyCase.baseShape().isEmpty());
900 REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty()); 963 REPORTER_ASSERT(reporter, fillEmptyCase.appliedPathEffectShape().isEmpty());
901 REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty()); 964 REPORTER_ASSERT(reporter, fillEmptyCase.appliedFullStyleShape().isEmpty());
902 965
903 Key emptyKey(fillEmptyCase.baseKey()); 966 Key emptyKey(fillEmptyCase.baseKey());
904 REPORTER_ASSERT(reporter, emptyKey.count()); 967 REPORTER_ASSERT(reporter, emptyKey.count());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 SkIntToScalar(2), SkIntToScalar(4)); 1019 SkIntToScalar(2), SkIntToScalar(4));
957 test_stroke_param<SkRect, SkPaint::Join>( 1020 test_stroke_param<SkRect, SkPaint::Join>(
958 reporter, r, 1021 reporter, r,
959 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, 1022 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
960 SkPaint::kMiter_Join, SkPaint::kRound_Join); 1023 SkPaint::kMiter_Join, SkPaint::kRound_Join);
961 test_stroke_cap(reporter, r); 1024 test_stroke_cap(reporter, r);
962 test_miter_limit(reporter, r); 1025 test_miter_limit(reporter, r);
963 test_path_effect_makes_rrect(reporter, r); 1026 test_path_effect_makes_rrect(reporter, r);
964 test_unknown_path_effect(reporter, r); 1027 test_unknown_path_effect(reporter, r);
965 test_path_effect_makes_empty_shape(reporter, r); 1028 test_path_effect_makes_empty_shape(reporter, r);
1029 test_path_effect_fails(reporter, r);
966 test_make_hairline_path_effect(reporter, r, true); 1030 test_make_hairline_path_effect(reporter, r, true);
967 } 1031 }
968 1032
969 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)), 1033 for (auto rr : { SkRRect::MakeRect(SkRect::MakeWH(10, 10)),
970 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4), 1034 SkRRect::MakeRectXY(SkRect::MakeWH(10, 10), 3, 4),
971 SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) { 1035 SkRRect::MakeOval(SkRect::MakeWH(20, 20))}) {
972 test_basic(reporter, rr); 1036 test_basic(reporter, rr);
973 test_scale(reporter, rr); 1037 test_scale(reporter, rr);
974 test_dash_fill(reporter, rr); 1038 test_dash_fill(reporter, rr);
975 test_null_dash(reporter, rr); 1039 test_null_dash(reporter, rr);
976 // Test modifying various stroke params. 1040 // Test modifying various stroke params.
977 test_stroke_param<SkRRect, SkScalar>( 1041 test_stroke_param<SkRRect, SkScalar>(
978 reporter, rr, 1042 reporter, rr,
979 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, 1043 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
980 SkIntToScalar(2), SkIntToScalar(4)); 1044 SkIntToScalar(2), SkIntToScalar(4));
981 test_stroke_param<SkRRect, SkPaint::Join>( 1045 test_stroke_param<SkRRect, SkPaint::Join>(
982 reporter, rr, 1046 reporter, rr,
983 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); }, 1047 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j); },
984 SkPaint::kMiter_Join, SkPaint::kRound_Join); 1048 SkPaint::kMiter_Join, SkPaint::kRound_Join);
985 test_stroke_cap(reporter, rr); 1049 test_stroke_cap(reporter, rr);
986 test_miter_limit(reporter, rr); 1050 test_miter_limit(reporter, rr);
987 test_path_effect_makes_rrect(reporter, rr); 1051 test_path_effect_makes_rrect(reporter, rr);
988 test_unknown_path_effect(reporter, rr); 1052 test_unknown_path_effect(reporter, rr);
989 test_path_effect_makes_empty_shape(reporter, rr); 1053 test_path_effect_makes_empty_shape(reporter, rr);
1054 test_path_effect_fails(reporter, rr);
990 test_make_hairline_path_effect(reporter, rr, true); 1055 test_make_hairline_path_effect(reporter, rr, true);
991 } 1056 }
992 1057
993 struct TestPath { 1058 struct TestPath {
994 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const SkRRect& rrect) 1059 TestPath(const SkPath& path, bool isRRectFill, bool isRRectStroke ,const SkRRect& rrect)
995 : fPath(path) 1060 : fPath(path)
996 , fIsRRectForFill(isRRectFill) 1061 , fIsRRectForFill(isRRectFill)
997 , fIsRRectForStroke(isRRectStroke) 1062 , fIsRRectForStroke(isRRectStroke)
998 , fRRect(rrect) {} 1063 , fRRect(rrect) {}
999 SkPath fPath; 1064 SkPath fPath;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);}, 1107 [](SkPaint* p, SkScalar w) { p->setStrokeWidth(w);},
1043 SkIntToScalar(2), SkIntToScalar(4)); 1108 SkIntToScalar(2), SkIntToScalar(4));
1044 test_stroke_param<SkPath, SkPaint::Join>( 1109 test_stroke_param<SkPath, SkPaint::Join>(
1045 reporter, path, 1110 reporter, path,
1046 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);}, 1111 [](SkPaint* p, SkPaint::Join j) { p->setStrokeJoin(j);},
1047 SkPaint::kMiter_Join, SkPaint::kRound_Join); 1112 SkPaint::kMiter_Join, SkPaint::kRound_Join);
1048 test_stroke_cap(reporter, path); 1113 test_stroke_cap(reporter, path);
1049 test_miter_limit(reporter, path); 1114 test_miter_limit(reporter, path);
1050 test_unknown_path_effect(reporter, path); 1115 test_unknown_path_effect(reporter, path);
1051 test_path_effect_makes_empty_shape(reporter, path); 1116 test_path_effect_makes_empty_shape(reporter, path);
1117 test_path_effect_fails(reporter, path);
1052 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok e); 1118 test_make_hairline_path_effect(reporter, path, testPath.fIsRRectForStrok e);
1053 1119
1054 SkPaint fillPaint; 1120 SkPaint fillPaint;
1055 TestCase fillPathCase(path, fillPaint, reporter); 1121 TestCase fillPathCase(path, fillPaint, reporter);
1056 SkRRect rrect; 1122 SkRRect rrect;
1057 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill == 1123 REPORTER_ASSERT(reporter, testPath.fIsRRectForFill ==
1058 fillPathCase.baseShape().asRRect(&rrect, nullp tr, nullptr)); 1124 fillPathCase.baseShape().asRRect(&rrect, nullp tr, nullptr));
1059 if (testPath.fIsRRectForFill) { 1125 if (testPath.fIsRRectForFill) {
1060 TestCase fillPathCase2(path, fillPaint, reporter); 1126 TestCase fillPathCase2(path, fillPaint, reporter);
1061 REPORTER_ASSERT(reporter, rrect == testPath.fRRect); 1127 REPORTER_ASSERT(reporter, rrect == testPath.fRRect);
(...skipping 15 matching lines...) Expand all
1077 } 1143 }
1078 } 1144 }
1079 1145
1080 // Test a volatile empty path. 1146 // Test a volatile empty path.
1081 test_volatile_path(reporter, SkPath(), true); 1147 test_volatile_path(reporter, SkPath(), true);
1082 1148
1083 test_empty_shape(reporter); 1149 test_empty_shape(reporter);
1084 } 1150 }
1085 1151
1086 #endif 1152 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrShape.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698