| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 /////////////////////////////////////////////////////////////////////////////// | 25 /////////////////////////////////////////////////////////////////////////////// |
| 26 | 26 |
| 27 static void set_inset_fan(SkPoint* pts, size_t stride, | 27 static void set_inset_fan(SkPoint* pts, size_t stride, |
| 28 const SkRect& r, SkScalar dx, SkScalar dy) { | 28 const SkRect& r, SkScalar dx, SkScalar dy) { |
| 29 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 29 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
| 30 r.fRight - dx, r.fBottom - dy, stride); | 30 r.fRight - dx, r.fBottom - dy, stride); |
| 31 } | 31 } |
| 32 | 32 |
| 33 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, | 33 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, |
| 34 const SkMatrix& localMatri
x, | 34 const SkMatrix& localMatri
x) { |
| 35 bool usesLocalCoords, | |
| 36 bool coverageIgnored) { | |
| 37 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; | 35 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; |
| 38 const GrGeometryProcessor* gp; | 36 const GrGeometryProcessor* gp; |
| 39 if (tweakAlphaForCoverage) { | 37 if (tweakAlphaForCoverage) { |
| 40 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor
ds, coverageIgnored, | 38 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, SkMatrix::I()
, localMatrix); |
| 41 SkMatrix::I(), localMatrix); | |
| 42 } else { | 39 } else { |
| 43 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; | 40 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
| 44 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor
ds, coverageIgnored, | 41 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, SkMatrix::I()
, localMatrix); |
| 45 SkMatrix::I(), localMatrix); | |
| 46 } | 42 } |
| 47 return gp; | 43 return gp; |
| 48 } | 44 } |
| 49 | 45 |
| 50 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); | 46 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); |
| 51 | 47 |
| 52 class AAFillRectBatch : public GrBatch { | 48 class AAFillRectBatch : public GrBatch { |
| 53 public: | 49 public: |
| 54 struct Geometry { | 50 struct Geometry { |
| 55 GrColor fColor; | 51 GrColor fColor; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 88 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
| 93 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 89 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 94 | 90 |
| 95 SkMatrix localMatrix; | 91 SkMatrix localMatrix; |
| 96 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 92 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 97 SkDebugf("Cannot invert\n"); | 93 SkDebugf("Cannot invert\n"); |
| 98 return; | 94 return; |
| 99 } | 95 } |
| 100 | 96 |
| 101 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 97 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 102 localMatr
ix, | 98 localMatr
ix)); |
| 103 this->use
sLocalCoords(), | |
| 104 this->cov
erageIgnored())); | |
| 105 | 99 |
| 106 batchTarget->initDraw(gp, pipeline); | 100 batchTarget->initDraw(gp, pipeline); |
| 107 | 101 |
| 102 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 103 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 104 // everywhere we can remove this nastiness |
| 105 GrPipelineInfo init; |
| 106 init.fColorIgnored = fBatch.fColorIgnored; |
| 107 init.fOverrideColor = GrColor_ILLEGAL; |
| 108 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 109 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 110 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 111 |
| 108 size_t vertexStride = gp->getVertexStride(); | 112 size_t vertexStride = gp->getVertexStride(); |
| 109 SkASSERT(canTweakAlphaForCoverage ? | 113 SkASSERT(canTweakAlphaForCoverage ? |
| 110 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 111 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 115 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 112 int instanceCount = fGeoData.count(); | 116 int instanceCount = fGeoData.count(); |
| 113 | 117 |
| 114 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( | 118 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( |
| 115 batchTarget->resourceProvider())); | 119 batchTarget->resourceProvider())); |
| 116 InstancedHelper helper; | 120 InstancedHelper helper; |
| 117 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, | 121 void* vertices = helper.init(batchTarget, kTriangles_GrPrimitiveType, ve
rtexStride, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 return resourceProvider->refOrCreateInstancedIndexBuffer(gFillAARectIdx, | 169 return resourceProvider->refOrCreateInstancedIndexBuffer(gFillAARectIdx, |
| 166 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill
Rect, | 170 kIndicesPerAAFillRect, kNumAAFillRectsInIndexBuffer, kVertsPerAAFill
Rect, |
| 167 gAAFillRectIndexBufferKey); | 171 gAAFillRectIndexBufferKey); |
| 168 } | 172 } |
| 169 | 173 |
| 170 GrColor color() const { return fBatch.fColor; } | 174 GrColor color() const { return fBatch.fColor; } |
| 171 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 175 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 172 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 176 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 173 bool colorIgnored() const { return fBatch.fColorIgnored; } | 177 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 174 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 178 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 175 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 176 | 179 |
| 177 bool onCombineIfPossible(GrBatch* t) override { | 180 bool onCombineIfPossible(GrBatch* t) override { |
| 178 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); | 181 AAFillRectBatch* that = t->cast<AAFillRectBatch>(); |
| 179 | 182 |
| 180 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 183 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 181 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 184 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| 182 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix | 185 // local coords then we won't be able to batch. We could actually uploa
d the viewmatrix |
| 183 // using vertex attributes in these cases, but haven't investigated that | 186 // using vertex attributes in these cases, but haven't investigated that |
| 184 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { | 187 if (this->usesLocalCoords() && !this->viewMatrix().cheapEqualTo(that->vi
ewMatrix())) { |
| 185 return false; | 188 return false; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 446 |
| 444 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only | 447 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only |
| 445 // batch with identical view matrices | 448 // batch with identical view matrices |
| 446 SkMatrix localMatrix; | 449 SkMatrix localMatrix; |
| 447 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ | 450 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
| 448 SkDebugf("Cannot invert\n"); | 451 SkDebugf("Cannot invert\n"); |
| 449 return; | 452 return; |
| 450 } | 453 } |
| 451 | 454 |
| 452 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 455 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 453 localMatr
ix, | 456 localMatr
ix)); |
| 454 this->use
sLocalCoords(), | |
| 455 this->cov
erageIgnored())); | |
| 456 | 457 |
| 457 batchTarget->initDraw(gp, pipeline); | 458 batchTarget->initDraw(gp, pipeline); |
| 458 | 459 |
| 460 // TODO this is hacky, but the only way we have to initialize the GP is
to use the |
| 461 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch |
| 462 // everywhere we can remove this nastiness |
| 463 GrPipelineInfo init; |
| 464 init.fColorIgnored = fBatch.fColorIgnored; |
| 465 init.fOverrideColor = GrColor_ILLEGAL; |
| 466 init.fCoverageIgnored = fBatch.fCoverageIgnored; |
| 467 init.fUsesLocalCoords = this->usesLocalCoords(); |
| 468 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); |
| 469 |
| 459 size_t vertexStride = gp->getVertexStride(); | 470 size_t vertexStride = gp->getVertexStride(); |
| 460 | 471 |
| 461 SkASSERT(canTweakAlphaForCoverage ? | 472 SkASSERT(canTweakAlphaForCoverage ? |
| 462 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 473 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 463 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 474 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 464 int innerVertexNum = 4; | 475 int innerVertexNum = 4; |
| 465 int outerVertexNum = this->miterStroke() ? 4 : 8; | 476 int outerVertexNum = this->miterStroke() ? 4 : 8; |
| 466 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; | 477 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; |
| 467 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; | 478 int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIn
dexCnt; |
| 468 int instanceCount = fGeoData.count(); | 479 int instanceCount = fGeoData.count(); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 gBevelIndexBufferKey); | 619 gBevelIndexBufferKey); |
| 609 } | 620 } |
| 610 } | 621 } |
| 611 | 622 |
| 612 GrColor color() const { return fBatch.fColor; } | 623 GrColor color() const { return fBatch.fColor; } |
| 613 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 624 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 614 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } | 625 bool canTweakAlphaForCoverage() const { return fBatch.fCanTweakAlphaForCover
age; } |
| 615 bool colorIgnored() const { return fBatch.fColorIgnored; } | 626 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 616 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 627 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| 617 bool miterStroke() const { return fBatch.fMiterStroke; } | 628 bool miterStroke() const { return fBatch.fMiterStroke; } |
| 618 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 619 | 629 |
| 620 bool onCombineIfPossible(GrBatch* t) override { | 630 bool onCombineIfPossible(GrBatch* t) override { |
| 621 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); | 631 AAStrokeRectBatch* that = t->cast<AAStrokeRectBatch>(); |
| 622 | 632 |
| 623 // TODO batch across miterstroke changes | 633 // TODO batch across miterstroke changes |
| 624 if (this->miterStroke() != that->miterStroke()) { | 634 if (this->miterStroke() != that->miterStroke()) { |
| 625 return false; | 635 return false; |
| 626 } | 636 } |
| 627 | 637 |
| 628 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses | 638 // We apply the viewmatrix to the rect points on the cpu. However, if t
he pipeline uses |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 geo.fColor = GrRandomColor(random); | 853 geo.fColor = GrRandomColor(random); |
| 844 geo.fDevOutside = outside; | 854 geo.fDevOutside = outside; |
| 845 geo.fDevOutsideAssist = outsideAssist; | 855 geo.fDevOutsideAssist = outsideAssist; |
| 846 geo.fDevInside = inside; | 856 geo.fDevInside = inside; |
| 847 geo.fMiterStroke = miterStroke; | 857 geo.fMiterStroke = miterStroke; |
| 848 | 858 |
| 849 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 859 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
| 850 } | 860 } |
| 851 | 861 |
| 852 #endif | 862 #endif |
| OLD | NEW |