| 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 #include "SkClipStack.h" | 9 #include "SkClipStack.h" |
| 10 #include "SkPath.h" | 10 #include "SkPath.h" |
| (...skipping 994 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 if (doSave) { | 1005 if (doSave) { |
| 1006 stack.save(); | 1006 stack.save(); |
| 1007 } | 1007 } |
| 1008 } | 1008 } |
| 1009 | 1009 |
| 1010 // Get the reduced version of the stack. | 1010 // Get the reduced version of the stack. |
| 1011 SkRect queryBounds = kBounds; | 1011 SkRect queryBounds = kBounds; |
| 1012 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); | 1012 queryBounds.outset(kBounds.width() / 2, kBounds.height() / 2); |
| 1013 const GrReducedClip reduced(stack, queryBounds); | 1013 const GrReducedClip reduced(stack, queryBounds); |
| 1014 | 1014 |
| 1015 REPORTER_ASSERT_MESSAGE(reporter, SkClipStack::kInvalidGenID != reduced.
genID(), | 1015 REPORTER_ASSERT_MESSAGE(reporter, |
| 1016 reduced.elements().isEmpty() || |
| 1017 SkClipStack::kInvalidGenID != reduced.elementsGe
nID(), |
| 1016 testCase.c_str()); | 1018 testCase.c_str()); |
| 1017 | 1019 |
| 1018 if (!reduced.elements().isEmpty()) { | 1020 if (!reduced.elements().isEmpty()) { |
| 1019 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testCase.c_s
tr()); | 1021 REPORTER_ASSERT_MESSAGE(reporter, reduced.hasIBounds(), testCase.c_s
tr()); |
| 1020 SkRect stackBounds; | 1022 SkRect stackBounds; |
| 1021 SkClipStack::BoundsType stackBoundsType; | 1023 SkClipStack::BoundsType stackBoundsType; |
| 1022 stack.getBounds(&stackBounds, &stackBoundsType); | 1024 stack.getBounds(&stackBounds, &stackBoundsType); |
| 1023 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { | 1025 if (SkClipStack::kNormal_BoundsType == stackBoundsType) { |
| 1024 // Unless GrReducedClip starts doing some heroic tightening of t
he clip bounds, this | 1026 // 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. | 1027 // will be true since the stack bounds are completely contained
inside the query. |
| 1026 REPORTER_ASSERT_MESSAGE(reporter, GrClip::IsInsideClip(reduced.i
bounds(), stackBounds), | 1028 REPORTER_ASSERT_MESSAGE(reporter, |
| 1029 GrClip::IsInsideClip(reduced.ibounds(),
stackBounds), |
| 1027 testCase.c_str()); | 1030 testCase.c_str()); |
| 1028 } | 1031 } |
| 1029 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == doAA, test
Case.c_str()); | 1032 REPORTER_ASSERT_MESSAGE(reporter, reduced.requiresAA() == doAA, test
Case.c_str()); |
| 1030 } | 1033 } |
| 1031 | 1034 |
| 1032 // Build a new clip stack based on the reduced clip elements | 1035 // Build a new clip stack based on the reduced clip elements |
| 1033 SkClipStack reducedStack; | 1036 SkClipStack reducedStack; |
| 1034 if (GrReducedClip::InitialState::kAllOut == reduced.initialState()) { | 1037 if (GrReducedClip::InitialState::kAllOut == reduced.initialState()) { |
| 1035 // whether the result is bounded or not, the whole plane should star
t outside the clip. | 1038 // whether the result is bounded or not, the whole plane should star
t outside the clip. |
| 1036 reducedStack.clipEmpty(); | 1039 reducedStack.clipEmpty(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1066 { | 1069 { |
| 1067 SkClipStack stack; | 1070 SkClipStack stack; |
| 1068 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O
p, true); | 1071 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); | 1072 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); | 1073 SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100); |
| 1071 | 1074 |
| 1072 const GrReducedClip reduced(stack, bounds); | 1075 const GrReducedClip reduced(stack, bounds); |
| 1073 | 1076 |
| 1074 REPORTER_ASSERT(reporter, reduced.elements().count() == 1); | 1077 REPORTER_ASSERT(reporter, reduced.elements().count() == 1); |
| 1075 // Clips will be cached based on the generation id. Make sure the gen id
is valid. | 1078 // Clips will be cached based on the generation id. Make sure the gen id
is valid. |
| 1076 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced.genID())
; | 1079 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reduced.elements
GenID()); |
| 1077 } | 1080 } |
| 1078 { | 1081 { |
| 1079 SkClipStack stack; | 1082 SkClipStack stack; |
| 1080 | 1083 |
| 1081 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: | 1084 // Create a clip with following 25.3, 25.3 boxes which are 25 apart: |
| 1082 // A B | 1085 // A B |
| 1083 // C D | 1086 // C D |
| 1084 | 1087 |
| 1085 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3))
, SkRegion::kReplace_Op, true); | 1088 stack.clipDevRect(SkRect::MakeXYWH(0, 0, SkScalar(25.3), SkScalar(25.3))
, SkRegion::kReplace_Op, true); |
| 1086 int32_t genIDA = stack.getTopmostGenID(); | 1089 int32_t genIDA = stack.getTopmostGenID(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1108 static const struct SUPPRESS_VISIBILITY_WARNING { | 1111 static const struct SUPPRESS_VISIBILITY_WARNING { |
| 1109 SkRect testBounds; | 1112 SkRect testBounds; |
| 1110 int reducedClipCount; | 1113 int reducedClipCount; |
| 1111 int32_t reducedGenID; | 1114 int32_t reducedGenID; |
| 1112 InitialState initialState; | 1115 InitialState initialState; |
| 1113 SkIRect clipIRect; | 1116 SkIRect clipIRect; |
| 1114 // parameter. | 1117 // parameter. |
| 1115 } testCases[] = { | 1118 } testCases[] = { |
| 1116 | 1119 |
| 1117 // Rect A. | 1120 // Rect A. |
| 1118 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip:
:InitialState::kAllIn, IXYWH(0, 0, 25, 25) }, | 1121 { 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) }, | 1122 { 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)}, | 1123 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::InitialState::kAllOu
t, IXYWH(0, 0, 27, 27)}, |
| 1121 | 1124 |
| 1122 // Rect B. | 1125 // Rect B. |
| 1123 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::InitialState::kAllIn, IXYWH(50, 0, 25, 25) }, | 1126 { 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) }, | 1127 { 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) }, | 1128 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::InitialState::kAllO
ut, IXYWH(50, 0, 26, 27) }, |
| 1126 | 1129 |
| 1127 // Rect C. | 1130 // Rect C. |
| 1128 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip
::InitialState::kAllIn, IXYWH(0, 50, 25, 25) }, | 1131 { 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) }, | 1132 { 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) }, | 1133 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::InitialState::kAllO
ut, IXYWH(0, 50, 27, 26) }, |
| 1131 | 1134 |
| 1132 // Rect D. | 1135 // Rect D. |
| 1133 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli
p::InitialState::kAllIn, IXYWH(50, 50, 25, 25)}, | 1136 { 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)}, | 1137 { 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)}, | 1138 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::InitialState::kAll
Out, IXYWH(50, 50, 26, 26)}, |
| 1136 | 1139 |
| 1137 // Other tests: | 1140 // Other tests: |
| 1138 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAll
Out, stackBounds }, | 1141 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::InitialState::kAll
Out, stackBounds }, |
| 1139 | 1142 |
| 1140 // Rect in the middle, touches none. | 1143 // Rect in the middle, touches none. |
| 1141 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip::
InitialState::kAllOut, IXYWH(26, 26, 24, 24) }, | 1144 { XYWH(26, 26, 24, 24), 0, SkClipStack::kInvalidGenID, GrReducedClip
::InitialState::kAllOut, IXYWH(26, 26, 24, 24) }, |
| 1142 | 1145 |
| 1143 // Rect in the middle, touches all the rects. GenID is the last rect
. | 1146 // 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) }, | 1147 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::InitialState::kAll
Out, IXYWH(24, 24, 27, 27) }, |
| 1145 }; | 1148 }; |
| 1146 | 1149 |
| 1147 #undef XYWH | 1150 #undef XYWH |
| 1148 #undef IXYWH | 1151 #undef IXYWH |
| 1149 | 1152 |
| 1150 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { | 1153 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) { |
| 1151 const GrReducedClip reduced(stack, testCases[i].testBounds); | 1154 const GrReducedClip reduced(stack, testCases[i].testBounds); |
| 1152 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i]
.reducedClipCount); | 1155 REPORTER_ASSERT(reporter, reduced.elements().count() == testCases[i]
.reducedClipCount); |
| 1153 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount
); | 1156 SkASSERT(reduced.elements().count() == testCases[i].reducedClipCount
); |
| 1154 REPORTER_ASSERT(reporter, reduced.genID() == testCases[i].reducedGen
ID); | 1157 if (reduced.elements().count()) { |
| 1155 SkASSERT(reduced.genID() == testCases[i].reducedGenID); | 1158 REPORTER_ASSERT(reporter, reduced.elementsGenID() == testCases[i
].reducedGenID); |
| 1159 SkASSERT(reduced.elementsGenID() == testCases[i].reducedGenID); |
| 1160 } |
| 1156 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini
tialState); | 1161 REPORTER_ASSERT(reporter, reduced.initialState() == testCases[i].ini
tialState); |
| 1157 SkASSERT(reduced.initialState() == testCases[i].initialState); | 1162 SkASSERT(reduced.initialState() == testCases[i].initialState); |
| 1158 REPORTER_ASSERT(reporter, reduced.hasIBounds()); | 1163 REPORTER_ASSERT(reporter, reduced.hasIBounds()); |
| 1159 SkASSERT(reduced.hasIBounds()); | 1164 SkASSERT(reduced.hasIBounds()); |
| 1160 REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRec
t); | 1165 REPORTER_ASSERT(reporter, reduced.ibounds() == testCases[i].clipIRec
t); |
| 1161 SkASSERT(reduced.ibounds() == testCases[i].clipIRect); | 1166 SkASSERT(reduced.ibounds() == testCases[i].clipIRect); |
| 1162 } | 1167 } |
| 1163 } | 1168 } |
| 1164 } | 1169 } |
| 1165 | 1170 |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 test_path_replace(reporter); | 1381 test_path_replace(reporter); |
| 1377 test_quickContains(reporter); | 1382 test_quickContains(reporter); |
| 1378 test_invfill_diff_bug(reporter); | 1383 test_invfill_diff_bug(reporter); |
| 1379 #if SK_SUPPORT_GPU | 1384 #if SK_SUPPORT_GPU |
| 1380 test_reduced_clip_stack(reporter); | 1385 test_reduced_clip_stack(reporter); |
| 1381 test_reduced_clip_stack_genid(reporter); | 1386 test_reduced_clip_stack_genid(reporter); |
| 1382 test_reduced_clip_stack_no_aa_crash(reporter); | 1387 test_reduced_clip_stack_no_aa_crash(reporter); |
| 1383 test_reduced_clip_stack_aa(reporter); | 1388 test_reduced_clip_stack_aa(reporter); |
| 1384 #endif | 1389 #endif |
| 1385 } | 1390 } |
| OLD | NEW |