| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 GrColor fColor; | 59 GrColor fColor; |
| 60 SkMatrix fViewMatrix; | 60 SkMatrix fViewMatrix; |
| 61 SkRect fRect; | 61 SkRect fRect; |
| 62 SkRect fDevRect; | 62 SkRect fDevRect; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB
uffer) { | 65 static GrBatch* Create(const Geometry& geometry, const GrIndexBuffer* indexB
uffer) { |
| 66 return SkNEW_ARGS(AAFillRectBatch, (geometry, indexBuffer)); | 66 return SkNEW_ARGS(AAFillRectBatch, (geometry, indexBuffer)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 const char* name() const SK_OVERRIDE { return "AAFillRectBatch"; } | 69 const char* name() const override { return "AAFillRectBatch"; } |
| 70 | 70 |
| 71 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { | 71 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 72 // When this is called on a batch, there is only one geometry bundle | 72 // When this is called on a batch, there is only one geometry bundle |
| 73 out->setKnownFourComponents(fGeoData[0].fColor); | 73 out->setKnownFourComponents(fGeoData[0].fColor); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { | 76 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 77 out->setUnknownSingleComponent(); | 77 out->setUnknownSingleComponent(); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { | 80 void initBatchTracker(const GrPipelineInfo& init) override { |
| 81 // Handle any color overrides | 81 // Handle any color overrides |
| 82 if (init.fColorIgnored) { | 82 if (init.fColorIgnored) { |
| 83 fGeoData[0].fColor = GrColor_ILLEGAL; | 83 fGeoData[0].fColor = GrColor_ILLEGAL; |
| 84 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 84 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 85 fGeoData[0].fColor = init.fOverrideColor; | 85 fGeoData[0].fColor = init.fOverrideColor; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // setup batch properties | 88 // setup batch properties |
| 89 fBatch.fColorIgnored = init.fColorIgnored; | 89 fBatch.fColorIgnored = init.fColorIgnored; |
| 90 fBatch.fColor = fGeoData[0].fColor; | 90 fBatch.fColor = fGeoData[0].fColor; |
| 91 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 91 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 92 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 92 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 93 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; | 93 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { | 96 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 97 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 97 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 98 | 98 |
| 99 SkMatrix localMatrix; | 99 SkMatrix localMatrix; |
| 100 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 100 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 101 SkDebugf("Cannot invert\n"); | 101 SkDebugf("Cannot invert\n"); |
| 102 return; | 102 return; |
| 103 } | 103 } |
| 104 | 104 |
| 105 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 105 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 106 localMatr
ix)); | 106 localMatr
ix)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 this->initClassID<AAFillRectBatch>(); | 183 this->initClassID<AAFillRectBatch>(); |
| 184 fGeoData.push_back(geometry); | 184 fGeoData.push_back(geometry); |
| 185 } | 185 } |
| 186 | 186 |
| 187 GrColor color() const { return fBatch.fColor; } | 187 GrColor color() const { return fBatch.fColor; } |
| 188 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 188 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 189 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 189 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 190 bool colorIgnored() const { return fBatch.fColorIgnored; } | 190 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 191 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 191 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 192 | 192 |
| 193 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { | 193 bool onCombineIfPossible(GrBatch* t) override { |
| 194 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); | 194 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); |
| 195 | 195 |
| 196 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 196 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 197 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 197 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 198 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 198 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 199 // using vertex attributes in these cases, but haven't investigated that | 199 // using vertex attributes in these cases, but haven't investigated that |
| 200 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 200 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 | 203 |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 SkRect fDevOutsideAssist; | 551 SkRect fDevOutsideAssist; |
| 552 SkRect fDevInside; | 552 SkRect fDevInside; |
| 553 bool fMiterStroke; | 553 bool fMiterStroke; |
| 554 }; | 554 }; |
| 555 | 555 |
| 556 static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, | 556 static GrBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix, |
| 557 const GrIndexBuffer* indexBuffer) { | 557 const GrIndexBuffer* indexBuffer) { |
| 558 return SkNEW_ARGS(AAStrokeRectBatch, (geometry, viewMatrix, indexBuffer)
); | 558 return SkNEW_ARGS(AAStrokeRectBatch, (geometry, viewMatrix, indexBuffer)
); |
| 559 } | 559 } |
| 560 | 560 |
| 561 const char* name() const SK_OVERRIDE { return "AAStrokeRect"; } | 561 const char* name() const override { return "AAStrokeRect"; } |
| 562 | 562 |
| 563 void getInvariantOutputColor(GrInitInvariantOutput* out) const SK_OVERRIDE { | 563 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
| 564 // When this is called on a batch, there is only one geometry bundle | 564 // When this is called on a batch, there is only one geometry bundle |
| 565 out->setKnownFourComponents(fGeoData[0].fColor); | 565 out->setKnownFourComponents(fGeoData[0].fColor); |
| 566 } | 566 } |
| 567 | 567 |
| 568 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const SK_OVERRID
E { | 568 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 569 out->setUnknownSingleComponent(); | 569 out->setUnknownSingleComponent(); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void initBatchTracker(const GrPipelineInfo& init) SK_OVERRIDE { | 572 void initBatchTracker(const GrPipelineInfo& init) override { |
| 573 // Handle any color overrides | 573 // Handle any color overrides |
| 574 if (init.fColorIgnored) { | 574 if (init.fColorIgnored) { |
| 575 fGeoData[0].fColor = GrColor_ILLEGAL; | 575 fGeoData[0].fColor = GrColor_ILLEGAL; |
| 576 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | 576 } else if (GrColor_ILLEGAL != init.fOverrideColor) { |
| 577 fGeoData[0].fColor = init.fOverrideColor; | 577 fGeoData[0].fColor = init.fOverrideColor; |
| 578 } | 578 } |
| 579 | 579 |
| 580 // setup batch properties | 580 // setup batch properties |
| 581 fBatch.fColorIgnored = init.fColorIgnored; | 581 fBatch.fColorIgnored = init.fColorIgnored; |
| 582 fBatch.fColor = fGeoData[0].fColor; | 582 fBatch.fColor = fGeoData[0].fColor; |
| 583 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; | 583 fBatch.fUsesLocalCoords = init.fUsesLocalCoords; |
| 584 fBatch.fCoverageIgnored = init.fCoverageIgnored; | 584 fBatch.fCoverageIgnored = init.fCoverageIgnored; |
| 585 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; | 585 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; |
| 586 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; | 586 fBatch.fCanTweakAlphaForCoverage = init.fCanTweakAlphaForCoverage; |
| 587 } | 587 } |
| 588 | 588 |
| 589 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) SK_OVERRIDE { | 589 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 590 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 590 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 591 | 591 |
| 592 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only | 592 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only |
| 593 // batch with identical view matrices | 593 // batch with identical view matrices |
| 594 SkMatrix localMatrix; | 594 SkMatrix localMatrix; |
| 595 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 595 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 596 SkDebugf("Cannot invert\n"); | 596 SkDebugf("Cannot invert\n"); |
| 597 return; | 597 return; |
| 598 } | 598 } |
| 599 | 599 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 fGeoData.push_back(geometry); | 688 fGeoData.push_back(geometry); |
| 689 } | 689 } |
| 690 | 690 |
| 691 GrColor color() const { return fBatch.fColor; } | 691 GrColor color() const { return fBatch.fColor; } |
| 692 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 692 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 693 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 693 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 694 bool colorIgnored() const { return fBatch.fColorIgnored; } | 694 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 695 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 695 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 696 bool miterStroke() const { return fBatch.fMiterStroke; } | 696 bool miterStroke() const { return fBatch.fMiterStroke; } |
| 697 | 697 |
| 698 bool onCombineIfPossible(GrBatch* t) SK_OVERRIDE { | 698 bool onCombineIfPossible(GrBatch* t) override { |
| 699 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); | 699 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); |
| 700 | 700 |
| 701 // TODO batch across miterstroke changes | 701 // TODO batch across miterstroke changes |
| 702 if (this->miterStroke() != that->miterStroke()) { | 702 if (this->miterStroke() != that->miterStroke()) { |
| 703 return false; | 703 return false; |
| 704 } | 704 } |
| 705 | 705 |
| 706 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 706 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 707 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 707 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 708 // using vertex attributes in these cases, but haven't investigated that | 708 // using vertex attributes in these cases, but haven't investigated that |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 viewMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2); | 891 viewMatrix.mapPoints((SkPoint*)&devInside, (const SkPoint*)&rects[1], 2); |
| 892 | 892 |
| 893 if (devInside.isEmpty()) { | 893 if (devInside.isEmpty()) { |
| 894 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); | 894 this->fillAARect(target, pipelineBuilder, color, viewMatrix, devOutside,
devOutside); |
| 895 return; | 895 return; |
| 896 } | 896 } |
| 897 | 897 |
| 898 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, | 898 this->geometryStrokeAARect(target, pipelineBuilder, color, viewMatrix, devOu
tside, |
| 899 devOutsideAssist, devInside, true); | 899 devOutsideAssist, devInside, true); |
| 900 } | 900 } |
| OLD | NEW |