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 "Test.h" | 8 #include "Test.h" |
9 #if SK_SUPPORT_GPU | 9 #if SK_SUPPORT_GPU |
10 #include "GrReducedClip.h" | 10 #include "GrReducedClip.h" |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 SkRect inflatedBounds = kBounds; | 956 SkRect inflatedBounds = kBounds; |
957 inflatedBounds.outset(kBounds.width() / 2, kBounds.height() / 2); | 957 inflatedBounds.outset(kBounds.width() / 2, kBounds.height() / 2); |
958 SkIRect inflatedIBounds; | 958 SkIRect inflatedIBounds; |
959 inflatedBounds.roundOut(&inflatedIBounds); | 959 inflatedBounds.roundOut(&inflatedIBounds); |
960 | 960 |
961 typedef GrReducedClip::ElementList ElementList; | 961 typedef GrReducedClip::ElementList ElementList; |
962 // Get the reduced version of the stack. | 962 // Get the reduced version of the stack. |
963 ElementList reducedClips; | 963 ElementList reducedClips; |
964 int32_t reducedGenID; | 964 int32_t reducedGenID; |
965 GrReducedClip::InitialState initial; | 965 GrReducedClip::InitialState initial; |
966 SkIRect tBounds(inflatedIBounds); | 966 SkIRect tighterBounds; |
967 SkIRect* tightBounds = r.nextBool() ? &tBounds : nullptr; | 967 bool requiresAA; |
968 GrReducedClip::ReduceClipStack(stack, | 968 GrReducedClip::ReduceClipStack(stack, |
969 inflatedIBounds, | 969 inflatedIBounds, |
970 &reducedClips, | 970 &reducedClips, |
971 &reducedGenID, | 971 &reducedGenID, |
972 &initial, | 972 &initial, |
973 tightBounds); | 973 &tighterBounds, |
| 974 &requiresAA); |
974 | 975 |
975 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); | 976 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); |
976 | 977 |
977 // Build a new clip stack based on the reduced clip elements | 978 // Build a new clip stack based on the reduced clip elements |
978 SkClipStack reducedStack; | 979 SkClipStack reducedStack; |
979 if (GrReducedClip::kAllOut_InitialState == initial) { | 980 if (GrReducedClip::kAllOut_InitialState == initial) { |
980 // whether the result is bounded or not, the whole plane should star
t outside the clip. | 981 // whether the result is bounded or not, the whole plane should star
t outside the clip. |
981 reducedStack.clipEmpty(); | 982 reducedStack.clipEmpty(); |
982 } | 983 } |
983 for (ElementList::Iter iter = reducedClips.headIter(); iter.get(); iter.
next()) { | 984 for (ElementList::Iter iter = reducedClips.headIter(); iter.get(); iter.
next()) { |
984 add_elem_to_stack(*iter.get(), &reducedStack); | 985 add_elem_to_stack(*iter.get(), &reducedStack); |
985 } | 986 } |
986 | 987 |
987 // GrReducedClipStack assumes that the final result is clipped to the re
turned bounds | 988 // GrReducedClipStack assumes that the final result is clipped to the re
turned bounds |
988 if (tightBounds) { | 989 reducedStack.clipDevRect(tighterBounds, SkRegion::kIntersect_Op); |
989 reducedStack.clipDevRect(*tightBounds, SkRegion::kIntersect_Op); | 990 stack.clipDevRect(tighterBounds, SkRegion::kIntersect_Op); |
990 } | |
991 | 991 |
992 // convert both the original stack and reduced stack to SkRegions and se
e if they're equal | 992 // convert both the original stack and reduced stack to SkRegions and se
e if they're equal |
993 SkRegion region; | 993 SkRegion region; |
994 SkRegion reducedRegion; | 994 SkRegion reducedRegion; |
995 | 995 |
996 region.setRect(inflatedIBounds); | 996 region.setRect(inflatedIBounds); |
997 const SkClipStack::Element* element; | 997 const SkClipStack::Element* element; |
998 SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); | 998 SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart); |
999 while ((element = iter.next())) { | 999 while ((element = iter.next())) { |
1000 add_elem_to_region(*element, inflatedIBounds, ®ion); | 1000 add_elem_to_region(*element, inflatedIBounds, ®ion); |
(...skipping 20 matching lines...) Expand all Loading... |
1021 { | 1021 { |
1022 SkClipStack stack; | 1022 SkClipStack stack; |
1023 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O
p, true); | 1023 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O
p, true); |
1024 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3))
, SkRegion::kReplace_Op, true); | 1024 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(50.3), SkScalar(50.3))
, SkRegion::kReplace_Op, true); |
1025 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 1025 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
1026 | 1026 |
1027 GrReducedClip::ElementList reducedClips; | 1027 GrReducedClip::ElementList reducedClips; |
1028 int32_t reducedGenID; | 1028 int32_t reducedGenID; |
1029 GrReducedClip::InitialState initial; | 1029 GrReducedClip::InitialState initial; |
1030 SkIRect tightBounds; | 1030 SkIRect tightBounds; |
| 1031 bool requiresAA; |
1031 | 1032 |
1032 GrReducedClip::ReduceClipStack(stack, | 1033 GrReducedClip::ReduceClipStack(stack, |
1033 inflatedIBounds, | 1034 inflatedIBounds, |
1034 &reducedClips, | 1035 &reducedClips, |
1035 &reducedGenID, | 1036 &reducedGenID, |
1036 &initial, | 1037 &initial, |
1037 &tightBounds); | 1038 &tightBounds, |
| 1039 &requiresAA); |
1038 | 1040 |
1039 REPORTER_ASSERT(reporter, reducedClips.count() == 1); | 1041 REPORTER_ASSERT(reporter, reducedClips.count() == 1); |
1040 // Clips will be cached based on the generation id. Make sure the gen id
is valid. | 1042 // Clips will be cached based on the generation id. Make sure the gen id
is valid. |
1041 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); | 1043 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID); |
1042 } | 1044 } |
1043 { | 1045 { |
1044 SkClipStack stack; | 1046 SkClipStack stack; |
1045 | 1047 |
1046 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: | 1048 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: |
1047 // A B | 1049 // A B |
1048 // C D | 1050 // C D |
1049 | 1051 |
1050 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3))
, SkRegion::kReplace_Op, true); | 1052 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3))
, SkRegion::kReplace_Op, true); |
1051 int32_t genIDA = stack.getTopmostGenID(); | 1053 int32_t genIDA = stack.getTopmostGenID(); |
1052 stack.clipDevRect(SkRect::MakeXYWH(50, 0, SkScalar(25.3), SkScalar(25.3)
), SkRegion::kUnion_Op, true); | 1054 stack.clipDevRect(SkRect::MakeXYWH(50, 0, SkScalar(25.3), SkScalar(25.3)
), SkRegion::kUnion_Op, true); |
1053 int32_t genIDB = stack.getTopmostGenID(); | 1055 int32_t genIDB = stack.getTopmostGenID(); |
1054 stack.clipDevRect(SkRect::MakeXYWH(0, 50, SkScalar(25.3), SkScalar(25.3)
), SkRegion::kUnion_Op, true); | 1056 stack.clipDevRect(SkRect::MakeXYWH(0, 50, SkScalar(25.3), SkScalar(25.3)
), SkRegion::kUnion_Op, true); |
1055 int32_t genIDC = stack.getTopmostGenID(); | 1057 int32_t genIDC = stack.getTopmostGenID(); |
1056 stack.clipDevRect(SkRect::MakeXYWH(50, 50, SkScalar(25.3), SkScalar(25.3
)), SkRegion::kUnion_Op, true); | 1058 stack.clipDevRect(SkRect::MakeXYWH(50, 50, SkScalar(25.3), SkScalar(25.3
)), SkRegion::kUnion_Op, true); |
1057 int32_t genIDD = stack.getTopmostGenID(); | 1059 int32_t genIDD = stack.getTopmostGenID(); |
1058 | 1060 |
1059 | 1061 |
1060 #define XYWH SkIRect::MakeXYWH | 1062 #define XYWH SkIRect::MakeXYWH |
1061 | 1063 |
1062 SkIRect unused; | |
1063 unused.setEmpty(); | |
1064 SkIRect stackBounds = XYWH(0, 0, 76, 76); | 1064 SkIRect stackBounds = XYWH(0, 0, 76, 76); |
1065 | 1065 |
1066 // The base test is to test each rect in two ways: | 1066 // The base test is to test each rect in two ways: |
1067 // 1) The box dimensions. (Should reduce to "all in", no elements). | 1067 // 1) The box dimensions. (Should reduce to "all in", no elements). |
1068 // 2) A bit over the box dimensions. | 1068 // 2) A bit over the box dimensions. |
1069 // In the case 2, test that the generation id is what is expected. | 1069 // In the case 2, test that the generation id is what is expected. |
1070 // The rects are of fractional size so that case 2 never gets optimized
to an empty element | 1070 // The rects are of fractional size so that case 2 never gets optimized
to an empty element |
1071 // list. | 1071 // list. |
1072 | 1072 |
1073 // Not passing in tighter bounds is tested for consistency. | 1073 // Not passing in tighter bounds is tested for consistency. |
1074 static const struct SUPPRESS_VISIBILITY_WARNING { | 1074 static const struct SUPPRESS_VISIBILITY_WARNING { |
1075 SkIRect testBounds; | 1075 SkIRect testBounds; |
1076 int reducedClipCount; | 1076 int reducedClipCount; |
1077 int32_t reducedGenID; | 1077 int32_t reducedGenID; |
1078 GrReducedClip::InitialState initialState; | 1078 GrReducedClip::InitialState initialState; |
1079 SkIRect tighterBounds; // If this is empty, the query will not pass
tighter bounds | 1079 SkIRect tighterBounds; // If this is empty, the query will not pass
tighter bounds |
1080 // parameter. | 1080 // parameter. |
1081 } testCases[] = { | 1081 } testCases[] = { |
1082 // Rect A. | 1082 // Rect A. |
1083 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, XYWH(0, 0, 25, 25) }, | 1083 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, XYWH(0, 0, 25, 25) }, |
1084 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:kAllIn_InitialState, unused }, | |
1085 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, XYWH(0, 0, 27, 27)}, | 1084 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, XYWH(0, 0, 27, 27)}, |
1086 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState
, unused }, | |
1087 | 1085 |
1088 // Rect B. | 1086 // Rect B. |
1089 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(50, 0, 25, 25) }, | 1087 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(50, 0, 25, 25) }, |
1090 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, unused }, | |
1091 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat
e, XYWH(50, 0, 26, 27) }, | 1088 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat
e, XYWH(50, 0, 26, 27) }, |
1092 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat
e, unused }, | |
1093 | 1089 |
1094 // Rect C. | 1090 // Rect C. |
1095 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(0, 50, 25, 25) }, | 1091 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, XYWH(0, 50, 25, 25) }, |
1096 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::kAllIn_InitialState, unused }, | |
1097 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialStat
e, XYWH(0, 50, 27, 26) }, | 1092 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialStat
e, XYWH(0, 50, 27, 26) }, |
1098 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialStat
e, unused }, | |
1099 | 1093 |
1100 // Rect D. | 1094 // Rect D. |
1101 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli
p::kAllIn_InitialState, unused }, | |
1102 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli
p::kAllIn_InitialState, XYWH(50, 50, 25, 25)}, | 1095 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli
p::kAllIn_InitialState, XYWH(50, 50, 25, 25)}, |
1103 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialSta
te, unused }, | |
1104 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialSta
te, XYWH(50, 50, 26, 26)}, | 1096 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialSta
te, XYWH(50, 50, 26, 26)}, |
1105 | 1097 |
1106 // Other tests: | 1098 // Other tests: |
1107 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, unused }, | |
1108 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, stackBounds }, | 1099 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, stackBounds }, |
1109 | 1100 |
1110 // Rect in the middle, touches none. | 1101 // Rect in the middle, touches none. |
1111 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::
kAllOut_InitialState, unused }, | |
1112 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::
kAllOut_InitialState, XYWH(26, 26, 24, 24) }, | 1102 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::
kAllOut_InitialState, XYWH(26, 26, 24, 24) }, |
1113 | 1103 |
1114 // Rect in the middle, touches all the rects. GenID is the last rect
. | 1104 // Rect in the middle, touches all the rects. GenID is the last rect
. |
1115 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, unused }, | |
1116 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, XYWH(24, 24, 27, 27) }, | 1105 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialSta
te, XYWH(24, 24, 27, 27) }, |
1117 }; | 1106 }; |
1118 | 1107 |
1119 #undef XYWH | 1108 #undef XYWH |
1120 | 1109 |
1121 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { | 1110 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { |
1122 GrReducedClip::ElementList reducedClips; | 1111 GrReducedClip::ElementList reducedClips; |
1123 int32_t reducedGenID; | 1112 int32_t reducedGenID; |
1124 GrReducedClip::InitialState initial; | 1113 GrReducedClip::InitialState initial; |
1125 SkIRect tightBounds; | 1114 SkIRect tightBounds; |
| 1115 bool requiresAA; |
1126 | 1116 |
1127 GrReducedClip::ReduceClipStack(stack, | 1117 GrReducedClip::ReduceClipStack(stack, |
1128 testCases[i].testBounds, | 1118 testCases[i].testBounds, |
1129 &reducedClips, | 1119 &reducedClips, |
1130 &reducedGenID, | 1120 &reducedGenID, |
1131 &initial, | 1121 &initial, |
1132 testCases[i].tighterBounds.isEmpty()
? nullptr : &tightBounds); | 1122 &tightBounds, |
| 1123 &requiresAA); |
1133 | 1124 |
1134 REPORTER_ASSERT(reporter, reducedClips.count() == testCases[i].reduc
edClipCount); | 1125 REPORTER_ASSERT(reporter, reducedClips.count() == testCases[i].reduc
edClipCount); |
1135 SkASSERT(reducedClips.count() == testCases[i].reducedClipCount); | 1126 SkASSERT(reducedClips.count() == testCases[i].reducedClipCount); |
1136 REPORTER_ASSERT(reporter, reducedGenID == testCases[i].reducedGenID)
; | 1127 REPORTER_ASSERT(reporter, reducedGenID == testCases[i].reducedGenID)
; |
1137 SkASSERT(reducedGenID == testCases[i].reducedGenID); | 1128 SkASSERT(reducedGenID == testCases[i].reducedGenID); |
1138 REPORTER_ASSERT(reporter, initial == testCases[i].initialState); | 1129 REPORTER_ASSERT(reporter, initial == testCases[i].initialState); |
1139 SkASSERT(initial == testCases[i].initialState); | 1130 SkASSERT(initial == testCases[i].initialState); |
1140 if (!testCases[i].tighterBounds.isEmpty()) { | 1131 REPORTER_ASSERT(reporter, tightBounds == testCases[i].tighterBounds)
; |
1141 REPORTER_ASSERT(reporter, tightBounds == testCases[i].tighterBou
nds); | 1132 SkASSERT(tightBounds == testCases[i].tighterBounds); |
1142 SkASSERT(tightBounds == testCases[i].tighterBounds); | |
1143 } | |
1144 } | 1133 } |
1145 } | 1134 } |
1146 } | 1135 } |
1147 | 1136 |
1148 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { | 1137 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { |
1149 SkClipStack stack; | 1138 SkClipStack stack; |
1150 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op); | 1139 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op); |
1151 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op); | 1140 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op); |
1152 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); | 1141 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
1153 | 1142 |
1154 GrReducedClip::ElementList reducedClips; | 1143 GrReducedClip::ElementList reducedClips; |
1155 int32_t reducedGenID; | 1144 int32_t reducedGenID; |
1156 GrReducedClip::InitialState initial; | 1145 GrReducedClip::InitialState initial; |
1157 SkIRect tightBounds; | 1146 SkIRect tightBounds; |
| 1147 bool requiresAA; |
1158 | 1148 |
1159 // At the time, this would crash. | 1149 // At the time, this would crash. |
1160 GrReducedClip::ReduceClipStack(stack, | 1150 GrReducedClip::ReduceClipStack(stack, |
1161 inflatedIBounds, | 1151 inflatedIBounds, |
1162 &reducedClips, | 1152 &reducedClips, |
1163 &reducedGenID, | 1153 &reducedGenID, |
1164 &initial, | 1154 &initial, |
1165 &tightBounds); | 1155 &tightBounds, |
| 1156 &requiresAA); |
1166 | 1157 |
1167 REPORTER_ASSERT(reporter, 0 == reducedClips.count()); | 1158 REPORTER_ASSERT(reporter, 0 == reducedClips.count()); |
1168 } | 1159 } |
1169 | 1160 |
1170 #endif | 1161 #endif |
1171 | 1162 |
1172 DEF_TEST(ClipStack, reporter) { | 1163 DEF_TEST(ClipStack, reporter) { |
1173 SkClipStack stack; | 1164 SkClipStack stack; |
1174 | 1165 |
1175 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); | 1166 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 test_rect_replace(reporter); | 1203 test_rect_replace(reporter); |
1213 test_rect_inverse_fill(reporter); | 1204 test_rect_inverse_fill(reporter); |
1214 test_path_replace(reporter); | 1205 test_path_replace(reporter); |
1215 test_quickContains(reporter); | 1206 test_quickContains(reporter); |
1216 #if SK_SUPPORT_GPU | 1207 #if SK_SUPPORT_GPU |
1217 test_reduced_clip_stack(reporter); | 1208 test_reduced_clip_stack(reporter); |
1218 test_reduced_clip_stack_genid(reporter); | 1209 test_reduced_clip_stack_genid(reporter); |
1219 test_reduced_clip_stack_no_aa_crash(reporter); | 1210 test_reduced_clip_stack_no_aa_crash(reporter); |
1220 #endif | 1211 #endif |
1221 } | 1212 } |
OLD | NEW |