| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 class GLEffect : public GrGLVertexEffect { | 92 class GLEffect : public GrGLVertexEffect { |
| 93 public: | 93 public: |
| 94 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 94 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 95 : INHERITED (factory) {} | 95 : INHERITED (factory) {} |
| 96 | 96 |
| 97 virtual void emitCode(GrGLFullShaderBuilder* builder, | 97 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 98 const GrDrawEffect& drawEffect, | 98 const GrDrawEffect& drawEffect, |
| 99 EffectKey key, | 99 EffectKey key, |
| 100 const char* outputColor, | 100 const char* outputColor, |
| 101 const char* inputColor, | 101 const GrGLSLExpr4& inputColor, |
| 102 const TransformedCoordsArray&, | 102 const TransformedCoordsArray&, |
| 103 const TextureSamplerArray& samplers) SK_OVERRIDE { | 103 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 104 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); | 104 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); |
| 105 const char *vsName, *fsName; | 105 const char *vsName, *fsName; |
| 106 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; | 106 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; |
| 107 | 107 |
| 108 const SkString* attrName = | 108 const SkString* attrName = |
| 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 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 119 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 120 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 120 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str
()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 123 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 124 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); | 124 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); |
| 125 | 125 |
| 126 return circleEffect.isStroked() ? 0x1 : 0x0; | 126 return circleEffect.isStroked() ? 0x1 : 0x0; |
| 127 } | 127 } |
| 128 | 128 |
| 129 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 129 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 130 | 130 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 | 202 |
| 203 class GLEffect : public GrGLVertexEffect { | 203 class GLEffect : public GrGLVertexEffect { |
| 204 public: | 204 public: |
| 205 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 205 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 206 : INHERITED (factory) {} | 206 : INHERITED (factory) {} |
| 207 | 207 |
| 208 virtual void emitCode(GrGLFullShaderBuilder* builder, | 208 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 209 const GrDrawEffect& drawEffect, | 209 const GrDrawEffect& drawEffect, |
| 210 EffectKey key, | 210 EffectKey key, |
| 211 const char* outputColor, | 211 const char* outputColor, |
| 212 const char* inputColor, | 212 const GrGLSLExpr4& inputColor, |
| 213 const TransformedCoordsArray&, | 213 const TransformedCoordsArray&, |
| 214 const TextureSamplerArray& samplers) SK_OVERRIDE { | 214 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 215 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); | 215 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); |
| 216 | 216 |
| 217 const char *vsOffsetName, *fsOffsetName; | 217 const char *vsOffsetName, *fsOffsetName; |
| 218 const char *vsRadiiName, *fsRadiiName; | 218 const char *vsRadiiName, *fsRadiiName; |
| 219 | 219 |
| 220 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); | 220 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); |
| 221 const SkString* attr0Name = | 221 const SkString* attr0Name = |
| 222 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); | 222 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 242 // for inner curve | 242 // for inner curve |
| 243 if (ellipseEffect.isStroked()) { | 243 if (ellipseEffect.isStroked()) { |
| 244 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN
ame, fsRadiiName); | 244 builder->fsCodeAppendf("\tscaledOffset = %s*%s.zw;\n", fsOffsetN
ame, fsRadiiName); |
| 245 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); | 245 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); |
| 246 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); | 246 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); |
| 247 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 247 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
| 248 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"); |
| 249 } | 249 } |
| 250 | 250 |
| 251 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 251 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 252 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 252 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str
()); |
| 253 } | 253 } |
| 254 | 254 |
| 255 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 255 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 256 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); | 256 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); |
| 257 | 257 |
| 258 return ellipseEffect.isStroked() ? 0x1 : 0x0; | 258 return ellipseEffect.isStroked() ? 0x1 : 0x0; |
| 259 } | 259 } |
| 260 | 260 |
| 261 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 261 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 262 } | 262 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 342 |
| 343 class GLEffect : public GrGLVertexEffect { | 343 class GLEffect : public GrGLVertexEffect { |
| 344 public: | 344 public: |
| 345 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 345 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 346 : INHERITED (factory) {} | 346 : INHERITED (factory) {} |
| 347 | 347 |
| 348 virtual void emitCode(GrGLFullShaderBuilder* builder, | 348 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 349 const GrDrawEffect& drawEffect, | 349 const GrDrawEffect& drawEffect, |
| 350 EffectKey key, | 350 EffectKey key, |
| 351 const char* outputColor, | 351 const char* outputColor, |
| 352 const char* inputColor, | 352 const GrGLSLExpr4& inputColor, |
| 353 const TransformedCoordsArray&, | 353 const TransformedCoordsArray&, |
| 354 const TextureSamplerArray& samplers) SK_OVERRIDE { | 354 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 355 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); | 355 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); |
| 356 | 356 |
| 357 SkAssertResult(builder->enableFeature( | 357 SkAssertResult(builder->enableFeature( |
| 358 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | 358 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); |
| 359 | 359 |
| 360 const char *vsOffsetName0, *fsOffsetName0; | 360 const char *vsOffsetName0, *fsOffsetName0; |
| 361 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets0", | 361 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets0", |
| 362 &vsOffsetName0, &fsOffsetName0); | 362 &vsOffsetName0, &fsOffsetName0); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 builder->fsCodeAppendf("\tduvdx = dFdx(%s);\n", fsOffsetName1); | 400 builder->fsCodeAppendf("\tduvdx = dFdx(%s);\n", fsOffsetName1); |
| 401 builder->fsCodeAppendf("\tduvdy = dFdy(%s);\n", fsOffsetName1); | 401 builder->fsCodeAppendf("\tduvdy = dFdy(%s);\n", fsOffsetName1); |
| 402 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" |
| 403 "\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", |
| 404 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); | 404 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); |
| 405 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 405 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
| 406 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"); |
| 407 } | 407 } |
| 408 | 408 |
| 409 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 409 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 410 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 410 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str
()); |
| 411 } | 411 } |
| 412 | 412 |
| 413 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 413 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { |
| 414 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); | 414 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); |
| 415 | 415 |
| 416 return ellipseEffect.getMode(); | 416 return ellipseEffect.getMode(); |
| 417 } | 417 } |
| 418 | 418 |
| 419 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 419 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 420 } | 420 } |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 } | 1132 } |
| 1133 | 1133 |
| 1134 // drop out the middle quad if we're stroked | 1134 // drop out the middle quad if we're stroked |
| 1135 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); |
| 1136 target->setIndexSourceToBuffer(indexBuffer); | 1136 target->setIndexSourceToBuffer(indexBuffer); |
| 1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1137 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 return true; | 1140 return true; |
| 1141 } | 1141 } |
| OLD | NEW |