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

Side by Side Diff: tests/ClipStackTest.cpp

Issue 54543008: Revert "Avoid re-rendering stencil clip for every draw with reducable clip stack" (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « tests/ClipCacheTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 264
265 if (useRects) { 265 if (useRects) {
266 stack.clipDevRect(rectA, SkRegion::kIntersect_Op, false); 266 stack.clipDevRect(rectA, SkRegion::kIntersect_Op, false);
267 stack.clipDevRect(rectB, gOps[op], false); 267 stack.clipDevRect(rectB, gOps[op], false);
268 } else { 268 } else {
269 stack.clipDevPath(clipA, SkRegion::kIntersect_Op, false); 269 stack.clipDevPath(clipA, SkRegion::kIntersect_Op, false);
270 stack.clipDevPath(clipB, gOps[op], false); 270 stack.clipDevPath(clipB, gOps[op], false);
271 } 271 }
272 272
273 REPORTER_ASSERT(reporter, !stack.isWideOpen()); 273 REPORTER_ASSERT(reporter, !stack.isWideOpen());
274 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTo pmostGenID());
275 274
276 stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, 275 stack.getConservativeBounds(0, 0, 100, 100, &devClipBound,
277 &isIntersectionOfRects); 276 &isIntersectionOfRects);
278 277
279 if (useRects) { 278 if (useRects) {
280 REPORTER_ASSERT(reporter, isIntersectionOfRects == 279 REPORTER_ASSERT(reporter, isIntersectionOfRects ==
281 (gOps[op] == SkRegion::kIntersect_Op)); 280 (gOps[op] == SkRegion::kIntersect_Op));
282 } else { 281 } else {
283 REPORTER_ASSERT(reporter, !isIntersectionOfRects); 282 REPORTER_ASSERT(reporter, !isIntersectionOfRects);
284 } 283 }
285 284
286 SkASSERT(testCase < gNumCases); 285 SkASSERT(testCase < gNumCases);
287 REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); 286 REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]);
288 ++testCase; 287 ++testCase;
289 288
290 stack.restore(); 289 stack.restore();
291 } 290 }
292 } 291 }
293 } 292 }
294 293
295 // Test out 'isWideOpen' entry point 294 // Test out 'isWideOpen' entry point
296 static void test_isWideOpen(skiatest::Reporter* reporter) { 295 static void test_isWideOpen(skiatest::Reporter* reporter) {
297 {
298 // Empty stack is wide open. Wide open stack means that gen id is wide o pen.
299 SkClipStack stack;
300 REPORTER_ASSERT(reporter, stack.isWideOpen());
301 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
302 }
303 296
304 SkRect rectA, rectB; 297 SkRect rectA, rectB;
305 298
306 rectA.iset(10, 10, 40, 40); 299 rectA.iset(10, 10, 40, 40);
307 rectB.iset(50, 50, 80, 80); 300 rectB.iset(50, 50, 80, 80);
308 301
309 // Stack should initially be wide open 302 // Stack should initially be wide open
310 { 303 {
311 SkClipStack stack; 304 SkClipStack stack;
312 305
313 REPORTER_ASSERT(reporter, stack.isWideOpen()); 306 REPORTER_ASSERT(reporter, stack.isWideOpen());
314 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
315 } 307 }
316 308
317 // Test out case where the user specifies a union that includes everything 309 // Test out case where the user specifies a union that includes everything
318 { 310 {
319 SkClipStack stack; 311 SkClipStack stack;
320 312
321 SkPath clipA, clipB; 313 SkPath clipA, clipB;
322 314
323 clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); 315 clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5));
324 clipA.setFillType(SkPath::kInverseEvenOdd_FillType); 316 clipA.setFillType(SkPath::kInverseEvenOdd_FillType);
325 317
326 clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); 318 clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5));
327 clipB.setFillType(SkPath::kInverseEvenOdd_FillType); 319 clipB.setFillType(SkPath::kInverseEvenOdd_FillType);
328 320
329 stack.clipDevPath(clipA, SkRegion::kReplace_Op, false); 321 stack.clipDevPath(clipA, SkRegion::kReplace_Op, false);
330 stack.clipDevPath(clipB, SkRegion::kUnion_Op, false); 322 stack.clipDevPath(clipB, SkRegion::kUnion_Op, false);
331 323
332 REPORTER_ASSERT(reporter, stack.isWideOpen()); 324 REPORTER_ASSERT(reporter, stack.isWideOpen());
333 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
334 } 325 }
335 326
336 // Test out union w/ a wide open clip 327 // Test out union w/ a wide open clip
337 { 328 {
338 SkClipStack stack; 329 SkClipStack stack;
339 330
340 stack.clipDevRect(rectA, SkRegion::kUnion_Op, false); 331 stack.clipDevRect(rectA, SkRegion::kUnion_Op, false);
341 332
342 REPORTER_ASSERT(reporter, stack.isWideOpen()); 333 REPORTER_ASSERT(reporter, stack.isWideOpen());
343 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
344 } 334 }
345 335
346 // Test out empty difference from a wide open clip 336 // Test out empty difference from a wide open clip
347 { 337 {
348 SkClipStack stack; 338 SkClipStack stack;
349 339
350 SkRect emptyRect; 340 SkRect emptyRect;
351 emptyRect.setEmpty(); 341 emptyRect.setEmpty();
352 342
353 stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false); 343 stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false);
354 344
355 REPORTER_ASSERT(reporter, stack.isWideOpen()); 345 REPORTER_ASSERT(reporter, stack.isWideOpen());
356 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
357 } 346 }
358 347
359 // Test out return to wide open 348 // Test out return to wide open
360 { 349 {
361 SkClipStack stack; 350 SkClipStack stack;
362 351
363 stack.save(); 352 stack.save();
364 353
365 stack.clipDevRect(rectA, SkRegion::kReplace_Op, false); 354 stack.clipDevRect(rectA, SkRegion::kReplace_Op, false);
366 355
367 REPORTER_ASSERT(reporter, !stack.isWideOpen()); 356 REPORTER_ASSERT(reporter, !stack.isWideOpen());
368 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmos tGenID());
369 357
370 stack.restore(); 358 stack.restore();
371 359
372 REPORTER_ASSERT(reporter, stack.isWideOpen()); 360 REPORTER_ASSERT(reporter, stack.isWideOpen());
373 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos tGenID());
374 } 361 }
375 } 362 }
376 363
377 static int count(const SkClipStack& stack) { 364 static int count(const SkClipStack& stack) {
378 365
379 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); 366 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
380 367
381 const SkClipStack::Element* element = NULL; 368 const SkClipStack::Element* element = NULL;
382 int count = 0; 369 int count = 0;
383 370
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 } 933 }
947 934
948 SkRect inflatedBounds = kBounds; 935 SkRect inflatedBounds = kBounds;
949 inflatedBounds.outset(kBounds.width() / 2, kBounds.height() / 2); 936 inflatedBounds.outset(kBounds.width() / 2, kBounds.height() / 2);
950 SkIRect inflatedIBounds; 937 SkIRect inflatedIBounds;
951 inflatedBounds.roundOut(&inflatedIBounds); 938 inflatedBounds.roundOut(&inflatedIBounds);
952 939
953 typedef GrReducedClip::ElementList ElementList; 940 typedef GrReducedClip::ElementList ElementList;
954 // Get the reduced version of the stack. 941 // Get the reduced version of the stack.
955 ElementList reducedClips; 942 ElementList reducedClips;
956 int32_t reducedGenID; 943
957 GrReducedClip::InitialState initial; 944 GrReducedClip::InitialState initial;
958 SkIRect tBounds(inflatedIBounds); 945 SkIRect tBounds(inflatedIBounds);
959 SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL; 946 SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL;
960 GrReducedClip::ReduceClipStack(stack, 947 GrReducedClip::ReduceClipStack(stack,
961 inflatedIBounds, 948 inflatedIBounds,
962 &reducedClips, 949 &reducedClips,
963 &reducedGenID,
964 &initial, 950 &initial,
965 tightBounds); 951 tightBounds);
966 952
967 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID);
968
969 // Build a new clip stack based on the reduced clip elements 953 // Build a new clip stack based on the reduced clip elements
970 SkClipStack reducedStack; 954 SkClipStack reducedStack;
971 if (GrReducedClip::kAllOut_InitialState == initial) { 955 if (GrReducedClip::kAllOut_InitialState == initial) {
972 // whether the result is bounded or not, the whole plane should star t outside the clip. 956 // whether the result is bounded or not, the whole plane should star t outside the clip.
973 reducedStack.clipEmpty(); 957 reducedStack.clipEmpty();
974 } 958 }
975 for (ElementList::Iter iter = reducedClips.headIter(); NULL != iter.get( ); iter.next()) { 959 for (ElementList::Iter iter = reducedClips.headIter(); NULL != iter.get( ); iter.next()) {
976 add_elem_to_stack(*iter.get(), &reducedStack); 960 add_elem_to_stack(*iter.get(), &reducedStack);
977 } 961 }
978 962
(...skipping 16 matching lines...) Expand all
995 reducedRegion.setRect(inflatedIBounds); 979 reducedRegion.setRect(inflatedIBounds);
996 iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart); 980 iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart);
997 while ((element = iter.next())) { 981 while ((element = iter.next())) {
998 add_elem_to_region(*element, inflatedIBounds, &reducedRegion); 982 add_elem_to_region(*element, inflatedIBounds, &reducedRegion);
999 } 983 }
1000 984
1001 REPORTER_ASSERT(reporter, region == reducedRegion); 985 REPORTER_ASSERT(reporter, region == reducedRegion);
1002 } 986 }
1003 } 987 }
1004 988
1005 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) {
1006 {
1007 SkClipStack stack;
1008 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_O p, true);
1009 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 50.3f, 50.3f), SkRegion::kRepla ce_Op, true);
1010 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
1011
1012 GrReducedClip::ElementList reducedClips;
1013 int32_t reducedGenID;
1014 GrReducedClip::InitialState initial;
1015 SkIRect tightBounds;
1016
1017 GrReducedClip::ReduceClipStack(stack,
1018 inflatedIBounds,
1019 &reducedClips,
1020 &reducedGenID,
1021 &initial,
1022 &tightBounds);
1023
1024 REPORTER_ASSERT(reporter, reducedClips.count() == 1);
1025 // Clips will be cached based on the generation id. Make sure the gen id is valid.
1026 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedGenID);
1027 }
1028 {
1029 SkClipStack stack;
1030
1031 // Create a clip with following 25.3, 25.3 boxes which are 25 apart:
1032 // A B
1033 // C D
1034
1035 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 25.3f, 25.3f), SkRegion::kRepla ce_Op, true);
1036 int32_t genIDA = stack.getTopmostGenID();
1037 stack.clipDevRect(SkRect::MakeXYWH(50, 0, 25.3f, 25.3f), SkRegion::kUnio n_Op, true);
1038 int32_t genIDB = stack.getTopmostGenID();
1039 stack.clipDevRect(SkRect::MakeXYWH(0, 50, 25.3f, 25.3f), SkRegion::kUnio n_Op, true);
1040 int32_t genIDC = stack.getTopmostGenID();
1041 stack.clipDevRect(SkRect::MakeXYWH(50, 50, 25.3f, 25.3f), SkRegion::kUni on_Op, true);
1042 int32_t genIDD = stack.getTopmostGenID();
1043
1044 #define XYWH SkIRect::MakeXYWH
1045
1046 SkIRect unused;
1047 unused.setEmpty();
1048 SkIRect stackBounds = XYWH(0, 0, 76, 76);
1049
1050 // The base test is to test each rect in two ways:
1051 // 1) The box dimensions. (Should reduce to "all in", no elements).
1052 // 2) A bit over the box dimensions.
1053 // In the case 2, test that the generation id is what is expected.
1054 // The rects are of fractional size so that case 2 never gets optimized to an empty element
1055 // list.
1056
1057 // Not passing in tighter bounds is tested for consistency.
1058 struct {
1059 SkIRect testBounds;
1060 int reducedClipCount;
1061 int32_t reducedGenID;
1062 GrReducedClip::InitialState initialState;
1063 SkIRect tighterBounds; // If this is empty, the query will not pass tighter bounds
1064 // parameter.
1065 } testCases[] = {
1066 // Rect A.
1067 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip: :kAllIn_InitialState, XYWH(0, 0, 25, 25) },
1068 { XYWH(0, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip: :kAllIn_InitialState, unused },
1069 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState , XYWH(0, 0, 27, 27)},
1070 { XYWH(0, 0, 27, 27), 1, genIDA, GrReducedClip::kAllOut_InitialState , unused },
1071
1072 // Rect B.
1073 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::kAllIn_InitialState, XYWH(50, 0, 25, 25) },
1074 { XYWH(50, 0, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::kAllIn_InitialState, unused },
1075 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat e, XYWH(50, 0, 26, 27) },
1076 { XYWH(50, 0, 27, 27), 1, genIDB, GrReducedClip::kAllOut_InitialStat e, unused },
1077
1078 // Rect C.
1079 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::kAllIn_InitialState, XYWH(0, 50, 25, 25) },
1080 { XYWH(0, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedClip ::kAllIn_InitialState, unused },
1081 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialStat e, XYWH(0, 50, 27, 26) },
1082 { XYWH(0, 50, 27, 27), 1, genIDC, GrReducedClip::kAllOut_InitialStat e, unused },
1083
1084 // Rect D.
1085 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli p::kAllIn_InitialState, unused },
1086 { XYWH(50, 50, 25, 25), 0, SkClipStack::kWideOpenGenID, GrReducedCli p::kAllIn_InitialState, XYWH(50, 50, 25, 25)},
1087 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialSta te, unused },
1088 { XYWH(50, 50, 27, 27), 1, genIDD, GrReducedClip::kAllOut_InitialSta te, XYWH(50, 50, 26, 26)},
1089
1090 // Other tests:
1091 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialSta te, unused },
1092 { XYWH(0, 0, 100, 100), 4, genIDD, GrReducedClip::kAllOut_InitialSta te, stackBounds },
1093
1094 // Rect in the middle, touches none.
1095 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip:: kAllOut_InitialState, unused },
1096 { XYWH(26, 26, 24, 24), 0, SkClipStack::kEmptyGenID, GrReducedClip:: kAllOut_InitialState, XYWH(26, 26, 24, 24) },
1097
1098 // Rect in the middle, touches all the rects. GenID is the last rect .
1099 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialSta te, unused },
1100 { XYWH(24, 24, 27, 27), 4, genIDD, GrReducedClip::kAllOut_InitialSta te, XYWH(24, 24, 27, 27) },
1101 };
1102
1103 #undef XYWH
1104
1105 for (size_t i = 0; i < SK_ARRAY_COUNT(testCases); ++i) {
1106 GrReducedClip::ElementList reducedClips;
1107 int32_t reducedGenID;
1108 GrReducedClip::InitialState initial;
1109 SkIRect tightBounds;
1110
1111 GrReducedClip::ReduceClipStack(stack,
1112 testCases[i].testBounds,
1113 &reducedClips,
1114 &reducedGenID,
1115 &initial,
1116 testCases[i].tighterBounds.isEmpty() ? NULL : &tightBounds);
1117
1118 REPORTER_ASSERT(reporter, reducedClips.count() == testCases[i].reduc edClipCount);
1119 SkASSERT(reducedClips.count() == testCases[i].reducedClipCount);
1120 REPORTER_ASSERT(reporter, reducedGenID == testCases[i].reducedGenID) ;
1121 SkASSERT(reducedGenID == testCases[i].reducedGenID);
1122 REPORTER_ASSERT(reporter, initial == testCases[i].initialState);
1123 SkASSERT(initial == testCases[i].initialState);
1124 if (!testCases[i].tighterBounds.isEmpty()) {
1125 REPORTER_ASSERT(reporter, tightBounds == testCases[i].tighterBou nds);
1126 SkASSERT(tightBounds == testCases[i].tighterBounds);
1127 }
1128 }
1129 }
1130 }
1131
1132 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) {
1133 SkClipStack stack;
1134 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op);
1135 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op);
1136 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100);
1137
1138 GrReducedClip::ElementList reducedClips;
1139 int32_t reducedGenID;
1140 GrReducedClip::InitialState initial;
1141 SkIRect tightBounds;
1142
1143 // At the time, this would crash.
1144 GrReducedClip::ReduceClipStack(stack,
1145 inflatedIBounds,
1146 &reducedClips,
1147 &reducedGenID,
1148 &initial,
1149 &tightBounds);
1150
1151 REPORTER_ASSERT(reporter, 0 == reducedClips.count());
1152 }
1153
1154 #endif 989 #endif
1155 //////////////////////////////////////////////////////////////////////////////// /////////////////// 990 //////////////////////////////////////////////////////////////////////////////// ///////////////////
1156 991
1157 static void TestClipStack(skiatest::Reporter* reporter) { 992 static void TestClipStack(skiatest::Reporter* reporter) {
1158 SkClipStack stack; 993 SkClipStack stack;
1159 994
1160 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); 995 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount());
1161 assert_count(reporter, stack, 0); 996 assert_count(reporter, stack, 0);
1162 997
1163 static const SkIRect gRects[] = { 998 static const SkIRect gRects[] = {
(...skipping 28 matching lines...) Expand all
1192 test_bounds(reporter, true); // once with rects 1027 test_bounds(reporter, true); // once with rects
1193 test_bounds(reporter, false); // once with paths 1028 test_bounds(reporter, false); // once with paths
1194 test_isWideOpen(reporter); 1029 test_isWideOpen(reporter);
1195 test_rect_merging(reporter); 1030 test_rect_merging(reporter);
1196 test_rect_replace(reporter); 1031 test_rect_replace(reporter);
1197 test_rect_inverse_fill(reporter); 1032 test_rect_inverse_fill(reporter);
1198 test_path_replace(reporter); 1033 test_path_replace(reporter);
1199 test_quickContains(reporter); 1034 test_quickContains(reporter);
1200 #if SK_SUPPORT_GPU 1035 #if SK_SUPPORT_GPU
1201 test_reduced_clip_stack(reporter); 1036 test_reduced_clip_stack(reporter);
1202 test_reduced_clip_stack_genid(reporter);
1203 test_reduced_clip_stack_no_aa_crash(reporter);
1204 #endif 1037 #endif
1205 } 1038 }
1206 1039
1207 #include "TestClassDef.h" 1040 #include "TestClassDef.h"
1208 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) 1041 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack)
OLDNEW
« no previous file with comments | « tests/ClipCacheTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698