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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 args.fTransformsOut); | 138 args.fTransformsOut); |
139 | 139 |
140 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); | 140 fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn()); |
141 fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 -
d);", v.fsIn()); | 141 fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 -
d);", v.fsIn()); |
142 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdg
e, 0.0, 1.0);"); | 142 fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdg
e, 0.0, 1.0);"); |
143 if (cgp.fStroke) { | 143 if (cgp.fStroke) { |
144 fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d
- %s.w);", | 144 fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d
- %s.w);", |
145 v.fsIn(), v.fsIn()); | 145 v.fsIn(), v.fsIn()); |
146 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne
rEdge, 0.0, 1.0);"); | 146 fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInne
rEdge, 0.0, 1.0);"); |
147 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); | 147 fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); |
148 } else { | |
149 fragBuilder->codeAppend("float distanceToInnerEdge = 0.0;"); | |
150 } | 148 } |
151 | 149 |
152 if (args.fDistanceVectorName) { | 150 if (args.fDistanceVectorName) { |
| 151 const char* innerEdgeDistance = cgp.fStroke ? "distanceToInnerEd
ge" : "0.0"; |
153 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center
of the circle | 152 fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center
of the circle |
154 fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOute
rEdge, " | 153 fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOute
rEdge, " |
155 "distanceToInnerEdge);", // no normaliz
e | 154 "%s);", // no normalize |
156 args.fDistanceVectorName); | 155 args.fDistanceVectorName, innerEdgeDist
ance); |
157 fragBuilder->codeAppend ("} else {"); | 156 fragBuilder->codeAppend ("} else {"); |
158 fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distan
ceToOuterEdge, " | 157 fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distan
ceToOuterEdge, " |
159 "distanceToInnerEdge);", | 158 "%s);", |
160 args.fDistanceVectorName, v.fsIn()); | 159 args.fDistanceVectorName, v.fsIn(), inn
erEdgeDistance); |
161 fragBuilder->codeAppend ("}"); | 160 fragBuilder->codeAppend ("}"); |
162 } | 161 } |
163 | 162 |
164 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); | 163 fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCovera
ge); |
165 } | 164 } |
166 | 165 |
167 static void GenKey(const GrGeometryProcessor& gp, | 166 static void GenKey(const GrGeometryProcessor& gp, |
168 const GrGLSLCaps&, | 167 const GrGLSLCaps&, |
169 GrProcessorKeyBuilder* b) { | 168 GrProcessorKeyBuilder* b) { |
170 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); | 169 const CircleGeometryProcessor& cgp = gp.cast<CircleGeometryProcessor
>(); |
(...skipping 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 } | 1694 } |
1696 | 1695 |
1697 DRAW_BATCH_TEST_DEFINE(RRectBatch) { | 1696 DRAW_BATCH_TEST_DEFINE(RRectBatch) { |
1698 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); | 1697 SkMatrix viewMatrix = GrTest::TestMatrixRectStaysRect(random); |
1699 GrColor color = GrRandomColor(random); | 1698 GrColor color = GrRandomColor(random); |
1700 const SkRRect& rrect = GrTest::TestRRectSimple(random); | 1699 const SkRRect& rrect = GrTest::TestRRectSimple(random); |
1701 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); | 1700 return create_rrect_batch(color, viewMatrix, rrect, GrTest::TestStrokeRec(ra
ndom)); |
1702 } | 1701 } |
1703 | 1702 |
1704 #endif | 1703 #endif |
OLD | NEW |