| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 inline bool isStroked() const { return fStroke; } | 91 inline bool isStroked() const { return fStroke; } |
| 92 | 92 |
| 93 class GLEffect : public GrGLVertexEffect { | 93 class GLEffect : public GrGLVertexEffect { |
| 94 public: | 94 public: |
| 95 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 95 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 96 : INHERITED (factory) {} | 96 : INHERITED (factory) {} |
| 97 | 97 |
| 98 virtual void emitCode(GrGLFullShaderBuilder* builder, | 98 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 99 const GrDrawEffect& drawEffect, | 99 const GrDrawEffect& drawEffect, |
| 100 EffectKey key, | 100 const GrEffectKey& key, |
| 101 const char* outputColor, | 101 const char* outputColor, |
| 102 const char* inputColor, | 102 const char* inputColor, |
| 103 const TransformedCoordsArray&, | 103 const TransformedCoordsArray&, |
| 104 const TextureSamplerArray& samplers) SK_OVERRIDE { | 104 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 105 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); | 105 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); |
| 106 const char *vsName, *fsName; | 106 const char *vsName, *fsName; |
| 107 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; | 107 builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName)
; |
| 108 | 108 |
| 109 const SkString* attrName = | 109 const SkString* attrName = |
| 110 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); | 110 builder->getEffectAttributeName(drawEffect.getVertexAttribIndice
s()[0]); |
| 111 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 111 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
| 112 | 112 |
| 113 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); | 113 builder->fsCodeAppendf("\tfloat d = length(%s.xy);\n", fsName); |
| 114 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); | 114 builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0
);\n", fsName); |
| 115 if (circleEffect.isStroked()) { | 115 if (circleEffect.isStroked()) { |
| 116 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); | 116 builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0
, 1.0);\n", fsName); |
| 117 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); | 117 builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n"); |
| 118 } | 118 } |
| 119 | 119 |
| 120 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 120 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 121 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 121 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
| 122 } | 122 } |
| 123 | 123 |
| 124 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 124 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 125 GrEffectKeyBuilder* b) { |
| 125 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); | 126 const CircleEdgeEffect& circleEffect = drawEffect.castEffect<CircleE
dgeEffect>(); |
| 126 | 127 b->add32(circleEffect.isStroked()); |
| 127 return circleEffect.isStroked() ? 0x1 : 0x0; | |
| 128 } | 128 } |
| 129 | 129 |
| 130 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} | 130 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE {} |
| 131 | 131 |
| 132 private: | 132 private: |
| 133 typedef GrGLVertexEffect INHERITED; | 133 typedef GrGLVertexEffect INHERITED; |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 | 136 |
| 137 private: | 137 private: |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 201 |
| 202 inline bool isStroked() const { return fStroke; } | 202 inline bool isStroked() const { return fStroke; } |
| 203 | 203 |
| 204 class GLEffect : public GrGLVertexEffect { | 204 class GLEffect : public GrGLVertexEffect { |
| 205 public: | 205 public: |
| 206 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 206 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 207 : INHERITED (factory) {} | 207 : INHERITED (factory) {} |
| 208 | 208 |
| 209 virtual void emitCode(GrGLFullShaderBuilder* builder, | 209 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 210 const GrDrawEffect& drawEffect, | 210 const GrDrawEffect& drawEffect, |
| 211 EffectKey key, | 211 const GrEffectKey& key, |
| 212 const char* outputColor, | 212 const char* outputColor, |
| 213 const char* inputColor, | 213 const char* inputColor, |
| 214 const TransformedCoordsArray&, | 214 const TransformedCoordsArray&, |
| 215 const TextureSamplerArray& samplers) SK_OVERRIDE { | 215 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 216 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); | 216 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); |
| 217 | 217 |
| 218 const char *vsOffsetName, *fsOffsetName; | 218 const char *vsOffsetName, *fsOffsetName; |
| 219 const char *vsRadiiName, *fsRadiiName; | 219 const char *vsRadiiName, *fsRadiiName; |
| 220 | 220 |
| 221 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); | 221 builder->addVarying(kVec2f_GrSLType, "EllipseOffsets", &vsOffsetName
, &fsOffsetName); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 244 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); | 244 builder->fsCodeAppend("\ttest = dot(scaledOffset, scaledOffset)
- 1.0;\n"); |
| 245 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); | 245 builder->fsCodeAppendf("\tgrad = 2.0*scaledOffset*%s.zw;\n", fsR
adiiName); |
| 246 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 246 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
| 247 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); | 247 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); |
| 248 } | 248 } |
| 249 | 249 |
| 250 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 250 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 251 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 251 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
| 252 } | 252 } |
| 253 | 253 |
| 254 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 254 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 255 GrEffectKeyBuilder* b) { |
| 255 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); | 256 const EllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<Ellip
seEdgeEffect>(); |
| 256 | 257 b->add32(ellipseEffect.isStroked()); |
| 257 return ellipseEffect.isStroked() ? 0x1 : 0x0; | |
| 258 } | 258 } |
| 259 | 259 |
| 260 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 260 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 261 } | 261 } |
| 262 | 262 |
| 263 private: | 263 private: |
| 264 typedef GrGLVertexEffect INHERITED; | 264 typedef GrGLVertexEffect INHERITED; |
| 265 }; | 265 }; |
| 266 | 266 |
| 267 private: | 267 private: |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 inline Mode getMode() const { return fMode; } | 340 inline Mode getMode() const { return fMode; } |
| 341 | 341 |
| 342 class GLEffect : public GrGLVertexEffect { | 342 class GLEffect : public GrGLVertexEffect { |
| 343 public: | 343 public: |
| 344 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) | 344 GLEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&) |
| 345 : INHERITED (factory) {} | 345 : INHERITED (factory) {} |
| 346 | 346 |
| 347 virtual void emitCode(GrGLFullShaderBuilder* builder, | 347 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 348 const GrDrawEffect& drawEffect, | 348 const GrDrawEffect& drawEffect, |
| 349 EffectKey key, | 349 const GrEffectKey& key, |
| 350 const char* outputColor, | 350 const char* outputColor, |
| 351 const char* inputColor, | 351 const char* inputColor, |
| 352 const TransformedCoordsArray&, | 352 const TransformedCoordsArray&, |
| 353 const TextureSamplerArray& samplers) SK_OVERRIDE { | 353 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 354 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); | 354 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); |
| 355 | 355 |
| 356 SkAssertResult(builder->enableFeature( | 356 SkAssertResult(builder->enableFeature( |
| 357 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); | 357 GrGLShaderBuilder::kStandardDeriva
tives_GLSLFeature)); |
| 358 | 358 |
| 359 const char *vsOffsetName0, *fsOffsetName0; | 359 const char *vsOffsetName0, *fsOffsetName0; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 "\t 2.0*%s.x*duvdy.x + 2.0*%s.
y*duvdy.y);\n", | 400 "\t 2.0*%s.x*duvdy.x + 2.0*%s.
y*duvdy.y);\n", |
| 401 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); | 401 fsOffsetName1, fsOffsetName1, fsOffsetNam
e1, fsOffsetName1); |
| 402 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); | 402 builder->fsCodeAppend("\tinvlen = inversesqrt(dot(grad, grad));\
n"); |
| 403 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); | 403 builder->fsCodeAppend("\tedgeAlpha *= clamp(0.5+test*invlen, 0.0
, 1.0);\n"); |
| 404 } | 404 } |
| 405 | 405 |
| 406 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 406 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 407 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); | 407 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeA
lpha")).c_str()); |
| 408 } | 408 } |
| 409 | 409 |
| 410 static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrG
LCaps&) { | 410 static void GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&, |
| 411 const DIEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<DIE
llipseEdgeEffect>(); | 411 GrEffectKeyBuilder* b) { |
| 412 const DIEllipseEdgeEffect& ellipseEffect = |
| 413 drawEffect.castEffect<DIEllipseEdgeEffect>(); |
| 412 | 414 |
| 413 return ellipseEffect.getMode(); | 415 b->add32(ellipseEffect.getMode()); |
| 414 } | 416 } |
| 415 | 417 |
| 416 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { | 418 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_
OVERRIDE { |
| 417 } | 419 } |
| 418 | 420 |
| 419 private: | 421 private: |
| 420 typedef GrGLVertexEffect INHERITED; | 422 typedef GrGLVertexEffect INHERITED; |
| 421 }; | 423 }; |
| 422 | 424 |
| 423 private: | 425 private: |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1216 | 1218 |
| 1217 // drop out the middle quad if we're stroked | 1219 // drop out the middle quad if we're stroked |
| 1218 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : | 1220 int indexCnt = isStrokeOnly ? SK_ARRAY_COUNT(gRRectIndices) - 6 : |
| 1219 SK_ARRAY_COUNT(gRRectIndices); | 1221 SK_ARRAY_COUNT(gRRectIndices); |
| 1220 target->setIndexSourceToBuffer(indexBuffer); | 1222 target->setIndexSourceToBuffer(indexBuffer); |
| 1221 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); | 1223 target->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 16, indexCnt, &bou
nds); |
| 1222 } | 1224 } |
| 1223 | 1225 |
| 1224 return true; | 1226 return true; |
| 1225 } | 1227 } |
| OLD | NEW |