| 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 "GrBatch.h" | 9 #include "GrBatch.h" |
| 10 #include "GrBatchTarget.h" | 10 #include "GrBatchTarget.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 vertexStride, | 150 vertexStride, |
| 151 args.fColor, | 151 args.fColor, |
| 152 args.fViewMatrix, | 152 args.fViewMatrix, |
| 153 args.fRect, | 153 args.fRect, |
| 154 args.fDevRect, | 154 args.fDevRect, |
| 155 canTweakAlphaForCoverage); | 155 canTweakAlphaForCoverage); |
| 156 } | 156 } |
| 157 | 157 |
| 158 GrDrawTarget::DrawInfo drawInfo; | 158 GrDrawTarget::DrawInfo drawInfo; |
| 159 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); | 159 drawInfo.setPrimitiveType(kTriangles_GrPrimitiveType); |
| 160 drawInfo.setStartVertex(0); | 160 drawInfo.setStartVertex(firstVertex); |
| 161 drawInfo.setStartIndex(0); | 161 drawInfo.setStartIndex(0); |
| 162 drawInfo.setVerticesPerInstance(kVertsPerAAFillRect); | 162 drawInfo.setVerticesPerInstance(kVertsPerAAFillRect); |
| 163 drawInfo.setIndicesPerInstance(kIndicesPerAAFillRect); | 163 drawInfo.setIndicesPerInstance(kIndicesPerAAFillRect); |
| 164 drawInfo.adjustStartVertex(firstVertex); | |
| 165 drawInfo.setVertexBuffer(vertexBuffer); | 164 drawInfo.setVertexBuffer(vertexBuffer); |
| 166 drawInfo.setIndexBuffer(fIndexBuffer); | 165 drawInfo.setIndexBuffer(fIndexBuffer); |
| 167 | 166 |
| 168 int maxInstancesPerDraw = kNumAAFillRectsInIndexBuffer; | 167 int maxInstancesPerDraw = kNumAAFillRectsInIndexBuffer; |
| 169 | 168 |
| 170 while (instanceCount) { | 169 while (instanceCount) { |
| 171 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); | 170 drawInfo.setInstanceCount(SkTMin(instanceCount, maxInstancesPerDraw)
); |
| 172 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); | 171 drawInfo.setVertexCount(drawInfo.instanceCount() * drawInfo.vertices
PerInstance()); |
| 173 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); | 172 drawInfo.setIndexCount(drawInfo.instanceCount() * drawInfo.indicesPe
rInstance()); |
| 174 | 173 |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 582 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 584 fGeoData[0].fColor = init.fOverrideColor; | 583 fGeoData[0].fColor = init.fOverrideColor; |
| 585 } | 584 } |
| 586 | 585 |
| 587 // setup batch properties | 586 // setup batch properties |
| 588 fBatch.fColorIgnored = init.fColorIgnored; | 587 fBatch.fColorIgnored = init.fColorIgnored; |
| 589 fBatch.fColor = fGeoData[0].fColor; | 588 fBatch.fColor = fGeoData[0].fColor; |
| 590 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 589 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 591 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 590 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 592 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; | 591 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; |
| 593 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; | 592 fBatch.fCanTweakAlphaForCoverage1 = init.fCanTweakAlphaForCoverage; |
| 594 } | 593 } |
| 595 | 594 |
| 596 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 595 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 597 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 596 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage1(); |
| 598 | 597 |
| 599 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only | 598 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only |
| 600 // batch with identical view matrices | 599 // batch with identical view matrices |
| 601 SkMatrix localMatrix; | 600 SkMatrix localMatrix; |
| 602 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 601 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 603 SkDebugf("Cannot invert\n"); | 602 SkDebugf("Cannot invert\n"); |
| 604 return; | 603 return; |
| 605 } | 604 } |
| 606 | 605 |
| 607 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 606 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix, | 689 AAStrokeRectBatch(const Geometry& geometry, const SkMatrix& viewMatrix, |
| 691 const GrIndexBuffer* indexBuffer) | 690 const GrIndexBuffer* indexBuffer) |
| 692 : fIndexBuffer(indexBuffer) { | 691 : fIndexBuffer(indexBuffer) { |
| 693 this->initClassID<AAStrokeRectBatch>(); | 692 this->initClassID<AAStrokeRectBatch>(); |
| 694 fBatch.fViewMatrix = viewMatrix; | 693 fBatch.fViewMatrix = viewMatrix; |
| 695 fGeoData.push_back(geometry); | 694 fGeoData.push_back(geometry); |
| 696 } | 695 } |
| 697 | 696 |
| 698 GrColor color() const { return fBatch.fColor; } | 697 GrColor color() const { return fBatch.fColor; } |
| 699 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 698 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 700 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 699 bool canTweakAlphaForCoverage1() const { return fBatch.fCanTweakAlphaForCove
rage1; } |
| 701 bool colorIgnored() const { return fBatch.fColorIgnored; } | 700 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 702 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 701 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 703 bool miterStroke() const { return fBatch.fMiterStroke; } | 702 bool miterStroke() const { return fBatch.fMiterStroke; } |
| 704 | 703 |
| 705 bool onCombineIfPossible(GrBatch* t) override { | 704 bool onCombineIfPossible(GrBatch* t) override { |
| 706 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); | 705 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); |
| 707 | 706 |
| 708 // TODO batch across miterstroke changes | 707 // TODO batch across miterstroke changes |
| 709 if (this->miterStroke() != that->miterStroke()) { | 708 if (this->miterStroke() != that->miterStroke()) { |
| 710 return false; | 709 return false; |
| 711 } | 710 } |
| 712 | 711 |
| 713 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 712 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 714 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 713 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 715 // using vertex attributes in these cases, but haven't investigated that | 714 // using vertex attributes in these cases, but haven't investigated that |
| 716 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 715 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| 717 return false; | 716 return false; |
| 718 } | 717 } |
| 719 | 718 |
| 720 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to | 719 // In the event of two batches, one who can tweak, one who cannot, we ju
st fall back to |
| 721 // not tweaking | 720 // not tweaking |
| 722 if (this->canTweakAlphaForCoverage() != that->canTweakAlphaForCoverage()
) { | 721 if (this->canTweakAlphaForCoverage1() != that->canTweakAlphaForCoverage1
()) { |
| 723 fBatch.fCanTweakAlphaForCoverage = false; | 722 fBatch.fCanTweakAlphaForCoverage1 = false; |
| 724 } | 723 } |
| 725 | 724 |
| 726 if (this->color() != that->color()) { | 725 if (this->color() != that->color()) { |
| 727 fBatch.fColor = GrColor_ILLEGAL; | 726 fBatch.fColor = GrColor_ILLEGAL; |
| 728 } | 727 } |
| 729 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; | 728 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin())
; |
| 730 return true; | 729 return true; |
| 731 } | 730 } |
| 732 | 731 |
| 733 void generateAAStrokeRectGeometry(void* vertices, | 732 void generateAAStrokeRectGeometry(void* vertices, |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 } | 842 } |
| 844 } | 843 } |
| 845 | 844 |
| 846 struct BatchTracker { | 845 struct BatchTracker { |
| 847 SkMatrix fViewMatrix; | 846 SkMatrix fViewMatrix; |
| 848 GrColor fColor; | 847 GrColor fColor; |
| 849 bool fUsesLocalCoords; | 848 bool fUsesLocalCoords; |
| 850 bool fColorIgnored; | 849 bool fColorIgnored; |
| 851 bool fCoverageIgnored; | 850 bool fCoverageIgnored; |
| 852 bool fMiterStroke; | 851 bool fMiterStroke; |
| 853 bool fCanTweakAlphaForCoverage; | 852 bool fCanTweakAlphaForCoverage1; |
| 854 }; | 853 }; |
| 855 | 854 |
| 856 BatchTracker fBatch; | 855 BatchTracker fBatch; |
| 857 const GrIndexBuffer* fIndexBuffer; | 856 const GrIndexBuffer* fIndexBuffer; |
| 858 SkSTArray<1, Geometry, true> fGeoData; | 857 SkSTArray<1, Geometry, true> fGeoData; |
| 859 }; | 858 }; |
| 860 | 859 |
| 861 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, | 860 void GrAARectRenderer::geometryStrokeAARect(GrDrawTarget* target, |
| 862 GrPipelineBuilder* pipelineBuilder, | 861 GrPipelineBuilder* pipelineBuilder, |
| 863 GrColor color, | 862 GrColor color, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 geo.fColor = GrRandomColor(random); | 954 geo.fColor = GrRandomColor(random); |
| 956 geo.fDevOutside = outside; | 955 geo.fDevOutside = outside; |
| 957 geo.fDevOutsideAssist = outsideAssist; | 956 geo.fDevOutsideAssist = outsideAssist; |
| 958 geo.fDevInside = inside; | 957 geo.fDevInside = inside; |
| 959 geo.fMiterStroke = miterStroke; | 958 geo.fMiterStroke = miterStroke; |
| 960 | 959 |
| 961 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffe
r); | 960 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random), indexBuffe
r); |
| 962 } | 961 } |
| 963 | 962 |
| 964 #endif | 963 #endif |
| OLD | NEW |