| OLD | NEW |
| 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 Loading... |
| 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()); |
| 274 | 275 |
| 275 stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, | 276 stack.getConservativeBounds(0, 0, 100, 100, &devClipBound, |
| 276 &isIntersectionOfRects); | 277 &isIntersectionOfRects); |
| 277 | 278 |
| 278 if (useRects) { | 279 if (useRects) { |
| 279 REPORTER_ASSERT(reporter, isIntersectionOfRects == | 280 REPORTER_ASSERT(reporter, isIntersectionOfRects == |
| 280 (gOps[op] == SkRegion::kIntersect_Op)); | 281 (gOps[op] == SkRegion::kIntersect_Op)); |
| 281 } else { | 282 } else { |
| 282 REPORTER_ASSERT(reporter, !isIntersectionOfRects); | 283 REPORTER_ASSERT(reporter, !isIntersectionOfRects); |
| 283 } | 284 } |
| 284 | 285 |
| 285 SkASSERT(testCase < gNumCases); | 286 SkASSERT(testCase < gNumCases); |
| 286 REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); | 287 REPORTER_ASSERT(reporter, devClipBound == gAnswerRectsBW[testCase]); |
| 287 ++testCase; | 288 ++testCase; |
| 288 | 289 |
| 289 stack.restore(); | 290 stack.restore(); |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 } | 293 } |
| 293 | 294 |
| 294 // Test out 'isWideOpen' entry point | 295 // Test out 'isWideOpen' entry point |
| 295 static void test_isWideOpen(skiatest::Reporter* reporter) { | 296 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 } |
| 296 | 303 |
| 297 SkRect rectA, rectB; | 304 SkRect rectA, rectB; |
| 298 | 305 |
| 299 rectA.iset(10, 10, 40, 40); | 306 rectA.iset(10, 10, 40, 40); |
| 300 rectB.iset(50, 50, 80, 80); | 307 rectB.iset(50, 50, 80, 80); |
| 301 | 308 |
| 302 // Stack should initially be wide open | 309 // Stack should initially be wide open |
| 303 { | 310 { |
| 304 SkClipStack stack; | 311 SkClipStack stack; |
| 305 | 312 |
| 306 REPORTER_ASSERT(reporter, stack.isWideOpen()); | 313 REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 314 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos
tGenID()); |
| 307 } | 315 } |
| 308 | 316 |
| 309 // Test out case where the user specifies a union that includes everything | 317 // Test out case where the user specifies a union that includes everything |
| 310 { | 318 { |
| 311 SkClipStack stack; | 319 SkClipStack stack; |
| 312 | 320 |
| 313 SkPath clipA, clipB; | 321 SkPath clipA, clipB; |
| 314 | 322 |
| 315 clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); | 323 clipA.addRoundRect(rectA, SkIntToScalar(5), SkIntToScalar(5)); |
| 316 clipA.setFillType(SkPath::kInverseEvenOdd_FillType); | 324 clipA.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 317 | 325 |
| 318 clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); | 326 clipB.addRoundRect(rectB, SkIntToScalar(5), SkIntToScalar(5)); |
| 319 clipB.setFillType(SkPath::kInverseEvenOdd_FillType); | 327 clipB.setFillType(SkPath::kInverseEvenOdd_FillType); |
| 320 | 328 |
| 321 stack.clipDevPath(clipA, SkRegion::kReplace_Op, false); | 329 stack.clipDevPath(clipA, SkRegion::kReplace_Op, false); |
| 322 stack.clipDevPath(clipB, SkRegion::kUnion_Op, false); | 330 stack.clipDevPath(clipB, SkRegion::kUnion_Op, false); |
| 323 | 331 |
| 324 REPORTER_ASSERT(reporter, stack.isWideOpen()); | 332 REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 333 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos
tGenID()); |
| 325 } | 334 } |
| 326 | 335 |
| 327 // Test out union w/ a wide open clip | 336 // Test out union w/ a wide open clip |
| 328 { | 337 { |
| 329 SkClipStack stack; | 338 SkClipStack stack; |
| 330 | 339 |
| 331 stack.clipDevRect(rectA, SkRegion::kUnion_Op, false); | 340 stack.clipDevRect(rectA, SkRegion::kUnion_Op, false); |
| 332 | 341 |
| 333 REPORTER_ASSERT(reporter, stack.isWideOpen()); | 342 REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 343 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos
tGenID()); |
| 334 } | 344 } |
| 335 | 345 |
| 336 // Test out empty difference from a wide open clip | 346 // Test out empty difference from a wide open clip |
| 337 { | 347 { |
| 338 SkClipStack stack; | 348 SkClipStack stack; |
| 339 | 349 |
| 340 SkRect emptyRect; | 350 SkRect emptyRect; |
| 341 emptyRect.setEmpty(); | 351 emptyRect.setEmpty(); |
| 342 | 352 |
| 343 stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false); | 353 stack.clipDevRect(emptyRect, SkRegion::kDifference_Op, false); |
| 344 | 354 |
| 345 REPORTER_ASSERT(reporter, stack.isWideOpen()); | 355 REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 356 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos
tGenID()); |
| 346 } | 357 } |
| 347 | 358 |
| 348 // Test out return to wide open | 359 // Test out return to wide open |
| 349 { | 360 { |
| 350 SkClipStack stack; | 361 SkClipStack stack; |
| 351 | 362 |
| 352 stack.save(); | 363 stack.save(); |
| 353 | 364 |
| 354 stack.clipDevRect(rectA, SkRegion::kReplace_Op, false); | 365 stack.clipDevRect(rectA, SkRegion::kReplace_Op, false); |
| 355 | 366 |
| 356 REPORTER_ASSERT(reporter, !stack.isWideOpen()); | 367 REPORTER_ASSERT(reporter, !stack.isWideOpen()); |
| 368 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID != stack.getTopmos
tGenID()); |
| 357 | 369 |
| 358 stack.restore(); | 370 stack.restore(); |
| 359 | 371 |
| 360 REPORTER_ASSERT(reporter, stack.isWideOpen()); | 372 REPORTER_ASSERT(reporter, stack.isWideOpen()); |
| 373 REPORTER_ASSERT(reporter, SkClipStack::kWideOpenGenID == stack.getTopmos
tGenID()); |
| 361 } | 374 } |
| 362 } | 375 } |
| 363 | 376 |
| 364 static int count(const SkClipStack& stack) { | 377 static int count(const SkClipStack& stack) { |
| 365 | 378 |
| 366 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); | 379 SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart); |
| 367 | 380 |
| 368 const SkClipStack::Element* element = NULL; | 381 const SkClipStack::Element* element = NULL; |
| 369 int count = 0; | 382 int count = 0; |
| 370 | 383 |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 | 956 |
| 944 GrReducedClip::InitialState initial; | 957 GrReducedClip::InitialState initial; |
| 945 SkIRect tBounds(inflatedIBounds); | 958 SkIRect tBounds(inflatedIBounds); |
| 946 SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL; | 959 SkIRect* tightBounds = r.nextBool() ? &tBounds : NULL; |
| 947 GrReducedClip::ReduceClipStack(stack, | 960 GrReducedClip::ReduceClipStack(stack, |
| 948 inflatedIBounds, | 961 inflatedIBounds, |
| 949 &reducedClips, | 962 &reducedClips, |
| 950 &initial, | 963 &initial, |
| 951 tightBounds); | 964 tightBounds); |
| 952 | 965 |
| 966 REPORTER_ASSERT(reporter, reducedClips.count() == 0 || |
| 967 reducedClips.tail()->getGenID() != SkClipStack::kInvalid
GenID); |
| 968 |
| 953 // Build a new clip stack based on the reduced clip elements | 969 // Build a new clip stack based on the reduced clip elements |
| 954 SkClipStack reducedStack; | 970 SkClipStack reducedStack; |
| 955 if (GrReducedClip::kAllOut_InitialState == initial) { | 971 if (GrReducedClip::kAllOut_InitialState == initial) { |
| 956 // whether the result is bounded or not, the whole plane should star
t outside the clip. | 972 // whether the result is bounded or not, the whole plane should star
t outside the clip. |
| 957 reducedStack.clipEmpty(); | 973 reducedStack.clipEmpty(); |
| 958 } | 974 } |
| 959 for (ElementList::Iter iter = reducedClips.headIter(); NULL != iter.get(
); iter.next()) { | 975 for (ElementList::Iter iter = reducedClips.headIter(); NULL != iter.get(
); iter.next()) { |
| 960 add_elem_to_stack(*iter.get(), &reducedStack); | 976 add_elem_to_stack(*iter.get(), &reducedStack); |
| 961 } | 977 } |
| 962 | 978 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 979 reducedRegion.setRect(inflatedIBounds); | 995 reducedRegion.setRect(inflatedIBounds); |
| 980 iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart); | 996 iter.reset(reducedStack, SkClipStack::Iter::kBottom_IterStart); |
| 981 while ((element = iter.next())) { | 997 while ((element = iter.next())) { |
| 982 add_elem_to_region(*element, inflatedIBounds, &reducedRegion); | 998 add_elem_to_region(*element, inflatedIBounds, &reducedRegion); |
| 983 } | 999 } |
| 984 | 1000 |
| 985 REPORTER_ASSERT(reporter, region == reducedRegion); | 1001 REPORTER_ASSERT(reporter, region == reducedRegion); |
| 986 } | 1002 } |
| 987 } | 1003 } |
| 988 | 1004 |
| 1005 static void test_reduced_clip_stack_genid(skiatest::Reporter* reporter) { |
| 1006 SkClipStack stack; |
| 1007 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op, t
rue); |
| 1008 stack.clipDevRect(SkRect::MakeXYWH(0, 0, 50.3, 50.3), SkRegion::kReplace_Op,
true); |
| 1009 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 1010 |
| 1011 GrReducedClip::ElementList reducedClips; |
| 1012 GrReducedClip::InitialState initial; |
| 1013 SkIRect tightBounds; |
| 1014 |
| 1015 GrReducedClip::ReduceClipStack(stack, |
| 1016 inflatedIBounds, |
| 1017 &reducedClips, |
| 1018 &initial, |
| 1019 &tightBounds); |
| 1020 |
| 1021 REPORTER_ASSERT(reporter, reducedClips.count() == 1); |
| 1022 // Clips will be cached based on the generation id. Make sure the gen id is
valid. |
| 1023 REPORTER_ASSERT(reporter, SkClipStack::kInvalidGenID != reducedClips.head()-
>getGenID()); |
| 1024 |
| 1025 } |
| 1026 |
| 1027 static void test_reduced_clip_stack_no_aa_crash(skiatest::Reporter* reporter) { |
| 1028 SkClipStack stack; |
| 1029 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 100, 100), SkRegion::kReplace_Op); |
| 1030 stack.clipDevRect(SkIRect::MakeXYWH(0, 0, 50, 50), SkRegion::kReplace_Op); |
| 1031 SkIRect inflatedIBounds = SkIRect::MakeXYWH(0, 0, 100, 100); |
| 1032 |
| 1033 GrReducedClip::ElementList reducedClips; |
| 1034 GrReducedClip::InitialState initial; |
| 1035 SkIRect tightBounds; |
| 1036 |
| 1037 // At the time, this would crash. |
| 1038 GrReducedClip::ReduceClipStack(stack, |
| 1039 inflatedIBounds, |
| 1040 &reducedClips, |
| 1041 &initial, |
| 1042 &tightBounds); |
| 1043 |
| 1044 REPORTER_ASSERT(reporter, 0 == reducedClips.count()); |
| 1045 } |
| 1046 |
| 989 #endif | 1047 #endif |
| 990 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1048 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 991 | 1049 |
| 992 static void TestClipStack(skiatest::Reporter* reporter) { | 1050 static void TestClipStack(skiatest::Reporter* reporter) { |
| 993 SkClipStack stack; | 1051 SkClipStack stack; |
| 994 | 1052 |
| 995 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); | 1053 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
| 996 assert_count(reporter, stack, 0); | 1054 assert_count(reporter, stack, 0); |
| 997 | 1055 |
| 998 static const SkIRect gRects[] = { | 1056 static const SkIRect gRects[] = { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1027 test_bounds(reporter, true); // once with rects | 1085 test_bounds(reporter, true); // once with rects |
| 1028 test_bounds(reporter, false); // once with paths | 1086 test_bounds(reporter, false); // once with paths |
| 1029 test_isWideOpen(reporter); | 1087 test_isWideOpen(reporter); |
| 1030 test_rect_merging(reporter); | 1088 test_rect_merging(reporter); |
| 1031 test_rect_replace(reporter); | 1089 test_rect_replace(reporter); |
| 1032 test_rect_inverse_fill(reporter); | 1090 test_rect_inverse_fill(reporter); |
| 1033 test_path_replace(reporter); | 1091 test_path_replace(reporter); |
| 1034 test_quickContains(reporter); | 1092 test_quickContains(reporter); |
| 1035 #if SK_SUPPORT_GPU | 1093 #if SK_SUPPORT_GPU |
| 1036 test_reduced_clip_stack(reporter); | 1094 test_reduced_clip_stack(reporter); |
| 1095 test_reduced_clip_stack_genid(reporter); |
| 1096 test_reduced_clip_stack_no_aa_crash(reporter); |
| 1037 #endif | 1097 #endif |
| 1038 } | 1098 } |
| 1039 | 1099 |
| 1040 #include "TestClassDef.h" | 1100 #include "TestClassDef.h" |
| 1041 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) | 1101 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) |
| OLD | NEW |