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 "GrTessellator.h" | 8 #include "GrTessellator.h" |
9 | 9 |
10 #include "GrPathUtils.h" | 10 #include "GrPathUtils.h" |
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID, | 1270 LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID, |
1271 e->fLeftPoly ? e->fLeftPoly->fID : -1, e->fRightPoly ? e->fRight
Poly->fID : -1); | 1271 e->fLeftPoly ? e->fLeftPoly->fID : -1, e->fRightPoly ? e->fRight
Poly->fID : -1); |
1272 } | 1272 } |
1273 #endif | 1273 #endif |
1274 } | 1274 } |
1275 return polys; | 1275 return polys; |
1276 } | 1276 } |
1277 | 1277 |
1278 // This is a driver function which calls stages 2-5 in turn. | 1278 // This is a driver function which calls stages 2-5 in turn. |
1279 | 1279 |
1280 Poly* contours_to_polys(Vertex** contours, int contourCnt, const SkRect& pathBou
nds, | 1280 Poly* contours_to_polys(Vertex** contours, int contourCnt, const SkRect& pathBou
nds, |
1281 SkChunkAlloc& alloc) { | 1281 SkChunkAlloc& alloc) { |
1282 Comparator c; | 1282 Comparator c; |
1283 if (pathBounds.width() > pathBounds.height()) { | 1283 if (pathBounds.width() > pathBounds.height()) { |
1284 c.sweep_lt = sweep_lt_horiz; | 1284 c.sweep_lt = sweep_lt_horiz; |
1285 c.sweep_gt = sweep_gt_horiz; | 1285 c.sweep_gt = sweep_gt_horiz; |
1286 } else { | 1286 } else { |
1287 c.sweep_lt = sweep_lt_vert; | 1287 c.sweep_lt = sweep_lt_vert; |
1288 c.sweep_gt = sweep_gt_vert; | 1288 c.sweep_gt = sweep_gt_vert; |
1289 } | 1289 } |
1290 #if LOGGING_ENABLED | 1290 #if LOGGING_ENABLED |
(...skipping 18 matching lines...) Expand all Loading... |
1309 #if LOGGING_ENABLED | 1309 #if LOGGING_ENABLED |
1310 for (Vertex* v = vertices; v != nullptr; v = v->fNext) { | 1310 for (Vertex* v = vertices; v != nullptr; v = v->fNext) { |
1311 static float gID = 0.0f; | 1311 static float gID = 0.0f; |
1312 v->fID = gID++; | 1312 v->fID = gID++; |
1313 } | 1313 } |
1314 #endif | 1314 #endif |
1315 simplify(vertices, c, alloc); | 1315 simplify(vertices, c, alloc); |
1316 return tessellate(vertices, alloc); | 1316 return tessellate(vertices, alloc); |
1317 } | 1317 } |
1318 | 1318 |
1319 Poly* path_to_polys(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, | 1319 Poly* path_to_polys(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, |
1320 int contourCnt, SkChunkAlloc& alloc, bool* isLinear) { | 1320 int contourCnt, SkChunkAlloc& alloc, bool* isLinear) { |
1321 SkPath::FillType fillType = path.getFillType(); | 1321 SkPath::FillType fillType = path.getFillType(); |
1322 if (SkPath::IsInverseFillType(fillType)) { | 1322 if (SkPath::IsInverseFillType(fillType)) { |
1323 contourCnt++; | 1323 contourCnt++; |
1324 } | 1324 } |
1325 SkAutoTDeleteArray<Vertex*> contours(new Vertex* [contourCnt]); | 1325 SkAutoTDeleteArray<Vertex*> contours(new Vertex* [contourCnt]); |
1326 | 1326 |
1327 path_to_contours(path, tolerance, clipBounds, contours.get(), alloc, isLinea
r); | 1327 path_to_contours(path, tolerance, clipBounds, contours.get(), alloc, isLinea
r); |
1328 return contours_to_polys(contours.get(), contourCnt, path.getBounds(), alloc
); | 1328 return contours_to_polys(contours.get(), contourCnt, path.getBounds(), alloc
); |
1329 } | 1329 } |
1330 | 1330 |
1331 void get_contour_count_and_size_estimate(const SkPath& path, SkScalar tolerance,
int* contourCnt, | 1331 void get_contour_count_and_size_estimate(const SkPath& path, SkScalar tolerance,
int* contourCnt, |
1332 int* sizeEstimate) { | 1332 int* sizeEstimate) { |
1333 int maxPts = GrPathUtils::worstCasePointCount(path, contourCnt, tolerance); | 1333 int maxPts = GrPathUtils::worstCasePointCount(path, contourCnt, tolerance); |
1334 if (maxPts <= 0) { | 1334 if (maxPts <= 0) { |
1335 *contourCnt = 0; | 1335 *contourCnt = 0; |
1336 return; | 1336 return; |
1337 } | 1337 } |
1338 if (maxPts > ((int)SK_MaxU16 + 1)) { | 1338 if (maxPts > ((int)SK_MaxU16 + 1)) { |
1339 SkDebugf("Path not rendered, too many verts (%d)\n", maxPts); | 1339 SkDebugf("Path not rendered, too many verts (%d)\n", maxPts); |
1340 *contourCnt = 0; | 1340 *contourCnt = 0; |
1341 return; | 1341 return; |
(...skipping 14 matching lines...) Expand all Loading... |
1356 } | 1356 } |
1357 return count; | 1357 return count; |
1358 } | 1358 } |
1359 | 1359 |
1360 } // namespace | 1360 } // namespace |
1361 | 1361 |
1362 namespace GrTessellator { | 1362 namespace GrTessellator { |
1363 | 1363 |
1364 // Stage 6: Triangulate the monotone polygons into a vertex buffer. | 1364 // Stage 6: Triangulate the monotone polygons into a vertex buffer. |
1365 | 1365 |
1366 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, | 1366 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, |
1367 VertexAllocator* vertexAllocator, bool* isLinear) { | 1367 VertexAllocator* vertexAllocator, bool* isLinear) { |
1368 int contourCnt; | 1368 int contourCnt; |
1369 int sizeEstimate; | 1369 int sizeEstimate; |
1370 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); | 1370 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); |
1371 if (contourCnt <= 0) { | 1371 if (contourCnt <= 0) { |
1372 *isLinear = true; | 1372 *isLinear = true; |
1373 return 0; | 1373 return 0; |
1374 } | 1374 } |
1375 SkChunkAlloc alloc(sizeEstimate); | 1375 SkChunkAlloc alloc(sizeEstimate); |
1376 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
isLinear); | 1376 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
isLinear); |
(...skipping 14 matching lines...) Expand all Loading... |
1391 end = poly->emit(end); | 1391 end = poly->emit(end); |
1392 } | 1392 } |
1393 } | 1393 } |
1394 int actualCount = static_cast<int>(end - verts); | 1394 int actualCount = static_cast<int>(end - verts); |
1395 LOG("actual count: %d\n", actualCount); | 1395 LOG("actual count: %d\n", actualCount); |
1396 SkASSERT(actualCount <= count); | 1396 SkASSERT(actualCount <= count); |
1397 vertexAllocator->unlock(actualCount); | 1397 vertexAllocator->unlock(actualCount); |
1398 return actualCount; | 1398 return actualCount; |
1399 } | 1399 } |
1400 | 1400 |
1401 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBou
nds, | 1401 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBou
nds, |
1402 GrTessellator::WindingVertex** verts) { | 1402 GrTessellator::WindingVertex** verts) { |
1403 int contourCnt; | 1403 int contourCnt; |
1404 int sizeEstimate; | 1404 int sizeEstimate; |
1405 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); | 1405 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); |
1406 if (contourCnt <= 0) { | 1406 if (contourCnt <= 0) { |
1407 return 0; | 1407 return 0; |
1408 } | 1408 } |
1409 SkChunkAlloc alloc(sizeEstimate); | 1409 SkChunkAlloc alloc(sizeEstimate); |
1410 bool isLinear; | 1410 bool isLinear; |
1411 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
&isLinear); | 1411 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
&isLinear); |
(...skipping 21 matching lines...) Expand all Loading... |
1433 } | 1433 } |
1434 } | 1434 } |
1435 int actualCount = static_cast<int>(vertsEnd - *verts); | 1435 int actualCount = static_cast<int>(vertsEnd - *verts); |
1436 SkASSERT(actualCount <= count); | 1436 SkASSERT(actualCount <= count); |
1437 SkASSERT(pointsEnd - points == actualCount); | 1437 SkASSERT(pointsEnd - points == actualCount); |
1438 delete[] points; | 1438 delete[] points; |
1439 return actualCount; | 1439 return actualCount; |
1440 } | 1440 } |
1441 | 1441 |
1442 } // namespace | 1442 } // namespace |
OLD | NEW |