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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 outerRadius += SK_ScalarHalf; | 565 outerRadius += SK_ScalarHalf; |
566 innerRadius -= SK_ScalarHalf; | 566 innerRadius -= SK_ScalarHalf; |
567 | 567 |
568 fGeoData.emplace_back(Geometry { | 568 fGeoData.emplace_back(Geometry { |
569 color, | 569 color, |
570 innerRadius, | 570 innerRadius, |
571 outerRadius, | 571 outerRadius, |
572 SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, | 572 SkRect::MakeLTRB(center.fX - outerRadius, center.fY - outerRadius, |
573 center.fX + outerRadius, center.fY + outerRadius) | 573 center.fX + outerRadius, center.fY + outerRadius) |
574 }); | 574 }); |
575 this->setBounds(fGeoData.back().fDevBounds); | 575 // Use the original radius and stroke radius for the bounds so that it d
oes not include the |
| 576 // AA bloat. |
| 577 radius += halfWidth; |
| 578 this->setBounds({center.fX - radius, center.fY - radius, |
| 579 center.fX + radius, center.fY + radius}, |
| 580 HasAABloat::kYes, IsZeroArea::kNo); |
576 fStroked = isStrokeOnly && innerRadius > 0; | 581 fStroked = isStrokeOnly && innerRadius > 0; |
577 } | 582 } |
578 | 583 |
579 const char* name() const override { return "CircleBatch"; } | 584 const char* name() const override { return "CircleBatch"; } |
580 | 585 |
581 SkString dumpInfo() const override { | 586 SkString dumpInfo() const override { |
582 SkString string; | 587 SkString string; |
583 for (int i = 0; i < fGeoData.count(); ++i) { | 588 for (int i = 0; i < fGeoData.count(); ++i) { |
584 string.appendf("Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.
2f]," | 589 string.appendf("Color: 0x%08x Rect [L: %.2f, T: %.2f, R: %.2f, B: %.
2f]," |
585 "InnerRad: %.2f, OuterRad: %.2f\n", | 590 "InnerRad: %.2f, OuterRad: %.2f\n", |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 | 683 |
679 if (this->fStroked != that->fStroked) { | 684 if (this->fStroked != that->fStroked) { |
680 return false; | 685 return false; |
681 } | 686 } |
682 | 687 |
683 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { | 688 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { |
684 return false; | 689 return false; |
685 } | 690 } |
686 | 691 |
687 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 692 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
688 this->joinBounds(that->bounds()); | 693 this->joinBounds(*that); |
689 return true; | 694 return true; |
690 } | 695 } |
691 | 696 |
692 struct Geometry { | 697 struct Geometry { |
693 GrColor fColor; | 698 GrColor fColor; |
694 SkScalar fInnerRadius; | 699 SkScalar fInnerRadius; |
695 SkScalar fOuterRadius; | 700 SkScalar fOuterRadius; |
696 SkRect fDevBounds; | 701 SkRect fDevBounds; |
697 }; | 702 }; |
698 | 703 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 batch->fGeoData.emplace_back(Geometry { | 775 batch->fGeoData.emplace_back(Geometry { |
771 color, | 776 color, |
772 xRadius, | 777 xRadius, |
773 yRadius, | 778 yRadius, |
774 innerXRadius, | 779 innerXRadius, |
775 innerYRadius, | 780 innerYRadius, |
776 SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRadius, | 781 SkRect::MakeLTRB(center.fX - xRadius, center.fY - yRadius, |
777 center.fX + xRadius, center.fY + yRadius) | 782 center.fX + xRadius, center.fY + yRadius) |
778 }); | 783 }); |
779 | 784 |
| 785 batch->setBounds(batch->fGeoData.back().fDevBounds, HasAABloat::kYes, Is
ZeroArea::kNo); |
| 786 |
780 // Outset bounds to include half-pixel width antialiasing. | 787 // Outset bounds to include half-pixel width antialiasing. |
781 batch->fGeoData[0].fDevBounds.outset(SK_ScalarHalf, SK_ScalarHalf); | 788 batch->fGeoData[0].fDevBounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
782 | 789 |
783 batch->fStroked = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; | 790 batch->fStroked = isStrokeOnly && innerXRadius > 0 && innerYRadius > 0; |
784 batch->fViewMatrixIfUsingLocalCoords = viewMatrix; | 791 batch->fViewMatrixIfUsingLocalCoords = viewMatrix; |
785 batch->setBounds(batch->fGeoData.back().fDevBounds); | |
786 return batch; | 792 return batch; |
787 } | 793 } |
788 | 794 |
789 const char* name() const override { return "EllipseBatch"; } | 795 const char* name() const override { return "EllipseBatch"; } |
790 | 796 |
791 void computePipelineOptimizations(GrInitInvariantOutput* color, | 797 void computePipelineOptimizations(GrInitInvariantOutput* color, |
792 GrInitInvariantOutput* coverage, | 798 GrInitInvariantOutput* coverage, |
793 GrBatchToXPOverrides* overrides) const ove
rride { | 799 GrBatchToXPOverrides* overrides) const ove
rride { |
794 // When this is called on a batch, there is only one geometry bundle | 800 // When this is called on a batch, there is only one geometry bundle |
795 color->setKnownFourComponents(fGeoData[0].fColor); | 801 color->setKnownFourComponents(fGeoData[0].fColor); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 | 893 |
888 if (fStroked != that->fStroked) { | 894 if (fStroked != that->fStroked) { |
889 return false; | 895 return false; |
890 } | 896 } |
891 | 897 |
892 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { | 898 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { |
893 return false; | 899 return false; |
894 } | 900 } |
895 | 901 |
896 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 902 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
897 this->joinBounds(that->bounds()); | 903 this->joinBounds(*that); |
898 return true; | 904 return true; |
899 } | 905 } |
900 | 906 |
901 struct Geometry { | 907 struct Geometry { |
902 GrColor fColor; | 908 GrColor fColor; |
903 SkScalar fXRadius; | 909 SkScalar fXRadius; |
904 SkScalar fYRadius; | 910 SkScalar fYRadius; |
905 SkScalar fInnerXRadius; | 911 SkScalar fInnerXRadius; |
906 SkScalar fInnerYRadius; | 912 SkScalar fInnerYRadius; |
907 SkRect fDevBounds; | 913 SkRect fDevBounds; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 xRadius, | 992 xRadius, |
987 yRadius, | 993 yRadius, |
988 innerXRadius, | 994 innerXRadius, |
989 innerYRadius, | 995 innerYRadius, |
990 geoDx, | 996 geoDx, |
991 geoDy, | 997 geoDy, |
992 dieStyle, | 998 dieStyle, |
993 SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius -
geoDy, | 999 SkRect::MakeLTRB(center.fX - xRadius - geoDx, center.fY - yRadius -
geoDy, |
994 center.fX + xRadius + geoDx, center.fY + yRadius +
geoDy) | 1000 center.fX + xRadius + geoDx, center.fY + yRadius +
geoDy) |
995 }); | 1001 }); |
996 SkRect devBounds = batch->fGeoData.back().fBounds; | 1002 batch->setTransformedBounds(batch->fGeoData[0].fBounds, viewMatrix, HasA
ABloat::kYes, |
997 viewMatrix.mapRect(&devBounds); | 1003 IsZeroArea::kNo); |
998 batch->setBounds(devBounds); | |
999 return batch; | 1004 return batch; |
1000 } | 1005 } |
1001 | 1006 |
1002 const char* name() const override { return "DIEllipseBatch"; } | 1007 const char* name() const override { return "DIEllipseBatch"; } |
1003 | 1008 |
1004 void computePipelineOptimizations(GrInitInvariantOutput* color, | 1009 void computePipelineOptimizations(GrInitInvariantOutput* color, |
1005 GrInitInvariantOutput* coverage, | 1010 GrInitInvariantOutput* coverage, |
1006 GrBatchToXPOverrides* overrides) const ove
rride { | 1011 GrBatchToXPOverrides* overrides) const ove
rride { |
1007 // When this is called on a batch, there is only one geometry bundle | 1012 // When this is called on a batch, there is only one geometry bundle |
1008 color->setKnownFourComponents(fGeoData[0].fColor); | 1013 color->setKnownFourComponents(fGeoData[0].fColor); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1085 if (this->style() != that->style()) { | 1090 if (this->style() != that->style()) { |
1086 return false; | 1091 return false; |
1087 } | 1092 } |
1088 | 1093 |
1089 // TODO rewrite to allow positioning on CPU | 1094 // TODO rewrite to allow positioning on CPU |
1090 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | 1095 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
1091 return false; | 1096 return false; |
1092 } | 1097 } |
1093 | 1098 |
1094 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 1099 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
1095 this->joinBounds(that->bounds()); | 1100 this->joinBounds(*that); |
1096 return true; | 1101 return true; |
1097 } | 1102 } |
1098 | 1103 |
1099 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 1104 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
1100 DIEllipseStyle style() const { return fGeoData[0].fStyle; } | 1105 DIEllipseStyle style() const { return fGeoData[0].fStyle; } |
1101 | 1106 |
1102 struct Geometry { | 1107 struct Geometry { |
1103 SkMatrix fViewMatrix; | 1108 SkMatrix fViewMatrix; |
1104 GrColor fColor; | 1109 GrColor fColor; |
1105 SkScalar fXRadius; | 1110 SkScalar fXRadius; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 } | 1200 } |
1196 | 1201 |
1197 // The radii are outset for two reasons. First, it allows the shader to
simply perform | 1202 // The radii are outset for two reasons. First, it allows the shader to
simply perform |
1198 // simpler computation because the computed alpha is zero, rather than 5
0%, at the radius. | 1203 // simpler computation because the computed alpha is zero, rather than 5
0%, at the radius. |
1199 // Second, the outer radius is used to compute the verts of the bounding
box that is | 1204 // Second, the outer radius is used to compute the verts of the bounding
box that is |
1200 // rendered and the outset ensures the box will cover all partially cove
red by the rrect | 1205 // rendered and the outset ensures the box will cover all partially cove
red by the rrect |
1201 // corners. | 1206 // corners. |
1202 outerRadius += SK_ScalarHalf; | 1207 outerRadius += SK_ScalarHalf; |
1203 innerRadius -= SK_ScalarHalf; | 1208 innerRadius -= SK_ScalarHalf; |
1204 | 1209 |
1205 // Expand the rect so all the pixels will be captured. | 1210 this->setBounds(bounds, HasAABloat::kYes, IsZeroArea::kNo); |
| 1211 |
| 1212 // Expand the rect for aa to generate correct vertices. |
1206 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); | 1213 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
1207 | 1214 |
1208 fGeoData.emplace_back(Geometry { color, innerRadius, outerRadius, bounds
}); | 1215 fGeoData.emplace_back(Geometry { color, innerRadius, outerRadius, bounds
}); |
1209 this->setBounds(bounds); | |
1210 } | 1216 } |
1211 | 1217 |
1212 const char* name() const override { return "RRectCircleBatch"; } | 1218 const char* name() const override { return "RRectCircleBatch"; } |
1213 | 1219 |
1214 void computePipelineOptimizations(GrInitInvariantOutput* color, | 1220 void computePipelineOptimizations(GrInitInvariantOutput* color, |
1215 GrInitInvariantOutput* coverage, | 1221 GrInitInvariantOutput* coverage, |
1216 GrBatchToXPOverrides* overrides) const ove
rride { | 1222 GrBatchToXPOverrides* overrides) const ove
rride { |
1217 // When this is called on a batch, there is only one geometry bundle | 1223 // When this is called on a batch, there is only one geometry bundle |
1218 color->setKnownFourComponents(fGeoData[0].fColor); | 1224 color->setKnownFourComponents(fGeoData[0].fColor); |
1219 coverage->setUnknownSingleComponent(); | 1225 coverage->setUnknownSingleComponent(); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 | 1323 |
1318 if (fStroked != that->fStroked) { | 1324 if (fStroked != that->fStroked) { |
1319 return false; | 1325 return false; |
1320 } | 1326 } |
1321 | 1327 |
1322 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { | 1328 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { |
1323 return false; | 1329 return false; |
1324 } | 1330 } |
1325 | 1331 |
1326 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 1332 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
1327 this->joinBounds(that->bounds()); | 1333 this->joinBounds(*that); |
1328 return true; | 1334 return true; |
1329 } | 1335 } |
1330 | 1336 |
1331 struct Geometry { | 1337 struct Geometry { |
1332 GrColor fColor; | 1338 GrColor fColor; |
1333 SkScalar fInnerRadius; | 1339 SkScalar fInnerRadius; |
1334 SkScalar fOuterRadius; | 1340 SkScalar fOuterRadius; |
1335 SkRect fDevBounds; | 1341 SkRect fDevBounds; |
1336 }; | 1342 }; |
1337 | 1343 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 innerXRadius = devXRadius - devStrokeWidths.fX; | 1393 innerXRadius = devXRadius - devStrokeWidths.fX; |
1388 innerYRadius = devYRadius - devStrokeWidths.fY; | 1394 innerYRadius = devYRadius - devStrokeWidths.fY; |
1389 stroked = (innerXRadius >= 0 && innerYRadius >= 0); | 1395 stroked = (innerXRadius >= 0 && innerYRadius >= 0); |
1390 } | 1396 } |
1391 | 1397 |
1392 devXRadius += devStrokeWidths.fX; | 1398 devXRadius += devStrokeWidths.fX; |
1393 devYRadius += devStrokeWidths.fY; | 1399 devYRadius += devStrokeWidths.fY; |
1394 bounds.outset(devStrokeWidths.fX, devStrokeWidths.fY); | 1400 bounds.outset(devStrokeWidths.fX, devStrokeWidths.fY); |
1395 } | 1401 } |
1396 | 1402 |
1397 // Expand the rect so all the pixels will be captured. | |
1398 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); | |
1399 | |
1400 RRectEllipseRendererBatch* batch = new RRectEllipseRendererBatch(); | 1403 RRectEllipseRendererBatch* batch = new RRectEllipseRendererBatch(); |
1401 batch->fStroked = stroked; | 1404 batch->fStroked = stroked; |
1402 batch->fViewMatrixIfUsingLocalCoords = viewMatrix; | 1405 batch->fViewMatrixIfUsingLocalCoords = viewMatrix; |
| 1406 batch->setBounds(bounds, HasAABloat::kYes, IsZeroArea::kNo); |
| 1407 // Expand the rect for aa in order to generate the correct vertices. |
| 1408 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
1403 batch->fGeoData.emplace_back( | 1409 batch->fGeoData.emplace_back( |
1404 Geometry {color, devXRadius, devYRadius, innerXRadius, innerYRadius,
bounds}); | 1410 Geometry {color, devXRadius, devYRadius, innerXRadius, innerYRadius,
bounds}); |
1405 batch->setBounds(bounds); | |
1406 return batch; | 1411 return batch; |
1407 } | 1412 } |
1408 | 1413 |
1409 const char* name() const override { return "RRectEllipseRendererBatch"; } | 1414 const char* name() const override { return "RRectEllipseRendererBatch"; } |
1410 | 1415 |
1411 void computePipelineOptimizations(GrInitInvariantOutput* color, | 1416 void computePipelineOptimizations(GrInitInvariantOutput* color, |
1412 GrInitInvariantOutput* coverage, | 1417 GrInitInvariantOutput* coverage, |
1413 GrBatchToXPOverrides* overrides) const ove
rride { | 1418 GrBatchToXPOverrides* overrides) const ove
rride { |
1414 // When this is called on a batch, there is only one geometry bundle | 1419 // When this is called on a batch, there is only one geometry bundle |
1415 color->setKnownFourComponents(fGeoData[0].fColor); | 1420 color->setKnownFourComponents(fGeoData[0].fColor); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1527 | 1532 |
1528 if (fStroked != that->fStroked) { | 1533 if (fStroked != that->fStroked) { |
1529 return false; | 1534 return false; |
1530 } | 1535 } |
1531 | 1536 |
1532 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { | 1537 if (!fViewMatrixIfUsingLocalCoords.cheapEqualTo(that->fViewMatrixIfUsing
LocalCoords)) { |
1533 return false; | 1538 return false; |
1534 } | 1539 } |
1535 | 1540 |
1536 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); | 1541 fGeoData.push_back_n(that->fGeoData.count(), that->fGeoData.begin()); |
1537 this->joinBounds(that->bounds()); | 1542 this->joinBounds(*that); |
1538 return true; | 1543 return true; |
1539 } | 1544 } |
1540 | 1545 |
1541 struct Geometry { | 1546 struct Geometry { |
1542 GrColor fColor; | 1547 GrColor fColor; |
1543 SkScalar fXRadius; | 1548 SkScalar fXRadius; |
1544 SkScalar fYRadius; | 1549 SkScalar fYRadius; |
1545 SkScalar fInnerXRadius; | 1550 SkScalar fInnerXRadius; |
1546 SkScalar fInnerYRadius; | 1551 SkScalar fInnerYRadius; |
1547 SkRect fDevBounds; | 1552 SkRect fDevBounds; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 } | 1693 } |
1689 | 1694 |
1690 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1695 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1691 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1696 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1692 GrColor color = GrRandomColor(random); | 1697 GrColor color = GrRandomColor(random); |
1693 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1698 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1694 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 1699 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
1695 } | 1700 } |
1696 | 1701 |
1697 #endif | 1702 #endif |
OLD | NEW |