OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrOvalRenderer.h" | 8 #include "GrOvalRenderer.h" |
9 | 9 |
10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 /** | 62 /** |
63 * The output of this effect is a modulation of the input color and coverage for
a circle. It | 63 * The output of this effect is a modulation of the input color and coverage for
a circle. It |
64 * operates in a space normalized by the circle radius (outer radius in the case
of a stroke) | 64 * operates in a space normalized by the circle radius (outer radius in the case
of a stroke) |
65 * with origin at the circle center. Three vertex attributes are used: | 65 * with origin at the circle center. Three vertex attributes are used: |
66 * vec2f : position in device space of the bounding geometry vertices | 66 * vec2f : position in device space of the bounding geometry vertices |
67 * vec4ub: color | 67 * vec4ub: color |
68 * vec4f : (p.xy, outerRad, innerRad) | 68 * vec4f : (p.xy, outerRad, innerRad) |
69 * p is the position in the normalized space. | 69 * p is the position in the normalized space. |
70 * outerRad is the outerRadius in device space. | 70 * outerRad is the outerRadius in device space. |
71 * innerRad is the innerRadius in normalized space (ignored if not s
troking). | 71 * innerRad is the innerRadius in normalized space (ignored if not s
troking). |
| 72 * If fUsesDistanceVectorField is set in fragment processors in the same program
, then |
| 73 * an additional vertex attribute is available via args.fFragBuilder->distanceVe
ctorName(): |
| 74 * vec4f : (v.xy, outerDistance, innerDistance) |
| 75 * v is a normalized vector pointing to the outer edge |
| 76 * outerDistance is the distance to the outer edge, < 0 if we are ou
tside of the shape |
| 77 * if stroking, innerDistance is the distance to the inner edge, < 0
if outside |
72 */ | 78 */ |
73 | 79 |
74 class CircleGeometryProcessor : public GrGeometryProcessor { | 80 class CircleGeometryProcessor : public GrGeometryProcessor { |
75 public: | 81 public: |
76 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa
trix(localMatrix){ | 82 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa
trix(localMatrix){ |
77 this->initClassID<CircleGeometryProcessor>(); | 83 this->initClassID<CircleGeometryProcessor>(); |
78 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, | 84 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe
rtexAttribType, |
79 kHigh_GrSLPrecision)); | 85 kHigh_GrSLPrecision)); |
80 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); | 86 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA
ttribType)); |
81 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", | 87 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 this->emitTransforms(vertBuilder, | 128 this->emitTransforms(vertBuilder, |
123 varyingHandler, | 129 varyingHandler, |
124 uniformHandler, | 130 uniformHandler, |
125 gpArgs->fPositionVar, | 131 gpArgs->fPositionVar, |
126 cgp.inPosition()->fName, | 132 cgp.inPosition()->fName, |
127 cgp.localMatrix(), | 133 cgp.localMatrix(), |
128 args.fTransformsIn, | 134 args.fTransformsIn, |
129 args.fTransformsOut); | 135 args.fTransformsOut); |
130 | 136 |
131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 137 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
132 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);",
v.fsIn()); | 138 fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 -
d);", v.fsIn()); |
133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0.
0, 1.0);"); | 139 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdg
e, 0.0, 1.0);"); |
134 if (cgp.fStroke) { | 140 if (cgp.fStroke) { |
135 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %
s.w), 0.0, 1.0);", | 141 fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d
- %s.w);", |
136 v.fsIn(), v.fsIn()); | 142 v.fsIn(), v.fsIn()); |
| 143 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne
rEdge, 0.0, 1.0);"); |
137 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 144 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
| 145 } else { |
| 146 fragBuilder->codeAppend("float distanceToInnerEdge = 0.0;"); |
138 } | 147 } |
139 | 148 |
140 if (args.fDistanceVectorName) { | 149 if (args.fDistanceVectorName) { |
141 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center
of the circle | 150 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center
of the circle |
142 fragBuilder->codeAppendf(" %s = vec3(1.0, 0.0, distanceToEdge
);", // no normalize | 151 fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOute
rEdge, " |
| 152 "distanceToInnerEdge);", // no normaliz
e |
143 args.fDistanceVectorName); | 153 args.fDistanceVectorName); |
144 fragBuilder->codeAppend ("} else {"); | 154 fragBuilder->codeAppend ("} else {"); |
145 fragBuilder->codeAppendf(" %s = vec3(normalize(%s.xy), distan
ceToEdge);", | 155 fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distan
ceToOuterEdge, " |
| 156 "distanceToInnerEdge);", |
146 args.fDistanceVectorName, v.fsIn()); | 157 args.fDistanceVectorName, v.fsIn()); |
147 fragBuilder->codeAppend ("}"); | 158 fragBuilder->codeAppend ("}"); |
148 } | 159 } |
149 | 160 |
150 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); | 161 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); |
151 } | 162 } |
152 | 163 |
153 static void GenKey(const GrGeometryProcessor& gp, | 164 static void GenKey(const GrGeometryProcessor& gp, |
154 const GrGLSLCaps&, | 165 const GrGLSLCaps&, |
155 GrProcessorKeyBuilder* b) { | 166 GrProcessorKeyBuilder* b) { |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 } | 1717 } |
1707 | 1718 |
1708 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1719 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1709 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1720 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1710 GrColor color = GrRandomColor(random); | 1721 GrColor color = GrRandomColor(random); |
1711 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1722 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1712 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 1723 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
1713 } | 1724 } |
1714 | 1725 |
1715 #endif | 1726 #endif |
OLD | NEW |