Index: src/gpu/GrAARectRenderer.cpp |
diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp |
index f28d91456308143206a0f77310df60cd8a24f263..142f6a8232d1aef1801acf09b0897bd0cc2d8d38 100644 |
--- a/src/gpu/GrAARectRenderer.cpp |
+++ b/src/gpu/GrAARectRenderer.cpp |
@@ -59,23 +59,28 @@ public: |
builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
builder->vsCodeAppendf("\t%s = %s;\n", vsRectName, attr0Name->c_str()); |
- // TODO: compute these scale factors in the VS |
- // These scale factors adjust the coverage for < 1 pixel wide/high rects |
- builder->fsCodeAppendf("\tfloat wScale = max(1.0, 2.0/(0.5+%s.z));\n", |
- fsRectName); |
- builder->fsCodeAppendf("\tfloat hScale = max(1.0, 2.0/(0.5+%s.w));\n", |
- fsRectName); |
+ // TODO: compute all these offsets, spans, and scales in the VS |
+ builder->fsCodeAppendf("\tfloat insetW = min(1.0, %s.z) - 0.5;\n", fsRectName); |
+ builder->fsCodeAppendf("\tfloat insetH = min(1.0, %s.w) - 0.5;\n", fsRectName); |
+ builder->fsCodeAppend("\tfloat outset = 0.5;\n"); |
+ // For rects > 1 pixel wide and tall the span's are noops (i.e., 1.0). For rects |
+ // < 1 pixel wide or tall they serve to normalize the < 1 ramp to a 0 .. 1 range. |
+ builder->fsCodeAppend("\tfloat spanW = insetW + outset;\n"); |
+ builder->fsCodeAppend("\tfloat spanH = insetH + outset;\n"); |
+ // For rects < 1 pixel wide or tall, these scale factors are used to cap the maximum |
+ // value of coverage that is used. In other words it is the coverage that is |
+ // used in the interior of the rect after the ramp. |
+ builder->fsCodeAppend("\tfloat scaleW = min(1.0, 2.0*insetW/spanW);\n"); |
+ builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2.0*insetH/spanH);\n"); |
// Compute the coverage for the rect's width |
- builder->fsCodeAppendf("\tfloat coverage = clamp(wScale*(%s.z-abs(%s.x)), 0.0, 1.0);\n", |
- fsRectName, |
- fsRectName); |
- |
+ builder->fsCodeAppendf( |
+ "\tfloat coverage = scaleW*clamp((%s.z-abs(%s.x))/spanW, 0.0, 1.0);\n", fsRectName, |
+ fsRectName); |
// Compute the coverage for the rect's height and merge with the width |
builder->fsCodeAppendf( |
- "\tcoverage = min(coverage, clamp(hScale*(%s.w-abs(%s.y)), 0.0, 1.0));\n", |
- fsRectName, |
- fsRectName); |
+ "\tcoverage = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n", |
+ fsRectName, fsRectName); |
SkString modulate; |
GrGLSLModulatef<4>(&modulate, inputColor, "coverage"); |