OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrAAHairLinePathRenderer.h" | 8 #include "GrAAHairLinePathRenderer.h" |
9 | 9 |
10 #include "GrBatch.h" | 10 #include "GrBatch.h" |
11 #include "GrBatchTarget.h" | 11 #include "GrBatchTarget.h" |
12 #include "GrBufferAllocPool.h" | 12 #include "GrBufferAllocPool.h" |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrDefaultGeoProcFactory.h" | 14 #include "GrDefaultGeoProcFactory.h" |
15 #include "GrDrawTargetCaps.h" | 15 #include "GrDrawTargetCaps.h" |
16 #include "GrGpu.h" | 16 #include "GrGpu.h" |
17 #include "GrIndexBuffer.h" | 17 #include "GrIndexBuffer.h" |
18 #include "GrPathUtils.h" | 18 #include "GrPathUtils.h" |
19 #include "GrPipelineBuilder.h" | 19 #include "GrPipelineBuilder.h" |
20 #include "GrProcessor.h" | 20 #include "GrProcessor.h" |
| 21 #include "GrStrokeInfo.h" |
21 #include "SkGeometry.h" | 22 #include "SkGeometry.h" |
22 #include "SkStroke.h" | 23 #include "SkStroke.h" |
23 #include "SkTemplates.h" | 24 #include "SkTemplates.h" |
24 | 25 |
25 #include "effects/GrBezierEffect.h" | 26 #include "effects/GrBezierEffect.h" |
26 | 27 |
27 // quadratics are rendered as 5-sided polys in order to bound the | 28 // quadratics are rendered as 5-sided polys in order to bound the |
28 // AA stroke around the center-curve. See comments in push_quad_index_buffer and | 29 // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
29 // bloat_quad. Quadratics and conics share an index buffer | 30 // bloat_quad. Quadratics and conics share an index buffer |
30 | 31 |
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 } | 631 } |
631 | 632 |
632 } | 633 } |
633 | 634 |
634 /////////////////////////////////////////////////////////////////////////////// | 635 /////////////////////////////////////////////////////////////////////////////// |
635 | 636 |
636 bool GrAAHairLinePathRenderer::canDrawPath(const GrDrawTarget* target, | 637 bool GrAAHairLinePathRenderer::canDrawPath(const GrDrawTarget* target, |
637 const GrPipelineBuilder* pipelineBuil
der, | 638 const GrPipelineBuilder* pipelineBuil
der, |
638 const SkMatrix& viewMatrix, | 639 const SkMatrix& viewMatrix, |
639 const SkPath& path, | 640 const SkPath& path, |
640 const SkStrokeRec& stroke, | 641 const GrStrokeInfo& stroke, |
641 bool antiAlias) const { | 642 bool antiAlias) const { |
642 if (!antiAlias) { | 643 if (!antiAlias) { |
643 return false; | 644 return false; |
644 } | 645 } |
645 | 646 |
646 if (!IsStrokeHairlineOrEquivalent(stroke, viewMatrix, NULL)) { | 647 if (!IsStrokeHairlineOrEquivalent(stroke.getStrokeRec(), viewMatrix, NULL))
{ |
647 return false; | 648 return false; |
648 } | 649 } |
649 | 650 |
650 if (SkPath::kLine_SegmentMask == path.getSegmentMasks() || | 651 if (SkPath::kLine_SegmentMask == path.getSegmentMasks() || |
651 target->caps()->shaderDerivativeSupport()) { | 652 target->caps()->shaderDerivativeSupport()) { |
652 return true; | 653 return true; |
653 } | 654 } |
654 return false; | 655 return false; |
655 } | 656 } |
656 | 657 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 } | 1023 } |
1023 } | 1024 } |
1024 } | 1025 } |
1025 } | 1026 } |
1026 | 1027 |
1027 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, | 1028 bool GrAAHairLinePathRenderer::onDrawPath(GrDrawTarget* target, |
1028 GrPipelineBuilder* pipelineBuilder, | 1029 GrPipelineBuilder* pipelineBuilder, |
1029 GrColor color, | 1030 GrColor color, |
1030 const SkMatrix& viewMatrix, | 1031 const SkMatrix& viewMatrix, |
1031 const SkPath& path, | 1032 const SkPath& path, |
1032 const SkStrokeRec& stroke, | 1033 const GrStrokeInfo& stroke, |
1033 bool) { | 1034 bool) { |
1034 if (!fLinesIndexBuffer || !fQuadsIndexBuffer) { | 1035 if (!fLinesIndexBuffer || !fQuadsIndexBuffer) { |
1035 SkDebugf("unable to allocate indices\n"); | 1036 SkDebugf("unable to allocate indices\n"); |
1036 return false; | 1037 return false; |
1037 } | 1038 } |
1038 | 1039 |
1039 SkScalar hairlineCoverage; | 1040 SkScalar hairlineCoverage; |
1040 uint8_t newCoverage = 0xff; | 1041 uint8_t newCoverage = 0xff; |
1041 if (IsStrokeHairlineOrEquivalent(stroke, viewMatrix, &hairlineCoverage)) { | 1042 if (IsStrokeHairlineOrEquivalent(stroke.getStrokeRec(), viewMatrix, &hairlin
eCoverage)) { |
1042 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); | 1043 newCoverage = SkScalarRoundToInt(hairlineCoverage * 0xff); |
1043 } | 1044 } |
1044 | 1045 |
1045 SkIRect devClipBounds; | 1046 SkIRect devClipBounds; |
1046 pipelineBuilder->clip().getConservativeBounds(pipelineBuilder->getRenderTarg
et(), | 1047 pipelineBuilder->clip().getConservativeBounds(pipelineBuilder->getRenderTarg
et(), |
1047 &devClipBounds); | 1048 &devClipBounds); |
1048 | 1049 |
1049 // This outset was determined experimentally by running skps and gms. It pr
obably could be a | 1050 // This outset was determined experimentally by running skps and gms. It pr
obably could be a |
1050 // bit tighter | 1051 // bit tighter |
1051 SkRect devRect = path.getBounds(); | 1052 SkRect devRect = path.getBounds(); |
1052 viewMatrix.mapRect(&devRect); | 1053 viewMatrix.mapRect(&devRect); |
1053 devRect.outset(2, 2); | 1054 devRect.outset(2, 2); |
1054 | 1055 |
1055 AAHairlineBatch::Geometry geometry; | 1056 AAHairlineBatch::Geometry geometry; |
1056 geometry.fColor = color; | 1057 geometry.fColor = color; |
1057 geometry.fCoverage = newCoverage; | 1058 geometry.fCoverage = newCoverage; |
1058 geometry.fViewMatrix = viewMatrix; | 1059 geometry.fViewMatrix = viewMatrix; |
1059 geometry.fPath = path; | 1060 geometry.fPath = path; |
1060 SkDEBUGCODE(geometry.fDevBounds = devRect;) | 1061 SkDEBUGCODE(geometry.fDevBounds = devRect;) |
1061 geometry.fDevClipBounds = devClipBounds; | 1062 geometry.fDevClipBounds = devClipBounds; |
1062 | 1063 |
1063 SkAutoTUnref<GrBatch> batch(AAHairlineBatch::Create(geometry, fLinesIndexBuf
fer, | 1064 SkAutoTUnref<GrBatch> batch(AAHairlineBatch::Create(geometry, fLinesIndexBuf
fer, |
1064 fQuadsIndexBuffer)); | 1065 fQuadsIndexBuffer)); |
1065 target->drawBatch(pipelineBuilder, batch, &devRect); | 1066 target->drawBatch(pipelineBuilder, batch, &devRect); |
1066 | 1067 |
1067 return true; | 1068 return true; |
1068 } | 1069 } |
OLD | NEW |