| 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 1400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 if (!overrides.readsColor()) { | 1411 if (!overrides.readsColor()) { |
| 1412 fColor = GrColor_ILLEGAL; | 1412 fColor = GrColor_ILLEGAL; |
| 1413 } | 1413 } |
| 1414 overrides.getOverrideColorIfSet(&fColor); | 1414 overrides.getOverrideColorIfSet(&fColor); |
| 1415 fPipelineInfo = overrides; | 1415 fPipelineInfo = overrides; |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 int tessellate(GrUniqueKey* key, | 1418 int tessellate(GrUniqueKey* key, |
| 1419 GrResourceProvider* resourceProvider, | 1419 GrResourceProvider* resourceProvider, |
| 1420 SkAutoTUnref<GrVertexBuffer>& vertexBuffer, | 1420 SkAutoTUnref<GrVertexBuffer>& vertexBuffer, |
| 1421 bool canMapVB) { | 1421 bool canMapVB) const { |
| 1422 SkPath path; | 1422 SkPath path; |
| 1423 GrStrokeInfo stroke(fStroke); | 1423 GrStrokeInfo stroke(fStroke); |
| 1424 if (stroke.isDashed()) { | 1424 if (stroke.isDashed()) { |
| 1425 if (!stroke.applyDashToPath(&path, &stroke, fPath)) { | 1425 if (!stroke.applyDashToPath(&path, &stroke, fPath)) { |
| 1426 return 0; | 1426 return 0; |
| 1427 } | 1427 } |
| 1428 } else { | 1428 } else { |
| 1429 path = fPath; | 1429 path = fPath; |
| 1430 } | 1430 } |
| 1431 if (!stroke.isFillStyle()) { | 1431 if (!stroke.isFillStyle()) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1514 info.fTolerance = isLinear ? 0 : tol; | 1514 info.fTolerance = isLinear ? 0 : tol; |
| 1515 info.fCount = actualCount; | 1515 info.fCount = actualCount; |
| 1516 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); | 1516 SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); |
| 1517 key->setCustomData(data.get()); | 1517 key->setCustomData(data.get()); |
| 1518 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get()
); | 1518 resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get()
); |
| 1519 SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key))
; | 1519 SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key))
; |
| 1520 } | 1520 } |
| 1521 return actualCount; | 1521 return actualCount; |
| 1522 } | 1522 } |
| 1523 | 1523 |
| 1524 void onPrepareDraws(Target* target) override { | 1524 void onPrepareDraws(Target* target) const override { |
| 1525 // construct a cache key from the path's genID and the view matrix | 1525 // construct a cache key from the path's genID and the view matrix |
| 1526 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; | 1526 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain()
; |
| 1527 GrUniqueKey key; | 1527 GrUniqueKey key; |
| 1528 int clipBoundsSize32 = | 1528 int clipBoundsSize32 = |
| 1529 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; | 1529 fPath.isInverseFillType() ? sizeof(fClipBounds) / sizeof(uint32_t) :
0; |
| 1530 int strokeDataSize32 = fStroke.computeUniqueKeyFragmentData32Cnt(); | 1530 int strokeDataSize32 = fStroke.computeUniqueKeyFragmentData32Cnt(); |
| 1531 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok
eDataSize32); | 1531 GrUniqueKey::Builder builder(&key, kDomain, 2 + clipBoundsSize32 + strok
eDataSize32); |
| 1532 builder[0] = fPath.getGenerationID(); | 1532 builder[0] = fPath.getGenerationID(); |
| 1533 builder[1] = fPath.getFillType(); | 1533 builder[1] = fPath.getFillType(); |
| 1534 // For inverse fills, the tessellation is dependent on clip bounds. | 1534 // For inverse fills, the tessellation is dependent on clip bounds. |
| 1535 if (fPath.isInverseFillType()) { | 1535 if (fPath.isInverseFillType()) { |
| 1536 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); | 1536 memcpy(&builder[2], &fClipBounds, sizeof(fClipBounds)); |
| 1537 } | 1537 } |
| 1538 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); | 1538 fStroke.asUniqueKeyFragment(&builder[2 + clipBoundsSize32]); |
| 1539 builder.finish(); | 1539 builder.finish(); |
| 1540 GrResourceProvider* rp = target->resourceProvider(); | 1540 GrResourceProvider* rp = target->resourceProvider(); |
| 1541 SkAutoTUnref<GrVertexBuffer> vertexBuffer(rp->findAndRefTByUniqueKey<GrV
ertexBuffer>(key)); | 1541 SkAutoTUnref<GrVertexBuffer> vertexBuffer(rp->findAndRefTByUniqueKey<GrV
ertexBuffer>(key)); |
| 1542 int actualCount; | 1542 int actualCount; |
| 1543 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; | 1543 SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
| 1544 SkScalar tol = GrPathUtils::scaleToleranceToSrc( | 1544 SkScalar tol = GrPathUtils::scaleToleranceToSrc( |
| 1545 screenSpaceTol, fViewMatrix, fPath.getBounds()); | 1545 screenSpaceTol, fViewMatrix, fPath.getBounds()); |
| 1546 if (!cache_match(vertexBuffer.get(), tol, &actualCount)) { | 1546 if (!cache_match(vertexBuffer.get(), tol, &actualCount)) { |
| 1547 bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFl
ags(); | 1547 bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFl
ags(); |
| 1548 actualCount = tessellate(&key, rp, vertexBuffer, canMapVB); | 1548 actualCount = this->tessellate(&key, rp, vertexBuffer, canMapVB); |
| 1549 } | 1549 } |
| 1550 | 1550 |
| 1551 if (actualCount == 0) { | 1551 if (actualCount == 0) { |
| 1552 return; | 1552 return; |
| 1553 } | 1553 } |
| 1554 | 1554 |
| 1555 SkAutoTUnref<const GrGeometryProcessor> gp; | 1555 SkAutoTUnref<const GrGeometryProcessor> gp; |
| 1556 { | 1556 { |
| 1557 using namespace GrDefaultGeoProcFactory; | 1557 using namespace GrDefaultGeoProcFactory; |
| 1558 | 1558 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 bool result = viewMatrix.invert(&vmi); | 1662 bool result = viewMatrix.invert(&vmi); |
| 1663 if (!result) { | 1663 if (!result) { |
| 1664 SkFAIL("Cannot invert matrix\n"); | 1664 SkFAIL("Cannot invert matrix\n"); |
| 1665 } | 1665 } |
| 1666 vmi.mapRect(&clipBounds); | 1666 vmi.mapRect(&clipBounds); |
| 1667 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); | 1667 GrStrokeInfo strokeInfo = GrTest::TestStrokeInfo(random); |
| 1668 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); | 1668 return TessellatingPathBatch::Create(color, path, strokeInfo, viewMatrix, cl
ipBounds); |
| 1669 } | 1669 } |
| 1670 | 1670 |
| 1671 #endif | 1671 #endif |
| OLD | NEW |