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

Side by Side Diff: tests/GrShapeTest.cpp

Issue 2058343002: Make large array of GrShapes in test code heap allocated (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « 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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 case SkRRect::kRect_Type: 1035 case SkRRect::kRect_Type:
1036 return (s + 1) & 0b110; 1036 return (s + 1) & 0b110;
1037 case SkRRect::kOval_Type: 1037 case SkRRect::kOval_Type:
1038 return s & 0b110; 1038 return s & 0b110;
1039 default: 1039 default:
1040 return s; 1040 return s;
1041 } 1041 }
1042 } 1042 }
1043 1043
1044 void test_rrect(skiatest::Reporter* r, const SkRRect& rrect) { 1044 void test_rrect(skiatest::Reporter* r, const SkRRect& rrect) {
1045 enum { 1045 enum Style {
1046 kFill, 1046 kFill,
1047 kStroke, 1047 kStroke,
1048 kHairline, 1048 kHairline,
1049 kStrokeAndFill 1049 kStrokeAndFill
1050 }; 1050 };
1051 1051
1052 // SkStrokeRec has no default cons., so init with kFill before calling the s etters below. 1052 // SkStrokeRec has no default cons., so init with kFill before calling the s etters below.
1053 SkStrokeRec strokeRecs[4] { SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill _InitStyle, 1053 SkStrokeRec strokeRecs[4] { SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill _InitStyle,
1054 SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill _InitStyle}; 1054 SkStrokeRec::kFill_InitStyle, SkStrokeRec::kFill _InitStyle};
1055 strokeRecs[kFill].setFillStyle(); 1055 strokeRecs[kFill].setFillStyle();
1056 strokeRecs[kStroke].setStrokeStyle(2.f); 1056 strokeRecs[kStroke].setStrokeStyle(2.f);
1057 strokeRecs[kHairline].setHairlineStyle(); 1057 strokeRecs[kHairline].setHairlineStyle();
1058 strokeRecs[kStrokeAndFill].setStrokeStyle(3.f, true); 1058 strokeRecs[kStrokeAndFill].setStrokeStyle(3.f, true);
1059 sk_sp<SkPathEffect> dashEffect = make_dash(); 1059 sk_sp<SkPathEffect> dashEffect = make_dash();
1060 1060
1061 GrShape shapes[2 /* inverted */] 1061 static constexpr Style kStyleCnt = static_cast<Style>(SK_ARRAY_COUNT(strokeR ecs));
1062 [2 /* direction */] 1062
1063 [8 /* start index */] 1063 auto index = [](bool inverted,
1064 [SK_ARRAY_COUNT(strokeRecs)] 1064 SkPath::Direction dir,
1065 [2 /* dash */]; 1065 unsigned start,
1066 for (int inverted = 0; inverted < 2; ++inverted) { 1066 Style style,
1067 for (int ccw = 0; ccw < 2; ++ccw) { 1067 bool dash) -> int {
1068 for (unsigned s = 0; s < 8; ++s) { 1068 return inverted * (2 * 8 * kStyleCnt * 2) +
1069 for (size_t style = 0; style < SK_ARRAY_COUNT(strokeRecs); ++sty le) { 1069 dir * ( 8 * kStyleCnt * 2) +
1070 for (int dash = 0; dash < 2; ++dash) { 1070 start * ( kStyleCnt * 2) +
1071 SkPath::Direction dir = ccw ? SkPath::kCCW_Direction 1071 style * ( 2) +
1072 : SkPath::kCW_Direction; 1072 dash;
1073 };
1074 static const SkPath::Direction kSecondDirection = static_cast<SkPath::Direct ion>(1);
1075 const int cnt = index(true, kSecondDirection, 7, static_cast<Style>(kStyleCn t - 1), true) + 1;
1076 SkAutoTArray<GrShape> shapes(cnt);
1077 for (bool inverted : {false, true}) {
1078 for (SkPath::Direction dir : {SkPath::kCW_Direction, SkPath::kCCW_Direct ion}) {
1079 for (unsigned start = 0; start < 8; ++start) {
1080 for (Style style : {kFill, kStroke, kHairline, kStrokeAndFill}) {
1081 for (bool dash : {false, true}) {
1073 SkPathEffect* pe = dash ? dashEffect.get() : nullptr; 1082 SkPathEffect* pe = dash ? dashEffect.get() : nullptr;
1074 shapes[inverted][ccw][s][style][dash] = 1083 shapes[index(inverted, dir, start, style, dash)] =
1075 GrShape(rrect, dir, s, SkToBool(inverted), 1084 GrShape(rrect, dir, start, SkToBool(inverted),
1076 GrStyle(strokeRecs[style], pe)); 1085 GrStyle(strokeRecs[style], pe));
1077 } 1086 }
1078 } 1087 }
1079 } 1088 }
1080 } 1089 }
1081 } 1090 }
1082 1091
1083 const GrShape& exampleFillCase = shapes[0][0][0][kFill][0]; 1092 static const SkPath::Direction kDir = SkPath::kCW_Direction; // arbitrary
1093 const GrShape& exampleFillCase = shapes[index(false, kDir, 0, kFill, false)] ;
1084 Key exampleFillCaseKey; 1094 Key exampleFillCaseKey;
1085 make_key(&exampleFillCaseKey, exampleFillCase); 1095 make_key(&exampleFillCaseKey, exampleFillCase);
1086 1096
1087 const GrShape& exampleStrokeAndFillCase = shapes[0][0][0][kStrokeAndFill][0] ; 1097 const GrShape& exampleStrokeAndFillCase = shapes[index(false, kDir, 0, kStro keAndFill, false)];
1088 Key exampleStrokeAndFillCaseKey; 1098 Key exampleStrokeAndFillCaseKey;
1089 make_key(&exampleStrokeAndFillCaseKey, exampleStrokeAndFillCase); 1099 make_key(&exampleStrokeAndFillCaseKey, exampleStrokeAndFillCase);
1090 1100
1091 const GrShape& exampleInvFillCase = shapes[1][0][0][kFill][0]; 1101 const GrShape& exampleInvFillCase = shapes[index(true, kDir, 0, kFill, false )];
1092 Key exampleInvFillCaseKey; 1102 Key exampleInvFillCaseKey;
1093 make_key(&exampleInvFillCaseKey, exampleInvFillCase); 1103 make_key(&exampleInvFillCaseKey, exampleInvFillCase);
1094 1104
1095 const GrShape& exampleInvStrokeAndFillCase = shapes[1][0][0][kStrokeAndFill] [0]; 1105 const GrShape& exampleInvStrokeAndFillCase =
1106 shapes[index(true, kDir, 0, kStrokeAndFill, false)];
1096 Key exampleInvStrokeAndFillCaseKey; 1107 Key exampleInvStrokeAndFillCaseKey;
1097 make_key(&exampleInvStrokeAndFillCaseKey, exampleInvStrokeAndFillCase); 1108 make_key(&exampleInvStrokeAndFillCaseKey, exampleInvStrokeAndFillCase);
1098 1109
1099 const GrShape& exampleStrokeCase = shapes[0][0][0][kStroke][0]; 1110 const GrShape& exampleStrokeCase = shapes[index(false, kDir, 0, kStroke, fal se)];
1100 Key exampleStrokeCaseKey; 1111 Key exampleStrokeCaseKey;
1101 make_key(&exampleStrokeCaseKey, exampleStrokeCase); 1112 make_key(&exampleStrokeCaseKey, exampleStrokeCase);
1102 1113
1103 const GrShape& exampleHairlineCase = shapes[0][0][0][kHairline][0]; 1114 const GrShape& exampleHairlineCase = shapes[index(false, kDir, 0, kHairline, false)];
1104 Key exampleHairlineCaseKey; 1115 Key exampleHairlineCaseKey;
1105 make_key(&exampleHairlineCaseKey, exampleHairlineCase); 1116 make_key(&exampleHairlineCaseKey, exampleHairlineCase);
1106 1117
1107 // These are dummy initializations to suppress warnings. 1118 // These are dummy initializations to suppress warnings.
1108 SkRRect rr = SkRRect::MakeEmpty(); 1119 SkRRect queryRR = SkRRect::MakeEmpty();
1109 SkPath::Direction dir = SkPath::kCW_Direction; 1120 SkPath::Direction queryDir = SkPath::kCW_Direction;
1110 unsigned start = ~0U; 1121 unsigned queryStart = ~0U;
1111 bool inv = true; 1122 bool queryInverted = true;
1112 1123
1113 REPORTER_ASSERT(r, exampleFillCase.asRRect(&rr, &dir, &start, &inv)); 1124 REPORTER_ASSERT(r, exampleFillCase.asRRect(&queryRR, &queryDir, &queryStart, &queryInverted));
1114 REPORTER_ASSERT(r, rr == rrect); 1125 REPORTER_ASSERT(r, queryRR == rrect);
1115 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1126 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1116 REPORTER_ASSERT(r, 0 == start); 1127 REPORTER_ASSERT(r, 0 == queryStart);
1117 REPORTER_ASSERT(r, !inv); 1128 REPORTER_ASSERT(r, !queryInverted);
1118 1129
1119 REPORTER_ASSERT(r, exampleInvFillCase.asRRect(&rr, &dir, &start, &inv)); 1130 REPORTER_ASSERT(r, exampleInvFillCase.asRRect(&queryRR, &queryDir, &querySta rt,
1120 REPORTER_ASSERT(r, rr == rrect); 1131 &queryInverted));
1121 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1132 REPORTER_ASSERT(r, queryRR == rrect);
1122 REPORTER_ASSERT(r, 0 == start); 1133 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1123 REPORTER_ASSERT(r, inv); 1134 REPORTER_ASSERT(r, 0 == queryStart);
1135 REPORTER_ASSERT(r, queryInverted);
1124 1136
1125 REPORTER_ASSERT(r, exampleStrokeAndFillCase.asRRect(&rr, &dir, &start, &inv) ); 1137 REPORTER_ASSERT(r, exampleStrokeAndFillCase.asRRect(&queryRR, &queryDir, &qu eryStart,
1126 REPORTER_ASSERT(r, rr == rrect); 1138 &queryInverted));
1127 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1139 REPORTER_ASSERT(r, queryRR == rrect);
1128 REPORTER_ASSERT(r, 0 == start); 1140 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1129 REPORTER_ASSERT(r, !inv); 1141 REPORTER_ASSERT(r, 0 == queryStart);
1142 REPORTER_ASSERT(r, !queryInverted);
1130 1143
1131 REPORTER_ASSERT(r, exampleInvStrokeAndFillCase.asRRect(&rr, &dir, &start, &i nv)); 1144 REPORTER_ASSERT(r, exampleInvStrokeAndFillCase.asRRect(&queryRR, &queryDir, &queryStart,
1132 REPORTER_ASSERT(r, rr == rrect); 1145 &queryInverted));
1133 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1146 REPORTER_ASSERT(r, queryRR == rrect);
1134 REPORTER_ASSERT(r, 0 == start); 1147 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1135 REPORTER_ASSERT(r, inv); 1148 REPORTER_ASSERT(r, 0 == queryStart);
1149 REPORTER_ASSERT(r, queryInverted);
1136 1150
1137 REPORTER_ASSERT(r, exampleHairlineCase.asRRect(&rr, &dir, &start, &inv)); 1151 REPORTER_ASSERT(r, exampleHairlineCase.asRRect(&queryRR, &queryDir, &querySt art,
1138 REPORTER_ASSERT(r, rr == rrect); 1152 &queryInverted));
1139 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1153 REPORTER_ASSERT(r, queryRR == rrect);
1140 REPORTER_ASSERT(r, 0 == start); 1154 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1141 REPORTER_ASSERT(r, !inv); 1155 REPORTER_ASSERT(r, 0 == queryStart);
1156 REPORTER_ASSERT(r, !queryInverted);
1142 1157
1143 REPORTER_ASSERT(r, exampleStrokeCase.asRRect(&rr, &dir, &start, &inv)); 1158 REPORTER_ASSERT(r, exampleStrokeCase.asRRect(&queryRR, &queryDir, &queryStar t, &queryInverted));
1144 REPORTER_ASSERT(r, rr == rrect); 1159 REPORTER_ASSERT(r, queryRR == rrect);
1145 REPORTER_ASSERT(r, SkPath::kCW_Direction == dir); 1160 REPORTER_ASSERT(r, SkPath::kCW_Direction == queryDir);
1146 REPORTER_ASSERT(r, 0 == start); 1161 REPORTER_ASSERT(r, 0 == queryStart);
1147 REPORTER_ASSERT(r, !inv); 1162 REPORTER_ASSERT(r, !queryInverted);
1148 1163
1149 // Remember that the key reflects the geometry before styling is applied. 1164 // Remember that the key reflects the geometry before styling is applied.
1150 REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvFillCaseKey); 1165 REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvFillCaseKey);
1151 REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeAndFillCaseKey); 1166 REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeAndFillCaseKey);
1152 REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeAndFillCaseKey); 1167 REPORTER_ASSERT(r, exampleFillCaseKey != exampleInvStrokeAndFillCaseKey);
1153 REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeCaseKey); 1168 REPORTER_ASSERT(r, exampleFillCaseKey == exampleStrokeCaseKey);
1154 REPORTER_ASSERT(r, exampleFillCaseKey == exampleHairlineCaseKey); 1169 REPORTER_ASSERT(r, exampleFillCaseKey == exampleHairlineCaseKey);
1155 REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvFillCaseKey); 1170 REPORTER_ASSERT(r, exampleInvStrokeAndFillCaseKey == exampleInvFillCaseKey);
1156 1171
1157 for (int inverted = 0; inverted < 2; ++inverted) { 1172 for (bool inverted : {false, true}) {
1158 for (int ccw = 0; ccw < 2; ++ccw) { 1173 for (SkPath::Direction dir : {SkPath::kCW_Direction, SkPath::kCCW_Direct ion}) {
1159 for (unsigned s = 0; s < 8; ++s) { 1174 for (unsigned start = 0; start < 8; ++start) {
1160 for (int dash = 0; dash < 2; ++dash) { 1175 for (bool dash : {false, true}) {
1161 const GrShape& fillCase = shapes[inverted][ccw][s][kFill][da sh]; 1176 const GrShape& fillCase = shapes[index(inverted, dir, start, kFill, dash)];
1162 Key fillCaseKey; 1177 Key fillCaseKey;
1163 make_key(&fillCaseKey, fillCase); 1178 make_key(&fillCaseKey, fillCase);
1164 1179
1165 const GrShape& strokeAndFillCase = 1180 const GrShape& strokeAndFillCase = shapes[index(inverted, di r, start,
1166 shapes[inverted][ccw][s][kStrokeAndFill][dash]; 1181 kStrokeAndFi ll, dash)];
1167 Key strokeAndFillCaseKey; 1182 Key strokeAndFillCaseKey;
1168 make_key(&strokeAndFillCaseKey, strokeAndFillCase); 1183 make_key(&strokeAndFillCaseKey, strokeAndFillCase);
1169 1184
1170 // Both fill and stroke-and-fill shapes must respect the inv erseness and both 1185 // Both fill and stroke-and-fill shapes must respect the inv erseness and both
1171 // ignore dashing. 1186 // ignore dashing.
1172 REPORTER_ASSERT(r, !fillCase.style().pathEffect()); 1187 REPORTER_ASSERT(r, !fillCase.style().pathEffect());
1173 REPORTER_ASSERT(r, !strokeAndFillCase.style().pathEffect()); 1188 REPORTER_ASSERT(r, !strokeAndFillCase.style().pathEffect());
1174 TestCase a(fillCase, r); 1189 TestCase a(fillCase, r);
1175 TestCase b(inverted ? exampleInvFillCase : exampleFillCase, r); 1190 TestCase b(inverted ? exampleInvFillCase : exampleFillCase, r);
1176 TestCase c(strokeAndFillCase, r); 1191 TestCase c(strokeAndFillCase, r);
1177 TestCase d(inverted ? exampleInvStrokeAndFillCase 1192 TestCase d(inverted ? exampleInvStrokeAndFillCase
1178 : exampleStrokeAndFillCase, r); 1193 : exampleStrokeAndFillCase, r);
1179 a.compare(r, b, TestCase::kAllSame_ComparisonExpecation); 1194 a.compare(r, b, TestCase::kAllSame_ComparisonExpecation);
1180 c.compare(r, d, TestCase::kAllSame_ComparisonExpecation); 1195 c.compare(r, d, TestCase::kAllSame_ComparisonExpecation);
1181 1196
1182 const GrShape& strokeCase = shapes[inverted][ccw][s][kStroke ][dash]; 1197 const GrShape& strokeCase = shapes[index(inverted, dir, star t, kStroke, dash)];
1183 const GrShape& hairlineCase = shapes[inverted][ccw][s][kHair line][dash]; 1198 const GrShape& hairlineCase = shapes[index(inverted, dir, st art, kHairline,
1199 dash)];
1184 1200
1185 TestCase e(strokeCase, r); 1201 TestCase e(strokeCase, r);
1186 TestCase f(exampleStrokeCase, r); 1202 TestCase f(exampleStrokeCase, r);
1187 TestCase g(hairlineCase, r); 1203 TestCase g(hairlineCase, r);
1188 TestCase h(exampleHairlineCase, r); 1204 TestCase h(exampleHairlineCase, r);
1189 1205
1190 // Both hairline and stroke shapes must respect the dashing and both 1206 // Both hairline and stroke shapes must respect the dashing and both
1191 // ignore inverseness. 1207 // ignore inverseness.
1192 if (dash) { 1208 if (dash) {
1193 unsigned expectedStart = canonicalize_rrect_start(s, rre ct); 1209 unsigned expectedStart = canonicalize_rrect_start(start, rrect);
1194 REPORTER_ASSERT(r, strokeCase.style().pathEffect()); 1210 REPORTER_ASSERT(r, strokeCase.style().pathEffect());
1195 REPORTER_ASSERT(r, hairlineCase.style().pathEffect()); 1211 REPORTER_ASSERT(r, hairlineCase.style().pathEffect());
1196 1212
1197 REPORTER_ASSERT(r, strokeCase.asRRect(&rr, &dir, &start, &inv)); 1213 REPORTER_ASSERT(r, strokeCase.asRRect(&queryRR, &queryDi r, &queryStart,
1198 REPORTER_ASSERT(r, rr == rrect); 1214 &queryInverted));
1199 REPORTER_ASSERT(r, (SkPath::kCCW_Direction == dir) == cc w); 1215 REPORTER_ASSERT(r, queryRR == rrect);
1200 REPORTER_ASSERT(r, start == expectedStart); 1216 REPORTER_ASSERT(r, queryDir == dir);
1201 REPORTER_ASSERT(r, !inv); 1217 REPORTER_ASSERT(r, queryStart == expectedStart);
1202 REPORTER_ASSERT(r, hairlineCase.asRRect(&rr, &dir, &star t, &inv)); 1218 REPORTER_ASSERT(r, !queryInverted);
1203 REPORTER_ASSERT(r, rr == rrect); 1219 REPORTER_ASSERT(r, hairlineCase.asRRect(&queryRR, &query Dir, &queryStart,
1204 REPORTER_ASSERT(r, (SkPath::kCCW_Direction == dir) == cc w); 1220 &queryInverted)) ;
1205 REPORTER_ASSERT(r, start == expectedStart); 1221 REPORTER_ASSERT(r, queryRR == rrect);
1206 REPORTER_ASSERT(r, !inv); 1222 REPORTER_ASSERT(r, queryDir == dir);
1223 REPORTER_ASSERT(r, queryStart == expectedStart);
1224 REPORTER_ASSERT(r, !queryInverted);
1207 1225
1208 // The pre-style case for the dash will match the non-da sh example iff the 1226 // The pre-style case for the dash will match the non-da sh example iff the
1209 // dir and start match (dir=cw, start=0). 1227 // dir and start match (dir=cw, start=0).
1210 if (0 == expectedStart && 0 == ccw) { 1228 if (0 == expectedStart && SkPath::kCW_Direction == dir) {
1211 e.compare(r, f, TestCase::kSameUpToPE_ComparisonExpe cation); 1229 e.compare(r, f, TestCase::kSameUpToPE_ComparisonExpe cation);
1212 g.compare(r, h, TestCase::kSameUpToPE_ComparisonExpe cation); 1230 g.compare(r, h, TestCase::kSameUpToPE_ComparisonExpe cation);
1213 } else { 1231 } else {
1214 e.compare(r, f, TestCase::kAllDifferent_ComparisonEx pecation); 1232 e.compare(r, f, TestCase::kAllDifferent_ComparisonEx pecation);
1215 g.compare(r, h, TestCase::kAllDifferent_ComparisonEx pecation); 1233 g.compare(r, h, TestCase::kAllDifferent_ComparisonEx pecation);
1216 } 1234 }
1217 } else { 1235 } else {
1218 REPORTER_ASSERT(r, !strokeCase.style().pathEffect()); 1236 REPORTER_ASSERT(r, !strokeCase.style().pathEffect());
1219 REPORTER_ASSERT(r, !hairlineCase.style().pathEffect()); 1237 REPORTER_ASSERT(r, !hairlineCase.style().pathEffect());
1220 e.compare(r, f, TestCase::kAllSame_ComparisonExpecation) ; 1238 e.compare(r, f, TestCase::kAllSame_ComparisonExpecation) ;
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 } 1401 }
1384 } 1402 }
1385 1403
1386 // Test a volatile empty path. 1404 // Test a volatile empty path.
1387 test_volatile_path(reporter, SkPath(), true); 1405 test_volatile_path(reporter, SkPath(), true);
1388 1406
1389 test_empty_shape(reporter); 1407 test_empty_shape(reporter);
1390 } 1408 }
1391 1409
1392 #endif 1410 #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