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 "GrAALinearizingConvexPathRenderer.h" | 8 #include "GrAALinearizingConvexPathRenderer.h" |
9 | 9 |
10 #include "GrAAConvexTessellator.h" | 10 #include "GrAAConvexTessellator.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)
) = | 89 *reinterpret_cast<float*>(verts + i * vertexStride + sizeof(GrColor)
) = |
90 tess.coverage(i); | 90 tess.coverage(i); |
91 } | 91 } |
92 } | 92 } |
93 | 93 |
94 for (int i = 0; i < tess.numIndices(); ++i) { | 94 for (int i = 0; i < tess.numIndices(); ++i) { |
95 idxs[i] = tess.index(i) + firstIndex; | 95 idxs[i] = tess.index(i) + firstIndex; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 static const GrGeometryProcessor* create_fill_gp(bool tweakAlphaForCoverage, | 99 static sk_sp<GrGeometryProcessor> create_fill_gp(bool tweakAlphaForCoverage, |
100 const SkMatrix& viewMatrix, | 100 const SkMatrix& viewMatrix, |
101 bool usesLocalCoords, | 101 bool usesLocalCoords, |
102 bool coverageIgnored) { | 102 bool coverageIgnored) { |
103 using namespace GrDefaultGeoProcFactory; | 103 using namespace GrDefaultGeoProcFactory; |
104 | 104 |
105 Color color(Color::kAttribute_Type); | 105 Color color(Color::kAttribute_Type); |
106 Coverage::Type coverageType; | 106 Coverage::Type coverageType; |
107 // TODO remove coverage if coverage is ignored | 107 // TODO remove coverage if coverage is ignored |
108 /*if (coverageIgnored) { | 108 /*if (coverageIgnored) { |
109 coverageType = Coverage::kNone_Type; | 109 coverageType = Coverage::kNone_Type; |
110 } else*/ if (tweakAlphaForCoverage) { | 110 } else*/ if (tweakAlphaForCoverage) { |
111 coverageType = Coverage::kSolid_Type; | 111 coverageType = Coverage::kSolid_Type; |
112 } else { | 112 } else { |
113 coverageType = Coverage::kAttribute_Type; | 113 coverageType = Coverage::kAttribute_Type; |
114 } | 114 } |
115 Coverage coverage(coverageType); | 115 Coverage coverage(coverageType); |
116 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : | 116 LocalCoords localCoords(usesLocalCoords ? LocalCoords::kUsePosition_Type : |
117 LocalCoords::kUnused_Type); | 117 LocalCoords::kUnused_Type); |
118 return CreateForDeviceSpace(color, coverage, localCoords, viewMatrix); | 118 return MakeForDeviceSpace(color, coverage, localCoords, viewMatrix); |
119 } | 119 } |
120 | 120 |
121 class AAFlatteningConvexPathBatch : public GrVertexBatch { | 121 class AAFlatteningConvexPathBatch : public GrVertexBatch { |
122 public: | 122 public: |
123 DEFINE_BATCH_CLASS_ID | 123 DEFINE_BATCH_CLASS_ID |
124 | 124 |
125 struct Geometry { | 125 struct Geometry { |
126 GrColor fColor; | 126 GrColor fColor; |
127 SkMatrix fViewMatrix; | 127 SkMatrix fViewMatrix; |
128 SkPath fPath; | 128 SkPath fPath; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); | 188 memcpy(idxs, indices, indexCount * sizeof(uint16_t)); |
189 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, | 189 mesh.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
firstVertex, |
190 firstIndex, vertexCount, indexCount); | 190 firstIndex, vertexCount, indexCount); |
191 target->draw(gp, mesh); | 191 target->draw(gp, mesh); |
192 } | 192 } |
193 | 193 |
194 void onPrepareDraws(Target* target) const override { | 194 void onPrepareDraws(Target* target) const override { |
195 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); | 195 bool canTweakAlphaForCoverage = this->canTweakAlphaForCoverage(); |
196 | 196 |
197 // Setup GrGeometryProcessor | 197 // Setup GrGeometryProcessor |
198 SkAutoTUnref<const GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaF
orCoverage, | 198 sk_sp<GrGeometryProcessor> gp(create_fill_gp(canTweakAlphaForCoverage, |
199 this->viewMatr
ix(), | 199 this->viewMatrix(), |
200 this->usesLoca
lCoords(), | 200 this->usesLocalCoords(), |
201 this->coverage
Ignored())); | 201 this->coverageIgnored())); |
202 if (!gp) { | 202 if (!gp) { |
203 SkDebugf("Couldn't create a GrGeometryProcessor\n"); | 203 SkDebugf("Couldn't create a GrGeometryProcessor\n"); |
204 return; | 204 return; |
205 } | 205 } |
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)); |
(...skipping 12 matching lines...) Expand all Loading... |
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 this->draw(target, gp, vertexCount, vertexStride, vertices, inde
xCount, indices); | 234 this->draw(target, gp.get(), |
| 235 vertexCount, vertexStride, vertices, indexCount, indi
ces); |
235 vertexCount = 0; | 236 vertexCount = 0; |
236 indexCount = 0; | 237 indexCount = 0; |
237 } | 238 } |
238 int currentVertices = tess.numPts(); | 239 int currentVertices = tess.numPts(); |
239 if (vertexCount + currentVertices > maxVertices) { | 240 if (vertexCount + currentVertices > maxVertices) { |
240 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); | 241 maxVertices = SkTMax(vertexCount + currentVertices, maxVertices
* 2); |
241 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v
ertexStride); | 242 vertices = (uint8_t*) sk_realloc_throw(vertices, maxVertices * v
ertexStride); |
242 } | 243 } |
243 if (indexCount + currentIndices > maxIndices) { | 244 if (indexCount + currentIndices > maxIndices) { |
244 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; | 245 maxIndices = SkTMax(indexCount + currentIndices, maxIndices * 2)
; |
245 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)); |
246 } | 247 } |
247 | 248 |
248 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, | 249 extract_verts(tess, vertices + vertexStride * vertexCount, vertexStr
ide, args.fColor, |
249 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; | 250 vertexCount, indices + indexCount, canTweakAlphaForCoverage)
; |
250 vertexCount += currentVertices; | 251 vertexCount += currentVertices; |
251 indexCount += currentIndices; | 252 indexCount += currentIndices; |
252 } | 253 } |
253 this->draw(target, gp, vertexCount, vertexStride, vertices, indexCount,
indices); | 254 this->draw(target, gp.get(), vertexCount, vertexStride, vertices, indexC
ount, indices); |
254 sk_free(vertices); | 255 sk_free(vertices); |
255 sk_free(indices); | 256 sk_free(indices); |
256 } | 257 } |
257 | 258 |
258 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } | 259 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } |
259 | 260 |
260 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID())
{ | 261 AAFlatteningConvexPathBatch(const Geometry& geometry) : INHERITED(ClassID())
{ |
261 fGeoData.push_back(geometry); | 262 fGeoData.push_back(geometry); |
262 | 263 |
263 // compute bounds | 264 // compute bounds |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { | 354 DRAW_BATCH_TEST_DEFINE(AAFlatteningConvexPathBatch) { |
354 AAFlatteningConvexPathBatch::Geometry geometry; | 355 AAFlatteningConvexPathBatch::Geometry geometry; |
355 geometry.fColor = GrRandomColor(random); | 356 geometry.fColor = GrRandomColor(random); |
356 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); | 357 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); |
357 geometry.fPath = GrTest::TestPathConvex(random); | 358 geometry.fPath = GrTest::TestPathConvex(random); |
358 | 359 |
359 return AAFlatteningConvexPathBatch::Create(geometry); | 360 return AAFlatteningConvexPathBatch::Create(geometry); |
360 } | 361 } |
361 | 362 |
362 #endif | 363 #endif |
OLD | NEW |