| 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 "GrBatchTarget.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 const GrGeometryProcessor* set_vertex_attributes(bool hasLocalCoords, |
| 15 bool hasColors, | 15 bool hasColors, |
| 16 int* colorOffset, | 16 int* colorOffset, |
| 17 int* texOffset, | 17 int* texOffset, |
| 18 GrColor color, | 18 GrColor color, |
| 19 const SkMatrix& viewMatr
ix, | 19 const SkMatrix& viewMatr
ix, |
| 20 bool coverageIgnored) { | 20 bool coverageIgnored) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 100 } |
| 101 opt.getOverrideColorIfSet(&fGeoData[0].fColor); | 101 opt.getOverrideColorIfSet(&fGeoData[0].fColor); |
| 102 | 102 |
| 103 // setup batch properties | 103 // setup batch properties |
| 104 fBatch.fColorIgnored = !opt.readsColor(); | 104 fBatch.fColorIgnored = !opt.readsColor(); |
| 105 fBatch.fColor = fGeoData[0].fColor; | 105 fBatch.fColor = fGeoData[0].fColor; |
| 106 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 106 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
| 107 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 107 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
| 108 } | 108 } |
| 109 | 109 |
| 110 void GrDrawVerticesBatch::generateGeometry(GrBatchTarget* batchTarget) { | 110 void GrDrawVerticesBatch::onPrepareDraws(Target* target) { |
| 111 int colorOffset = -1, texOffset = -1; | 111 int colorOffset = -1, texOffset = -1; |
| 112 SkAutoTUnref<const GrGeometryProcessor> gp( | 112 SkAutoTUnref<const GrGeometryProcessor> gp( |
| 113 set_vertex_attributes(this->hasLocalCoords(), this->hasColors(), &co
lorOffset, | 113 set_vertex_attributes(this->hasLocalCoords(), this->hasColors(), &co
lorOffset, |
| 114 &texOffset, this->color(), this->viewMatrix(), | 114 &texOffset, this->color(), this->viewMatrix(), |
| 115 this->coverageIgnored())); | 115 this->coverageIgnored())); |
| 116 | 116 |
| 117 batchTarget->initDraw(gp, this->pipeline()); | 117 target->initDraw(gp, this->pipeline()); |
| 118 | 118 |
| 119 size_t vertexStride = gp->getVertexStride(); | 119 size_t vertexStride = gp->getVertexStride(); |
| 120 | 120 |
| 121 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? sizeof(
SkPoint) : 0) | 121 SkASSERT(vertexStride == sizeof(SkPoint) + (this->hasLocalCoords() ? sizeof(
SkPoint) : 0) |
| 122 + (this->hasColors() ? sizeof(GrCol
or) : 0)); | 122 + (this->hasColors() ? sizeof(GrCol
or) : 0)); |
| 123 | 123 |
| 124 int instanceCount = fGeoData.count(); | 124 int instanceCount = fGeoData.count(); |
| 125 | 125 |
| 126 const GrVertexBuffer* vertexBuffer; | 126 const GrVertexBuffer* vertexBuffer; |
| 127 int firstVertex; | 127 int firstVertex; |
| 128 | 128 |
| 129 void* verts = batchTarget->makeVertSpace(vertexStride, this->vertexCount(), | 129 void* verts = target->makeVertexSpace(vertexStride, this->vertexCount(), |
| 130 &vertexBuffer, &firstVertex); | 130 &vertexBuffer, &firstVertex); |
| 131 | 131 |
| 132 if (!verts) { | 132 if (!verts) { |
| 133 SkDebugf("Could not allocate vertices\n"); | 133 SkDebugf("Could not allocate vertices\n"); |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 | 136 |
| 137 const GrIndexBuffer* indexBuffer = NULL; | 137 const GrIndexBuffer* indexBuffer = NULL; |
| 138 int firstIndex = 0; | 138 int firstIndex = 0; |
| 139 | 139 |
| 140 uint16_t* indices = NULL; | 140 uint16_t* indices = NULL; |
| 141 if (this->hasIndices()) { | 141 if (this->hasIndices()) { |
| 142 indices = batchTarget->makeIndexSpace(this->indexCount(), &indexBuffer,
&firstIndex); | 142 indices = target->makeIndexSpace(this->indexCount(), &indexBuffer, &firs
tIndex); |
| 143 | 143 |
| 144 if (!indices) { | 144 if (!indices) { |
| 145 SkDebugf("Could not allocate indices\n"); | 145 SkDebugf("Could not allocate indices\n"); |
| 146 return; | 146 return; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 int indexOffset = 0; | 150 int indexOffset = 0; |
| 151 int vertexOffset = 0; | 151 int vertexOffset = 0; |
| 152 for (int i = 0; i < instanceCount; i++) { | 152 for (int i = 0; i < instanceCount; i++) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 173 } | 173 } |
| 174 | 174 |
| 175 GrVertices vertices; | 175 GrVertices vertices; |
| 176 if (this->hasIndices()) { | 176 if (this->hasIndices()) { |
| 177 vertices.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, f
irstVertex, | 177 vertices.initIndexed(this->primitiveType(), vertexBuffer, indexBuffer, f
irstVertex, |
| 178 firstIndex, this->vertexCount(), this->indexCount()
); | 178 firstIndex, this->vertexCount(), this->indexCount()
); |
| 179 | 179 |
| 180 } else { | 180 } else { |
| 181 vertices.init(this->primitiveType(), vertexBuffer, firstVertex, this->ve
rtexCount()); | 181 vertices.init(this->primitiveType(), vertexBuffer, firstVertex, this->ve
rtexCount()); |
| 182 } | 182 } |
| 183 batchTarget->draw(vertices); | 183 target->draw(vertices); |
| 184 } | 184 } |
| 185 | 185 |
| 186 bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { | 186 bool GrDrawVerticesBatch::onCombineIfPossible(GrBatch* t, const GrCaps& caps) { |
| 187 GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); | 187 GrDrawVerticesBatch* that = t->cast<GrDrawVerticesBatch>(); |
| 188 | 188 |
| 189 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), | 189 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeli
ne(), |
| 190 that->bounds(), caps)) { | 190 that->bounds(), caps)) { |
| 191 return false; | 191 return false; |
| 192 } | 192 } |
| 193 | 193 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 geometry.fColor = GrRandomColor(random); | 340 geometry.fColor = GrRandomColor(random); |
| 341 return GrDrawVerticesBatch::Create(geometry, type, viewMatrix, | 341 return GrDrawVerticesBatch::Create(geometry, type, viewMatrix, |
| 342 positions.begin(), vertexCount, | 342 positions.begin(), vertexCount, |
| 343 indices.begin(), hasIndices ? vertexCount
: 0, | 343 indices.begin(), hasIndices ? vertexCount
: 0, |
| 344 colors.begin(), | 344 colors.begin(), |
| 345 texCoords.begin(), | 345 texCoords.begin(), |
| 346 bounds); | 346 bounds); |
| 347 } | 347 } |
| 348 | 348 |
| 349 #endif | 349 #endif |
| OLD | NEW |