| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "GrAARectRenderer.h" | 8 #include "GrAARectRenderer.h" |
| 9 #include "GrRefCnt.h" | 9 #include "GrRefCnt.h" |
| 10 #include "GrGpu.h" | 10 #include "GrGpu.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 465 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
| 466 SkASSERT(scale >= 0 && scale <= 255); | 466 SkASSERT(scale >= 0 && scale <= 255); |
| 467 } else { | 467 } else { |
| 468 scale = 0xff; | 468 scale = 0xff; |
| 469 } | 469 } |
| 470 | 470 |
| 471 GrColor innerColor; | 471 GrColor innerColor; |
| 472 if (useVertexCoverage) { | 472 if (useVertexCoverage) { |
| 473 innerColor = GrColorPackRGBA(scale, scale, scale, scale); | 473 innerColor = GrColorPackRGBA(scale, scale, scale, scale); |
| 474 } else { | 474 } else { |
| 475 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale); | 475 if (0xff == scale) { |
| 476 innerColor = target->getDrawState().getColor();» |
| 477 } else {» |
| 478 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale);» |
| 479 }» |
| 476 } | 480 } |
| 477 | 481 |
| 478 verts += 4 * vsize; | 482 verts += 4 * vsize; |
| 479 for (int i = 0; i < 4; ++i) { | 483 for (int i = 0; i < 4; ++i) { |
| 480 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; | 484 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; |
| 481 } | 485 } |
| 482 | 486 |
| 483 target->setIndexSourceToBuffer(indexBuffer); | 487 target->setIndexSourceToBuffer(indexBuffer); |
| 484 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, | 488 target->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, |
| 485 kVertsPerAAFillRect, | 489 kVertsPerAAFillRect, |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); | 721 GrAssert(sizeof(GrPoint) + sizeof(GrColor) == vsize); |
| 718 | 722 |
| 719 // We create vertices for four nested rectangles. There are two ramps from 0
to full | 723 // We create vertices for four nested rectangles. There are two ramps from 0
to full |
| 720 // coverage, one on the exterior of the stroke and the other on the interior
. | 724 // coverage, one on the exterior of the stroke and the other on the interior
. |
| 721 // The following pointers refer to the four rects, from outermost to innermo
st. | 725 // The following pointers refer to the four rects, from outermost to innermo
st. |
| 722 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); | 726 GrPoint* fan0Pos = reinterpret_cast<GrPoint*>(verts); |
| 723 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); | 727 GrPoint* fan1Pos = reinterpret_cast<GrPoint*>(verts + 4 * vsize); |
| 724 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize); | 728 GrPoint* fan2Pos = reinterpret_cast<GrPoint*>(verts + 8 * vsize); |
| 725 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize); | 729 GrPoint* fan3Pos = reinterpret_cast<GrPoint*>(verts + 12 * vsize); |
| 726 | 730 |
| 731 #ifndef SK_IGNORE_THIN_STROKED_RECT_FIX |
| 727 // TODO: this only really works if the X & Y margins are the same all around | 732 // TODO: this only really works if the X & Y margins are the same all around |
| 728 // the rect | 733 // the rect |
| 729 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh
t); | 734 SkScalar inset = SkMinScalar(SK_Scalar1, devOutside.fRight - devInside.fRigh
t); |
| 730 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); | 735 inset = SkMinScalar(inset, devInside.fLeft - devOutside.fLeft); |
| 731 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); | 736 inset = SkMinScalar(inset, devInside.fTop - devOutside.fTop); |
| 732 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fB
ottom); | 737 inset = SK_ScalarHalf * SkMinScalar(inset, devOutside.fBottom - devInside.fB
ottom); |
| 733 SkASSERT(inset >= 0); | 738 SkASSERT(inset >= 0); |
| 739 #else |
| 740 SkScalar inset = SK_ScalarHalf; |
| 741 #endif |
| 734 | 742 |
| 735 // outermost | 743 // outermost |
| 736 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf); | 744 set_inset_fan(fan0Pos, vsize, devOutside, -SK_ScalarHalf, -SK_ScalarHalf); |
| 737 // inner two | 745 // inner two |
| 738 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); | 746 set_inset_fan(fan1Pos, vsize, devOutside, inset, inset); |
| 739 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); | 747 set_inset_fan(fan2Pos, vsize, devInside, -inset, -inset); |
| 740 // innermost | 748 // innermost |
| 741 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf); | 749 set_inset_fan(fan3Pos, vsize, devInside, SK_ScalarHalf, SK_ScalarHalf); |
| 742 | 750 |
| 743 // The outermost rect has 0 coverage | 751 // The outermost rect has 0 coverage |
| 744 verts += sizeof(GrPoint); | 752 verts += sizeof(GrPoint); |
| 745 for (int i = 0; i < 4; ++i) { | 753 for (int i = 0; i < 4; ++i) { |
| 746 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; | 754 *reinterpret_cast<GrColor*>(verts + i * vsize) = 0; |
| 747 } | 755 } |
| 748 | 756 |
| 749 int scale; | 757 int scale; |
| 750 if (inset < SK_ScalarHalf) { | 758 if (inset < SK_ScalarHalf) { |
| 751 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); | 759 scale = SkScalarFloorToInt(512.0f * inset / (inset + SK_ScalarHalf)); |
| 752 SkASSERT(scale >= 0 && scale <= 255); | 760 SkASSERT(scale >= 0 && scale <= 255); |
| 753 } else { | 761 } else { |
| 754 scale = 0xff; | 762 scale = 0xff; |
| 755 } | 763 } |
| 756 | 764 |
| 757 // The inner two rects have full coverage | 765 // The inner two rects have full coverage |
| 758 GrColor innerColor; | 766 GrColor innerColor; |
| 759 if (useVertexCoverage) { | 767 if (useVertexCoverage) { |
| 760 innerColor = GrColorPackRGBA(scale, scale, scale, scale); | 768 innerColor = GrColorPackRGBA(scale, scale, scale, scale); |
| 761 } else { | 769 } else { |
| 762 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale); | 770 if (0xff == scale) { |
| 771 innerColor = target->getDrawState().getColor();» |
| 772 } else {» |
| 773 innerColor = SkAlphaMulQ(target->getDrawState().getColor(), scale); |
| 774 } |
| 763 } | 775 } |
| 764 | 776 |
| 765 verts += 4 * vsize; | 777 verts += 4 * vsize; |
| 766 for (int i = 0; i < 8; ++i) { | 778 for (int i = 0; i < 8; ++i) { |
| 767 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; | 779 *reinterpret_cast<GrColor*>(verts + i * vsize) = innerColor; |
| 768 } | 780 } |
| 769 | 781 |
| 770 // The innermost rect has 0 coverage | 782 // The innermost rect has 0 coverage |
| 771 verts += 8 * vsize; | 783 verts += 8 * vsize; |
| 772 for (int i = 0; i < 4; ++i) { | 784 for (int i = 0; i < 4; ++i) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 791 // can't call mapRect for devInside since it calls sort | 803 // can't call mapRect for devInside since it calls sort |
| 792 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; | 804 combinedMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2)
; |
| 793 | 805 |
| 794 if (devInside.isEmpty()) { | 806 if (devInside.isEmpty()) { |
| 795 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); | 807 this->fillAARect(gpu, target, devOutside, SkMatrix::I(), devOutside, use
VertexCoverage); |
| 796 return; | 808 return; |
| 797 } | 809 } |
| 798 | 810 |
| 799 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); | 811 this->geometryStrokeAARect(gpu, target, devOutside, devInside, useVertexCove
rage); |
| 800 } | 812 } |
| OLD | NEW |