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 "GrTessellatingPathRenderer.h" | 8 #include "GrTessellatingPathRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 */ | 82 */ |
83 #define LOGGING_ENABLED 0 | 83 #define LOGGING_ENABLED 0 |
84 #define WIREFRAME 0 | 84 #define WIREFRAME 0 |
85 | 85 |
86 #if LOGGING_ENABLED | 86 #if LOGGING_ENABLED |
87 #define LOG printf | 87 #define LOG printf |
88 #else | 88 #else |
89 #define LOG(...) | 89 #define LOG(...) |
90 #endif | 90 #endif |
91 | 91 |
92 #define ALLOC_NEW(Type, args, alloc) \ | 92 #define ALLOC_NEW(Type, args, alloc) new (alloc.allocThrow(sizeof(Type))) Type a
rgs |
93 SkNEW_PLACEMENT_ARGS(alloc.allocThrow(sizeof(Type)), Type, args) | |
94 | 93 |
95 namespace { | 94 namespace { |
96 | 95 |
97 struct Vertex; | 96 struct Vertex; |
98 struct Edge; | 97 struct Edge; |
99 struct Poly; | 98 struct Poly; |
100 | 99 |
101 template <class T, T* T::*Prev, T* T::*Next> | 100 template <class T, T* T::*Prev, T* T::*Next> |
102 void insert(T* t, T* prev, T* next, T** head, T** tail) { | 101 void insert(T* t, T* prev, T* next, T** head, T** tail) { |
103 t->*Prev = prev; | 102 t->*Prev = prev; |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1385 } | 1384 } |
1386 | 1385 |
1387 class TessellatingPathBatch : public GrVertexBatch { | 1386 class TessellatingPathBatch : public GrVertexBatch { |
1388 public: | 1387 public: |
1389 | 1388 |
1390 static GrDrawBatch* Create(const GrColor& color, | 1389 static GrDrawBatch* Create(const GrColor& color, |
1391 const SkPath& path, | 1390 const SkPath& path, |
1392 const GrStrokeInfo& stroke, | 1391 const GrStrokeInfo& stroke, |
1393 const SkMatrix& viewMatrix, | 1392 const SkMatrix& viewMatrix, |
1394 SkRect clipBounds) { | 1393 SkRect clipBounds) { |
1395 return SkNEW_ARGS(TessellatingPathBatch, (color, path, stroke, viewMatri
x, clipBounds)); | 1394 return new TessellatingPathBatch(color, path, stroke, viewMatrix, clipBo
unds); |
1396 } | 1395 } |
1397 | 1396 |
1398 const char* name() const override { return "TessellatingPathBatch"; } | 1397 const char* name() const override { return "TessellatingPathBatch"; } |
1399 | 1398 |
1400 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 1399 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
1401 out->setKnownFourComponents(fColor); | 1400 out->setKnownFourComponents(fColor); |
1402 } | 1401 } |
1403 | 1402 |
1404 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 1403 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
1405 out->setUnknownSingleComponent(); | 1404 out->setUnknownSingleComponent(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 if (maxPts > ((int)SK_MaxU16 + 1)) { | 1453 if (maxPts > ((int)SK_MaxU16 + 1)) { |
1455 SkDebugf("Path not rendered, too many verts (%d)\n", maxPts); | 1454 SkDebugf("Path not rendered, too many verts (%d)\n", maxPts); |
1456 return 0; | 1455 return 0; |
1457 } | 1456 } |
1458 SkPath::FillType fillType = path.getFillType(); | 1457 SkPath::FillType fillType = path.getFillType(); |
1459 if (SkPath::IsInverseFillType(fillType)) { | 1458 if (SkPath::IsInverseFillType(fillType)) { |
1460 contourCnt++; | 1459 contourCnt++; |
1461 } | 1460 } |
1462 | 1461 |
1463 LOG("got %d pts, %d contours\n", maxPts, contourCnt); | 1462 LOG("got %d pts, %d contours\n", maxPts, contourCnt); |
1464 SkAutoTDeleteArray<Vertex*> contours(SkNEW_ARRAY(Vertex *, contourCnt)); | 1463 SkAutoTDeleteArray<Vertex*> contours(new Vertex* [contourCnt]); |
1465 | 1464 |
1466 // For the initial size of the chunk allocator, estimate based on the po
int count: | 1465 // For the initial size of the chunk allocator, estimate based on the po
int count: |
1467 // one vertex per point for the initial passes, plus two for the vertice
s in the | 1466 // one vertex per point for the initial passes, plus two for the vertice
s in the |
1468 // resulting Polys, since the same point may end up in two Polys. Assum
e minimal | 1467 // resulting Polys, since the same point may end up in two Polys. Assum
e minimal |
1469 // connectivity of one Edge per Vertex (will grow for intersections). | 1468 // connectivity of one Edge per Vertex (will grow for intersections). |
1470 SkChunkAlloc alloc(maxPts * (3 * sizeof(Vertex) + sizeof(Edge))); | 1469 SkChunkAlloc alloc(maxPts * (3 * sizeof(Vertex) + sizeof(Edge))); |
1471 bool isLinear; | 1470 bool isLinear; |
1472 path_to_contours(path, tol, fClipBounds, contours.get(), alloc, &isLinea
r); | 1471 path_to_contours(path, tol, fClipBounds, contours.get(), alloc, &isLinea
r); |
1473 Poly* polys; | 1472 Poly* polys; |
1474 polys = contours_to_polys(contours.get(), contourCnt, c, alloc); | 1473 polys = contours_to_polys(contours.get(), contourCnt, c, alloc); |
(...skipping 13 matching lines...) Expand all Loading... |
1488 size, GrResourceProvider::kStatic_BufferUsage, 0)); | 1487 size, GrResourceProvider::kStatic_BufferUsage, 0)); |
1489 } | 1488 } |
1490 if (!vertexBuffer.get()) { | 1489 if (!vertexBuffer.get()) { |
1491 SkDebugf("Could not allocate vertices\n"); | 1490 SkDebugf("Could not allocate vertices\n"); |
1492 return 0; | 1491 return 0; |
1493 } | 1492 } |
1494 SkPoint* verts; | 1493 SkPoint* verts; |
1495 if (canMapVB) { | 1494 if (canMapVB) { |
1496 verts = static_cast<SkPoint*>(vertexBuffer->map()); | 1495 verts = static_cast<SkPoint*>(vertexBuffer->map()); |
1497 } else { | 1496 } else { |
1498 verts = SkNEW_ARRAY(SkPoint, count); | 1497 verts = new SkPoint[count]; |
1499 } | 1498 } |
1500 SkPoint* end = polys_to_triangles(polys, fillType, verts); | 1499 SkPoint* end = polys_to_triangles(polys, fillType, verts); |
1501 int actualCount = static_cast<int>(end - verts); | 1500 int actualCount = static_cast<int>(end - verts); |
1502 LOG("actual count: %d\n", actualCount); | 1501 LOG("actual count: %d\n", actualCount); |
1503 SkASSERT(actualCount <= count); | 1502 SkASSERT(actualCount <= count); |
1504 if (canMapVB) { | 1503 if (canMapVB) { |
1505 vertexBuffer->unmap(); | 1504 vertexBuffer->unmap(); |
1506 } else { | 1505 } else { |
1507 vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); | 1506 vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); |
1508 SkDELETE_ARRAY(verts); | 1507 delete[] verts; |
1509 } | 1508 } |
1510 | 1509 |
1511 | 1510 |
1512 if (!fPath.isVolatile()) { | 1511 if (!fPath.isVolatile()) { |
1513 TessInfo info; | 1512 TessInfo info; |
1514 info.fTolerance = isLinear ? 0 : tol; | 1513 info.fTolerance = isLinear ? 0 : tol; |
1515 info.fCount = actualCount; | 1514 info.fCount = actualCount; |
1516 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); | 1515 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); |
1517 key->setCustomData(data.get()); | 1516 key->setCustomData(data.get()); |
1518 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get()
); | 1517 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get()
); |
1519 SkPathPriv::AddGenIDChangeListener(fPath, SkNEW(PathInvalidator(*key
))); | 1518 SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key))
; |
1520 } | 1519 } |
1521 return actualCount; | 1520 return actualCount; |
1522 } | 1521 } |
1523 | 1522 |
1524 void onPrepareDraws(Target* target) override { | 1523 void onPrepareDraws(Target* target) override { |
1525 // construct a cache key from the path's genID and the view matrix | 1524 // construct a cache key from the path's genID and the view matrix |
1526 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; | 1525 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; |
1527 GrUniqueKey key; | 1526 GrUniqueKey key; |
1528 int clipBoundsSize32 = | 1527 int clipBoundsSize32 = |
1529 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; | 1528 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1653 bool result = viewMatrix.invert(&vmi); | 1652 bool result = viewMatrix.invert(&vmi); |
1654 if (!result) { | 1653 if (!result) { |
1655 SkFAIL("Cannot invert matrix\n"); | 1654 SkFAIL("Cannot invert matrix\n"); |
1656 } | 1655 } |
1657 vmi.mapRect(&clipBounds); | 1656 vmi.mapRect(&clipBounds); |
1658 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); | 1657 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); |
1659 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); | 1658 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); |
1660 } | 1659 } |
1661 | 1660 |
1662 #endif | 1661 #endif |
OLD | NEW |