OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1519 } | 1519 } |
1520 | 1520 |
1521 void onPrepareDraws(Target* target) const override { | 1521 void onPrepareDraws(Target* target) const override { |
1522 // Invert the view matrix as a local matrix (if any other processors req
uire coords). | 1522 // Invert the view matrix as a local matrix (if any other processors req
uire coords). |
1523 SkMatrix localMatrix; | 1523 SkMatrix localMatrix; |
1524 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { | 1524 if (!fViewMatrixIfUsingLocalCoords.invert(&localMatrix)) { |
1525 return; | 1525 return; |
1526 } | 1526 } |
1527 | 1527 |
1528 // Setup geometry processor | 1528 // Setup geometry processor |
1529 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(kStroke
_RRectType == fType, | 1529 SkAutoTUnref<GrGeometryProcessor> gp(new CircleGeometryProcessor(kFill_R
RectType != fType, |
1530 false,
false, | 1530 false,
false, |
1531 false,
localMatrix)); | 1531 false,
localMatrix)); |
1532 | 1532 |
1533 struct CircleVertex { | 1533 struct CircleVertex { |
1534 SkPoint fPos; | 1534 SkPoint fPos; |
1535 GrColor fColor; | 1535 GrColor fColor; |
1536 SkPoint fOffset; | 1536 SkPoint fOffset; |
1537 SkScalar fOuterRadius; | 1537 SkScalar fOuterRadius; |
1538 SkScalar fInnerRadius; | 1538 SkScalar fInnerRadius; |
1539 // No half plane, we don't use it here. | 1539 // No half plane, we don't use it here. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1605 verts++; | 1605 verts++; |
1606 | 1606 |
1607 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); | 1607 verts->fPos = SkPoint::Make(bounds.fRight, yCoords[i]); |
1608 verts->fColor = color; | 1608 verts->fColor = color; |
1609 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); | 1609 verts->fOffset = SkPoint::Make(1, yOuterRadii[i]); |
1610 verts->fOuterRadius = outerRadius; | 1610 verts->fOuterRadius = outerRadius; |
1611 verts->fInnerRadius = innerRadius; | 1611 verts->fInnerRadius = innerRadius; |
1612 verts++; | 1612 verts++; |
1613 } | 1613 } |
1614 // Add the additional vertices for overstroked rrects. | 1614 // Add the additional vertices for overstroked rrects. |
1615 // Effectively this is an additional rrect, drawn inside out, | 1615 // Effectively this is an additional stroked rrect, with its |
1616 // with outerRadius == -innerRadius. This will give us correct AA in
the center. | 1616 // outer radius = outerRadius - innerRadius, and inner radius = 0. |
| 1617 // This will give us correct AA in the center and the correct |
| 1618 // distance to the outer edge. |
1617 // | 1619 // |
1618 // Note that args.fInnerRadius is negative in this case. | 1620 // Also, the outer offset is a constant vector pointing to the right
, which |
1619 // Also, the offset is a constant vector pointing to the right, whic
h guarantees | 1621 // guarantees that the distance value along the outer rectangle is c
onstant. |
1620 // that the distance value along the inner rectangle is constant, wh
ich | |
1621 // is what we want to get nice anti-aliasing. | |
1622 if (kOverstroke_RRectType == fType) { | 1622 if (kOverstroke_RRectType == fType) { |
| 1623 SkScalar overstrokeOuterRadius = outerRadius - args.fInnerRadius
; |
| 1624 // this is the normalized distance from the outer rectangle of t
his |
| 1625 // geometry to the outer edge |
| 1626 SkScalar maxOffset = -args.fInnerRadius/overstrokeOuterRadius; |
| 1627 |
1623 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[
1]); | 1628 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[
1]); |
1624 verts->fColor = color; | 1629 verts->fColor = color; |
1625 verts->fOffset = SkPoint::Make(0, 0); | 1630 verts->fOffset = SkPoint::Make(maxOffset, 0); |
1626 verts->fOuterRadius = -args.fInnerRadius; | 1631 verts->fOuterRadius = overstrokeOuterRadius; |
1627 verts->fInnerRadius = innerRadius; | 1632 verts->fInnerRadius = 0; |
1628 verts++; | 1633 verts++; |
1629 | 1634 |
1630 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords
[1]); | 1635 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords
[1]); |
1631 verts->fColor = color; | 1636 verts->fColor = color; |
1632 verts->fOffset = SkPoint::Make(0, 0); | 1637 verts->fOffset = SkPoint::Make(maxOffset, 0); |
1633 verts->fOuterRadius = -args.fInnerRadius; | 1638 verts->fOuterRadius = overstrokeOuterRadius; |
1634 verts->fInnerRadius = innerRadius; | 1639 verts->fInnerRadius = 0; |
1635 verts++; | 1640 verts++; |
1636 | 1641 |
1637 SkScalar inset = outerRadius - args.fInnerRadius; | 1642 verts->fPos = SkPoint::Make(bounds.fLeft + overstrokeOuterRadius
, |
1638 verts->fPos = SkPoint::Make(bounds.fLeft + inset, | 1643 bounds.fTop + overstrokeOuterRadius)
; |
1639 bounds.fTop + inset); | |
1640 verts->fColor = color; | 1644 verts->fColor = color; |
1641 verts->fOffset = SkPoint::Make(1, 0); | 1645 verts->fOffset = SkPoint::Make(0, 0); |
1642 verts->fOuterRadius = -args.fInnerRadius; | 1646 verts->fOuterRadius = overstrokeOuterRadius; |
1643 verts->fInnerRadius = innerRadius; | 1647 verts->fInnerRadius = 0; |
1644 verts++; | 1648 verts++; |
1645 | 1649 |
1646 verts->fPos = SkPoint::Make(bounds.fRight - inset, | 1650 verts->fPos = SkPoint::Make(bounds.fRight - overstrokeOuterRadiu
s, |
1647 bounds.fTop + inset); | 1651 bounds.fTop + overstrokeOuterRadius)
; |
1648 verts->fColor = color; | 1652 verts->fColor = color; |
1649 verts->fOffset = SkPoint::Make(1, 0); | 1653 verts->fOffset = SkPoint::Make(0, 0); |
1650 verts->fOuterRadius = -args.fInnerRadius; | 1654 verts->fOuterRadius = overstrokeOuterRadius; |
1651 verts->fInnerRadius = innerRadius; | 1655 verts->fInnerRadius = 0; |
1652 verts++; | 1656 verts++; |
1653 | 1657 |
1654 verts->fPos = SkPoint::Make(bounds.fLeft + inset, | 1658 verts->fPos = SkPoint::Make(bounds.fLeft + overstrokeOuterRadius
, |
1655 bounds.fBottom - inset); | 1659 bounds.fBottom - overstrokeOuterRadi
us); |
1656 verts->fColor = color; | 1660 verts->fColor = color; |
1657 verts->fOffset = SkPoint::Make(1, 0); | 1661 verts->fOffset = SkPoint::Make(0, 0); |
1658 verts->fOuterRadius = -args.fInnerRadius; | 1662 verts->fOuterRadius = overstrokeOuterRadius; |
1659 verts->fInnerRadius = innerRadius; | 1663 verts->fInnerRadius = 0; |
1660 verts++; | 1664 verts++; |
1661 | 1665 |
1662 verts->fPos = SkPoint::Make(bounds.fRight - inset, | 1666 verts->fPos = SkPoint::Make(bounds.fRight - overstrokeOuterRadiu
s, |
1663 bounds.fBottom - inset); | 1667 bounds.fBottom - overstrokeOuterRadi
us); |
1664 verts->fColor = color; | 1668 verts->fColor = color; |
1665 verts->fOffset = SkPoint::Make(1, 0); | 1669 verts->fOffset = SkPoint::Make(0, 0); |
1666 verts->fOuterRadius = -args.fInnerRadius; | 1670 verts->fOuterRadius = overstrokeOuterRadius; |
1667 verts->fInnerRadius = innerRadius; | 1671 verts->fInnerRadius = 0; |
1668 verts++; | 1672 verts++; |
1669 | 1673 |
1670 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[
2]); | 1674 verts->fPos = SkPoint::Make(bounds.fLeft + outerRadius, yCoords[
2]); |
1671 verts->fColor = color; | 1675 verts->fColor = color; |
1672 verts->fOffset = SkPoint::Make(0, 0); | 1676 verts->fOffset = SkPoint::Make(maxOffset, 0); |
1673 verts->fOuterRadius = -args.fInnerRadius; | 1677 verts->fOuterRadius = overstrokeOuterRadius; |
1674 verts->fInnerRadius = innerRadius; | 1678 verts->fInnerRadius = 0; |
1675 verts++; | 1679 verts++; |
1676 | 1680 |
1677 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords
[2]); | 1681 verts->fPos = SkPoint::Make(bounds.fRight - outerRadius, yCoords
[2]); |
1678 verts->fColor = color; | 1682 verts->fColor = color; |
1679 verts->fOffset = SkPoint::Make(0, 0); | 1683 verts->fOffset = SkPoint::Make(maxOffset, 0); |
1680 verts->fOuterRadius = -args.fInnerRadius; | 1684 verts->fOuterRadius = overstrokeOuterRadius; |
1681 verts->fInnerRadius = innerRadius; | 1685 verts->fInnerRadius = 0; |
1682 verts++; | 1686 verts++; |
1683 } | 1687 } |
1684 } | 1688 } |
1685 | 1689 |
1686 helper.recordDraw(target, gp); | 1690 helper.recordDraw(target, gp); |
1687 } | 1691 } |
1688 | 1692 |
1689 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1693 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
1690 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); | 1694 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); |
1691 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), | 1695 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2124 } | 2128 } |
2125 | 2129 |
2126 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 2130 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
2127 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2131 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2128 GrColor color = GrRandomColor(random); | 2132 GrColor color = GrRandomColor(random); |
2129 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2133 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2130 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2134 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2131 } | 2135 } |
2132 | 2136 |
2133 #endif | 2137 #endif |
OLD | NEW |