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 "SkBlurMask.h" | 8 #include "SkBlurMask.h" |
9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
10 #include "SkBlurDrawLooper.h" | 10 #include "SkBlurDrawLooper.h" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 0.01f)); | 570 p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 0.01f)); |
571 | 571 |
572 canvas->drawRRect(rr, p); | 572 canvas->drawRRect(rr, p); |
573 } | 573 } |
574 | 574 |
575 #endif | 575 #endif |
576 | 576 |
577 | 577 |
578 DEF_TEST(BlurredRRectNinePatchComputation, reporter) { | 578 DEF_TEST(BlurredRRectNinePatchComputation, reporter) { |
579 const SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); | 579 const SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); |
| 580 static const SkScalar kBlurRad = 3.0f; |
580 | 581 |
581 bool ninePatchable; | 582 bool ninePatchable; |
582 SkRRect rrectToDraw; | 583 SkRRect rrectToDraw; |
583 SkISize size; | 584 SkISize size; |
584 SkScalar xs[4], ys[4]; | 585 SkScalar rectXs[SkBlurMaskFilter::kMaxDivisions], rectYs[SkBlurMaskFilter::k
MaxDivisions]; |
585 int numXs, numYs; | 586 SkScalar texXs[SkBlurMaskFilter::kMaxDivisions], texYs[SkBlurMaskFilter::kMa
xDivisions]; |
| 587 int numX, numY; |
| 588 uint32_t skipMask; |
586 | 589 |
587 // not nine-patchable | 590 // not nine-patchable |
588 { | 591 { |
589 SkVector radii[4] = { { 100, 100 }, { 0, 0 }, { 100, 100 }, { 0, 0 } }; | 592 SkVector radii[4] = { { 100, 100 }, { 0, 0 }, { 100, 100 }, { 0, 0 } }; |
590 | 593 |
591 SkRRect rr; | 594 SkRRect rr; |
592 rr.setRectRadii(r, radii); | 595 rr.setRectRadii(r, radii); |
593 | 596 |
594 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, 3.0f, &r
rectToDraw, &size, | 597 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRe
ct::MakeEmpty(), |
595 xs, &numXs,
ys, &numYs); | 598 kBlurRad, kB
lurRad, |
| 599 &rrectToDraw
, &size, |
| 600 rectXs, rect
Ys, texXs, texYs, |
| 601 &numX, &numY
, &skipMask); |
596 REPORTER_ASSERT(reporter, !ninePatchable); | 602 REPORTER_ASSERT(reporter, !ninePatchable); |
597 } | 603 } |
598 | 604 |
599 // simple circular | 605 // simple circular |
600 { | 606 { |
| 607 static const SkScalar kCornerRad = 10.0f; |
601 SkRRect rr; | 608 SkRRect rr; |
602 rr.setRectXY(r, 10, 10); | 609 rr.setRectXY(r, kCornerRad, kCornerRad); |
603 | 610 |
604 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, 3.0f, &r
rectToDraw, &size, | 611 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRe
ct::MakeEmpty(), |
605 xs, &numXs,
ys, &numYs); | 612 kBlurRad, kB
lurRad, |
| 613 &rrectToDraw
, &size, |
| 614 rectXs, rect
Ys, texXs, texYs, |
| 615 &numX, &numY
, &skipMask); |
| 616 |
| 617 static const SkScalar kAns = 12.0f * kBlurRad + 2.0f * kCornerRad + 1.0f
; |
606 REPORTER_ASSERT(reporter, ninePatchable); | 618 REPORTER_ASSERT(reporter, ninePatchable); |
607 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth)
, 57.0f)); | 619 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth)
, kAns)); |
608 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight
), 57.0)); | 620 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight
), kAns)); |
609 REPORTER_ASSERT(reporter, 4 == numXs && 4 == numYs); | 621 REPORTER_ASSERT(reporter, 4 == numX && 4 == numY); |
610 for (int i = 0; i < numXs; ++i) { | 622 REPORTER_ASSERT(reporter, !skipMask); |
611 REPORTER_ASSERT(reporter, xs[i] >= 0.0f && xs[i] <= 1.0f); | |
612 } | |
613 for (int i = 0; i < numYs; ++i) { | |
614 REPORTER_ASSERT(reporter, ys[i] >= 0.0f && ys[i] <= 1.0f); | |
615 } | |
616 } | 623 } |
617 | 624 |
618 // simple elliptical | 625 // simple elliptical |
619 { | 626 { |
| 627 static const SkScalar kXCornerRad = 2.0f; |
| 628 static const SkScalar kYCornerRad = 10.0f; |
620 SkRRect rr; | 629 SkRRect rr; |
621 rr.setRectXY(r, 2, 10); | 630 rr.setRectXY(r, kXCornerRad, kYCornerRad); |
622 | 631 |
623 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, 3.0f, &r
rectToDraw, &size, | 632 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectParams(rr, rr, SkRe
ct::MakeEmpty(), |
624 xs, &numXs,
ys, &numYs); | 633 kBlurRad, kB
lurRad, |
| 634 &rrectToDraw
, &size, |
| 635 rectXs, rect
Ys, texXs, texYs, |
| 636 &numX, &numY
, &skipMask); |
| 637 |
| 638 static const SkScalar kXAns = 12.0f * kBlurRad + 2.0f * kXCornerRad + 1.
0f; |
| 639 static const SkScalar kYAns = 12.0f * kBlurRad + 2.0f * kYCornerRad + 1.
0f; |
| 640 |
625 REPORTER_ASSERT(reporter, ninePatchable); | 641 REPORTER_ASSERT(reporter, ninePatchable); |
626 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth)
, 41.0f)); | 642 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fWidth)
, kXAns)); |
627 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight
), 57.0)); | 643 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkIntToScalar(size.fHeight
), kYAns)); |
628 REPORTER_ASSERT(reporter, 4 == numXs && 4 == numYs); | 644 REPORTER_ASSERT(reporter, 4 == numX && 4 == numY); |
629 for (int i = 0; i < numXs; ++i) { | 645 REPORTER_ASSERT(reporter, !skipMask); |
630 REPORTER_ASSERT(reporter, xs[i] >= 0.0f && xs[i] <= 1.0f); | 646 } |
| 647 |
| 648 // test-out occlusion |
| 649 { |
| 650 static const SkScalar kCornerRad = 10.0f; |
| 651 SkRRect rr; |
| 652 rr.setRectXY(r, kCornerRad, kCornerRad); |
| 653 |
| 654 // The rectXs & rectYs should be { 1, 29, 91, 119 }. Add two more points
around each. |
| 655 SkScalar testLocs[] = { |
| 656 -18.0f, -9.0f, |
| 657 1.0f, |
| 658 9.0f, 18.0f, |
| 659 29.0f, |
| 660 39.0f, 49.0f, |
| 661 91.0f, |
| 662 109.0f, 118.0f, |
| 663 119.0f, |
| 664 139.0f, 149.0f |
| 665 }; |
| 666 |
| 667 for (int minY = 0; minY < (int)SK_ARRAY_COUNT(testLocs); ++minY) { |
| 668 for (int maxY = minY+1; maxY < (int)SK_ARRAY_COUNT(testLocs); ++maxY
) { |
| 669 for (int minX = 0; minX < (int)SK_ARRAY_COUNT(testLocs); ++minX)
{ |
| 670 for (int maxX = minX+1; maxX < (int)SK_ARRAY_COUNT(testLocs)
; ++maxX) { |
| 671 SkRect occluder = SkRect::MakeLTRB(testLocs[minX], testL
ocs[minY], |
| 672 testLocs[maxX], testL
ocs[maxY]); |
| 673 if (occluder.isEmpty()) { |
| 674 continue; |
| 675 } |
| 676 |
| 677 ninePatchable = SkBlurMaskFilter::ComputeBlurredRRectPar
ams( |
| 678 rr, rr, occl
uder, |
| 679 kBlurRad, kB
lurRad, |
| 680 &rrectToDraw
, &size, |
| 681 rectXs, rect
Ys, texXs, texYs, |
| 682 &numX, &numY
, &skipMask); |
| 683 |
| 684 static const SkScalar kAns = 12.0f * kBlurRad + 2.0f * k
CornerRad + 1.0f; |
| 685 REPORTER_ASSERT(reporter, ninePatchable); |
| 686 REPORTER_ASSERT(reporter, |
| 687 SkScalarNearlyEqual(SkIntToScalar(si
ze.fWidth), kAns)); |
| 688 REPORTER_ASSERT(reporter, |
| 689 SkScalarNearlyEqual(SkIntToScalar(si
ze.fHeight), kAns)); |
| 690 |
| 691 int checkBit = 0x1; |
| 692 for (int y = 0; y < numY-1; ++y) { |
| 693 for (int x = 0; x < numX-1; ++x) { |
| 694 SkRect cell = SkRect::MakeLTRB(rectXs[x], rectYs
[y], |
| 695 rectXs[x+1], rect
Ys[y+1]); |
| 696 REPORTER_ASSERT(reporter, |
| 697 SkToBool(skipMask & checkBit
) == |
| 698 (cell.isEmpty() || occluder.
contains(cell))); |
| 699 |
| 700 REPORTER_ASSERT(reporter, texXs[x] >= 0 && |
| 701 texXs[x] <= size.fWidt
h); |
| 702 REPORTER_ASSERT(reporter, texYs[y] >= 0 && |
| 703 texXs[y] <= size.fHeig
ht); |
| 704 |
| 705 checkBit <<= 1; |
| 706 } |
| 707 } |
| 708 } |
| 709 } |
| 710 } |
631 } | 711 } |
632 for (int i = 0; i < numYs; ++i) { | 712 |
633 REPORTER_ASSERT(reporter, ys[i] >= 0.0f && ys[i] <= 1.0f); | 713 |
634 } | |
635 } | 714 } |
636 | 715 |
637 } | 716 } |
638 | 717 |
639 ////////////////////////////////////////////////////////////////////////////////
/////////// | 718 ////////////////////////////////////////////////////////////////////////////////
/////////// |
OLD | NEW |