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 "GrDrawState.h" | 11 #include "GrDrawState.h" |
12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
13 #include "GrEffect.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 "GrTBackendEffectFactory.h" | 17 #include "GrTBackendProcessorFactory.h" |
18 #include "SkGeometry.h" | 18 #include "SkGeometry.h" |
19 #include "SkStroke.h" | 19 #include "SkStroke.h" |
20 #include "SkTemplates.h" | 20 #include "SkTemplates.h" |
21 | 21 |
22 #include "effects/GrBezierEffect.h" | 22 #include "effects/GrBezierEffect.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 // 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 |
26 // 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 |
27 // bloat_quad. Quadratics and conics share an index buffer | 27 // bloat_quad. Quadratics and conics share an index buffer |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 | 701 |
702 } | 702 } |
703 | 703 |
704 /////////////////////////////////////////////////////////////////////////////// | 704 /////////////////////////////////////////////////////////////////////////////// |
705 | 705 |
706 namespace { | 706 namespace { |
707 | 707 |
708 // position + edge | 708 // position + edge |
709 extern const GrVertexAttrib gHairlineBezierAttribs[] = { | 709 extern const GrVertexAttrib gHairlineBezierAttribs[] = { |
710 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, | 710 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBind
ing}, |
711 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBindin
g} | 711 {kVec4f_GrVertexAttribType, sizeof(SkPoint), kGeometryProcessor_GrVertexA
ttribBinding} |
712 }; | 712 }; |
713 | 713 |
714 // position + coverage | 714 // position + coverage |
715 extern const GrVertexAttrib gHairlineLineAttribs[] = { | 715 extern const GrVertexAttrib gHairlineLineAttribs[] = { |
716 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 716 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
717 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindin
g}, | 717 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kCoverage_GrVertexAttribBindin
g}, |
718 }; | 718 }; |
719 | 719 |
720 }; | 720 }; |
721 | 721 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { | 988 } else if (!asr.setIdentity(target, GrDrawTarget::kPreserve_ASRInit)) { |
989 return false; | 989 return false; |
990 } | 990 } |
991 GrDrawState* drawState = target->drawState(); | 991 GrDrawState* drawState = target->drawState(); |
992 | 992 |
993 // Check devBounds | 993 // Check devBounds |
994 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, | 994 SkASSERT(check_bounds<BezierVertex>(drawState, devBounds, arg.vertices()
, |
995 kVertsPerQuad * quadCnt + kVertsPerQ
uad * conicCnt)); | 995 kVertsPerQuad * quadCnt + kVertsPerQ
uad * conicCnt)); |
996 | 996 |
997 if (quadCnt > 0) { | 997 if (quadCnt > 0) { |
998 GrEffect* hairQuadEffect = GrQuadEffect::Create(kHairlineAA_GrEffect
EdgeType, | 998 GrGeometryProcessor* hairQuadProcessor = |
999 *target->caps()); | 999 GrQuadEffect::Create(kHairlineAA_GrProcessorEdgeType, *targe
t->caps()); |
1000 SkASSERT(hairQuadEffect); | 1000 SkASSERT(hairQuadProcessor); |
1001 GrDrawState::AutoRestoreEffects are(drawState); | 1001 GrDrawState::AutoRestoreEffects are(drawState); |
1002 target->setIndexSourceToBuffer(fQuadsIndexBuffer); | 1002 target->setIndexSourceToBuffer(fQuadsIndexBuffer); |
1003 drawState->setGeometryProcessor(hairQuadEffect)->unref(); | 1003 drawState->setGeometryProcessor(hairQuadProcessor)->unref(); |
1004 int quads = 0; | 1004 int quads = 0; |
1005 while (quads < quadCnt) { | 1005 while (quads < quadCnt) { |
1006 int n = SkTMin(quadCnt - quads, kNumQuadsInIdxBuffer); | 1006 int n = SkTMin(quadCnt - quads, kNumQuadsInIdxBuffer); |
1007 target->drawIndexed(kTriangles_GrPrimitiveType, | 1007 target->drawIndexed(kTriangles_GrPrimitiveType, |
1008 kVertsPerQuad*quads, // startV | 1008 kVertsPerQuad*quads, // startV |
1009 0, // startI | 1009 0, // startI |
1010 kVertsPerQuad*n, // vCount | 1010 kVertsPerQuad*n, // vCount |
1011 kIdxsPerQuad*n, // iCount | 1011 kIdxsPerQuad*n, // iCount |
1012 &devBounds); | 1012 &devBounds); |
1013 quads += n; | 1013 quads += n; |
1014 } | 1014 } |
1015 } | 1015 } |
1016 | 1016 |
1017 if (conicCnt > 0) { | 1017 if (conicCnt > 0) { |
1018 GrDrawState::AutoRestoreEffects are(drawState); | 1018 GrDrawState::AutoRestoreEffects are(drawState); |
1019 GrEffect* hairConicEffect = GrConicEffect::Create(kHairlineAA_GrEffe
ctEdgeType, | 1019 GrGeometryProcessor* hairConicEffect = GrConicEffect::Create( |
1020 *target->caps()); | 1020 kHairlineAA_GrProcessorEdgeType, *target->caps()); |
1021 SkASSERT(hairConicEffect); | 1021 SkASSERT(hairConicEffect); |
1022 drawState->setGeometryProcessor(hairConicEffect)->unref(); | 1022 drawState->setGeometryProcessor(hairConicEffect)->unref(); |
1023 int conics = 0; | 1023 int conics = 0; |
1024 while (conics < conicCnt) { | 1024 while (conics < conicCnt) { |
1025 int n = SkTMin(conicCnt - conics, kNumQuadsInIdxBuffer); | 1025 int n = SkTMin(conicCnt - conics, kNumQuadsInIdxBuffer); |
1026 target->drawIndexed(kTriangles_GrPrimitiveType, | 1026 target->drawIndexed(kTriangles_GrPrimitiveType, |
1027 kVertsPerQuad*(quadCnt + conics), // startV | 1027 kVertsPerQuad*(quadCnt + conics), // startV |
1028 0, // startI | 1028 0, // startI |
1029 kVertsPerQuad*n, // vCount | 1029 kVertsPerQuad*n, // vCount |
1030 kIdxsPerQuad*n, // iCount | 1030 kIdxsPerQuad*n, // iCount |
1031 &devBounds); | 1031 &devBounds); |
1032 conics += n; | 1032 conics += n; |
1033 } | 1033 } |
1034 } | 1034 } |
1035 } | 1035 } |
1036 | 1036 |
1037 target->resetIndexSource(); | 1037 target->resetIndexSource(); |
1038 | 1038 |
1039 return true; | 1039 return true; |
1040 } | 1040 } |
OLD | NEW |