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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 | 61 |
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). |
robertphillips
2016/08/16 17:56:07
Should we be documenting the distance vector outpu
jvanverth1
2016/08/16 19:24:54
Done.
| |
72 */ | 72 */ |
73 | 73 |
74 class CircleGeometryProcessor : public GrGeometryProcessor { | 74 class CircleGeometryProcessor : public GrGeometryProcessor { |
75 public: | 75 public: |
76 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa trix(localMatrix){ | 76 CircleGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : fLocalMa trix(localMatrix){ |
77 this->initClassID<CircleGeometryProcessor>(); | 77 this->initClassID<CircleGeometryProcessor>(); |
78 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, | 78 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, |
79 kHigh_GrSLPrecision)); | 79 kHigh_GrSLPrecision)); |
80 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); | 80 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexA ttribType)); |
81 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", | 81 fInCircleEdge = &this->addVertexAttrib(Attribute("inCircleEdge", |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 this->emitTransforms(vertBuilder, | 122 this->emitTransforms(vertBuilder, |
123 varyingHandler, | 123 varyingHandler, |
124 uniformHandler, | 124 uniformHandler, |
125 gpArgs->fPositionVar, | 125 gpArgs->fPositionVar, |
126 cgp.inPosition()->fName, | 126 cgp.inPosition()->fName, |
127 cgp.localMatrix(), | 127 cgp.localMatrix(), |
128 args.fTransformsIn, | 128 args.fTransformsIn, |
129 args.fTransformsOut); | 129 args.fTransformsOut); |
130 | 130 |
131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 131 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
132 fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn()); | 132 fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 - d);", v.fsIn()); |
133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0. 0, 1.0);"); | 133 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdg e, 0.0, 1.0);"); |
134 if (cgp.fStroke) { | 134 if (cgp.fStroke) { |
135 fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - % s.w), 0.0, 1.0);", | 135 fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d - %s.w);", |
136 v.fsIn(), v.fsIn()); | 136 v.fsIn(), v.fsIn()); |
137 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne rEdge, 0.0, 1.0);"); | |
137 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 138 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
138 } | 139 } |
139 | 140 |
140 if (args.fDistanceVectorName) { | 141 if (args.fDistanceVectorName) { |
141 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center of the circle | 142 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 | 143 fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOute rEdge, " |
144 "distanceToInnerEdge);", // no normaliz e | |
143 args.fDistanceVectorName); | 145 args.fDistanceVectorName); |
144 fragBuilder->codeAppend ("} else {"); | 146 fragBuilder->codeAppend ("} else {"); |
145 fragBuilder->codeAppendf(" %s = vec3(normalize(%s.xy), distan ceToEdge);", | 147 fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distan ceToOuterEdge, " |
148 "distanceToInnerEdge);", | |
146 args.fDistanceVectorName, v.fsIn()); | 149 args.fDistanceVectorName, v.fsIn()); |
147 fragBuilder->codeAppend ("}"); | 150 fragBuilder->codeAppend ("}"); |
148 } | 151 } |
149 | 152 |
150 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); | 153 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera ge); |
151 } | 154 } |
152 | 155 |
153 static void GenKey(const GrGeometryProcessor& gp, | 156 static void GenKey(const GrGeometryProcessor& gp, |
154 const GrGLSLCaps&, | 157 const GrGLSLCaps&, |
155 GrProcessorKeyBuilder* b) { | 158 GrProcessorKeyBuilder* b) { |
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1706 } | 1709 } |
1707 | 1710 |
1708 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1711 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1709 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1712 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1710 GrColor color = GrRandomColor(random); | 1713 GrColor color = GrRandomColor(random); |
1711 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1714 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1712 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); | 1715 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra ndom)); |
1713 } | 1716 } |
1714 | 1717 |
1715 #endif | 1718 #endif |
OLD | NEW |