| 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // setup batch properties | 154 // setup batch properties |
| 155 fBatch.fColorIgnored = !opt.readsColor(); | 155 fBatch.fColorIgnored = !opt.readsColor(); |
| 156 fBatch.fColor = fGeoData[0].fColor; | 156 fBatch.fColor = fGeoData[0].fColor; |
| 157 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 157 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
| 158 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 158 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
| 159 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe
gmentMasks(); | 159 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe
gmentMasks(); |
| 160 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); | 160 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver
texCount, | 163 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver
texCount, |
| 164 size_t vertexStride, void* vertices, int indexCount, uint16_t* indic
es) { | 164 size_t vertexStride, void* vertices, int indexCount, uint16_t* ind
ices) const { |
| 165 if (vertexCount == 0 || indexCount == 0) { | 165 if (vertexCount == 0 || indexCount == 0) { |
| 166 return; | 166 return; |
| 167 } | 167 } |
| 168 const GrVertexBuffer* vertexBuffer; | 168 const GrVertexBuffer* vertexBuffer; |
| 169 GrVertices info; | 169 GrVertices info; |
| 170 int firstVertex; | 170 int firstVertex; |
| 171 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, | 171 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, |
| 172 &firstVertex); | 172 &firstVertex); |
| 173 if (!verts) { | 173 if (!verts) { |
| 174 SkDebugf("Could not allocate vertices\n"); | 174 SkDebugf("Could not allocate vertices\n"); |
| 175 return; | 175 return; |
| 176 } | 176 } |
| 177 memcpy(verts, vertices, vertexCount * vertexStride); | 177 memcpy(verts, vertices, vertexCount * vertexStride); |
| 178 | 178 |
| 179 const GrIndexBuffer* indexBuffer; | 179 const GrIndexBuffer* indexBuffer; |
| 180 int firstIndex; | 180 int firstIndex; |
| 181 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first
Index); | 181 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first
Index); |
| 182 if (!idxs) { | 182 if (!idxs) { |
| 183 SkDebugf("Could not allocate indices\n"); | 183 SkDebugf("Could not allocate indices\n"); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); | 186 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); |
| 187 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, | 187 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, |
| 188 firstIndex, vertexCount, indexCount); | 188 firstIndex, vertexCount, indexCount); |
| 189 target->draw(info); | 189 target->draw(info); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void onPrepareDraws(Target* target) override { | 192 void onPrepareDraws(Target* target) const override { |
| 193 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 193 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 194 | 194 |
| 195 // Setup GrGeometryProcessor | 195 // Setup GrGeometryProcessor |
| 196 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, | 196 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, |
| 197 this->viewMatr
ix(), | 197 this->viewMatr
ix(), |
| 198 this->usesLoca
lCoords(), | 198 this->usesLoca
lCoords(), |
| 199 this->coverage
Ignored())); | 199 this->coverage
Ignored())); |
| 200 if (!gp) { | 200 if (!gp) { |
| 201 SkDebugf("Couldn't create a GrGeometryProcessor\n"); | 201 SkDebugf("Couldn't create a GrGeometryProcessor\n"); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 | 204 |
| 205 target->initDraw(gp, this->pipeline()); | 205 target->initDraw(gp, this->pipeline()); |
| 206 | 206 |
| 207 size_t vertexStride = gp->getVertexStride(); | 207 size_t vertexStride = gp->getVertexStride(); |
| 208 | 208 |
| 209 SkASSERT(canTweakAlphaForCoverage ? | 209 SkASSERT(canTweakAlphaForCoverage ? |
| 210 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 210 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 211 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 211 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 212 | 212 |
| 213 int instanceCount = fGeoData.count(); | 213 int instanceCount = fGeoData.count(); |
| 214 | 214 |
| 215 int vertexCount = 0; | 215 int vertexCount = 0; |
| 216 int indexCount = 0; | 216 int indexCount = 0; |
| 217 int maxVertices = DEFAULT_BUFFER_SIZE; | 217 int maxVertices = DEFAULT_BUFFER_SIZE; |
| 218 int maxIndices = DEFAULT_BUFFER_SIZE; | 218 int maxIndices = DEFAULT_BUFFER_SIZE; |
| 219 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStrid
e); | 219 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStrid
e); |
| 220 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint
16_t)); | 220 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint
16_t)); |
| 221 for (int i = 0; i < instanceCount; i++) { | 221 for (int i = 0; i < instanceCount; i++) { |
| 222 Geometry& args = fGeoData[i]; | 222 const Geometry& args = fGeoData[i]; |
| 223 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); | 223 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); |
| 224 | 224 |
| 225 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { | 225 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 226 continue; | 226 continue; |
| 227 } | 227 } |
| 228 | 228 |
| 229 int currentIndices = tess.numIndices(); | 229 int currentIndices = tess.numIndices(); |
| 230 SkASSERT(currentIndices <= UINT16_MAX); | 230 SkASSERT(currentIndices <= UINT16_MAX); |
| 231 if (indexCount + currentIndices > UINT16_MAX) { | 231 if (indexCount + currentIndices > UINT16_MAX) { |
| 232 // if we added the current instance, we would overflow the indic
es we can store in a | 232 // if we added the current instance, we would overflow the indic
es we can store in a |
| 233 // uint16_t. Draw what we've got so far and reset. | 233 // uint16_t. Draw what we've got so far and reset. |
| 234 draw(target, this->pipeline(), vertexCount, vertexStride, vertic
es, indexCount, | 234 this->draw(target, this->pipeline(), vertexCount, vertexStride,
vertices, |
| 235 indices); | 235 indexCount, indices); |
| 236 vertexCount = 0; | 236 vertexCount = 0; |
| 237 indexCount = 0; | 237 indexCount = 0; |
| 238 } | 238 } |
| 239 int currentVertices = tess.numPts(); | 239 int currentVertices = tess.numPts(); |
| 240 if (vertexCount + currentVertices > maxVertices) { | 240 if (vertexCount + currentVertices > maxVertices) { |
| 241 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); | 241 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); |
| 242 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v
ertexStride); | 242 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v
ertexStride); |
| 243 } | 243 } |
| 244 if (indexCount + currentIndices > maxIndices) { | 244 if (indexCount + currentIndices > maxIndices) { |
| 245 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; | 245 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; |
| 246 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * siz
eof(uint16_t)); | 246 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * siz
eof(uint16_t)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, | 249 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, |
| 250 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; | 250 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; |
| 251 vertexCount += currentVertices; | 251 vertexCount += currentVertices; |
| 252 indexCount += currentIndices; | 252 indexCount += currentIndices; |
| 253 } | 253 } |
| 254 draw(target, this->pipeline(), vertexCount, vertexStride, vertices, inde
xCount, | 254 this->draw(target, this->pipeline(), vertexCount, vertexStride, vertices
, indexCount, |
| 255 indices); | 255 indices); |
| 256 sk_free(vertices); | 256 sk_free(vertices); |
| 257 sk_free(indices); | 257 sk_free(indices); |
| 258 } | 258 } |
| 259 | 259 |
| 260 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 260 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 261 | 261 |
| 262 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID())
{ | 262 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID())
{ |
| 263 fGeoData.push_back(geometry); | 263 fGeoData.push_back(geometry); |
| 264 | 264 |
| 265 // compute bounds | 265 // compute bounds |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { | 347 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { |
| 348 AAFlatteningConvexPathBatch::Geometry geometry; | 348 AAFlatteningConvexPathBatch::Geometry geometry; |
| 349 geometry.fColor = GrRandomColor(random); | 349 geometry.fColor = GrRandomColor(random); |
| 350 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 350 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
| 351 geometry.fPath = GrTest::TestPathConvex(random); | 351 geometry.fPath = GrTest::TestPathConvex(random); |
| 352 | 352 |
| 353 return AAFlatteningConvexPathBatch::Create(geometry); | 353 return AAFlatteningConvexPathBatch::Create(geometry); |
| 354 } | 354 } |
| 355 | 355 |
| 356 #endif | 356 #endif |
| OLD | NEW |