| 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 "GrBatchFlushState.h" | |
| 11 #include "GrBatchTest.h" | |
| 12 #include "GrDefaultGeoProcFactory.h" | |
| 13 #include "GrPathUtils.h" | 10 #include "GrPathUtils.h" |
| 14 #include "GrVertices.h" | 11 |
| 15 #include "GrResourceCache.h" | 12 #include "SkChunkAlloc.h" |
| 16 #include "GrResourceProvider.h" | |
| 17 #include "SkGeometry.h" | 13 #include "SkGeometry.h" |
| 18 #include "SkChunkAlloc.h" | 14 #include "SkPath.h" |
| 19 | |
| 20 #include "batches/GrVertexBatch.h" | |
| 21 | 15 |
| 22 #include <stdio.h> | 16 #include <stdio.h> |
| 23 | 17 |
| 24 /* | 18 /* |
| 25 * There are six stages to the algorithm: | 19 * There are six stages to the algorithm: |
| 26 * | 20 * |
| 27 * 1) Linearize the path contours into piecewise linear segments (path_to_contou
rs()). | 21 * 1) Linearize the path contours into piecewise linear segments (path_to_contou
rs()). |
| 28 * 2) Build a mesh of edges connecting the vertices (build_edges()). | 22 * 2) Build a mesh of edges connecting the vertices (build_edges()). |
| 29 * 3) Sort the vertices in Y (and secondarily in X) (merge_sort()). | 23 * 3) Sort the vertices in Y (and secondarily in X) (merge_sort()). |
| 30 * 4) Simplify the mesh by inserting new vertices at intersecting edges (simplif
y()). | 24 * 4) Simplify the mesh by inserting new vertices at intersecting edges (simplif
y()). |
| (...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 return count; | 1357 return count; |
| 1364 } | 1358 } |
| 1365 | 1359 |
| 1366 } // namespace | 1360 } // namespace |
| 1367 | 1361 |
| 1368 namespace GrTessellator { | 1362 namespace GrTessellator { |
| 1369 | 1363 |
| 1370 // Stage 6: Triangulate the monotone polygons into a vertex buffer. | 1364 // Stage 6: Triangulate the monotone polygons into a vertex buffer. |
| 1371 | 1365 |
| 1372 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, | 1366 int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBo
unds, |
| 1373 GrResourceProvider* resourceProvider, | 1367 VertexAllocator* vertexAllocator, bool* isLinear) { |
| 1374 SkAutoTUnref<GrVertexBuffer>& vertexBuffer, bool canMapVB, b
ool* isLinear) { | |
| 1375 int contourCnt; | 1368 int contourCnt; |
| 1376 int sizeEstimate; | 1369 int sizeEstimate; |
| 1377 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); | 1370 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); |
| 1378 if (contourCnt <= 0) { | 1371 if (contourCnt <= 0) { |
| 1379 *isLinear = true; | 1372 *isLinear = true; |
| 1380 return 0; | 1373 return 0; |
| 1381 } | 1374 } |
| 1382 SkChunkAlloc alloc(sizeEstimate); | 1375 SkChunkAlloc alloc(sizeEstimate); |
| 1383 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
isLinear); | 1376 Poly* polys = path_to_polys(path, tolerance, clipBounds, contourCnt, alloc,
isLinear); |
| 1384 SkPath::FillType fillType = path.getFillType(); | 1377 SkPath::FillType fillType = path.getFillType(); |
| 1385 int count = count_points(polys, fillType); | 1378 int count = count_points(polys, fillType); |
| 1386 if (0 == count) { | 1379 if (0 == count) { |
| 1387 return 0; | 1380 return 0; |
| 1388 } | 1381 } |
| 1389 | 1382 |
| 1390 size_t size = count * sizeof(SkPoint); | 1383 SkPoint* verts = vertexAllocator->lock(count); |
| 1391 if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) { | 1384 if (!verts) { |
| 1392 vertexBuffer.reset(resourceProvider->createVertexBuffer( | |
| 1393 size, GrResourceProvider::kStatic_BufferUsage, 0)); | |
| 1394 } | |
| 1395 if (!vertexBuffer.get()) { | |
| 1396 SkDebugf("Could not allocate vertices\n"); | 1385 SkDebugf("Could not allocate vertices\n"); |
| 1397 return 0; | 1386 return 0; |
| 1398 } | 1387 } |
| 1399 SkPoint* verts; | |
| 1400 if (canMapVB) { | |
| 1401 verts = static_cast<SkPoint*>(vertexBuffer->map()); | |
| 1402 } else { | |
| 1403 verts = new SkPoint[count]; | |
| 1404 } | |
| 1405 SkPoint* end = verts; | 1388 SkPoint* end = verts; |
| 1406 for (Poly* poly = polys; poly; poly = poly->fNext) { | 1389 for (Poly* poly = polys; poly; poly = poly->fNext) { |
| 1407 if (apply_fill_type(fillType, poly->fWinding)) { | 1390 if (apply_fill_type(fillType, poly->fWinding)) { |
| 1408 end = poly->emit(end); | 1391 end = poly->emit(end); |
| 1409 } | 1392 } |
| 1410 } | 1393 } |
| 1411 int actualCount = static_cast<int>(end - verts); | 1394 int actualCount = static_cast<int>(end - verts); |
| 1412 LOG("actual count: %d\n", actualCount); | 1395 LOG("actual count: %d\n", actualCount); |
| 1413 SkASSERT(actualCount <= count); | 1396 SkASSERT(actualCount <= count); |
| 1414 if (canMapVB) { | 1397 vertexAllocator->unlock(actualCount); |
| 1415 vertexBuffer->unmap(); | |
| 1416 } else { | |
| 1417 vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); | |
| 1418 delete[] verts; | |
| 1419 } | |
| 1420 | |
| 1421 return actualCount; | 1398 return actualCount; |
| 1422 } | 1399 } |
| 1423 | 1400 |
| 1424 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBou
nds, | 1401 int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBou
nds, |
| 1425 GrTessellator::WindingVertex** verts) { | 1402 GrTessellator::WindingVertex** verts) { |
| 1426 int contourCnt; | 1403 int contourCnt; |
| 1427 int sizeEstimate; | 1404 int sizeEstimate; |
| 1428 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); | 1405 get_contour_count_and_size_estimate(path, tolerance, &contourCnt, &sizeEstim
ate); |
| 1429 if (contourCnt <= 0) { | 1406 if (contourCnt <= 0) { |
| 1430 return 0; | 1407 return 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1456 } | 1433 } |
| 1457 } | 1434 } |
| 1458 int actualCount = static_cast<int>(vertsEnd - *verts); | 1435 int actualCount = static_cast<int>(vertsEnd - *verts); |
| 1459 SkASSERT(actualCount <= count); | 1436 SkASSERT(actualCount <= count); |
| 1460 SkASSERT(pointsEnd - points == actualCount); | 1437 SkASSERT(pointsEnd - points == actualCount); |
| 1461 delete[] points; | 1438 delete[] points; |
| 1462 return actualCount; | 1439 return actualCount; |
| 1463 } | 1440 } |
| 1464 | 1441 |
| 1465 } // namespace | 1442 } // namespace |
| OLD | NEW |