aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-11 15:54:51 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-11 15:54:51 +0000
commitc5c748c14797ae49ba73999a63e3b07315c888e1 (patch)
tree1546c65d26fb3487b7c1c66d920de6f34b100199 /src
parenta64ed0fd68c4edf01d43cbd7313eac584702bcf4 (diff)
Handle rrects with one circular corner and three square corners in GrRRectEffect.
BUG=skia:2181 R=jvanverth@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/193263002 git-svn-id: http://skia.googlecode.com/svn/trunk@13739 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r--src/gpu/effects/GrRRectEffect.cpp79
1 files changed, 75 insertions, 4 deletions
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index 868d18cd99..619cd99daf 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -165,10 +165,10 @@ void GLRRectEffect::emitCode(GrGLShaderBuilder* builder,
const RRectEffect& rre = drawEffect.castEffect<RRectEffect>();
const char *rectName;
const char *radiusPlusHalfName;
- // The inner rect is the rrect bounds inset by the radius. Its top, left, right, and bottom
- // edges correspond to components x, y, z, and w, respectively. When one side of the rrect has
- // rectangular corners, that side's value corresponds to the rect edge's value outset by half a
- // pixel.
+ // The inner rect is the rrect bounds inset by the radius. Its left, top, right, and bottom
+ // edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
+ // only rectangular corners, that side's value corresponds to the rect edge's value outset by
+ // half a pixel.
fInnerRectUniform = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType,
"innerRect",
@@ -201,6 +201,45 @@ void GLRRectEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppendf("\t\tfloat alpha = clamp(%s - length(dxy), 0.0, 1.0);\n",
radiusPlusHalfName);
break;
+ case RRectEffect::kTopLeft_CornerFlag:
+ builder->fsCodeAppendf("\t\tvec2 dxy = max(%s.xy - %s.xy, 0.0);\n", rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat rightAlpha = clamp(%s.z - %s.x, 0.0, 1.0);\n",
+ rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat bottomAlpha = clamp(%s.w - %s.y, 0.0, 1.0);\n",
+ rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat alpha = bottomAlpha * rightAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+ radiusPlusHalfName);
+ break;
+ case RRectEffect::kTopRight_CornerFlag:
+ builder->fsCodeAppendf("\t\tvec2 dxy = max(vec2(%s.x - %s.z, %s.y - %s.y), 0.0);\n",
+ fragmentPos, rectName, rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat leftAlpha = clamp(%s.x - %s.x, 0.0, 1.0);\n",
+ fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat bottomAlpha = clamp(%s.w - %s.y, 0.0, 1.0);\n",
+ rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat alpha = bottomAlpha * leftAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+ radiusPlusHalfName);
+ break;
+ case RRectEffect::kBottomRight_CornerFlag:
+ builder->fsCodeAppendf("\t\tvec2 dxy = max(%s.xy - %s.zw, 0.0);\n",
+ fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat leftAlpha = clamp(%s.x - %s.x, 0.0, 1.0);\n",
+ fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n",
+ fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * leftAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+ radiusPlusHalfName);
+ break;
+ case RRectEffect::kBottomLeft_CornerFlag:
+ builder->fsCodeAppendf("\t\tvec2 dxy = max(vec2(%s.x - %s.x, %s.y - %s.w), 0.0);\n",
+ rectName, fragmentPos, fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat rightAlpha = clamp(%s.z - %s.x, 0.0, 1.0);\n",
+ rectName, fragmentPos);
+ builder->fsCodeAppendf("\t\tfloat topAlpha = clamp(%s.y - %s.y, 0.0, 1.0);\n",
+ fragmentPos, rectName);
+ builder->fsCodeAppendf("\t\tfloat alpha = topAlpha * rightAlpha * clamp(%s - length(dxy), 0.0, 1.0);\n",
+ radiusPlusHalfName);
+ break;
case RRectEffect::kLeft_CornerFlags:
builder->fsCodeAppendf("\t\tvec2 dxy0 = %s.xy - %s.xy;\n", rectName, fragmentPos);
builder->fsCodeAppendf("\t\tfloat dy1 = %s.y - %s.w;\n", fragmentPos, rectName);
@@ -266,6 +305,34 @@ void GLRRectEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect&
SkASSERT(radius >= RRectEffect::kRadiusMin);
rect.inset(radius, radius);
break;
+ case RRectEffect::kTopLeft_CornerFlag:
+ radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX;
+ rect.fLeft += radius;
+ rect.fTop += radius;
+ rect.fRight += 0.5f;
+ rect.fBottom += 0.5f;
+ break;
+ case RRectEffect::kTopRight_CornerFlag:
+ radius = rrect.radii(SkRRect::kUpperRight_Corner).fX;
+ rect.fLeft -= 0.5;
+ rect.fTop += radius;
+ rect.fRight -= radius;
+ rect.fBottom += 0.5f;
+ break;
+ case RRectEffect::kBottomRight_CornerFlag:
+ radius = rrect.radii(SkRRect::kLowerRight_Corner).fX;
+ rect.fLeft -= 0.5;
+ rect.fTop -= 0.5;
+ rect.fRight -= radius;
+ rect.fBottom -= radius;
+ break;
+ case RRectEffect::kBottomLeft_CornerFlag:
+ radius = rrect.radii(SkRRect::kLowerLeft_Corner).fX;
+ rect.fLeft += radius;
+ rect.fTop -= 0.5;
+ rect.fRight += 0.5;
+ rect.fBottom -= radius;
+ break;
case RRectEffect::kLeft_CornerFlags:
radius = rrect.radii(SkRRect::kUpperLeft_Corner).fX;
rect.fLeft += radius;
@@ -343,6 +410,10 @@ GrEffectRef* GrRRectEffect::Create(GrEffectEdgeType edgeType, const SkRRect& rre
}
switch (cornerFlags) {
+ case RRectEffect::kTopLeft_CornerFlag:
+ case RRectEffect::kTopRight_CornerFlag:
+ case RRectEffect::kBottomRight_CornerFlag:
+ case RRectEffect::kBottomLeft_CornerFlag:
case RRectEffect::kLeft_CornerFlags:
case RRectEffect::kTop_CornerFlags:
case RRectEffect::kRight_CornerFlags: