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 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 SkClipStack stack; | 385 SkClipStack stack; |
386 stack.clipDevPath(path, SkRegion::kIntersect_Op, false); | 386 stack.clipDevPath(path, SkRegion::kIntersect_Op, false); |
387 | 387 |
388 SkRect bounds; | 388 SkRect bounds; |
389 SkClipStack::BoundsType boundsType; | 389 SkClipStack::BoundsType boundsType; |
390 stack.getBounds(&bounds, &boundsType); | 390 stack.getBounds(&bounds, &boundsType); |
391 REPORTER_ASSERT(reporter, SkClipStack::kInsideOut_BoundsType == boundsType); | 391 REPORTER_ASSERT(reporter, SkClipStack::kInsideOut_BoundsType == boundsType); |
392 REPORTER_ASSERT(reporter, bounds == rect); | 392 REPORTER_ASSERT(reporter, bounds == rect); |
393 } | 393 } |
394 | 394 |
| 395 static void test_rect_replace(skiatest::Reporter* reporter) { |
| 396 SkRect rect = SkRect::MakeWH(100, 100); |
| 397 SkRect rect2 = SkRect::MakeXYWH(50, 50, 100, 100); |
| 398 |
| 399 SkRect bound; |
| 400 SkClipStack::BoundsType type; |
| 401 bool isIntersectionOfRects; |
| 402 |
| 403 // Adding a new rect with the replace operator should not increase |
| 404 // the stack depth. BW replacing BW. |
| 405 { |
| 406 SkClipStack stack; |
| 407 REPORTER_ASSERT(reporter, 0 == count(stack)); |
| 408 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 409 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 410 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 411 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 412 } |
| 413 |
| 414 // Adding a new rect with the replace operator should not increase |
| 415 // the stack depth. AA replacing AA. |
| 416 { |
| 417 SkClipStack stack; |
| 418 REPORTER_ASSERT(reporter, 0 == count(stack)); |
| 419 stack.clipDevRect(rect, SkRegion::kReplace_Op, true); |
| 420 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 421 stack.clipDevRect(rect, SkRegion::kReplace_Op, true); |
| 422 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 423 } |
| 424 |
| 425 // Adding a new rect with the replace operator should not increase |
| 426 // the stack depth. BW replacing AA replacing BW. |
| 427 { |
| 428 SkClipStack stack; |
| 429 REPORTER_ASSERT(reporter, 0 == count(stack)); |
| 430 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 431 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 432 stack.clipDevRect(rect, SkRegion::kReplace_Op, true); |
| 433 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 434 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 435 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 436 } |
| 437 |
| 438 // Make sure replace clip rects don't collapse too much. |
| 439 { |
| 440 SkClipStack stack; |
| 441 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 442 stack.clipDevRect(rect2, SkRegion::kIntersect_Op, false); |
| 443 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 444 |
| 445 stack.save(); |
| 446 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 447 REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 448 stack.getBounds(&bound, &type, &isIntersectionOfRects); |
| 449 REPORTER_ASSERT(reporter, bound == rect); |
| 450 stack.restore(); |
| 451 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 452 |
| 453 stack.save(); |
| 454 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 455 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 456 REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 457 stack.restore(); |
| 458 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 459 |
| 460 stack.save(); |
| 461 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 462 stack.clipDevRect(rect2, SkRegion::kIntersect_Op, false); |
| 463 stack.clipDevRect(rect, SkRegion::kReplace_Op, false); |
| 464 REPORTER_ASSERT(reporter, 2 == count(stack)); |
| 465 stack.restore(); |
| 466 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 467 } |
| 468 } |
| 469 |
| 470 // Simplified path-based version of test_rect_replace. |
| 471 static void test_path_replace(skiatest::Reporter* reporter) { |
| 472 SkRect rect = SkRect::MakeWH(100, 100); |
| 473 SkPath path; |
| 474 path.addCircle(50, 50, 50); |
| 475 |
| 476 // Replace operation doesn't grow the stack. |
| 477 { |
| 478 SkClipStack stack; |
| 479 REPORTER_ASSERT(reporter, 0 == count(stack)); |
| 480 stack.clipDevPath(path, SkRegion::kReplace_Op, false); |
| 481 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 482 stack.clipDevPath(path, SkRegion::kReplace_Op, false); |
| 483 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 484 } |
| 485 |
| 486 // Replacing rect with path. |
| 487 { |
| 488 SkClipStack stack; |
| 489 stack.clipDevRect(rect, SkRegion::kReplace_Op, true); |
| 490 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 491 stack.clipDevPath(path, SkRegion::kReplace_Op, true); |
| 492 REPORTER_ASSERT(reporter, 1 == count(stack)); |
| 493 } |
| 494 } |
| 495 |
395 // Test out SkClipStack's merging of rect clips. In particular exercise | 496 // Test out SkClipStack's merging of rect clips. In particular exercise |
396 // merging of aa vs. bw rects. | 497 // merging of aa vs. bw rects. |
397 static void test_rect_merging(skiatest::Reporter* reporter) { | 498 static void test_rect_merging(skiatest::Reporter* reporter) { |
398 | 499 |
399 SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50); | 500 SkRect overlapLeft = SkRect::MakeLTRB(10, 10, 50, 50); |
400 SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80); | 501 SkRect overlapRight = SkRect::MakeLTRB(40, 40, 80, 80); |
401 | 502 |
402 SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90); | 503 SkRect nestedParent = SkRect::MakeLTRB(10, 10, 90, 90); |
403 SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60); | 504 SkRect nestedChild = SkRect::MakeLTRB(40, 40, 60, 60); |
404 | 505 |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 stack.reset(); | 1044 stack.reset(); |
944 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); | 1045 REPORTER_ASSERT(reporter, 0 == stack.getSaveCount()); |
945 assert_count(reporter, stack, 0); | 1046 assert_count(reporter, stack, 0); |
946 | 1047 |
947 test_assign_and_comparison(reporter); | 1048 test_assign_and_comparison(reporter); |
948 test_iterators(reporter); | 1049 test_iterators(reporter); |
949 test_bounds(reporter, true); // once with rects | 1050 test_bounds(reporter, true); // once with rects |
950 test_bounds(reporter, false); // once with paths | 1051 test_bounds(reporter, false); // once with paths |
951 test_isWideOpen(reporter); | 1052 test_isWideOpen(reporter); |
952 test_rect_merging(reporter); | 1053 test_rect_merging(reporter); |
| 1054 test_rect_replace(reporter); |
953 test_rect_inverse_fill(reporter); | 1055 test_rect_inverse_fill(reporter); |
| 1056 test_path_replace(reporter); |
954 test_quickContains(reporter); | 1057 test_quickContains(reporter); |
955 #if SK_SUPPORT_GPU | 1058 #if SK_SUPPORT_GPU |
956 test_reduced_clip_stack(reporter); | 1059 test_reduced_clip_stack(reporter); |
957 #endif | 1060 #endif |
958 } | 1061 } |
959 | 1062 |
960 #include "TestClassDef.h" | 1063 #include "TestClassDef.h" |
961 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) | 1064 DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) |
OLD | NEW |