| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 return false; | 47 return false; |
| 48 } | 48 } |
| 49 if (!args.fPath->isConvex()) { | 49 if (!args.fPath->isConvex()) { |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 if (args.fStroke->getStyle() == SkStrokeRec::kStroke_Style) { | 52 if (args.fStroke->getStyle() == SkStrokeRec::kStroke_Style) { |
| 53 if (!args.fViewMatrix->isSimilarity()) { | 53 if (!args.fViewMatrix->isSimilarity()) { |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * args.fStroke->g
etWidth(); | 56 SkScalar strokeWidth = args.fViewMatrix->getMaxScale() * args.fStroke->g
etWidth(); |
| 57 return strokeWidth >= 1.0f && strokeWidth <= kMaxStrokeWidth && !args.fS
troke->isDashed() && | 57 return strokeWidth >= 1.0f && strokeWidth <= kMaxStrokeWidth && !args.fS
troke->isDashed() && |
| 58 SkPathPriv::LastVerbIsClose(*args.fPath) && | 58 SkPathPriv::LastVerbIsClose(*args.fPath) && |
| 59 args.fStroke->getJoin() != SkPaint::Join::kRound_Join; | 59 args.fStroke->getJoin() != SkPaint::Join::kRound_Join; |
| 60 } | 60 } |
| 61 return args.fStroke->getStyle() == SkStrokeRec::kFill_Style; | 61 return args.fStroke->getStyle() == SkStrokeRec::kFill_Style; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // extract the result vertices and indices from the GrAAConvexTessellator | 64 // extract the result vertices and indices from the GrAAConvexTessellator |
| 65 static void extract_verts(const GrAAConvexTessellator& tess, | 65 static void extract_verts(const GrAAConvexTessellator& tess, |
| 66 void* vertices, | 66 void* vertices, |
| 67 size_t vertexStride, | 67 size_t vertexStride, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 // Make 'verts' point to the colors | 78 // Make 'verts' point to the colors |
| 79 verts += sizeof(SkPoint); | 79 verts += sizeof(SkPoint); |
| 80 for (int i = 0; i < tess.numPts(); ++i) { | 80 for (int i = 0; i < tess.numPts(); ++i) { |
| 81 if (tweakAlphaForCoverage) { | 81 if (tweakAlphaForCoverage) { |
| 82 SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); | 82 SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255); |
| 83 unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); | 83 unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i)); |
| 84 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, s
cale); | 84 GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, s
cale); |
| 85 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; | 85 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = scaledColor; |
| 86 } else { | 86 } else { |
| 87 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; | 87 *reinterpret_cast<GrColor*>(verts + i * vertexStride) = color; |
| 88 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)
) = | 88 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)
) = |
| 89 tess.coverage(i); | 89 tess.coverage(i); |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| 93 for (int i = 0; i < tess.numIndices(); ++i) { | 93 for (int i = 0; i < tess.numIndices(); ++i) { |
| 94 idxs[i] = tess.index(i) + firstIndex; | 94 idxs[i] = tess.index(i) + firstIndex; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 | 97 |
| 98 static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, | 98 static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 152 |
| 153 // setup batch properties | 153 // setup batch properties |
| 154 fBatch.fColorIgnored = !opt.readsColor(); | 154 fBatch.fColorIgnored = !opt.readsColor(); |
| 155 fBatch.fColor = fGeoData[0].fColor; | 155 fBatch.fColor = fGeoData[0].fColor; |
| 156 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); | 156 fBatch.fUsesLocalCoords = opt.readsLocalCoords(); |
| 157 fBatch.fCoverageIgnored = !opt.readsCoverage(); | 157 fBatch.fCoverageIgnored = !opt.readsCoverage(); |
| 158 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe
gmentMasks(); | 158 fBatch.fLinesOnly = SkPath::kLine_SegmentMask == fGeoData[0].fPath.getSe
gmentMasks(); |
| 159 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); | 159 fBatch.fCanTweakAlphaForCoverage = opt.canTweakAlphaForCoverage(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver
texCount, | 162 void draw(GrVertexBatch::Target* target, const GrPipeline* pipeline, int ver
texCount, |
| 163 size_t vertexStride, void* vertices, int indexCount, uint16_t* indic
es) { | 163 size_t vertexStride, void* vertices, int indexCount, uint16_t* indic
es) { |
| 164 if (vertexCount == 0 || indexCount == 0) { | 164 if (vertexCount == 0 || indexCount == 0) { |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 const GrVertexBuffer* vertexBuffer; | 167 const GrVertexBuffer* vertexBuffer; |
| 168 GrVertices info; | 168 GrVertices info; |
| 169 int firstVertex; | 169 int firstVertex; |
| 170 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, | 170 void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertex
Buffer, |
| 171 &firstVertex); | 171 &firstVertex); |
| 172 if (!verts) { | 172 if (!verts) { |
| 173 SkDebugf("Could not allocate vertices\n"); | 173 SkDebugf("Could not allocate vertices\n"); |
| 174 return; | 174 return; |
| 175 } | 175 } |
| 176 memcpy(verts, vertices, vertexCount * vertexStride); | 176 memcpy(verts, vertices, vertexCount * vertexStride); |
| 177 | 177 |
| 178 const GrIndexBuffer* indexBuffer; | 178 const GrIndexBuffer* indexBuffer; |
| 179 int firstIndex; | 179 int firstIndex; |
| 180 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first
Index); | 180 uint16_t* idxs = target->makeIndexSpace(indexCount, &indexBuffer, &first
Index); |
| 181 if (!idxs) { | 181 if (!idxs) { |
| 182 SkDebugf("Could not allocate indices\n"); | 182 SkDebugf("Could not allocate indices\n"); |
| 183 return; | 183 return; |
| 184 } | 184 } |
| 185 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); | 185 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); |
| 186 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, | 186 info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, |
| 187 firstIndex, vertexCount, indexCount); | 187 firstIndex, vertexCount, indexCount); |
| 188 target->draw(info); | 188 target->draw(info); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void onPrepareDraws(Target* target) override { | 191 void onPrepareDraws(Target* target) override { |
| 192 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 192 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
| 193 | 193 |
| 194 // Setup GrGeometryProcessor | 194 // Setup GrGeometryProcessor |
| 195 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, | 195 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, |
| 196 this->viewMatr
ix(), | 196 this->viewMatr
ix(), |
| 197 this->usesLoca
lCoords(), | 197 this->usesLoca
lCoords(), |
| 198 this->coverage
Ignored())); | 198 this->coverage
Ignored())); |
| 199 if (!gp) { | 199 if (!gp) { |
| 200 SkDebugf("Couldn't create a GrGeometryProcessor\n"); | 200 SkDebugf("Couldn't create a GrGeometryProcessor\n"); |
| 201 return; | 201 return; |
| 202 } | 202 } |
| 203 | 203 |
| 204 target->initDraw(gp, this->pipeline()); | 204 target->initDraw(gp, this->pipeline()); |
| 205 | 205 |
| 206 size_t vertexStride = gp->getVertexStride(); | 206 size_t vertexStride = gp->getVertexStride(); |
| 207 | 207 |
| 208 SkASSERT(canTweakAlphaForCoverage ? | 208 SkASSERT(canTweakAlphaForCoverage ? |
| 209 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : | 209 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAt
tr) : |
| 210 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); | 210 vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCo
verageAttr)); |
| 211 | 211 |
| 212 int instanceCount = fGeoData.count(); | 212 int instanceCount = fGeoData.count(); |
| 213 | 213 |
| 214 int vertexCount = 0; | 214 int vertexCount = 0; |
| 215 int indexCount = 0; | 215 int indexCount = 0; |
| 216 int maxVertices = DEFAULT_BUFFER_SIZE; | 216 int maxVertices = DEFAULT_BUFFER_SIZE; |
| 217 int maxIndices = DEFAULT_BUFFER_SIZE; | 217 int maxIndices = DEFAULT_BUFFER_SIZE; |
| 218 uint8_t* vertices = (uint8_t*) malloc(maxVertices * vertexStride); | 218 uint8_t* vertices = (uint8_t*) sk_malloc_throw(maxVertices * vertexStrid
e); |
| 219 uint16_t* indices = (uint16_t*) malloc(maxIndices * sizeof(uint16_t)); | 219 uint16_t* indices = (uint16_t*) sk_malloc_throw(maxIndices * sizeof(uint
16_t)); |
| 220 for (int i = 0; i < instanceCount; i++) { | 220 for (int i = 0; i < instanceCount; i++) { |
| 221 Geometry& args = fGeoData[i]; | 221 Geometry& args = fGeoData[i]; |
| 222 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); | 222 GrAAConvexTessellator tess(args.fStrokeWidth, args.fJoin, args.fMite
rLimit); |
| 223 | 223 |
| 224 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { | 224 if (!tess.tessellate(args.fViewMatrix, args.fPath)) { |
| 225 continue; | 225 continue; |
| 226 } | 226 } |
| 227 | 227 |
| 228 int currentIndices = tess.numIndices(); | 228 int currentIndices = tess.numIndices(); |
| 229 SkASSERT(currentIndices <= UINT16_MAX); | 229 SkASSERT(currentIndices <= UINT16_MAX); |
| 230 if (indexCount + currentIndices > UINT16_MAX) { | 230 if (indexCount + currentIndices > UINT16_MAX) { |
| 231 // if we added the current instance, we would overflow the indic
es we can store in a | 231 // if we added the current instance, we would overflow the indic
es we can store in a |
| 232 // uint16_t. Draw what we've got so far and reset. | 232 // uint16_t. Draw what we've got so far and reset. |
| 233 draw(target, this->pipeline(), vertexCount, vertexStride, vertic
es, indexCount, | 233 draw(target, this->pipeline(), vertexCount, vertexStride, vertic
es, indexCount, |
| 234 indices); | 234 indices); |
| 235 vertexCount = 0; | 235 vertexCount = 0; |
| 236 indexCount = 0; | 236 indexCount = 0; |
| 237 } | 237 } |
| 238 int currentVertices = tess.numPts(); | 238 int currentVertices = tess.numPts(); |
| 239 if (vertexCount + currentVertices > maxVertices) { | 239 if (vertexCount + currentVertices > maxVertices) { |
| 240 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); | 240 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); |
| 241 vertices = (uint8_t*) realloc(vertices, maxVertices * vertexStri
de); | 241 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v
ertexStride); |
| 242 } | 242 } |
| 243 if (indexCount + currentIndices > maxIndices) { | 243 if (indexCount + currentIndices > maxIndices) { |
| 244 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; | 244 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; |
| 245 indices = (uint16_t*) realloc(indices, maxIndices * sizeof(uint1
6_t)); | 245 indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * siz
eof(uint16_t)); |
| 246 } | 246 } |
| 247 | 247 |
| 248 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, | 248 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, |
| 249 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; | 249 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; |
| 250 vertexCount += currentVertices; | 250 vertexCount += currentVertices; |
| 251 indexCount += currentIndices; | 251 indexCount += currentIndices; |
| 252 } | 252 } |
| 253 draw(target, this->pipeline(), vertexCount, vertexStride, vertices, inde
xCount, | 253 draw(target, this->pipeline(), vertexCount, vertexStride, vertices, inde
xCount, |
| 254 indices); | 254 indices); |
| 255 free(vertices); | 255 sk_free(vertices); |
| 256 free(indices); | 256 sk_free(indices); |
| 257 } | 257 } |
| 258 | 258 |
| 259 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 259 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
| 260 | 260 |
| 261 AAFlatteningConvexPathBatch(const Geometry& geometry) { | 261 AAFlatteningConvexPathBatch(const Geometry& geometry) { |
| 262 this->initClassID<AAFlatteningConvexPathBatch>(); | 262 this->initClassID<AAFlatteningConvexPathBatch>(); |
| 263 fGeoData.push_back(geometry); | 263 fGeoData.push_back(geometry); |
| 264 | 264 |
| 265 // compute bounds | 265 // compute bounds |
| 266 fBounds = geometry.fPath.getBounds(); | 266 fBounds = geometry.fPath.getBounds(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { | 336 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { |
| 337 AAFlatteningConvexPathBatch::Geometry geometry; | 337 AAFlatteningConvexPathBatch::Geometry geometry; |
| 338 geometry.fColor = GrRandomColor(random); | 338 geometry.fColor = GrRandomColor(random); |
| 339 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 339 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
| 340 geometry.fPath = GrTest::TestPathConvex(random); | 340 geometry.fPath = GrTest::TestPathConvex(random); |
| 341 | 341 |
| 342 return AAFlatteningConvexPathBatch::Create(geometry); | 342 return AAFlatteningConvexPathBatch::Create(geometry); |
| 343 } | 343 } |
| 344 | 344 |
| 345 #endif | 345 #endif |
| OLD | NEW |