| 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 const SkMatrix* localMatrix, | 28 GrColor color, |
| 29 bool usesLocalCoords, | 29 const SkMatrix* localMatrix) { |
| 30 bool coverageIgnored) { | |
| 31 // TODO remove color when we have ignored color from the XP | |
| 32 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | | 30 uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 33 GrDefaultGeoProcFactory::kColor_GPType; | 31 GrDefaultGeoProcFactory::kColor_GPType; |
| 34 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; | 32 flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPTyp
e : 0; |
| 35 if (localMatrix) { | 33 if (localMatrix) { |
| 36 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo
ords, | 34 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *loc
alMatrix); |
| 37 coverageIgnored, SkMatrix::I(), *
localMatrix); | |
| 38 } else { | 35 } else { |
| 39 return GrDefaultGeoProcFactory::Create(flags, GrColor_WHITE, usesLocalCo
ords, | 36 return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMa
trix::I()); |
| 40 coverageIgnored, SkMatrix::I(), S
kMatrix::I()); | |
| 41 } | 37 } |
| 42 } | 38 } |
| 43 | 39 |
| 44 class RectBatch : public GrBatch { | 40 class RectBatch : public GrBatch { |
| 45 public: | 41 public: |
| 46 struct Geometry { | 42 struct Geometry { |
| 47 SkMatrix fViewMatrix; | 43 SkMatrix fViewMatrix; |
| 48 SkRect fRect; | 44 SkRect fRect; |
| 49 SkRect fLocalRect; | 45 SkRect fLocalRect; |
| 50 SkMatrix fLocalMatrix; | 46 SkMatrix fLocalMatrix; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 SkDebugf("Could not invert\n"); | 91 SkDebugf("Could not invert\n"); |
| 96 return; | 92 return; |
| 97 } | 93 } |
| 98 | 94 |
| 99 if (this->hasLocalMatrix()) { | 95 if (this->hasLocalMatrix()) { |
| 100 invert.preConcat(this->localMatrix()); | 96 invert.preConcat(this->localMatrix()); |
| 101 } | 97 } |
| 102 } | 98 } |
| 103 | 99 |
| 104 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc
alCoords, | 100 SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLoc
alCoords, |
| 105 &invert, | 101 this->color(), |
| 106 this->usesLoca
lCoords(), | 102 &invert)); |
| 107 this->coverage
Ignored())); | |
| 108 | 103 |
| 109 batchTarget->initDraw(gp, pipeline); | 104 batchTarget->initDraw(gp, pipeline); |
| 110 | 105 |
| 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 |
| 111 int instanceCount = fGeoData.count(); | 116 int instanceCount = fGeoData.count(); |
| 112 size_t vertexStride = gp->getVertexStride(); | 117 size_t vertexStride = gp->getVertexStride(); |
| 113 SkASSERT(hasExplicitLocalCoords ? | 118 SkASSERT(hasExplicitLocalCoords ? |
| 114 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : | 119 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorLo
calCoordAttr) : |
| 115 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); | 120 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr)); |
| 116 QuadHelper helper; | 121 QuadHelper helper; |
| 117 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); | 122 void* vertices = helper.init(batchTarget, vertexStride, instanceCount); |
| 118 | 123 |
| 119 if (!vertices) { | 124 if (!vertices) { |
| 120 return; | 125 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 geometry.fViewMatrix.mapRect(&fBounds); | 169 geometry.fViewMatrix.mapRect(&fBounds); |
| 165 } | 170 } |
| 166 | 171 |
| 167 GrColor color() const { return fBatch.fColor; } | 172 GrColor color() const { return fBatch.fColor; } |
| 168 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 173 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 169 bool colorIgnored() const { return fBatch.fColorIgnored; } | 174 bool colorIgnored() const { return fBatch.fColorIgnored; } |
| 170 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } | 175 const SkMatrix& viewMatrix() const { return fGeoData[0].fViewMatrix; } |
| 171 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } | 176 const SkMatrix& localMatrix() const { return fGeoData[0].fLocalMatrix; } |
| 172 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } | 177 bool hasLocalRect() const { return fGeoData[0].fHasLocalRect; } |
| 173 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } | 178 bool hasLocalMatrix() const { return fGeoData[0].fHasLocalMatrix; } |
| 174 bool coverageIgnored() const { return fBatch.fCoverageIgnored; } | |
| 175 | 179 |
| 176 bool onCombineIfPossible(GrBatch* t) override { | 180 bool onCombineIfPossible(GrBatch* t) override { |
| 177 RectBatch* that = t->cast<RectBatch>(); | 181 RectBatch* that = t->cast<RectBatch>(); |
| 178 | 182 |
| 179 if (this->hasLocalRect() != that->hasLocalRect()) { | 183 if (this->hasLocalRect() != that->hasLocalRect()) { |
| 180 return false; | 184 return false; |
| 181 } | 185 } |
| 182 | 186 |
| 183 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); | 187 SkASSERT(this->usesLocalCoords() == that->usesLocalCoords()); |
| 184 if (!this->hasLocalRect() && this->usesLocalCoords()) { | 188 if (!this->hasLocalRect() && this->usesLocalCoords()) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 if (hasLocalMatrix) { | 273 if (hasLocalMatrix) { |
| 270 localMatrix = GrTest::TestMatrix(random); | 274 localMatrix = GrTest::TestMatrix(random); |
| 271 } | 275 } |
| 272 | 276 |
| 273 return GrRectBatch::Create(color, viewMatrix, rect, | 277 return GrRectBatch::Create(color, viewMatrix, rect, |
| 274 hasLocalRect ? &localRect : NULL, | 278 hasLocalRect ? &localRect : NULL, |
| 275 hasLocalMatrix ? &localMatrix : NULL); | 279 hasLocalMatrix ? &localMatrix : NULL); |
| 276 } | 280 } |
| 277 | 281 |
| 278 #endif | 282 #endif |
| OLD | NEW |