| 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 "GrContext.h" | 10 #include "GrContext.h" |
| 11 #include "GrDefaultGeoProcFactory.h" |
| 11 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
| 12 #include "GrDrawTargetCaps.h" | 13 #include "GrDrawTargetCaps.h" |
| 13 #include "GrProcessor.h" | |
| 14 #include "GrGpu.h" | 14 #include "GrGpu.h" |
| 15 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
| 16 #include "GrPathUtils.h" | 16 #include "GrPathUtils.h" |
| 17 #include "GrProcessor.h" |
| 17 #include "GrTBackendProcessorFactory.h" | 18 #include "GrTBackendProcessorFactory.h" |
| 18 #include "SkGeometry.h" | 19 #include "SkGeometry.h" |
| 19 #include "SkStroke.h" | 20 #include "SkStroke.h" |
| 20 #include "SkTemplates.h" | 21 #include "SkTemplates.h" |
| 21 | 22 |
| 22 #include "effects/GrBezierEffect.h" | 23 #include "effects/GrBezierEffect.h" |
| 23 | 24 |
| 24 // quadratics are rendered as 5-sided polys in order to bound the | 25 // quadratics are rendered as 5-sided polys in order to bound the |
| 25 // AA stroke around the center-curve. See comments in push_quad_index_buffer and | 26 // AA stroke around the center-curve. See comments in push_quad_index_buffer and |
| 26 // bloat_quad. Quadratics and conics share an index buffer | 27 // bloat_quad. Quadratics and conics share an index buffer |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 } | 636 } |
| 636 | 637 |
| 637 *vert += kLineSegNumVertices; | 638 *vert += kLineSegNumVertices; |
| 638 } | 639 } |
| 639 | 640 |
| 640 } | 641 } |
| 641 | 642 |
| 642 /////////////////////////////////////////////////////////////////////////////// | 643 /////////////////////////////////////////////////////////////////////////////// |
| 643 | 644 |
| 644 namespace { | 645 namespace { |
| 645 | |
| 646 // position + edge | 646 // position + edge |
| 647 extern const GrVertexAttrib gHairlineBezierAttribs[] = { | 647 extern const GrVertexAttrib gHairlineBezierAttribs[] = { |
| 648 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, | 648 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, |
| 649 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding} | 649 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding} |
| 650 }; | 650 }; |
| 651 | |
| 652 // position + coverage | |
| 653 extern const GrVertexAttrib gHairlineLineAttribs[] = { | |
| 654 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | |
| 655 {kFloat_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBinding
}, | |
| 656 }; | |
| 657 | |
| 658 }; | 651 }; |
| 659 | 652 |
| 660 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, | 653 bool GrAAHairLinePathRenderer::createLineGeom(const SkPath& path, |
| 661 GrDrawTarget* target, | 654 GrDrawTarget* target, |
| 662 const PtArray& lines, | 655 const PtArray& lines, |
| 663 int lineCnt, | 656 int lineCnt, |
| 664 GrDrawTarget::AutoReleaseGeometry*
arg, | 657 GrDrawTarget::AutoReleaseGeometry*
arg, |
| 665 SkRect* devBounds) { | 658 SkRect* devBounds) { |
| 666 GrDrawState* drawState = target->drawState(); | 659 GrDrawState* drawState = target->drawState(); |
| 667 | 660 |
| 668 const SkMatrix& viewM = drawState->getViewMatrix(); | 661 const SkMatrix& viewM = drawState->getViewMatrix(); |
| 669 | 662 |
| 670 int vertCnt = kLineSegNumVertices * lineCnt; | 663 int vertCnt = kLineSegNumVertices * lineCnt; |
| 671 | 664 |
| 672 drawState->setVertexAttribs<gHairlineLineAttribs>(SK_ARRAY_COUNT(gHairlineLi
neAttribs), | 665 GrDefaultGeoProcFactory::SetAttribs(drawState, GrDefaultGeoProcFactory::kPos
ition_GPType | |
| 673 sizeof(LineVertex)); | 666 GrDefaultGeoProcFactory::kCov
erage_GPType); |
| 674 | 667 |
| 675 if (!arg->set(target, vertCnt, 0)) { | 668 if (!arg->set(target, vertCnt, 0)) { |
| 676 return false; | 669 return false; |
| 677 } | 670 } |
| 678 | 671 |
| 679 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); | 672 LineVertex* verts = reinterpret_cast<LineVertex*>(arg->vertices()); |
| 680 | 673 |
| 681 const SkMatrix* toSrc = NULL; | 674 const SkMatrix* toSrc = NULL; |
| 682 SkMatrix ivm; | 675 SkMatrix ivm; |
| 683 | 676 |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 return false; | 870 return false; |
| 878 } | 871 } |
| 879 GrDrawState* drawState = target->drawState(); | 872 GrDrawState* drawState = target->drawState(); |
| 880 | 873 |
| 881 // Check devBounds | 874 // Check devBounds |
| 882 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), | 875 SkASSERT(check_bounds<LineVertex>(drawState, devBounds, arg.vertices(), |
| 883 kLineSegNumVertices * lineCnt)); | 876 kLineSegNumVertices * lineCnt)); |
| 884 | 877 |
| 885 { | 878 { |
| 886 GrDrawState::AutoRestoreEffects are(drawState); | 879 GrDrawState::AutoRestoreEffects are(drawState); |
| 880 drawState->setGeometryProcessor(GrDefaultGeoProcFactory::Create(fals
e))->unref(); |
| 887 target->setIndexSourceToBuffer(fLinesIndexBuffer); | 881 target->setIndexSourceToBuffer(fLinesIndexBuffer); |
| 888 int lines = 0; | 882 int lines = 0; |
| 889 while (lines < lineCnt) { | 883 while (lines < lineCnt) { |
| 890 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); | 884 int n = SkTMin(lineCnt - lines, kLineSegsNumInIdxBuffer); |
| 891 target->drawIndexed(kTriangles_GrPrimitiveType, | 885 target->drawIndexed(kTriangles_GrPrimitiveType, |
| 892 kLineSegNumVertices*lines, // startV | 886 kLineSegNumVertices*lines, // startV |
| 893 0, // startI | 887 0, // startI |
| 894 kLineSegNumVertices*n, // vCount | 888 kLineSegNumVertices*n, // vCount |
| 895 kIdxsPerLineSeg*n, // iCount | 889 kIdxsPerLineSeg*n, // iCount |
| 896 &devBounds); | 890 &devBounds); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 &devBounds); | 963 &devBounds); |
| 970 conics += n; | 964 conics += n; |
| 971 } | 965 } |
| 972 } | 966 } |
| 973 } | 967 } |
| 974 | 968 |
| 975 target->resetIndexSource(); | 969 target->resetIndexSource(); |
| 976 | 970 |
| 977 return true; | 971 return true; |
| 978 } | 972 } |
| OLD | NEW |