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

Side by Side Diff: tests/ClipStackTest.cpp

Issue 2246113002: Convert GrAppliedClip interface to builder style (Closed) Base URL: https://skia.googlesource.com/skia.git@fixstencilpath
Patch Set: Convert GrAppliedClip interface to builder style Created 4 years, 4 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/GrReducedClip.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 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 "Test.h" 8 #include "Test.h"
9 #include "SkClipStack.h" 9 #include "SkClipStack.h"
10 #include "SkPath.h" 10 #include "SkPath.h"
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 stack->clipEmpty(); 909 stack->clipEmpty();
910 break; 910 break;
911 } 911 }
912 } 912 }
913 913
914 static void test_reduced_clip_stack(skiatest::Reporter* reporter) { 914 static void test_reduced_clip_stack(skiatest::Reporter* reporter) {
915 // We construct random clip stacks, reduce them, and then rasterize both ver sions to verify that 915 // We construct random clip stacks, reduce them, and then rasterize both ver sions to verify that
916 // they are equal. 916 // they are equal.
917 917
918 // All the clip elements will be contained within these bounds. 918 // All the clip elements will be contained within these bounds.
919 static const SkRect kBounds = SkRect::MakeWH(100, 100); 919 static const SkIRect kIBounds = SkIRect::MakeWH(100, 100);
920 static const SkRect kBounds = SkRect::Make(kIBounds);
920 921
921 enum { 922 enum {
922 kNumTests = 250, 923 kNumTests = 250,
923 kMinElemsPerTest = 1, 924 kMinElemsPerTest = 1,
924 kMaxElemsPerTest = 50, 925 kMaxElemsPerTest = 50,
925 }; 926 };
926 927
927 // min/max size of a clip element as a fraction of kBounds. 928 // min/max size of a clip element as a fraction of kBounds.
928 static const SkScalar kMinElemSizeFrac = SK_Scalar1 / 5; 929 static const SkScalar kMinElemSizeFrac = SK_Scalar1 / 5;
929 static const SkScalar kMaxElemSizeFrac = SK_Scalar1; 930 static const SkScalar kMaxElemSizeFrac = SK_Scalar1;
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 1009
1009 // Get the reduced version of the stack. 1010 // Get the reduced version of the stack.
1010 SkRect queryBounds = kBounds; 1011 SkRect queryBounds = kBounds;
1011 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); 1012 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2);
1012 const GrReducedClip reduced(stack, queryBounds); 1013 const GrReducedClip reduced(stack, queryBounds);
1013 1014
1014 REPORTER_ASSERT_MESSAGE(reporter, SkClipStack::kInvalidGenID != reduced. genID(), 1015 REPORTER_ASSERT_MESSAGE(reporter, SkClipStack::kInvalidGenID != reduced. genID(),
1015 testCase.c_str()); 1016 testCase.c_str());
1016 1017
1017 if (!reduced.elements().isEmpty()) { 1018 if (!reduced.elements().isEmpty()) {
1019 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testCase.c_s tr());
1018 SkRect stackBounds; 1020 SkRect stackBounds;
1019 SkClipStack::BoundsType stackBoundsType; 1021 SkClipStack::BoundsType stackBoundsType;
1020 stack.getBounds(&stackBounds, &stackBoundsType); 1022 stack.getBounds(&stackBounds, &stackBoundsType);
1021 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { 1023 if (SkClipStack::kNormal_BoundsType == stackBoundsType) {
1022 // Unless GrReducedClip starts doing some heroic tightening of t he clip bounds, this 1024 // Unless GrReducedClip starts doing some heroic tightening of t he clip bounds, this
1023 // will be true since the stack bounds are completely contained inside the query. 1025 // will be true since the stack bounds are completely contained inside the query.
1024 REPORTER_ASSERT_MESSAGE(reporter, GrClip::IsInsideClip(reduced.i Bounds(), stackBounds), 1026 REPORTER_ASSERT_MESSAGE(reporter, GrClip::IsInsideClip(reduced.i bounds(), stackBounds),
1025 testCase.c_str()); 1027 testCase.c_str());
1026 } 1028 }
1027 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == doAA, test Case.c_str()); 1029 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == doAA, test Case.c_str());
1028 } 1030 }
1029 1031
1030 // Build a new clip stack based on the reduced clip elements 1032 // Build a new clip stack based on the reduced clip elements
1031 SkClipStack reducedStack; 1033 SkClipStack reducedStack;
1032 if (GrReducedClip::InitialState::kAllOut == reduced.initialState()) { 1034 if (GrReducedClip::InitialState::kAllOut == reduced.initialState()) {
1033 // whether the result is bounded or not, the whole plane should star t outside the clip. 1035 // whether the result is bounded or not, the whole plane should star t outside the clip.
1034 reducedStack.clipEmpty(); 1036 reducedStack.clipEmpty();
1035 } 1037 }
1036 for (ElementList::Iter iter(reduced.elements()); iter.get(); iter.next() ) { 1038 for (ElementList::Iter iter(reduced.elements()); iter.get(); iter.next() ) {
1037 add_elem_to_stack(*iter.get(), &reducedStack); 1039 add_elem_to_stack(*iter.get(), &reducedStack);
1038 } 1040 }
1039 1041
1042 SkIRect ibounds = reduced.hasIBounds() ? reduced.ibounds() : kIBounds;
1043
1040 // GrReducedClipStack assumes that the final result is clipped to the re turned bounds 1044 // GrReducedClipStack assumes that the final result is clipped to the re turned bounds
1041 reducedStack.clipDevRect(reduced.iBounds(), SkRegion::kIntersect_Op); 1045 reducedStack.clipDevRect(ibounds, SkRegion::kIntersect_Op);
1042 stack.clipDevRect(reduced.iBounds(), SkRegion::kIntersect_Op); 1046 stack.clipDevRect(ibounds, SkRegion::kIntersect_Op);
1043 1047
1044 // convert both the original stack and reduced stack to SkRegions and se e if they're equal 1048 // convert both the original stack and reduced stack to SkRegions and se e if they're equal
1045 SkRegion region; 1049 SkRegion region;
1046 set_region_to_stack(stack, reduced.iBounds(), &region); 1050 set_region_to_stack(stack, ibounds, &region);
1047 1051
1048 SkRegion reducedRegion; 1052 SkRegion reducedRegion;
1049 set_region_to_stack(reducedStack, reduced.iBounds(), &reducedRegion); 1053 set_region_to_stack(reducedStack, ibounds, &reducedRegion);
1050 1054
1051 REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_st r()); 1055 REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_st r());
1052 } 1056 }
1053 } 1057 }
1054 1058
1055 #ifdef SK_BUILD_FOR_WIN 1059 #ifdef SK_BUILD_FOR_WIN
1056 #define SUPPRESS_VISIBILITY_WARNING 1060 #define SUPPRESS_VISIBILITY_WARNING
1057 #else 1061 #else
1058 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) 1062 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
1059 #endif 1063 #endif
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1144 #undef IXYWH 1148 #undef IXYWH
1145 1149
1146 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { 1150 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) {
1147 const GrReducedClip reduced(stack, testCases[i].testBounds); 1151 const GrReducedClip reduced(stack, testCases[i].testBounds);
1148 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i] .reducedClipCount); 1152 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i] .reducedClipCount);
1149 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount ); 1153 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount );
1150 REPORTER_ASSERT(reporter, reduced.genID() == testCases[i].reducedGen ID); 1154 REPORTER_ASSERT(reporter, reduced.genID() == testCases[i].reducedGen ID);
1151 SkASSERT(reduced.genID() == testCases[i].reducedGenID); 1155 SkASSERT(reduced.genID() == testCases[i].reducedGenID);
1152 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini tialState); 1156 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini tialState);
1153 SkASSERT(reduced.initialState() == testCases[i].initialState); 1157 SkASSERT(reduced.initialState() == testCases[i].initialState);
1154 REPORTER_ASSERT(reporter, reduced.iBounds() == testCases[i].clipIRec t); 1158 REPORTER_ASSERT(reporter, reduced.hasIBounds());
1155 SkASSERT(reduced.iBounds() == testCases[i].clipIRect); 1159 SkASSERT(reduced.hasIBounds());
1160 REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRec t);
1161 SkASSERT(reduced.ibounds() == testCases[i].clipIRect);
1156 } 1162 }
1157 } 1163 }
1158 } 1164 }
1159 1165
1160 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { 1166 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) {
1161 SkClipStack stack; 1167 SkClipStack stack;
1162 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op); 1168 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op);
1163 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op); 1169 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op);
1164 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); 1170 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
1165 1171
(...skipping 24 matching lines...) Expand all
1190 switch (expectedMethod) { 1196 switch (expectedMethod) {
1191 case ClipMethod::kSkipDraw: 1197 case ClipMethod::kSkipDraw:
1192 SkASSERT(0 == numExpectedElems); 1198 SkASSERT(0 == numExpectedElems);
1193 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str()); 1199 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str());
1194 REPORTER_ASSERT_MESSAGE(reporter, 1200 REPORTER_ASSERT_MESSAGE(reporter,
1195 GrReducedClip::InitialState::kAllOut == redu ced.initialState(), 1201 GrReducedClip::InitialState::kAllOut == redu ced.initialState(),
1196 testName.c_str()); 1202 testName.c_str());
1197 return; 1203 return;
1198 case ClipMethod::kIgnoreClip: 1204 case ClipMethod::kIgnoreClip:
1199 SkASSERT(0 == numExpectedElems); 1205 SkASSERT(0 == numExpectedElems);
1200 REPORTER_ASSERT_MESSAGE(reporter, GrClip::IsInsideClip(reduced.iBoun ds(), queryBounds), 1206 REPORTER_ASSERT_MESSAGE(reporter,
1207 !reduced.hasIBounds() ||
1208 GrClip::IsInsideClip(reduced.ibounds(), quer yBounds),
1201 testName.c_str()); 1209 testName.c_str());
1202 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str()); 1210 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str());
1203 REPORTER_ASSERT_MESSAGE(reporter, 1211 REPORTER_ASSERT_MESSAGE(reporter,
1204 GrReducedClip::InitialState::kAllIn == reduc ed.initialState(), 1212 GrReducedClip::InitialState::kAllIn == reduc ed.initialState(),
1205 testName.c_str()); 1213 testName.c_str());
1206 return; 1214 return;
1207 case ClipMethod::kScissor: { 1215 case ClipMethod::kScissor: {
1208 SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType); 1216 SkASSERT(SkClipStack::kNormal_BoundsType == stackBoundsType);
1209 SkASSERT(0 == numExpectedElems); 1217 SkASSERT(0 == numExpectedElems);
1210 SkIRect expectedScissor; 1218 SkIRect expectedScissor;
1211 stackBounds.round(&expectedScissor); 1219 stackBounds.round(&expectedScissor);
1212 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str()); 1220 REPORTER_ASSERT_MESSAGE(reporter, reduced.elements().isEmpty(), test Name.c_str());
1213 REPORTER_ASSERT_MESSAGE(reporter, expectedScissor == reduced.iBounds (), 1221 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testName.c_s tr());
1222 REPORTER_ASSERT_MESSAGE(reporter, expectedScissor == reduced.ibounds (),
1214 testName.c_str()); 1223 testName.c_str());
1215 REPORTER_ASSERT_MESSAGE(reporter, 1224 REPORTER_ASSERT_MESSAGE(reporter,
1216 GrReducedClip::InitialState::kAllIn == reduc ed.initialState(), 1225 GrReducedClip::InitialState::kAllIn == reduc ed.initialState(),
1217 testName.c_str()); 1226 testName.c_str());
1218 return; 1227 return;
1219 } 1228 }
1220 case ClipMethod::kAAElements: { 1229 case ClipMethod::kAAElements: {
1221 SkIRect expectedClipIBounds = GrClip::GetPixelIBounds(queryBounds); 1230 SkIRect expectedClipIBounds = GrClip::GetPixelIBounds(queryBounds);
1222 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { 1231 if (SkClipStack::kNormal_BoundsType == stackBoundsType) {
1223 SkAssertResult(expectedClipIBounds.intersect(GrClip::GetPixelIBo unds(stackBounds))); 1232 SkAssertResult(expectedClipIBounds.intersect(GrClip::GetPixelIBo unds(stackBounds)));
1224 } 1233 }
1225 REPORTER_ASSERT_MESSAGE(reporter, numExpectedElems == reduced.elemen ts().count(), 1234 REPORTER_ASSERT_MESSAGE(reporter, numExpectedElems == reduced.elemen ts().count(),
1226 testName.c_str()); 1235 testName.c_str());
1227 REPORTER_ASSERT_MESSAGE(reporter, expectedClipIBounds == reduced.iBo unds(), 1236 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testName.c_s tr());
1237 REPORTER_ASSERT_MESSAGE(reporter, expectedClipIBounds == reduced.ibo unds(),
1228 testName.c_str()); 1238 testName.c_str());
1229 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == !reduced.e lements().isEmpty(), 1239 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == !reduced.e lements().isEmpty(),
1230 testName.c_str()); 1240 testName.c_str());
1231 break; 1241 break;
1232 } 1242 }
1233 } 1243 }
1234 } 1244 }
1235 1245
1236 static void test_reduced_clip_stack_aa(skiatest::Reporter* reporter) { 1246 static void test_reduced_clip_stack_aa(skiatest::Reporter* reporter) {
1237 constexpr SkScalar IL = 2, IT = 1, IR = 6, IB = 7; // Pixel aligned rect. 1247 constexpr SkScalar IL = 2, IT = 1, IR = 6, IB = 7; // Pixel aligned rect.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 test_path_replace(reporter); 1376 test_path_replace(reporter);
1367 test_quickContains(reporter); 1377 test_quickContains(reporter);
1368 test_invfill_diff_bug(reporter); 1378 test_invfill_diff_bug(reporter);
1369 #if SK_SUPPORT_GPU 1379 #if SK_SUPPORT_GPU
1370 test_reduced_clip_stack(reporter); 1380 test_reduced_clip_stack(reporter);
1371 test_reduced_clip_stack_genid(reporter); 1381 test_reduced_clip_stack_genid(reporter);
1372 test_reduced_clip_stack_no_aa_crash(reporter); 1382 test_reduced_clip_stack_no_aa_crash(reporter);
1373 test_reduced_clip_stack_aa(reporter); 1383 test_reduced_clip_stack_aa(reporter);
1374 #endif 1384 #endif
1375 } 1385 }
OLDNEW
« no previous file with comments | « src/gpu/GrReducedClip.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698