Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Unified Diff: src/gpu/GrOvalRenderer.cpp

Issue 2249973003: Add alternative ambient shadow method to Android shadow sample (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Nits (again) Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkGaussianEdgeShader.cpp ('k') | src/gpu/batches/GrAnalyticRectBatch.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrOvalRenderer.cpp
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 89e35a1d707d49160005db46d0d289b66fc7bfad..77ed6c985411e2a72ec3e52cf4908a4c70ba1fde 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -69,6 +69,12 @@ inline bool circle_stays_circle(const SkMatrix& m) {
* p is the position in the normalized space.
* outerRad is the outerRadius in device space.
* innerRad is the innerRadius in normalized space (ignored if not stroking).
+ * If fUsesDistanceVectorField is set in fragment processors in the same program, then
+ * an additional vertex attribute is available via args.fFragBuilder->distanceVectorName():
+ * vec4f : (v.xy, outerDistance, innerDistance)
+ * v is a normalized vector pointing to the outer edge
+ * outerDistance is the distance to the outer edge, < 0 if we are outside of the shape
+ * if stroking, innerDistance is the distance to the inner edge, < 0 if outside
*/
class CircleGeometryProcessor : public GrGeometryProcessor {
@@ -129,20 +135,25 @@ public:
args.fTransformsOut);
fragBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
- fragBuilder->codeAppendf("float distanceToEdge = %s.z * (1.0 - d);", v.fsIn());
- fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToEdge, 0.0, 1.0);");
+ fragBuilder->codeAppendf("float distanceToOuterEdge = %s.z * (1.0 - d);", v.fsIn());
+ fragBuilder->codeAppendf("float edgeAlpha = clamp(distanceToOuterEdge, 0.0, 1.0);");
if (cgp.fStroke) {
- fragBuilder->codeAppendf("float innerAlpha = clamp(%s.z * (d - %s.w), 0.0, 1.0);",
+ fragBuilder->codeAppendf("float distanceToInnerEdge = %s.z * (d - %s.w);",
v.fsIn(), v.fsIn());
+ fragBuilder->codeAppend("float innerAlpha = clamp(distanceToInnerEdge, 0.0, 1.0);");
fragBuilder->codeAppend("edgeAlpha *= innerAlpha;");
+ } else {
+ fragBuilder->codeAppend("float distanceToInnerEdge = 0.0;");
}
if (args.fDistanceVectorName) {
fragBuilder->codeAppend ("if (d == 0.0) {"); // if on the center of the circle
- fragBuilder->codeAppendf(" %s = vec3(1.0, 0.0, distanceToEdge);", // no normalize
+ fragBuilder->codeAppendf(" %s = vec4(1.0, 0.0, distanceToOuterEdge, "
+ "distanceToInnerEdge);", // no normalize
args.fDistanceVectorName);
fragBuilder->codeAppend ("} else {");
- fragBuilder->codeAppendf(" %s = vec3(normalize(%s.xy), distanceToEdge);",
+ fragBuilder->codeAppendf(" %s = vec4(normalize(%s.xy), distanceToOuterEdge, "
+ "distanceToInnerEdge);",
args.fDistanceVectorName, v.fsIn());
fragBuilder->codeAppend ("}");
}
« no previous file with comments | « src/effects/SkGaussianEdgeShader.cpp ('k') | src/gpu/batches/GrAnalyticRectBatch.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698