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 "GrEffect.h" | 10 #include "GrEffect.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); | 109 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
110 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 110 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
111 | 111 |
112 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); | 112 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); |
113 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); | 113 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); |
114 if (circleEffect.isStroked()) { | 114 if (circleEffect.isStroked()) { |
115 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); | 115 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); |
116 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); | 116 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); |
117 } | 117 } |
118 | 118 |
119 SkString modulate; | 119 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
120 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); | 120 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<1>("e
dgeAlpha")).c_str()); |
121 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | |
122 } | 121 } |
123 | 122 |
124 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 123 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
125 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); | 124 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); |
126 | 125 |
127 return circleEffect.isStroked() ? 0x1 : 0x0; | 126 return circleEffect.isStroked() ? 0x1 : 0x0; |
128 } | 127 } |
129 | 128 |
130 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 129 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
131 | 130 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 241 |
243 // for inner curve | 242 // for inner curve |
244 if (ellipseEffect.isStroked()) { | 243 if (ellipseEffect.isStroked()) { |
245 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN
ame, fsRadiiName); | 244 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN
ame, fsRadiiName); |
246 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); | 245 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); |
247 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); | 246 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); |
248 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 247 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
249 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); | 248 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); |
250 } | 249 } |
251 | 250 |
252 SkString modulate; | 251 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
253 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); | 252 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<1>("e
dgeAlpha")).c_str()); |
254 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | |
255 } | 253 } |
256 | 254 |
257 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 255 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
258 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); | 256 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); |
259 | 257 |
260 return ellipseEffect.isStroked() ? 0x1 : 0x0; | 258 return ellipseEffect.isStroked() ? 0x1 : 0x0; |
261 } | 259 } |
262 | 260 |
263 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 261 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
264 } | 262 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); | 399 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); |
402 builder->fsCodeAppendf("\tduvdx = dFdx(%s);\n", fsOffsetName1); | 400 builder->fsCodeAppendf("\tduvdx = dFdx(%s);\n", fsOffsetName1); |
403 builder->fsCodeAppendf("\tduvdy = dFdy(%s);\n", fsOffsetName1); | 401 builder->fsCodeAppendf("\tduvdy = dFdy(%s);\n", fsOffsetName1); |
404 builder->fsCodeAppendf("\tgrad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.
y*duvdx.y,\n" | 402 builder->fsCodeAppendf("\tgrad = vec2(2.0*%s.x*duvdx.x + 2.0*%s.
y*duvdx.y,\n" |
405 "\t 2.0*%s.x*duvdy.x + 2.0*%s.
y*duvdy.y);\n", | 403 "\t 2.0*%s.x*duvdy.x + 2.0*%s.
y*duvdy.y);\n", |
406 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); | 404 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); |
407 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 405 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
408 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); | 406 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); |
409 } | 407 } |
410 | 408 |
411 SkString modulate; | 409 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
412 GrGLSLModulatef<4>(&modulate, inputColor, "edgeAlpha"); | 410 (GrGLSLExpr<4>(inputColor) * GrGLSLExpr<1>("e
dgeAlpha")).c_str()); |
413 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str()
); | |
414 } | 411 } |
415 | 412 |
416 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 413 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
417 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); | 414 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); |
418 | 415 |
419 return ellipseEffect.getMode(); | 416 return ellipseEffect.getMode(); |
420 } | 417 } |
421 | 418 |
422 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 419 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
423 } | 420 } |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1135 } | 1132 } |
1136 | 1133 |
1137 // drop out the middle quad if we're stroked | 1134 // drop out the middle quad if we're stroked |
1138 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); | 1135 int indexCnt = isStroked ? GR_ARRAY_COUNT(gRRectIndices)-6 : GR_ARRAY_CO
UNT(gRRectIndices); |
1139 target->setIndexSourceToBuffer(indexBuffer); | 1136 target->setIndexSourceToBuffer(indexBuffer); |
1140 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
1141 } | 1138 } |
1142 | 1139 |
1143 return true; | 1140 return true; |
1144 } | 1141 } |
OLD | NEW |