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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
27 | 27 |
28 static void set_inset_fan(SkPoint* pts, size_t stride, | 28 static void set_inset_fan(SkPoint* pts, size_t stride, |
29 const SkRect& r, SkScalar dx, SkScalar dy) { | 29 const SkRect& r, SkScalar dx, SkScalar dy) { |
30 pts->setRectFan(r.fLeft + dx, r.fTop + dy, | 30 pts->setRectFan(r.fLeft + dx, r.fTop + dy, |
31 r.fRight - dx, r.fBottom - dy, stride); | 31 r.fRight - dx, r.fBottom - dy, stride); |
32 } | 32 } |
33 | 33 |
34 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, | 34 static const GrGeometryProcessor* create_fill_rect_gp(bool tweakAlphaForCoverage
, |
35 const SkMatrix& viewMatrix
, | 35 const SkMatrix& localMatri
x, |
36 bool usesLocalCoords, | 36 bool usesLocalCoords, |
37 bool coverageIgnored) { | 37 bool coverageIgnored) { |
38 using namespace GrDefaultGeoProcFactory; | 38 uint32_t flags = GrDefaultGeoProcFactory::kColor_GPType; |
39 | 39 const GrGeometryProcessor* gp; |
40 Color color(Color::kAttribute_Type); | 40 if (tweakAlphaForCoverage) { |
41 Coverage::Type coverageType; | 41 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor
ds, coverageIgnored, |
42 if (coverageIgnored) { | 42 SkMatrix::I(), localMatrix); |
43 coverageType = Coverage::kNone_Type; | |
44 } else if (tweakAlphaForCoverage) { | |
45 coverageType = Coverage::kSolid_Type; | |
46 } else { | 43 } else { |
47 coverageType = Coverage::kAttribute_Type; | 44 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; |
| 45 gp = GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCoor
ds, coverageIgnored, |
| 46 SkMatrix::I(), localMatrix); |
48 } | 47 } |
49 Coverage coverage(coverageType); | 48 return gp; |
50 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : | |
51 LocalCoords::kUnused_Type); | |
52 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); | |
53 } | 49 } |
54 | 50 |
55 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); | 51 GR_DECLARE_STATIC_UNIQUE_KEY(gAAFillRectIndexBufferKey); |
56 | 52 |
57 class AAFillRectBatch : public GrBatch { | 53 class AAFillRectBatch : public GrBatch { |
58 public: | 54 public: |
59 struct Geometry { | 55 struct Geometry { |
60 GrColor fColor; | 56 GrColor fColor; |
61 SkMatrix fViewMatrix; | 57 SkMatrix fViewMatrix; |
62 SkRect fRect; | 58 SkRect fRect; |
(...skipping 26 matching lines...) Expand all Loading... |
89 fBatch.fColorIgnored = !init.readsColor(); | 85 fBatch.fColorIgnored = !init.readsColor(); |
90 fBatch.fColor = fGeoData[0].fColor; | 86 fBatch.fColor = fGeoData[0].fColor; |
91 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | 87 fBatch.fUsesLocalCoords = init.readsLocalCoords(); |
92 fBatch.fCoverageIgnored = !init.readsCoverage(); | 88 fBatch.fCoverageIgnored = !init.readsCoverage(); |
93 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); | 89 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); |
94 } | 90 } |
95 | 91 |
96 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 92 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
97 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 93 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
98 | 94 |
99 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 95 SkMatrix localMatrix; |
100 this->vie
wMatrix(), | 96 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
101 this->use
sLocalCoords(), | 97 SkDebugf("Cannot invert\n"); |
102 this->cov
erageIgnored())); | |
103 if (!gp) { | |
104 SkDebugf("Couldn't create GrGeometryProcessor\n"); | |
105 return; | 98 return; |
106 } | 99 } |
107 | 100 |
| 101 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 102 localMatr
ix, |
| 103 this->use
sLocalCoords(), |
| 104 this->cov
erageIgnored())); |
| 105 |
108 batchTarget->initDraw(gp, pipeline); | 106 batchTarget->initDraw(gp, pipeline); |
109 | 107 |
110 size_t vertexStride = gp->getVertexStride(); | 108 size_t vertexStride = gp->getVertexStride(); |
111 SkASSERT(canTweakAlphaForCoverage ? | 109 SkASSERT(canTweakAlphaForCoverage ? |
112 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 110 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
113 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 111 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
114 int instanceCount = fGeoData.count(); | 112 int instanceCount = fGeoData.count(); |
115 | 113 |
116 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( | 114 SkAutoTUnref<const GrIndexBuffer> indexBuffer(this->getIndexBuffer( |
117 batchTarget->resourceProvider())); | 115 batchTarget->resourceProvider())); |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 fBatch.fColor = fGeoData[0].fColor; | 437 fBatch.fColor = fGeoData[0].fColor; |
440 fBatch.fUsesLocalCoords = init.readsLocalCoords(); | 438 fBatch.fUsesLocalCoords = init.readsLocalCoords(); |
441 fBatch.fCoverageIgnored = !init.readsCoverage(); | 439 fBatch.fCoverageIgnored = !init.readsCoverage(); |
442 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; | 440 fBatch.fMiterStroke = fGeoData[0].fMiterStroke; |
443 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); | 441 fBatch.fCanTweakAlphaForCoverage = init.canTweakAlphaForCoverage(); |
444 } | 442 } |
445 | 443 |
446 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 444 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { |
447 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 445 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
448 | 446 |
449 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, | 447 // Local matrix is ignored if we don't have local coords. If we have lo
calcoords we only |
450 this->vie
wMatrix(), | 448 // batch with identical view matrices |
451 this->use
sLocalCoords(), | 449 SkMatrix localMatrix; |
452 this->cov
erageIgnored())); | 450 if (this->usesLocalCoords() && !this->viewMatrix().invert(&localMatrix))
{ |
453 if (!gp) { | 451 SkDebugf("Cannot invert\n"); |
454 SkDebugf("Couldn't create GrGeometryProcessor\n"); | |
455 return; | 452 return; |
456 } | 453 } |
457 | 454 |
| 455 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_rect_gp(canTweakA
lphaForCoverage, |
| 456 localMatr
ix, |
| 457 this->use
sLocalCoords(), |
| 458 this->cov
erageIgnored())); |
| 459 |
458 batchTarget->initDraw(gp, pipeline); | 460 batchTarget->initDraw(gp, pipeline); |
459 | 461 |
460 size_t vertexStride = gp->getVertexStride(); | 462 size_t vertexStride = gp->getVertexStride(); |
461 | 463 |
462 SkASSERT(canTweakAlphaForCoverage ? | 464 SkASSERT(canTweakAlphaForCoverage ? |
463 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 465 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
464 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 466 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
465 int innerVertexNum = 4; | 467 int innerVertexNum = 4; |
466 int outerVertexNum = this->miterStroke() ? 4 : 8; | 468 int outerVertexNum = this->miterStroke() ? 4 : 8; |
467 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; | 469 int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 geo.fColor = GrRandomColor(random); | 849 geo.fColor = GrRandomColor(random); |
848 geo.fDevOutside = outside; | 850 geo.fDevOutside = outside; |
849 geo.fDevOutsideAssist = outsideAssist; | 851 geo.fDevOutsideAssist = outsideAssist; |
850 geo.fDevInside = inside; | 852 geo.fDevInside = inside; |
851 geo.fMiterStroke = miterStroke; | 853 geo.fMiterStroke = miterStroke; |
852 | 854 |
853 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); | 855 return AAStrokeRectBatch::Create(geo, GrTest::TestMatrix(random)); |
854 } | 856 } |
855 | 857 |
856 #endif | 858 #endif |
OLD | NEW |