| 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 "GrDrawVerticesBatch.h" | 8 #include "GrDrawVerticesBatch.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| 11 #include "GrInvariantOutput.h" | 11 #include "GrInvariantOutput.h" |
| 12 #include "GrDefaultGeoProcFactory.h" | 12 #include "GrDefaultGeoProcFactory.h" |
| 13 | 13 |
| 14 static const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, | 14 static sk_sp<GrGeometryProcessor> set_vertex_attributes(bool hasLocalCoords, |
| 15 int* colorOffset, | 15 int* colorOffset, |
| 16 int* texOffset, | 16 int* texOffset, |
| 17 const SkMatrix& viewMatr
ix, | 17 const SkMatrix& viewMatr
ix, |
| 18 bool coverageIgnored) { | 18 bool coverageIgnored) { |
| 19 using namespace GrDefaultGeoProcFactory; | 19 using namespace GrDefaultGeoProcFactory; |
| 20 *texOffset = -1; | 20 *texOffset = -1; |
| 21 *colorOffset = -1; | 21 *colorOffset = -1; |
| 22 | 22 |
| 23 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); | 23 Coverage coverage(coverageIgnored ? Coverage::kNone_Type : Coverage::kSolid_
Type); |
| 24 LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type : | 24 LocalCoords localCoords(hasLocalCoords ? LocalCoords::kHasExplicit_Type : |
| 25 LocalCoords::kUsePosition_Type); | 25 LocalCoords::kUsePosition_Type); |
| 26 *colorOffset = sizeof(SkPoint); | 26 *colorOffset = sizeof(SkPoint); |
| 27 if (hasLocalCoords) { | 27 if (hasLocalCoords) { |
| 28 *texOffset = sizeof(SkPoint) + sizeof(GrColor); | 28 *texOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 29 } | 29 } |
| 30 return GrDefaultGeoProcFactory::Create(Color(Color::kAttribute_Type), | 30 return GrDefaultGeoProcFactory::Make(Color(Color::kAttribute_Type), |
| 31 coverage, localCoords, viewMatrix); | 31 coverage, localCoords, viewMatrix); |
| 32 } | 32 } |
| 33 | 33 |
| 34 GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy
pe primitiveType, | 34 GrDrawVerticesBatch::GrDrawVerticesBatch(const Geometry& geometry, GrPrimitiveTy
pe primitiveType, |
| 35 const SkMatrix& viewMatrix, | 35 const SkMatrix& viewMatrix, |
| 36 const SkPoint* positions, int vertexCou
nt, | 36 const SkPoint* positions, int vertexCou
nt, |
| 37 const uint16_t* indices, int indexCount
, | 37 const uint16_t* indices, int indexCount
, |
| 38 const GrColor* colors, const SkPoint* l
ocalCoords, | 38 const GrColor* colors, const SkPoint* l
ocalCoords, |
| 39 const SkRect& bounds) | 39 const SkRect& bounds) |
| 40 : INHERITED(ClassID()) { | 40 : INHERITED(ClassID()) { |
| 41 SkASSERT(positions); | 41 SkASSERT(positions); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 } | 87 } |
| 88 fCoverageIgnored = !overrides.readsCoverage(); | 88 fCoverageIgnored = !overrides.readsCoverage(); |
| 89 if (!overrides.readsLocalCoords()) { | 89 if (!overrides.readsLocalCoords()) { |
| 90 fGeoData[0].fLocalCoords.reset(); | 90 fGeoData[0].fLocalCoords.reset(); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { | 94 void GrDrawVerticesBatch::onPrepareDraws(Target* target) const { |
| 95 bool hasLocalCoords = !fGeoData[0].fLocalCoords.isEmpty(); | 95 bool hasLocalCoords = !fGeoData[0].fLocalCoords.isEmpty(); |
| 96 int colorOffset = -1, texOffset = -1; | 96 int colorOffset = -1, texOffset = -1; |
| 97 SkAutoTUnref<const GrGeometryProcessor> gp( | 97 sk_sp<GrGeometryProcessor> gp(set_vertex_attributes(hasLocalCoords, &colorOf
fset, &texOffset, |
| 98 set_vertex_attributes(hasLocalCoords, &colorOffset, &texOffset, fViewMat
rix, | 98 fViewMatrix, fCoverageIg
nored)); |
| 99 fCoverageIgnored)); | |
| 100 size_t vertexStride = gp->getVertexStride(); | 99 size_t vertexStride = gp->getVertexStride(); |
| 101 | 100 |
| 102 SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint)
: 0) | 101 SkASSERT(vertexStride == sizeof(SkPoint) + (hasLocalCoords ? sizeof(SkPoint)
: 0) |
| 103 + sizeof(GrColor)); | 102 + sizeof(GrColor)); |
| 104 | 103 |
| 105 int instanceCount = fGeoData.count(); | 104 int instanceCount = fGeoData.count(); |
| 106 | 105 |
| 107 const GrBuffer* vertexBuffer; | 106 const GrBuffer* vertexBuffer; |
| 108 int firstVertex; | 107 int firstVertex; |
| 109 | 108 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 } | 154 } |
| 156 | 155 |
| 157 GrMesh mesh; | 156 GrMesh mesh; |
| 158 if (indices) { | 157 if (indices) { |
| 159 mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, first
Vertex, | 158 mesh.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, first
Vertex, |
| 160 firstIndex, fVertexCount, fIndexCount); | 159 firstIndex, fVertexCount, fIndexCount); |
| 161 | 160 |
| 162 } else { | 161 } else { |
| 163 mesh.init(this->primitiveType(), vertexBuffer, firstVertex, fVertexCount
); | 162 mesh.init(this->primitiveType(), vertexBuffer, firstVertex, fVertexCount
); |
| 164 } | 163 } |
| 165 target->draw(gp, mesh); | 164 target->draw(gp.get(), mesh); |
| 166 } | 165 } |
| 167 | 166 |
| 168 bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { | 167 bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { |
| 169 GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); | 168 GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); |
| 170 | 169 |
| 171 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), | 170 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), |
| 172 that->bounds(), caps)) { | 171 that->bounds(), caps)) { |
| 173 return false; | 172 return false; |
| 174 } | 173 } |
| 175 | 174 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 geometry.fColor = GrRandomColor(random); | 314 geometry.fColor = GrRandomColor(random); |
| 316 return GrDrawVerticesBatch::Create(geometry, type, viewMatrix, | 315 return GrDrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 317 positions.begin(), vertexCount, | 316 positions.begin(), vertexCount, |
| 318 indices.begin(), hasIndices ? vertexCount
: 0, | 317 indices.begin(), hasIndices ? vertexCount
: 0, |
| 319 colors.begin(), | 318 colors.begin(), |
| 320 texCoords.begin(), | 319 texCoords.begin(), |
| 321 bounds); | 320 bounds); |
| 322 } | 321 } |
| 323 | 322 |
| 324 #endif | 323 #endif |
| OLD | NEW |