OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "GrAALinearizingConvexPathRenderer.h" | 9 #include "GrAALinearizingConvexPathRenderer.h" |
10 | 10 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (!idxs) { | 177 if (!idxs) { |
178 SkDebugf("Could not allocate indices\n"); | 178 SkDebugf("Could not allocate indices\n"); |
179 return; | 179 return; |
180 } | 180 } |
181 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); | 181 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); |
182 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, | 182 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, |
183 firstIndex, vertexCount, indexCount); | 183 firstIndex, vertexCount, indexCount); |
184 batchTarget->draw(info); | 184 batchTarget->draw(info); |
185 } | 185 } |
186 | 186 |
187 void generateGeometry(GrBatchTarget* batchTarget, const GrPipeline* pipeline
) override { | 187 void generateGeometry(GrBatchTarget* batchTarget) override { |
188 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 188 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
189 | 189 |
190 // Setup GrGeometryProcessor | 190 // Setup GrGeometryProcessor |
191 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, | 191 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, |
192 this->viewMatr
ix(), | 192 this->viewMatr
ix(), |
193 this->usesLoca
lCoords(), | 193 this->usesLoca
lCoords(), |
194 this->coverage
Ignored())); | 194 this->coverage
Ignored())); |
195 if (!gp) { | 195 if (!gp) { |
196 SkDebugf("Couldn't create a GrGeometryProcessor\n"); | 196 SkDebugf("Couldn't create a GrGeometryProcessor\n"); |
197 return; | 197 return; |
198 } | 198 } |
199 | 199 |
200 batchTarget->initDraw(gp, pipeline); | 200 batchTarget->initDraw(gp, this->pipeline()); |
201 | 201 |
202 size_t vertexStride = gp->getVertexStride(); | 202 size_t vertexStride = gp->getVertexStride(); |
203 | 203 |
204 SkASSERT(canTweakAlphaForCoverage ? | 204 SkASSERT(canTweakAlphaForCoverage ? |
205 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 205 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
206 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 206 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
207 | 207 |
208 int instanceCount = fGeoData.count(); | 208 int instanceCount = fGeoData.count(); |
209 | 209 |
210 int vertexCount = 0; | 210 int vertexCount = 0; |
211 int indexCount = 0; | 211 int indexCount = 0; |
212 int maxVertices = DEFAULT_BUFFER_SIZE; | 212 int maxVertices = DEFAULT_BUFFER_SIZE; |
213 int maxIndices = DEFAULT_BUFFER_SIZE; | 213 int maxIndices = DEFAULT_BUFFER_SIZE; |
214 uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); | 214 uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); |
215 uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); | 215 uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); |
216 for (int i = 0; i < instanceCount; i++) { | 216 for (int i = 0; i < instanceCount; i++) { |
217 Geometry& args = fGeoData[i]; | 217 Geometry& args = fGeoData[i]; |
218 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); | 218 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); |
219 | 219 |
220 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { | 220 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
221 continue; | 221 continue; |
222 } | 222 } |
223 | 223 |
224 int currentIndices = tess.numIndices(); | 224 int currentIndices = tess.numIndices(); |
225 SkASSERT(currentIndices <= UINT16_MAX); | 225 SkASSERT(currentIndices <= UINT16_MAX); |
226 if (indexCount + currentIndices > UINT16_MAX) { | 226 if (indexCount + currentIndices > UINT16_MAX) { |
227 // if we added the current instance, we would overflow the indic
es we can store in a | 227 // if we added the current instance, we would overflow the indic
es we can store in a |
228 // uint16_t. Draw what we've got so far and reset. | 228 // uint16_t. Draw what we've got so far and reset. |
229 draw(batchTarget, pipeline, vertexCount, vertexStride, vertices,
indexCount, | 229 draw(batchTarget, this->pipeline(), vertexCount, vertexStride, v
ertices, indexCount, |
230 indices); | 230 indices); |
231 vertexCount = 0; | 231 vertexCount = 0; |
232 indexCount = 0; | 232 indexCount = 0; |
233 } | 233 } |
234 int currentVertices = tess.numPts(); | 234 int currentVertices = tess.numPts(); |
235 if (vertexCount + currentVertices > maxVertices) { | 235 if (vertexCount + currentVertices > maxVertices) { |
236 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); | 236 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); |
237 vertices = (uint8_t*) realloc(vertices, maxVertices * vertexStri
de); | 237 vertices = (uint8_t*) realloc(vertices, maxVertices * vertexStri
de); |
238 } | 238 } |
239 if (indexCount + currentIndices > maxIndices) { | 239 if (indexCount + currentIndices > maxIndices) { |
240 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; | 240 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; |
241 indices = (uint16_t*) realloc(indices, maxIndices * sizeof(uint1
6_t)); | 241 indices = (uint16_t*) realloc(indices, maxIndices * sizeof(uint1
6_t)); |
242 } | 242 } |
243 | 243 |
244 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, | 244 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, |
245 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; | 245 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; |
246 vertexCount += currentVertices; | 246 vertexCount += currentVertices; |
247 indexCount += currentIndices; | 247 indexCount += currentIndices; |
248 } | 248 } |
249 draw(batchTarget, pipeline, vertexCount, vertexStride, vertices, indexCo
unt, indices); | 249 draw(batchTarget, this->pipeline(), vertexCount, vertexStride, vertices,
indexCount, |
| 250 indices); |
250 free(vertices); | 251 free(vertices); |
251 free(indices); | 252 free(indices); |
252 } | 253 } |
253 | 254 |
254 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 255 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
255 | 256 |
256 private: | 257 private: |
257 AAFlatteningConvexPathBatch(const Geometry& geometry) { | 258 AAFlatteningConvexPathBatch(const Geometry& geometry) { |
258 this->initClassID<AAFlatteningConvexPathBatch>(); | 259 this->initClassID<AAFlatteningConvexPathBatch>(); |
259 fGeoData.push_back(geometry); | 260 fGeoData.push_back(geometry); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { | 333 BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { |
333 AAFlatteningConvexPathBatch::Geometry geometry; | 334 AAFlatteningConvexPathBatch::Geometry geometry; |
334 geometry.fColor = GrRandomColor(random); | 335 geometry.fColor = GrRandomColor(random); |
335 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 336 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
336 geometry.fPath = GrTest::TestPathConvex(random); | 337 geometry.fPath = GrTest::TestPathConvex(random); |
337 | 338 |
338 return AAFlatteningConvexPathBatch::Create(geometry); | 339 return AAFlatteningConvexPathBatch::Create(geometry); |
339 } | 340 } |
340 | 341 |
341 #endif | 342 #endif |
OLD | NEW |