From 99e0d08113738dd8ea8f52af0cdd04c971ff074a Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 14 Jun 2013 14:58:50 +0000 Subject: [PATCH] Update Alligned Rect Shader to match geometry version -Also update to combine width and height coverage using multiplication instead of using min R=bsalomon@google.com, robertphillips@google.com Author: egdaniel@google.com Review URL: https://chromiumcodereview.appspot.com/16854012 git-svn-id: http://skia.googlecode.com/svn/trunk@9609 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/gpu/GrAARectRenderer.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gpu/GrAARectRenderer.cpp b/src/gpu/GrAARectRenderer.cpp index 7fe0517f7c..0f0d1d446c 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*insetW/spanW);\n"); + builder->fsCodeAppend("\tfloat scaleH = min(1.0, 2*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); - - // 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); + "\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 = coverage*scaleH*clamp((%s.w-abs(%s.y))/spanH, 0.0, 1.0);\n", + fsRectName, fsRectName); SkString modulate; GrGLSLModulatef<4>(&modulate, inputColor, "coverage");