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

Side by Side Diff: tests/ClipStackTest.cpp

Issue 2244223004: Make GrReducedClip's gen ID only apply to the element list (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: more improved testing 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 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 1000
1001 bool invert = r.nextBiasedBool(kFractionInverted); 1001 bool invert = r.nextBiasedBool(kFractionInverted);
1002 1002
1003 kElementFuncs[r.nextULessThan(SK_ARRAY_COUNT(kElementFuncs))](rect, invert, op, &stack, 1003 kElementFuncs[r.nextULessThan(SK_ARRAY_COUNT(kElementFuncs))](rect, invert, op, &stack,
1004 doAA); 1004 doAA);
1005 if (doSave) { 1005 if (doSave) {
1006 stack.save(); 1006 stack.save();
1007 } 1007 }
1008 } 1008 }
1009 1009
1010 // Zero the memory we will new the GrReducedClip into. This ensures the elements gen ID
1011 // will be kInvalidGenID if left uninitialized.
1012 SkAlignedSTStorage<1, GrReducedClip> storage;
1013 memset(storage.get(), 0, sizeof(GrReducedClip));
1014 GR_STATIC_ASSERT(0 == SkClipStack::kInvalidGenID);
1015
1010 // Get the reduced version of the stack. 1016 // Get the reduced version of the stack.
1011 SkRect queryBounds = kBounds; 1017 SkRect queryBounds = kBounds;
1012 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); 1018 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2);
1013 const GrReducedClip reduced(stack, queryBounds); 1019 const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, queryBounds);
1014 1020
1015 REPORTER_ASSERT_MESSAGE(reporter, SkClipStack::kInvalidGenID != reduced. genID(), 1021 REPORTER_ASSERT_MESSAGE(reporter,
1022 reduced->elements().isEmpty() ||
1023 SkClipStack::kInvalidGenID != reduced->elementsG enID(),
1016 testCase.c_str()); 1024 testCase.c_str());
1017 1025
1018 if (!reduced.elements().isEmpty()) { 1026 if (!reduced->elements().isEmpty()) {
1019 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testCase.c_s tr()); 1027 REPORTER_ASSERT_MESSAGE(reporter, reduced->hasIBounds(), testCase.c_ str());
1020 SkRect stackBounds; 1028 SkRect stackBounds;
1021 SkClipStack::BoundsType stackBoundsType; 1029 SkClipStack::BoundsType stackBoundsType;
1022 stack.getBounds(&stackBounds, &stackBoundsType); 1030 stack.getBounds(&stackBounds, &stackBoundsType);
1023 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { 1031 if (SkClipStack::kNormal_BoundsType == stackBoundsType) {
1024 // Unless GrReducedClip starts doing some heroic tightening of t he clip bounds, this 1032 // Unless GrReducedClip starts doing some heroic tightening of t he clip bounds, this
1025 // will be true since the stack bounds are completely contained inside the query. 1033 // will be true since the stack bounds are completely contained inside the query.
1026 REPORTER_ASSERT_MESSAGE(reporter, GrClip::IsInsideClip(reduced.i bounds(), stackBounds), 1034 REPORTER_ASSERT_MESSAGE(reporter,
1035 GrClip::IsInsideClip(reduced->ibounds(), stackBounds),
1027 testCase.c_str()); 1036 testCase.c_str());
1028 } 1037 }
1029 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == doAA, test Case.c_str()); 1038 REPORTER_ASSERT_MESSAGE(reporter, reduced->requiresAA() == doAA, tes tCase.c_str());
1030 } 1039 }
1031 1040
1032 // Build a new clip stack based on the reduced clip elements 1041 // Build a new clip stack based on the reduced clip elements
1033 SkClipStack reducedStack; 1042 SkClipStack reducedStack;
1034 if (GrReducedClip::InitialState::kAllOut == reduced.initialState()) { 1043 if (GrReducedClip::InitialState::kAllOut == reduced->initialState()) {
1035 // whether the result is bounded or not, the whole plane should star t outside the clip. 1044 // whether the result is bounded or not, the whole plane should star t outside the clip.
1036 reducedStack.clipEmpty(); 1045 reducedStack.clipEmpty();
1037 } 1046 }
1038 for (ElementList::Iter iter(reduced.elements()); iter.get(); iter.next() ) { 1047 for (ElementList::Iter iter(reduced->elements()); iter.get(); iter.next( )) {
1039 add_elem_to_stack(*iter.get(), &reducedStack); 1048 add_elem_to_stack(*iter.get(), &reducedStack);
1040 } 1049 }
1041 1050
1042 SkIRect ibounds = reduced.hasIBounds() ? reduced.ibounds() : kIBounds; 1051 SkIRect ibounds = reduced->hasIBounds() ? reduced->ibounds() : kIBounds;
1043 1052
1044 // GrReducedClipStack assumes that the final result is clipped to the re turned bounds 1053 // GrReducedClipStack assumes that the final result is clipped to the re turned bounds
1045 reducedStack.clipDevRect(ibounds, SkRegion::kIntersect_Op); 1054 reducedStack.clipDevRect(ibounds, SkRegion::kIntersect_Op);
1046 stack.clipDevRect(ibounds, SkRegion::kIntersect_Op); 1055 stack.clipDevRect(ibounds, SkRegion::kIntersect_Op);
1047 1056
1048 // convert both the original stack and reduced stack to SkRegions and se e if they're equal 1057 // convert both the original stack and reduced stack to SkRegions and se e if they're equal
1049 SkRegion region; 1058 SkRegion region;
1050 set_region_to_stack(stack, ibounds, &region); 1059 set_region_to_stack(stack, ibounds, &region);
1051 1060
1052 SkRegion reducedRegion; 1061 SkRegion reducedRegion;
1053 set_region_to_stack(reducedStack, ibounds, &reducedRegion); 1062 set_region_to_stack(reducedStack, ibounds, &reducedRegion);
1054 1063
1055 REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_st r()); 1064 REPORTER_ASSERT_MESSAGE(reporter, region == reducedRegion, testCase.c_st r());
1065
1066 reduced->~GrReducedClip();
1056 } 1067 }
1057 } 1068 }
1058 1069
1059 #ifdef SK_BUILD_FOR_WIN 1070 #ifdef SK_BUILD_FOR_WIN
1060 #define SUPPRESS_VISIBILITY_WARNING 1071 #define SUPPRESS_VISIBILITY_WARNING
1061 #else 1072 #else
1062 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) 1073 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
1063 #endif 1074 #endif
1064 1075
1065 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { 1076 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) {
1066 { 1077 {
1067 SkClipStack stack; 1078 SkClipStack stack;
1068 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O p, true); 1079 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O p, true);
1069 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3)) , SkRegion::kReplace_Op, true); 1080 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3)) , SkRegion::kReplace_Op, true);
1070 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); 1081 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
1071 1082
1072 const GrReducedClip reduced(stack, bounds); 1083 SkAlignedSTStorage<1, GrReducedClip> storage;
1084 memset(storage.get(), 0, sizeof(GrReducedClip));
1085 GR_STATIC_ASSERT(0 == SkClipStack::kInvalidGenID);
1086 const GrReducedClip* reduced = new (storage.get()) GrReducedClip(stack, bounds);
1073 1087
1074 REPORTER_ASSERT(reporter, reduced.elements().count() == 1); 1088 REPORTER_ASSERT(reporter, reduced->elements().count() == 1);
1075 // Clips will be cached based on the generation id. Make sure the gen id is valid. 1089 // Clips will be cached based on the generation id. Make sure the gen id is valid.
1076 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced.genID()) ; 1090 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced->element sGenID());
1091
1092 reduced->~GrReducedClip();
1077 } 1093 }
1078 { 1094 {
1079 SkClipStack stack; 1095 SkClipStack stack;
1080 1096
1081 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: 1097 // Create a clip with following 25.3, 25.3 boxes which are 25 apart:
1082 // A B 1098 // A B
1083 // C D 1099 // C D
1084 1100
1085 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3)) , SkRegion::kReplace_Op, true); 1101 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3)) , SkRegion::kReplace_Op, true);
1086 int32_t genIDA = stack.getTopmostGenID(); 1102 int32_t genIDA = stack.getTopmostGenID();
(...skipping 21 matching lines...) Expand all
1108 static const struct SUPPRESS_VISIBILITY_WARNING { 1124 static const struct SUPPRESS_VISIBILITY_WARNING {
1109 SkRect testBounds; 1125 SkRect testBounds;
1110 int reducedClipCount; 1126 int reducedClipCount;
1111 int32_t reducedGenID; 1127 int32_t reducedGenID;
1112 InitialState initialState; 1128 InitialState initialState;
1113 SkIRect clipIRect; 1129 SkIRect clipIRect;
1114 // parameter. 1130 // parameter.
1115 } testCases[] = { 1131 } testCases[] = {
1116 1132
1117 // Rect A. 1133 // Rect A.
1118 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip: :InitialState::kAllIn, IXYWH(0, 0, 25, 25) }, 1134 { XYWH(0, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip:: InitialState::kAllIn, IXYWH(0, 0, 25, 25) },
1119 { XYWH(0.1f, 0.1f, 25.1f, 25.1f), 0, SkClipStack::kWideOpenGenID, Gr ReducedClip::InitialState::kAllIn, IXYWH(0, 0, 26, 26) }, 1135 { XYWH(0.1f, 0.1f, 25.1f, 25.1f), 0, SkClipStack::kInvalidGenID, GrR educedClip::InitialState::kAllIn, IXYWH(0, 0, 26, 26) },
1120 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::InitialState::kAllOu t, IXYWH(0, 0, 27, 27)}, 1136 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::InitialState::kAllOu t, IXYWH(0, 0, 27, 27)},
1121 1137
1122 // Rect B. 1138 // Rect B.
1123 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::InitialState::kAllIn, IXYWH(50, 0, 25, 25) }, 1139 { XYWH(50, 0, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip: :InitialState::kAllIn, IXYWH(50, 0, 25, 25) },
1124 { XYWH(50, 0, 25.3f, 25.3f), 0, SkClipStack::kWideOpenGenID, GrReduc edClip::InitialState::kAllIn, IXYWH(50, 0, 26, 26) }, 1140 { XYWH(50, 0, 25.3f, 25.3f), 0, SkClipStack::kInvalidGenID, GrReduce dClip::InitialState::kAllIn, IXYWH(50, 0, 26, 26) },
1125 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::InitialState::kAllO ut, IXYWH(50, 0, 26, 27) }, 1141 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::InitialState::kAllO ut, IXYWH(50, 0, 26, 27) },
1126 1142
1127 // Rect C. 1143 // Rect C.
1128 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::InitialState::kAllIn, IXYWH(0, 50, 25, 25) }, 1144 { XYWH(0, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip: :InitialState::kAllIn, IXYWH(0, 50, 25, 25) },
1129 { XYWH(0.2f, 50.1f, 25.1f, 25.2f), 0, SkClipStack::kWideOpenGenID, G rReducedClip::InitialState::kAllIn, IXYWH(0, 50, 26, 26) }, 1145 { XYWH(0.2f, 50.1f, 25.1f, 25.2f), 0, SkClipStack::kInvalidGenID, Gr ReducedClip::InitialState::kAllIn, IXYWH(0, 50, 26, 26) },
1130 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::InitialState::kAllO ut, IXYWH(0, 50, 27, 26) }, 1146 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::InitialState::kAllO ut, IXYWH(0, 50, 27, 26) },
1131 1147
1132 // Rect D. 1148 // Rect D.
1133 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli p::InitialState::kAllIn, IXYWH(50, 50, 25, 25)}, 1149 { XYWH(50, 50, 25, 25), 0, SkClipStack::kInvalidGenID, GrReducedClip ::InitialState::kAllIn, IXYWH(50, 50, 25, 25)},
1134 { XYWH(50.3f, 50.3f, 25, 25), 0, SkClipStack::kWideOpenGenID, GrRedu cedClip::InitialState::kAllIn, IXYWH(50, 50, 26, 26)}, 1150 { XYWH(50.3f, 50.3f, 25, 25), 0, SkClipStack::kInvalidGenID, GrReduc edClip::InitialState::kAllIn, IXYWH(50, 50, 26, 26)},
1135 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::InitialState::kAll Out, IXYWH(50, 50, 26, 26)}, 1151 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::InitialState::kAll Out, IXYWH(50, 50, 26, 26)},
1136 1152
1137 // Other tests: 1153 // Other tests:
1138 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAll Out, stackBounds }, 1154 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAll Out, stackBounds },
1139 1155
1140 // Rect in the middle, touches none. 1156 // Rect in the middle, touches none.
1141 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip:: InitialState::kAllOut, IXYWH(26, 26, 24, 24) }, 1157 { XYWH(26, 26, 24, 24), 0, SkClipStack::kInvalidGenID, GrReducedClip ::InitialState::kAllOut, IXYWH(26, 26, 24, 24) },
1142 1158
1143 // Rect in the middle, touches all the rects. GenID is the last rect . 1159 // Rect in the middle, touches all the rects. GenID is the last rect .
1144 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::InitialState::kAll Out, IXYWH(24, 24, 27, 27) }, 1160 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::InitialState::kAll Out, IXYWH(24, 24, 27, 27) },
1145 }; 1161 };
1146 1162
1147 #undef XYWH 1163 #undef XYWH
1148 #undef IXYWH 1164 #undef IXYWH
1149 1165
1150 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { 1166 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) {
1151 const GrReducedClip reduced(stack, testCases[i].testBounds); 1167 const GrReducedClip reduced(stack, testCases[i].testBounds);
1152 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i] .reducedClipCount); 1168 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i] .reducedClipCount);
1153 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount ); 1169 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount );
1154 REPORTER_ASSERT(reporter, reduced.genID() == testCases[i].reducedGen ID); 1170 if (reduced.elements().count()) {
1155 SkASSERT(reduced.genID() == testCases[i].reducedGenID); 1171 REPORTER_ASSERT(reporter, reduced.elementsGenID() == testCases[i ].reducedGenID);
1172 SkASSERT(reduced.elementsGenID() == testCases[i].reducedGenID);
1173 }
1156 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini tialState); 1174 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini tialState);
1157 SkASSERT(reduced.initialState() == testCases[i].initialState); 1175 SkASSERT(reduced.initialState() == testCases[i].initialState);
1158 REPORTER_ASSERT(reporter, reduced.hasIBounds()); 1176 REPORTER_ASSERT(reporter, reduced.hasIBounds());
1159 SkASSERT(reduced.hasIBounds()); 1177 SkASSERT(reduced.hasIBounds());
1160 REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRec t); 1178 REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRec t);
1161 SkASSERT(reduced.ibounds() == testCases[i].clipIRect); 1179 SkASSERT(reduced.ibounds() == testCases[i].clipIRect);
1162 } 1180 }
1163 } 1181 }
1164 } 1182 }
1165 1183
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 test_path_replace(reporter); 1394 test_path_replace(reporter);
1377 test_quickContains(reporter); 1395 test_quickContains(reporter);
1378 test_invfill_diff_bug(reporter); 1396 test_invfill_diff_bug(reporter);
1379 #if SK_SUPPORT_GPU 1397 #if SK_SUPPORT_GPU
1380 test_reduced_clip_stack(reporter); 1398 test_reduced_clip_stack(reporter);
1381 test_reduced_clip_stack_genid(reporter); 1399 test_reduced_clip_stack_genid(reporter);
1382 test_reduced_clip_stack_no_aa_crash(reporter); 1400 test_reduced_clip_stack_no_aa_crash(reporter);
1383 test_reduced_clip_stack_aa(reporter); 1401 test_reduced_clip_stack_aa(reporter);
1384 #endif 1402 #endif
1385 } 1403 }
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