OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrRectBatch.h" | 8 #include "GrRectBatch.h" |
9 | 9 |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
11 #include "GrBatchTarget.h" | 11 #include "GrBatchTarget.h" |
12 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
13 #include "GrDefaultGeoProcFactory.h" | 13 #include "GrDefaultGeoProcFactory.h" |
14 #include "GrPrimitiveProcessor.h" | 14 #include "GrPrimitiveProcessor.h" |
15 #include "GrTemplates.h" | 15 #include "GrTemplates.h" |
16 | 16 |
17 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we | 17 /** We always use per-vertex colors so that rects can be batched across color ch
anges. Sometimes we |
18 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords | 18 have explicit local coords and sometimes not. We *could* always provide expl
icit local coords |
19 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we | 19 and just duplicate the positions when the caller hasn't provided a local coo
rd rect, but we |
20 haven't seen a use case which frequently switches between local rect and no
local rect draws. | 20 haven't seen a use case which frequently switches between local rect and no
local rect draws. |
21 | 21 |
22 The color param is used to determine whether the opaque hint can be set on t
he draw state. | 22 The color param is used to determine whether the opaque hint can be set on t
he draw state. |
23 The caller must populate the vertex colors itself. | 23 The caller must populate the vertex colors itself. |
24 | 24 |
25 The vertex attrib order is always pos, color, [local coords]. | 25 The vertex attrib order is always pos, color, [local coords]. |
26 */ | 26 */ |
27 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, | 27 static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
28 GrColor color, | 28 const SkMatrix* localMatrix, |
29 const SkMatrix* localMatrix) { | 29 bool usesLocalCoords, |
| 30 bool coverageIgnored) { |
| 31 // TODO remove color when we have ignored color from the XP |
30 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 32 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
31 GrDefaultGeoProcFactory::kColor_GPType; | 33 GrDefaultGeoProcFactory::kColor_GPType; |
32 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; | 34 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; |
33 if (localMatrix) { | 35 if (localMatrix) { |
34 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *loc
alMatrix); | 36 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo
ords, |
| 37 coverageIgnored, SkMatrix::I(), *
localMatrix); |
35 } else { | 38 } else { |
36 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMa
trix::I()); | 39 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo
ords, |
| 40 coverageIgnored, SkMatrix::I(), S
kMatrix::I()); |
37 } | 41 } |
38 } | 42 } |
39 | 43 |
40 class RectBatch : public GrBatch { | 44 class RectBatch : public GrBatch { |
41 public: | 45 public: |
42 struct Geometry { | 46 struct Geometry { |
43 SkMatrix fViewMatrix; | 47 SkMatrix fViewMatrix; |
44 SkRect fRect; | 48 SkRect fRect; |
45 SkRect fLocalRect; | 49 SkRect fLocalRect; |
46 SkMatrix fLocalMatrix; | 50 SkMatrix fLocalMatrix; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 SkDebugf("Could not invert\n"); | 95 SkDebugf("Could not invert\n"); |
92 return; | 96 return; |
93 } | 97 } |
94 | 98 |
95 if (this->hasLocalMatrix()) { | 99 if (this->hasLocalMatrix()) { |
96 invert.preConcat(this->localMatrix()); | 100 invert.preConcat(this->localMatrix()); |
97 } | 101 } |
98 } | 102 } |
99 | 103 |
100 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc
alCoords, | 104 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc
alCoords, |
101 this->color(), | 105 &invert, |
102 &invert)); | 106 this->usesLoca
lCoords(), |
| 107 this->coverage
Ignored())); |
103 | 108 |
104 batchTarget->initDraw(gp, pipeline); | 109 batchTarget->initDraw(gp, pipeline); |
105 | 110 |
106 // TODO this is hacky, but the only way we have to initialize the GP is
to use the | |
107 // GrPipelineInfo struct so we can generate the correct shader. Once we
have GrBatch | |
108 // everywhere we can remove this nastiness | |
109 GrPipelineInfo init; | |
110 init.fColorIgnored = fBatch.fColorIgnored; | |
111 init.fOverrideColor = GrColor_ILLEGAL; | |
112 init.fCoverageIgnored = fBatch.fCoverageIgnored; | |
113 init.fUsesLocalCoords = this->usesLocalCoords(); | |
114 gp->initBatchTracker(batchTarget->currentBatchTracker(), init); | |
115 | |
116 int instanceCount = fGeoData.count(); | 111 int instanceCount = fGeoData.count(); |
117 size_t vertexStride = gp->getVertexStride(); | 112 size_t vertexStride = gp->getVertexStride(); |
118 SkASSERT(hasExplicitLocalCoords ? | 113 SkASSERT(hasExplicitLocalCoords ? |
119 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : | 114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : |
120 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); | 115 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); |
121 QuadHelper helper; | 116 QuadHelper helper; |
122 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); | 117 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); |
123 | 118 |
124 if (!vertices) { | 119 if (!vertices) { |
125 return; | 120 return; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 geometry.fViewMatrix.mapRect(&fBounds); | 164 geometry.fViewMatrix.mapRect(&fBounds); |
170 } | 165 } |
171 | 166 |
172 GrColor color() const { return fBatch.fColor; } | 167 GrColor color() const { return fBatch.fColor; } |
173 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 168 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
174 bool colorIgnored() const { return fBatch.fColorIgnored; } | 169 bool colorIgnored() const { return fBatch.fColorIgnored; } |
175 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 170 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
176 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } | 171 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } |
177 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } | 172 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } |
178 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } | 173 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } |
| 174 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } |
179 | 175 |
180 bool onCombineIfPossible(GrBatch* t) override { | 176 bool onCombineIfPossible(GrBatch* t) override { |
181 RectBatch* that = t->cast<RectBatch>(); | 177 RectBatch* that = t->cast<RectBatch>(); |
182 | 178 |
183 if (this->hasLocalRect() != that->hasLocalRect()) { | 179 if (this->hasLocalRect() != that->hasLocalRect()) { |
184 return false; | 180 return false; |
185 } | 181 } |
186 | 182 |
187 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 183 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
188 if (!this->hasLocalRect() && this->usesLocalCoords()) { | 184 if (!this->hasLocalRect() && this->usesLocalCoords()) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 if (hasLocalMatrix) { | 269 if (hasLocalMatrix) { |
274 localMatrix = GrTest::TestMatrix(random); | 270 localMatrix = GrTest::TestMatrix(random); |
275 } | 271 } |
276 | 272 |
277 return GrRectBatch::Create(color, viewMatrix, rect, | 273 return GrRectBatch::Create(color, viewMatrix, rect, |
278 hasLocalRect ? &localRect : NULL, | 274 hasLocalRect ? &localRect : NULL, |
279 hasLocalMatrix ? &localMatrix : NULL); | 275 hasLocalMatrix ? &localMatrix : NULL); |
280 } | 276 } |
281 | 277 |
282 #endif | 278 #endif |
OLD | NEW |