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 "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 stroke); | 618 stroke); |
619 } else { | 619 } else { |
620 return false; | 620 return false; |
621 } | 621 } |
622 | 622 |
623 return true; | 623 return true; |
624 } | 624 } |
625 | 625 |
626 /////////////////////////////////////////////////////////////////////////////// | 626 /////////////////////////////////////////////////////////////////////////////// |
627 | 627 |
628 class CircleBatch : public GrBatch { | 628 class CircleBatch : public GrVertexBatch { |
629 public: | 629 public: |
630 struct Geometry { | 630 struct Geometry { |
631 GrColor fColor; | 631 GrColor fColor; |
632 SkMatrix fViewMatrix; | 632 SkMatrix fViewMatrix; |
633 SkScalar fInnerRadius; | 633 SkScalar fInnerRadius; |
634 SkScalar fOuterRadius; | 634 SkScalar fOuterRadius; |
635 bool fStroke; | 635 bool fStroke; |
636 SkRect fDevBounds; | 636 SkRect fDevBounds; |
637 }; | 637 }; |
638 | 638 |
639 static GrBatch* Create(const Geometry& geometry) { return SkNEW_ARGS(CircleB
atch, (geometry)); } | 639 static GrDrawBatch* Create(const Geometry& geometry) { |
| 640 return SkNEW_ARGS(CircleBatch, (geometry)); |
| 641 } |
640 | 642 |
641 const char* name() const override { return "CircleBatch"; } | 643 const char* name() const override { return "CircleBatch"; } |
642 | 644 |
643 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 645 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
644 // When this is called on a batch, there is only one geometry bundle | 646 // When this is called on a batch, there is only one geometry bundle |
645 out->setKnownFourComponents(fGeoData[0].fColor); | 647 out->setKnownFourComponents(fGeoData[0].fColor); |
646 } | 648 } |
647 | 649 |
648 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 650 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
649 out->setUnknownSingleComponent(); | 651 out->setUnknownSingleComponent(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 | 729 |
728 private: | 730 private: |
729 CircleBatch(const Geometry& geometry) { | 731 CircleBatch(const Geometry& geometry) { |
730 this->initClassID<CircleBatch>(); | 732 this->initClassID<CircleBatch>(); |
731 fGeoData.push_back(geometry); | 733 fGeoData.push_back(geometry); |
732 | 734 |
733 this->setBounds(geometry.fDevBounds); | 735 this->setBounds(geometry.fDevBounds); |
734 } | 736 } |
735 | 737 |
736 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 738 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
737 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 739 CircleBatch* that = t->cast<CircleBatch>(); |
738 caps)) { | 740 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 741 that->bounds(), caps)) { |
739 return false; | 742 return false; |
740 } | 743 } |
741 | 744 |
742 CircleBatch* that = t->cast<CircleBatch>(); | |
743 | |
744 // TODO use vertex color to avoid breaking batches | 745 // TODO use vertex color to avoid breaking batches |
745 if (this->color() != that->color()) { | 746 if (this->color() != that->color()) { |
746 return false; | 747 return false; |
747 } | 748 } |
748 | 749 |
749 if (this->stroke() != that->stroke()) { | 750 if (this->stroke() != that->stroke()) { |
750 return false; | 751 return false; |
751 } | 752 } |
752 | 753 |
753 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 754 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
(...skipping 16 matching lines...) Expand all Loading... |
770 bool fStroke; | 771 bool fStroke; |
771 bool fUsesLocalCoords; | 772 bool fUsesLocalCoords; |
772 bool fColorIgnored; | 773 bool fColorIgnored; |
773 bool fCoverageIgnored; | 774 bool fCoverageIgnored; |
774 }; | 775 }; |
775 | 776 |
776 BatchTracker fBatch; | 777 BatchTracker fBatch; |
777 SkSTArray<1, Geometry, true> fGeoData; | 778 SkSTArray<1, Geometry, true> fGeoData; |
778 }; | 779 }; |
779 | 780 |
780 static GrBatch* create_circle_batch(GrColor color, | 781 static GrDrawBatch* create_circle_batch(GrColor color, |
781 const SkMatrix& viewMatrix, | 782 const SkMatrix& viewMatrix, |
782 bool useCoverageAA, | 783 bool useCoverageAA, |
783 const SkRect& circle, | 784 const SkRect& circle, |
784 const SkStrokeRec& stroke) { | 785 const SkStrokeRec& stroke) { |
785 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); | 786 SkPoint center = SkPoint::Make(circle.centerX(), circle.centerY()); |
786 viewMatrix.mapPoints(¢er, 1); | 787 viewMatrix.mapPoints(¢er, 1); |
787 SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); | 788 SkScalar radius = viewMatrix.mapRadius(SkScalarHalf(circle.width())); |
788 SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); | 789 SkScalar strokeWidth = viewMatrix.mapRadius(stroke.getWidth()); |
789 | 790 |
790 SkStrokeRec::Style style = stroke.getStyle(); | 791 SkStrokeRec::Style style = stroke.getStyle(); |
791 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || | 792 bool isStrokeOnly = SkStrokeRec::kStroke_Style == style || |
792 SkStrokeRec::kHairline_Style == style; | 793 SkStrokeRec::kHairline_Style == style; |
793 bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; | 794 bool hasStroke = isStrokeOnly || SkStrokeRec::kStrokeAndFill_Style == style; |
794 | 795 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 return CircleBatch::Create(geometry); | 828 return CircleBatch::Create(geometry); |
828 } | 829 } |
829 | 830 |
830 void GrOvalRenderer::DrawCircle(GrDrawTarget* target, | 831 void GrOvalRenderer::DrawCircle(GrDrawTarget* target, |
831 const GrPipelineBuilder& pipelineBuilder, | 832 const GrPipelineBuilder& pipelineBuilder, |
832 GrColor color, | 833 GrColor color, |
833 const SkMatrix& viewMatrix, | 834 const SkMatrix& viewMatrix, |
834 bool useCoverageAA, | 835 bool useCoverageAA, |
835 const SkRect& circle, | 836 const SkRect& circle, |
836 const SkStrokeRec& stroke) { | 837 const SkStrokeRec& stroke) { |
837 SkAutoTUnref<GrBatch> batch(create_circle_batch(color, viewMatrix, useCovera
geAA, circle, | 838 SkAutoTUnref<GrDrawBatch> batch(create_circle_batch(color, viewMatrix, useCo
verageAA, circle, |
838 stroke)); | 839 stroke)); |
839 target->drawBatch(pipelineBuilder, batch); | 840 target->drawBatch(pipelineBuilder, batch); |
840 } | 841 } |
841 | 842 |
842 /////////////////////////////////////////////////////////////////////////////// | 843 /////////////////////////////////////////////////////////////////////////////// |
843 | 844 |
844 class EllipseBatch : public GrBatch { | 845 class EllipseBatch : public GrVertexBatch { |
845 public: | 846 public: |
846 struct Geometry { | 847 struct Geometry { |
847 GrColor fColor; | 848 GrColor fColor; |
848 SkMatrix fViewMatrix; | 849 SkMatrix fViewMatrix; |
849 SkScalar fXRadius; | 850 SkScalar fXRadius; |
850 SkScalar fYRadius; | 851 SkScalar fYRadius; |
851 SkScalar fInnerXRadius; | 852 SkScalar fInnerXRadius; |
852 SkScalar fInnerYRadius; | 853 SkScalar fInnerYRadius; |
853 bool fStroke; | 854 bool fStroke; |
854 SkRect fDevBounds; | 855 SkRect fDevBounds; |
855 }; | 856 }; |
856 | 857 |
857 static GrBatch* Create(const Geometry& geometry) { | 858 static GrDrawBatch* Create(const Geometry& geometry) { |
858 return SkNEW_ARGS(EllipseBatch, (geometry)); | 859 return SkNEW_ARGS(EllipseBatch, (geometry)); |
859 } | 860 } |
860 | 861 |
861 const char* name() const override { return "EllipseBatch"; } | 862 const char* name() const override { return "EllipseBatch"; } |
862 | 863 |
863 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 864 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
864 // When this is called on a batch, there is only one geometry bundle | 865 // When this is called on a batch, there is only one geometry bundle |
865 out->setKnownFourComponents(fGeoData[0].fColor); | 866 out->setKnownFourComponents(fGeoData[0].fColor); |
866 } | 867 } |
867 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 868 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 | 952 |
952 private: | 953 private: |
953 EllipseBatch(const Geometry& geometry) { | 954 EllipseBatch(const Geometry& geometry) { |
954 this->initClassID<EllipseBatch>(); | 955 this->initClassID<EllipseBatch>(); |
955 fGeoData.push_back(geometry); | 956 fGeoData.push_back(geometry); |
956 | 957 |
957 this->setBounds(geometry.fDevBounds); | 958 this->setBounds(geometry.fDevBounds); |
958 } | 959 } |
959 | 960 |
960 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 961 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
961 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 962 EllipseBatch* that = t->cast<EllipseBatch>(); |
962 caps)) { | 963 |
| 964 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 965 that->bounds(), caps)) { |
963 return false; | 966 return false; |
964 } | 967 } |
965 | 968 |
966 EllipseBatch* that = t->cast<EllipseBatch>(); | |
967 | |
968 // TODO use vertex color to avoid breaking batches | 969 // TODO use vertex color to avoid breaking batches |
969 if (this->color() != that->color()) { | 970 if (this->color() != that->color()) { |
970 return false; | 971 return false; |
971 } | 972 } |
972 | 973 |
973 if (this->stroke() != that->stroke()) { | 974 if (this->stroke() != that->stroke()) { |
974 return false; | 975 return false; |
975 } | 976 } |
976 | 977 |
977 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 978 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
(...skipping 16 matching lines...) Expand all Loading... |
994 bool fStroke; | 995 bool fStroke; |
995 bool fUsesLocalCoords; | 996 bool fUsesLocalCoords; |
996 bool fColorIgnored; | 997 bool fColorIgnored; |
997 bool fCoverageIgnored; | 998 bool fCoverageIgnored; |
998 }; | 999 }; |
999 | 1000 |
1000 BatchTracker fBatch; | 1001 BatchTracker fBatch; |
1001 SkSTArray<1, Geometry, true> fGeoData; | 1002 SkSTArray<1, Geometry, true> fGeoData; |
1002 }; | 1003 }; |
1003 | 1004 |
1004 static GrBatch* create_ellipse_batch(GrColor color, | 1005 static GrDrawBatch* create_ellipse_batch(GrColor color, |
1005 const SkMatrix& viewMatrix, | 1006 const SkMatrix& viewMatrix, |
1006 bool useCoverageAA, | 1007 bool useCoverageAA, |
1007 const SkRect& ellipse, | 1008 const SkRect& ellipse, |
1008 const SkStrokeRec& stroke) { | 1009 const SkStrokeRec& stroke) { |
1009 #ifdef SK_DEBUG | 1010 #ifdef SK_DEBUG |
1010 { | 1011 { |
1011 // we should have checked for this previously | 1012 // we should have checked for this previously |
1012 bool isAxisAlignedEllipse = viewMatrix.rectStaysRect(); | 1013 bool isAxisAlignedEllipse = viewMatrix.rectStaysRect(); |
1013 SkASSERT(useCoverageAA && isAxisAlignedEllipse); | 1014 SkASSERT(useCoverageAA && isAxisAlignedEllipse); |
1014 } | 1015 } |
1015 #endif | 1016 #endif |
1016 | 1017 |
1017 // do any matrix crunching before we reset the draw state for device coords | 1018 // do any matrix crunching before we reset the draw state for device coords |
1018 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); | 1019 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 return EllipseBatch::Create(geometry); | 1089 return EllipseBatch::Create(geometry); |
1089 } | 1090 } |
1090 | 1091 |
1091 bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, | 1092 bool GrOvalRenderer::DrawEllipse(GrDrawTarget* target, |
1092 const GrPipelineBuilder& pipelineBuilder, | 1093 const GrPipelineBuilder& pipelineBuilder, |
1093 GrColor color, | 1094 GrColor color, |
1094 const SkMatrix& viewMatrix, | 1095 const SkMatrix& viewMatrix, |
1095 bool useCoverageAA, | 1096 bool useCoverageAA, |
1096 const SkRect& ellipse, | 1097 const SkRect& ellipse, |
1097 const SkStrokeRec& stroke) { | 1098 const SkStrokeRec& stroke) { |
1098 SkAutoTUnref<GrBatch> batch(create_ellipse_batch(color, viewMatrix, useCover
ageAA, ellipse, | 1099 SkAutoTUnref<GrDrawBatch> batch(create_ellipse_batch(color, viewMatrix, useC
overageAA, ellipse, |
1099 stroke)); | 1100 stroke)); |
1100 if (!batch) { | 1101 if (!batch) { |
1101 return false; | 1102 return false; |
1102 } | 1103 } |
1103 | 1104 |
1104 target->drawBatch(pipelineBuilder, batch); | 1105 target->drawBatch(pipelineBuilder, batch); |
1105 return true; | 1106 return true; |
1106 } | 1107 } |
1107 | 1108 |
1108 ////////////////////////////////////////////////////////////////////////////////
///////////////// | 1109 ////////////////////////////////////////////////////////////////////////////////
///////////////// |
1109 | 1110 |
1110 class DIEllipseBatch : public GrBatch { | 1111 class DIEllipseBatch : public GrVertexBatch { |
1111 public: | 1112 public: |
1112 struct Geometry { | 1113 struct Geometry { |
1113 GrColor fColor; | 1114 GrColor fColor; |
1114 SkMatrix fViewMatrix; | 1115 SkMatrix fViewMatrix; |
1115 SkScalar fXRadius; | 1116 SkScalar fXRadius; |
1116 SkScalar fYRadius; | 1117 SkScalar fYRadius; |
1117 SkScalar fInnerXRadius; | 1118 SkScalar fInnerXRadius; |
1118 SkScalar fInnerYRadius; | 1119 SkScalar fInnerYRadius; |
1119 SkScalar fGeoDx; | 1120 SkScalar fGeoDx; |
1120 SkScalar fGeoDy; | 1121 SkScalar fGeoDy; |
1121 DIEllipseEdgeEffect::Mode fMode; | 1122 DIEllipseEdgeEffect::Mode fMode; |
1122 SkRect fBounds; | 1123 SkRect fBounds; |
1123 }; | 1124 }; |
1124 | 1125 |
1125 static GrBatch* Create(const Geometry& geometry, const SkRect& bounds) { | 1126 static GrDrawBatch* Create(const Geometry& geometry, const SkRect& bounds) { |
1126 return SkNEW_ARGS(DIEllipseBatch, (geometry, bounds)); | 1127 return SkNEW_ARGS(DIEllipseBatch, (geometry, bounds)); |
1127 } | 1128 } |
1128 | 1129 |
1129 const char* name() const override { return "DIEllipseBatch"; } | 1130 const char* name() const override { return "DIEllipseBatch"; } |
1130 | 1131 |
1131 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 1132 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
1132 // When this is called on a batch, there is only one geometry bundle | 1133 // When this is called on a batch, there is only one geometry bundle |
1133 out->setKnownFourComponents(fGeoData[0].fColor); | 1134 out->setKnownFourComponents(fGeoData[0].fColor); |
1134 } | 1135 } |
1135 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 1136 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 | 1211 |
1211 private: | 1212 private: |
1212 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { | 1213 DIEllipseBatch(const Geometry& geometry, const SkRect& bounds) { |
1213 this->initClassID<DIEllipseBatch>(); | 1214 this->initClassID<DIEllipseBatch>(); |
1214 fGeoData.push_back(geometry); | 1215 fGeoData.push_back(geometry); |
1215 | 1216 |
1216 this->setBounds(bounds); | 1217 this->setBounds(bounds); |
1217 } | 1218 } |
1218 | 1219 |
1219 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1220 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
1220 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 1221 DIEllipseBatch* that = t->cast<DIEllipseBatch>(); |
1221 caps)) { | 1222 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 1223 that->bounds(), caps)) { |
1222 return false; | 1224 return false; |
1223 } | 1225 } |
1224 | 1226 |
1225 DIEllipseBatch* that = t->cast<DIEllipseBatch>(); | |
1226 | |
1227 // TODO use vertex color to avoid breaking batches | 1227 // TODO use vertex color to avoid breaking batches |
1228 if (this->color() != that->color()) { | 1228 if (this->color() != that->color()) { |
1229 return false; | 1229 return false; |
1230 } | 1230 } |
1231 | 1231 |
1232 if (this->mode() != that->mode()) { | 1232 if (this->mode() != that->mode()) { |
1233 return false; | 1233 return false; |
1234 } | 1234 } |
1235 | 1235 |
1236 // TODO rewrite to allow positioning on CPU | 1236 // TODO rewrite to allow positioning on CPU |
(...skipping 16 matching lines...) Expand all Loading... |
1253 DIEllipseEdgeEffect::Mode fMode; | 1253 DIEllipseEdgeEffect::Mode fMode; |
1254 bool fUsesLocalCoords; | 1254 bool fUsesLocalCoords; |
1255 bool fColorIgnored; | 1255 bool fColorIgnored; |
1256 bool fCoverageIgnored; | 1256 bool fCoverageIgnored; |
1257 }; | 1257 }; |
1258 | 1258 |
1259 BatchTracker fBatch; | 1259 BatchTracker fBatch; |
1260 SkSTArray<1, Geometry, true> fGeoData; | 1260 SkSTArray<1, Geometry, true> fGeoData; |
1261 }; | 1261 }; |
1262 | 1262 |
1263 static GrBatch* create_diellipse_batch(GrColor color, | 1263 static GrDrawBatch* create_diellipse_batch(GrColor color, |
1264 const SkMatrix& viewMatrix, | 1264 const SkMatrix& viewMatrix, |
1265 bool useCoverageAA, | 1265 bool useCoverageAA, |
1266 const SkRect& ellipse, | 1266 const SkRect& ellipse, |
1267 const SkStrokeRec& stroke) { | 1267 const SkStrokeRec& stroke) { |
1268 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); | 1268 SkPoint center = SkPoint::Make(ellipse.centerX(), ellipse.centerY()); |
1269 SkScalar xRadius = SkScalarHalf(ellipse.width()); | 1269 SkScalar xRadius = SkScalarHalf(ellipse.width()); |
1270 SkScalar yRadius = SkScalarHalf(ellipse.height()); | 1270 SkScalar yRadius = SkScalarHalf(ellipse.height()); |
1271 | 1271 |
1272 SkStrokeRec::Style style = stroke.getStyle(); | 1272 SkStrokeRec::Style style = stroke.getStyle(); |
1273 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? | 1273 DIEllipseEdgeEffect::Mode mode = (SkStrokeRec::kStroke_Style == style) ? |
1274 DIEllipseEdgeEffect::kStroke : | 1274 DIEllipseEdgeEffect::kStroke : |
1275 (SkStrokeRec::kHairline_Style == style) ? | 1275 (SkStrokeRec::kHairline_Style == style) ? |
1276 DIEllipseEdgeEffect::kHairline : DIEllipseEd
geEffect::kFill; | 1276 DIEllipseEdgeEffect::kHairline : DIEllipseEd
geEffect::kFill; |
1277 | 1277 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1338 return DIEllipseBatch::Create(geometry, devBounds); | 1338 return DIEllipseBatch::Create(geometry, devBounds); |
1339 } | 1339 } |
1340 | 1340 |
1341 bool GrOvalRenderer::DrawDIEllipse(GrDrawTarget* target, | 1341 bool GrOvalRenderer::DrawDIEllipse(GrDrawTarget* target, |
1342 const GrPipelineBuilder& pipelineBuilder, | 1342 const GrPipelineBuilder& pipelineBuilder, |
1343 GrColor color, | 1343 GrColor color, |
1344 const SkMatrix& viewMatrix, | 1344 const SkMatrix& viewMatrix, |
1345 bool useCoverageAA, | 1345 bool useCoverageAA, |
1346 const SkRect& ellipse, | 1346 const SkRect& ellipse, |
1347 const SkStrokeRec& stroke) { | 1347 const SkStrokeRec& stroke) { |
1348 SkAutoTUnref<GrBatch> batch(create_diellipse_batch(color, viewMatrix, useCov
erageAA, ellipse, | 1348 SkAutoTUnref<GrDrawBatch> batch(create_diellipse_batch(color, viewMatrix, us
eCoverageAA, |
1349 stroke)); | 1349 ellipse, stroke)); |
1350 if (!batch) { | 1350 if (!batch) { |
1351 return false; | 1351 return false; |
1352 } | 1352 } |
1353 target->drawBatch(pipelineBuilder, batch); | 1353 target->drawBatch(pipelineBuilder, batch); |
1354 return true; | 1354 return true; |
1355 } | 1355 } |
1356 | 1356 |
1357 /////////////////////////////////////////////////////////////////////////////// | 1357 /////////////////////////////////////////////////////////////////////////////// |
1358 | 1358 |
1359 static const uint16_t gRRectIndices[] = { | 1359 static const uint16_t gRRectIndices[] = { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1456 SkRect bounds = outer->getBounds(); | 1456 SkRect bounds = outer->getBounds(); |
1457 if (applyAA) { | 1457 if (applyAA) { |
1458 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); | 1458 bounds.outset(SK_ScalarHalf, SK_ScalarHalf); |
1459 } | 1459 } |
1460 target->drawBWRect(pipelineBuilder, color, SkMatrix::I(), bounds, NULL, &inv
ert); | 1460 target->drawBWRect(pipelineBuilder, color, SkMatrix::I(), bounds, NULL, &inv
ert); |
1461 return true; | 1461 return true; |
1462 } | 1462 } |
1463 | 1463 |
1464 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 1464 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
1465 | 1465 |
1466 class RRectCircleRendererBatch : public GrBatch { | 1466 class RRectCircleRendererBatch : public GrVertexBatch { |
1467 public: | 1467 public: |
1468 struct Geometry { | 1468 struct Geometry { |
1469 GrColor fColor; | 1469 GrColor fColor; |
1470 SkMatrix fViewMatrix; | 1470 SkMatrix fViewMatrix; |
1471 SkScalar fInnerRadius; | 1471 SkScalar fInnerRadius; |
1472 SkScalar fOuterRadius; | 1472 SkScalar fOuterRadius; |
1473 bool fStroke; | 1473 bool fStroke; |
1474 SkRect fDevBounds; | 1474 SkRect fDevBounds; |
1475 }; | 1475 }; |
1476 | 1476 |
1477 static GrBatch* Create(const Geometry& geometry) { | 1477 static GrDrawBatch* Create(const Geometry& geometry) { |
1478 return SkNEW_ARGS(RRectCircleRendererBatch, (geometry)); | 1478 return SkNEW_ARGS(RRectCircleRendererBatch, (geometry)); |
1479 } | 1479 } |
1480 | 1480 |
1481 const char* name() const override { return "RRectCircleBatch"; } | 1481 const char* name() const override { return "RRectCircleBatch"; } |
1482 | 1482 |
1483 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 1483 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
1484 // When this is called on a batch, there is only one geometry bundle | 1484 // When this is called on a batch, there is only one geometry bundle |
1485 out->setKnownFourComponents(fGeoData[0].fColor); | 1485 out->setKnownFourComponents(fGeoData[0].fColor); |
1486 } | 1486 } |
1487 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 1487 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 | 1588 |
1589 private: | 1589 private: |
1590 RRectCircleRendererBatch(const Geometry& geometry) { | 1590 RRectCircleRendererBatch(const Geometry& geometry) { |
1591 this->initClassID<RRectCircleRendererBatch>(); | 1591 this->initClassID<RRectCircleRendererBatch>(); |
1592 fGeoData.push_back(geometry); | 1592 fGeoData.push_back(geometry); |
1593 | 1593 |
1594 this->setBounds(geometry.fDevBounds); | 1594 this->setBounds(geometry.fDevBounds); |
1595 } | 1595 } |
1596 | 1596 |
1597 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1597 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
1598 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 1598 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); |
1599 caps)) { | 1599 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 1600 that->bounds(), caps)) { |
1600 return false; | 1601 return false; |
1601 } | 1602 } |
1602 | 1603 |
1603 RRectCircleRendererBatch* that = t->cast<RRectCircleRendererBatch>(); | |
1604 | |
1605 // TODO use vertex color to avoid breaking batches | 1604 // TODO use vertex color to avoid breaking batches |
1606 if (this->color() != that->color()) { | 1605 if (this->color() != that->color()) { |
1607 return false; | 1606 return false; |
1608 } | 1607 } |
1609 | 1608 |
1610 if (this->stroke() != that->stroke()) { | 1609 if (this->stroke() != that->stroke()) { |
1611 return false; | 1610 return false; |
1612 } | 1611 } |
1613 | 1612 |
1614 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 1613 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
(...skipping 16 matching lines...) Expand all Loading... |
1631 bool fStroke; | 1630 bool fStroke; |
1632 bool fUsesLocalCoords; | 1631 bool fUsesLocalCoords; |
1633 bool fColorIgnored; | 1632 bool fColorIgnored; |
1634 bool fCoverageIgnored; | 1633 bool fCoverageIgnored; |
1635 }; | 1634 }; |
1636 | 1635 |
1637 BatchTracker fBatch; | 1636 BatchTracker fBatch; |
1638 SkSTArray<1, Geometry, true> fGeoData; | 1637 SkSTArray<1, Geometry, true> fGeoData; |
1639 }; | 1638 }; |
1640 | 1639 |
1641 class RRectEllipseRendererBatch : public GrBatch { | 1640 class RRectEllipseRendererBatch : public GrVertexBatch { |
1642 public: | 1641 public: |
1643 struct Geometry { | 1642 struct Geometry { |
1644 GrColor fColor; | 1643 GrColor fColor; |
1645 SkMatrix fViewMatrix; | 1644 SkMatrix fViewMatrix; |
1646 SkScalar fXRadius; | 1645 SkScalar fXRadius; |
1647 SkScalar fYRadius; | 1646 SkScalar fYRadius; |
1648 SkScalar fInnerXRadius; | 1647 SkScalar fInnerXRadius; |
1649 SkScalar fInnerYRadius; | 1648 SkScalar fInnerYRadius; |
1650 bool fStroke; | 1649 bool fStroke; |
1651 SkRect fDevBounds; | 1650 SkRect fDevBounds; |
1652 }; | 1651 }; |
1653 | 1652 |
1654 static GrBatch* Create(const Geometry& geometry) { | 1653 static GrDrawBatch* Create(const Geometry& geometry) { |
1655 return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry)); | 1654 return SkNEW_ARGS(RRectEllipseRendererBatch, (geometry)); |
1656 } | 1655 } |
1657 | 1656 |
1658 const char* name() const override { return "RRectEllipseRendererBatch"; } | 1657 const char* name() const override { return "RRectEllipseRendererBatch"; } |
1659 | 1658 |
1660 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 1659 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
1661 // When this is called on a batch, there is only one geometry bundle | 1660 // When this is called on a batch, there is only one geometry bundle |
1662 out->setKnownFourComponents(fGeoData[0].fColor); | 1661 out->setKnownFourComponents(fGeoData[0].fColor); |
1663 } | 1662 } |
1664 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 1663 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 | 1774 |
1776 private: | 1775 private: |
1777 RRectEllipseRendererBatch(const Geometry& geometry) { | 1776 RRectEllipseRendererBatch(const Geometry& geometry) { |
1778 this->initClassID<RRectEllipseRendererBatch>(); | 1777 this->initClassID<RRectEllipseRendererBatch>(); |
1779 fGeoData.push_back(geometry); | 1778 fGeoData.push_back(geometry); |
1780 | 1779 |
1781 this->setBounds(geometry.fDevBounds); | 1780 this->setBounds(geometry.fDevBounds); |
1782 } | 1781 } |
1783 | 1782 |
1784 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 1783 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
1785 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *t->pipel
ine(), t->bounds(), | 1784 RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); |
1786 caps)) { | 1785 |
| 1786 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi
peline(), |
| 1787 that->bounds(), caps)) { |
1787 return false; | 1788 return false; |
1788 } | 1789 } |
1789 | 1790 |
1790 RRectEllipseRendererBatch* that = t->cast<RRectEllipseRendererBatch>(); | |
1791 | |
1792 // TODO use vertex color to avoid breaking batches | 1791 // TODO use vertex color to avoid breaking batches |
1793 if (this->color() != that->color()) { | 1792 if (this->color() != that->color()) { |
1794 return false; | 1793 return false; |
1795 } | 1794 } |
1796 | 1795 |
1797 if (this->stroke() != that->stroke()) { | 1796 if (this->stroke() != that->stroke()) { |
1798 return false; | 1797 return false; |
1799 } | 1798 } |
1800 | 1799 |
1801 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 1800 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
(...skipping 16 matching lines...) Expand all Loading... |
1818 bool fStroke; | 1817 bool fStroke; |
1819 bool fUsesLocalCoords; | 1818 bool fUsesLocalCoords; |
1820 bool fColorIgnored; | 1819 bool fColorIgnored; |
1821 bool fCoverageIgnored; | 1820 bool fCoverageIgnored; |
1822 }; | 1821 }; |
1823 | 1822 |
1824 BatchTracker fBatch; | 1823 BatchTracker fBatch; |
1825 SkSTArray<1, Geometry, true> fGeoData; | 1824 SkSTArray<1, Geometry, true> fGeoData; |
1826 }; | 1825 }; |
1827 | 1826 |
1828 static GrBatch* create_rrect_batch(GrColor color, | 1827 static GrDrawBatch* create_rrect_batch(GrColor color, |
1829 const SkMatrix& viewMatrix, | 1828 const SkMatrix& viewMatrix, |
1830 const SkRRect& rrect, | 1829 const SkRRect& rrect, |
1831 const SkStrokeRec& stroke) { | 1830 const SkStrokeRec& stroke) { |
1832 SkASSERT(viewMatrix.rectStaysRect()); | 1831 SkASSERT(viewMatrix.rectStaysRect()); |
1833 SkASSERT(rrect.isSimple()); | 1832 SkASSERT(rrect.isSimple()); |
1834 SkASSERT(!rrect.isOval()); | 1833 SkASSERT(!rrect.isOval()); |
1835 | 1834 |
1836 // RRect batchs only handle simple, but not too simple, rrects | 1835 // RRect batchs only handle simple, but not too simple, rrects |
1837 // do any matrix crunching before we reset the draw state for device coords | 1836 // do any matrix crunching before we reset the draw state for device coords |
1838 const SkRect& rrectBounds = rrect.getBounds(); | 1837 const SkRect& rrectBounds = rrect.getBounds(); |
1839 SkRect bounds; | 1838 SkRect bounds; |
1840 viewMatrix.mapRect(&bounds, rrectBounds); | 1839 viewMatrix.mapRect(&bounds, rrectBounds); |
1841 | 1840 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 | 1989 |
1991 // only anti-aliased rrects for now | 1990 // only anti-aliased rrects for now |
1992 if (!useCoverageAA) { | 1991 if (!useCoverageAA) { |
1993 return false; | 1992 return false; |
1994 } | 1993 } |
1995 | 1994 |
1996 if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { | 1995 if (!viewMatrix.rectStaysRect() || !rrect.isSimple()) { |
1997 return false; | 1996 return false; |
1998 } | 1997 } |
1999 | 1998 |
2000 SkAutoTUnref<GrBatch> batch(create_rrect_batch(color, viewMatrix, rrect, str
oke)); | 1999 SkAutoTUnref<GrDrawBatch> batch(create_rrect_batch(color, viewMatrix, rrect,
stroke)); |
2001 if (!batch) { | 2000 if (!batch) { |
2002 return false; | 2001 return false; |
2003 } | 2002 } |
2004 | 2003 |
2005 target->drawBatch(pipelineBuilder, batch); | 2004 target->drawBatch(pipelineBuilder, batch); |
2006 return true; | 2005 return true; |
2007 } | 2006 } |
2008 | 2007 |
2009 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 2008 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
2010 | 2009 |
2011 #ifdef GR_TEST_UTILS | 2010 #ifdef GR_TEST_UTILS |
2012 | 2011 |
2013 BATCH_TEST_DEFINE(CircleBatch) { | 2012 DRAW_BATCH_TEST_DEFINE(CircleBatch) { |
2014 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 2013 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
2015 GrColor color = GrRandomColor(random); | 2014 GrColor color = GrRandomColor(random); |
2016 bool useCoverageAA = random->nextBool(); | 2015 bool useCoverageAA = random->nextBool(); |
2017 SkRect circle = GrTest::TestSquare(random); | 2016 SkRect circle = GrTest::TestSquare(random); |
2018 return create_circle_batch(color, viewMatrix, useCoverageAA, circle, | 2017 return create_circle_batch(color, viewMatrix, useCoverageAA, circle, |
2019 GrTest::TestStrokeRec(random)); | 2018 GrTest::TestStrokeRec(random)); |
2020 } | 2019 } |
2021 | 2020 |
2022 BATCH_TEST_DEFINE(EllipseBatch) { | 2021 DRAW_BATCH_TEST_DEFINE(EllipseBatch) { |
2023 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2022 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2024 GrColor color = GrRandomColor(random); | 2023 GrColor color = GrRandomColor(random); |
2025 SkRect ellipse = GrTest::TestSquare(random); | 2024 SkRect ellipse = GrTest::TestSquare(random); |
2026 return create_ellipse_batch(color, viewMatrix, true, ellipse, | 2025 return create_ellipse_batch(color, viewMatrix, true, ellipse, |
2027 GrTest::TestStrokeRec(random)); | 2026 GrTest::TestStrokeRec(random)); |
2028 } | 2027 } |
2029 | 2028 |
2030 BATCH_TEST_DEFINE(DIEllipseBatch) { | 2029 DRAW_BATCH_TEST_DEFINE(DIEllipseBatch) { |
2031 SkMatrix viewMatrix = GrTest::TestMatrix(random); | 2030 SkMatrix viewMatrix = GrTest::TestMatrix(random); |
2032 GrColor color = GrRandomColor(random); | 2031 GrColor color = GrRandomColor(random); |
2033 bool useCoverageAA = random->nextBool(); | 2032 bool useCoverageAA = random->nextBool(); |
2034 SkRect ellipse = GrTest::TestSquare(random); | 2033 SkRect ellipse = GrTest::TestSquare(random); |
2035 return create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, | 2034 return create_diellipse_batch(color, viewMatrix, useCoverageAA, ellipse, |
2036 GrTest::TestStrokeRec(random)); | 2035 GrTest::TestStrokeRec(random)); |
2037 } | 2036 } |
2038 | 2037 |
2039 BATCH_TEST_DEFINE(RRectBatch) { | 2038 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
2040 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 2039 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
2041 GrColor color = GrRandomColor(random); | 2040 GrColor color = GrRandomColor(random); |
2042 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 2041 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
2043 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 2042 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
2044 } | 2043 } |
2045 | 2044 |
2046 #endif | 2045 #endif |
OLD | NEW |