Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(417)

Side by Side Diff: src/gpu/GrTessellatingPathRenderer.cpp

Issue 1322023002: Minor cleanup in GrTessellatingPathRenderer. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 for (Poly* poly = polys; poly; poly = poly->fNext) { 1330 for (Poly* poly = polys; poly; poly = poly->fNext) {
1331 if (apply_fill_type(fillType, poly->fWinding)) { 1331 if (apply_fill_type(fillType, poly->fWinding)) {
1332 d = poly->emit(d); 1332 d = poly->emit(d);
1333 } 1333 }
1334 } 1334 }
1335 return d; 1335 return d;
1336 } 1336 }
1337 1337
1338 struct TessInfo { 1338 struct TessInfo {
1339 SkScalar fTolerance; 1339 SkScalar fTolerance;
1340 int fCount; 1340 int fVertexCount;
1341 }; 1341 };
1342 1342
1343 bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* actualCount) { 1343 bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* vertexCount) {
1344 if (!vertexBuffer) { 1344 if (!vertexBuffer) {
1345 return false; 1345 return false;
1346 } 1346 }
1347 const SkData* data = vertexBuffer->getUniqueKey().getCustomData(); 1347 const SkData* data = vertexBuffer->getUniqueKey().getCustomData();
1348 SkASSERT(data); 1348 SkASSERT(data);
1349 const TessInfo* info = static_cast<const TessInfo*>(data->data()); 1349 const TessInfo* info = static_cast<const TessInfo*>(data->data());
1350 if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) { 1350 if (info->fTolerance == 0 || info->fTolerance < 3.0f * tol) {
1351 *actualCount = info->fCount; 1351 *vertexCount = info->fVertexCount;
1352 return true; 1352 return true;
1353 } 1353 }
1354 return false; 1354 return false;
1355 } 1355 }
1356 1356
1357 }; 1357 };
1358 1358
1359 GrTessellatingPathRenderer::GrTessellatingPathRenderer() { 1359 GrTessellatingPathRenderer::GrTessellatingPathRenderer() {
1360 } 1360 }
1361 1361
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 1464
1465 // 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:
1466 // 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
1467 // 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
1468 // connectivity of one Edge per Vertex (will grow for intersections). 1468 // connectivity of one Edge per Vertex (will grow for intersections).
1469 SkChunkAlloc alloc(maxPts * (3 * sizeof(Vertex) + sizeof(Edge))); 1469 SkChunkAlloc alloc(maxPts * (3 * sizeof(Vertex) + sizeof(Edge)));
1470 bool isLinear; 1470 bool isLinear;
1471 path_to_contours(path, tol, fClipBounds, contours.get(), alloc, &isLinea r); 1471 path_to_contours(path, tol, fClipBounds, contours.get(), alloc, &isLinea r);
1472 Poly* polys; 1472 Poly* polys;
1473 polys = contours_to_polys(contours.get(), contourCnt, c, alloc); 1473 polys = contours_to_polys(contours.get(), contourCnt, c, alloc);
1474 int count = 0; 1474 int vertexCount = 0;
1475 for (Poly* poly = polys; poly; poly = poly->fNext) { 1475 for (Poly* poly = polys; poly; poly = poly->fNext) {
1476 if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) { 1476 if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) {
1477 count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3); 1477 vertexCount += (poly->fCount - 2) * (WIREFRAME ? 6 : 3);
1478 } 1478 }
1479 } 1479 }
1480 if (0 == count) { 1480 if (0 == vertexCount) {
1481 return 0; 1481 return 0;
1482 } 1482 }
1483 1483
1484 size_t size = count * sizeof(SkPoint); 1484 size_t size = vertexCount * sizeof(SkPoint);
1485 if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) { 1485 if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) {
1486 vertexBuffer.reset(resourceProvider->createVertexBuffer( 1486 vertexBuffer.reset(resourceProvider->createVertexBuffer(
1487 size, GrResourceProvider::kStatic_BufferUsage, 0)); 1487 size, GrResourceProvider::kStatic_BufferUsage, 0));
1488 } 1488 }
1489 if (!vertexBuffer.get()) { 1489 if (!vertexBuffer.get()) {
1490 SkDebugf("Could not allocate vertices\n"); 1490 SkDebugf("Could not allocate vertices\n");
1491 return 0; 1491 return 0;
1492 } 1492 }
1493 SkPoint* verts; 1493 SkPoint* verts;
1494 if (canMapVB) { 1494 if (canMapVB) {
1495 verts = static_cast<SkPoint*>(vertexBuffer->map()); 1495 verts = static_cast<SkPoint*>(vertexBuffer->map());
1496 } else { 1496 } else {
1497 verts = new SkPoint[count]; 1497 verts = new SkPoint[vertexCount];
1498 } 1498 }
1499 SkPoint* end = polys_to_triangles(polys, fillType, verts); 1499 SkDEBUGCODE(SkPoint* end = ) polys_to_triangles(polys, fillType, verts);
1500 int actualCount = static_cast<int>(end - verts); 1500 SkASSERT(static_cast<int>(end - verts) == vertexCount);
1501 LOG("actual count: %d\n", actualCount); 1501 LOG("vertex count: %d\n", vertexCount);
1502 SkASSERT(actualCount <= count);
1503 if (canMapVB) { 1502 if (canMapVB) {
1504 vertexBuffer->unmap(); 1503 vertexBuffer->unmap();
1505 } else { 1504 } else {
1506 vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); 1505 vertexBuffer->updateData(verts, vertexCount * sizeof(SkPoint));
1507 delete[] verts; 1506 delete[] verts;
1508 } 1507 }
1509 1508
1510 1509
1511 if (!fPath.isVolatile()) { 1510 if (!fPath.isVolatile()) {
1512 TessInfo info; 1511 TessInfo info;
1513 info.fTolerance = isLinear ? 0 : tol; 1512 info.fTolerance = isLinear ? 0 : tol;
1514 info.fCount = actualCount; 1513 info.fVertexCount = vertexCount;
1515 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); 1514 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info)));
1516 key->setCustomData(data.get()); 1515 key->setCustomData(data.get());
1517 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get() ); 1516 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get() );
1518 SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key)) ; 1517 SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key)) ;
1519 } 1518 }
1520 return actualCount; 1519 return vertexCount;
1521 } 1520 }
1522 1521
1523 void onPrepareDraws(Target* target) override { 1522 void onPrepareDraws(Target* target) override {
1524 // construct a cache key from the path's genID and the view matrix 1523 // construct a cache key from the path's genID and the view matrix
1525 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain() ; 1524 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain() ;
1526 GrUniqueKey key; 1525 GrUniqueKey key;
1527 int clipBoundsSize32 = 1526 int clipBoundsSize32 =
1528 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) : 0; 1527 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) : 0;
1529 int strokeDataSize32 = fStroke.computeUniqueKeyFragmentData32Cnt(); 1528 int strokeDataSize32 = fStroke.computeUniqueKeyFragmentData32Cnt();
1530 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok eDataSize32); 1529 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok eDataSize32);
1531 builder[0] = fPath.getGenerationID(); 1530 builder[0] = fPath.getGenerationID();
1532 builder[1] = fPath.getFillType(); 1531 builder[1] = fPath.getFillType();
1533 // For inverse fills, the tessellation is dependent on clip bounds. 1532 // For inverse fills, the tessellation is dependent on clip bounds.
1534 if (fPath.isInverseFillType()) { 1533 if (fPath.isInverseFillType()) {
1535 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); 1534 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds));
1536 } 1535 }
1537 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); 1536 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]);
1538 builder.finish(); 1537 builder.finish();
1539 GrResourceProvider* rp = target->resourceProvider(); 1538 GrResourceProvider* rp = target->resourceProvider();
1540 SkAutoTUnref<GrVertexBuffer> vertexBuffer(rp->findAndRefTByUniqueKey<GrV ertexBuffer>(key)); 1539 SkAutoTUnref<GrVertexBuffer> vertexBuffer(rp->findAndRefTByUniqueKey<GrV ertexBuffer>(key));
1541 int actualCount; 1540 int vertexCount;
1542 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; 1541 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance;
1543 SkScalar tol = GrPathUtils::scaleToleranceToSrc( 1542 SkScalar tol = GrPathUtils::scaleToleranceToSrc(
1544 screenSpaceTol, fViewMatrix, fPath.getBounds()); 1543 screenSpaceTol, fViewMatrix, fPath.getBounds());
1545 if (!cache_match(vertexBuffer.get(), tol, &actualCount)) { 1544 if (!cache_match(vertexBuffer.get(), tol, &vertexCount)) {
1546 bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFl ags(); 1545 bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFl ags();
1547 actualCount = tessellate(&key, rp, vertexBuffer, canMapVB); 1546 vertexCount = tessellate(&key, rp, vertexBuffer, canMapVB);
1548 } 1547 }
1549 1548
1550 if (actualCount == 0) { 1549 if (vertexCount == 0) {
1551 return; 1550 return;
1552 } 1551 }
1553 1552
1554 SkAutoTUnref<const GrGeometryProcessor> gp; 1553 SkAutoTUnref<const GrGeometryProcessor> gp;
1555 { 1554 {
1556 using namespace GrDefaultGeoProcFactory; 1555 using namespace GrDefaultGeoProcFactory;
1557 1556
1558 Color color(fColor); 1557 Color color(fColor);
1559 LocalCoords localCoords(fPipelineInfo.readsLocalCoords() ? 1558 LocalCoords localCoords(fPipelineInfo.readsLocalCoords() ?
1560 LocalCoords::kUsePosition_Type : 1559 LocalCoords::kUsePosition_Type :
1561 LocalCoords::kUnused_Type); 1560 LocalCoords::kUnused_Type);
1562 Coverage::Type coverageType; 1561 Coverage::Type coverageType;
1563 if (fPipelineInfo.readsCoverage()) { 1562 if (fPipelineInfo.readsCoverage()) {
1564 coverageType = Coverage::kSolid_Type; 1563 coverageType = Coverage::kSolid_Type;
1565 } else { 1564 } else {
1566 coverageType = Coverage::kNone_Type; 1565 coverageType = Coverage::kNone_Type;
1567 } 1566 }
1568 Coverage coverage(coverageType); 1567 Coverage coverage(coverageType);
1569 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s, 1568 gp.reset(GrDefaultGeoProcFactory::Create(color, coverage, localCoord s,
1570 fViewMatrix)); 1569 fViewMatrix));
1571 } 1570 }
1572 1571
1573 target->initDraw(gp, this->pipeline()); 1572 target->initDraw(gp, this->pipeline());
1574 SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); 1573 SkASSERT(gp->getVertexStride() == sizeof(SkPoint));
1575 1574
1576 GrPrimitiveType primitiveType = WIREFRAME ? kLines_GrPrimitiveType 1575 GrPrimitiveType primitiveType = WIREFRAME ? kLines_GrPrimitiveType
1577 : kTriangles_GrPrimitiveType; 1576 : kTriangles_GrPrimitiveType;
1578 GrVertices vertices; 1577 GrVertices vertices;
1579 vertices.init(primitiveType, vertexBuffer.get(), 0, actualCount); 1578 vertices.init(primitiveType, vertexBuffer.get(), 0, vertexCount);
1580 target->draw(vertices); 1579 target->draw(vertices);
1581 } 1580 }
1582 1581
1583 bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; } 1582 bool onCombineIfPossible(GrBatch*, const GrCaps&) override { return false; }
1584 1583
1585 TessellatingPathBatch(const GrColor& color, 1584 TessellatingPathBatch(const GrColor& color,
1586 const SkPath& path, 1585 const SkPath& path,
1587 const GrStrokeInfo& stroke, 1586 const GrStrokeInfo& stroke,
1588 const SkMatrix& viewMatrix, 1587 const SkMatrix& viewMatrix,
1589 const SkRect& clipBounds) 1588 const SkRect& clipBounds)
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 bool result = viewMatrix.invert(&vmi); 1651 bool result = viewMatrix.invert(&vmi);
1653 if (!result) { 1652 if (!result) {
1654 SkFAIL("Cannot invert matrix\n"); 1653 SkFAIL("Cannot invert matrix\n");
1655 } 1654 }
1656 vmi.mapRect(&clipBounds); 1655 vmi.mapRect(&clipBounds);
1657 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); 1656 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random);
1658 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl ipBounds); 1657 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl ipBounds);
1659 } 1658 }
1660 1659
1661 #endif 1660 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698