| 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 "GrBezierEffect.h" | 8 #include "GrBezierEffect.h" |
| 9 | 9 |
| 10 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLVertexEffect.h" | 12 #include "gl/GrGLVertexEffect.h" |
| 13 #include "GrTBackendEffectFactory.h" | 13 #include "GrTBackendEffectFactory.h" |
| 14 | 14 |
| 15 class GrGLConicEffect : public GrGLVertexEffect { | 15 class GrGLConicEffect : public GrGLVertexEffect { |
| 16 public: | 16 public: |
| 17 GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 17 GrGLConicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 18 | 18 |
| 19 virtual void emitCode(GrGLFullShaderBuilder* builder, | 19 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 20 const GrDrawEffect& drawEffect, | 20 const GrDrawEffect& drawEffect, |
| 21 EffectKey key, | 21 EffectKey key, |
| 22 const char* outputColor, | 22 const char* outputColor, |
| 23 const char* inputColor, | 23 const GrGLSLExpr4& inputColor, |
| 24 const TransformedCoordsArray&, | 24 const TransformedCoordsArray&, |
| 25 const TextureSamplerArray&) SK_OVERRIDE; | 25 const TextureSamplerArray&) SK_OVERRIDE; |
| 26 | 26 |
| 27 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 27 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
| 28 | 28 |
| 29 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 29 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 GrBezierEdgeType fEdgeType; | 32 GrBezierEdgeType fEdgeType; |
| 33 | 33 |
| 34 typedef GrGLVertexEffect INHERITED; | 34 typedef GrGLVertexEffect INHERITED; |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory, | 37 GrGLConicEffect::GrGLConicEffect(const GrBackendEffectFactory& factory, |
| 38 const GrDrawEffect& drawEffect) | 38 const GrDrawEffect& drawEffect) |
| 39 : INHERITED (factory) { | 39 : INHERITED (factory) { |
| 40 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); | 40 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); |
| 41 fEdgeType = ce.getEdgeType(); | 41 fEdgeType = ce.getEdgeType(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void GrGLConicEffect::emitCode(GrGLFullShaderBuilder* builder, | 44 void GrGLConicEffect::emitCode(GrGLFullShaderBuilder* builder, |
| 45 const GrDrawEffect& drawEffect, | 45 const GrDrawEffect& drawEffect, |
| 46 EffectKey key, | 46 EffectKey key, |
| 47 const char* outputColor, | 47 const char* outputColor, |
| 48 const char* inputColor, | 48 const GrGLSLExpr4& inputColor, |
| 49 const TransformedCoordsArray&, | 49 const TransformedCoordsArray&, |
| 50 const TextureSamplerArray& samplers) { | 50 const TextureSamplerArray& samplers) { |
| 51 const char *vsName, *fsName; | 51 const char *vsName, *fsName; |
| 52 | 52 |
| 53 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", | 53 builder->addVarying(kVec4f_GrSLType, "ConicCoeffs", |
| 54 &vsName, &fsName); | 54 &vsName, &fsName); |
| 55 const SkString* attr0Name = | 55 const SkString* attr0Name = |
| 56 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 56 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 57 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); | 57 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
| 58 | 58 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 104 } |
| 105 case kFillNoAA_GrBezierEdgeType: { | 105 case kFillNoAA_GrBezierEdgeType: { |
| 106 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x - %s.y*%s.z;\n", f
sName, fsName, | 106 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x - %s.y*%s.z;\n", f
sName, fsName, |
| 107 fsName, fsName); | 107 fsName, fsName); |
| 108 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); | 108 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); |
| 109 break; | 109 break; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 | 112 |
| 113 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 113 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 114 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 114 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str()); |
| 115 } | 115 } |
| 116 | 116 |
| 117 GrGLEffect::EffectKey GrGLConicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { | 117 GrGLEffect::EffectKey GrGLConicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { |
| 118 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); | 118 const GrConicEffect& ce = drawEffect.castEffect<GrConicEffect>(); |
| 119 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 119 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 120 } | 120 } |
| 121 | 121 |
| 122 ////////////////////////////////////////////////////////////////////////////// | 122 ////////////////////////////////////////////////////////////////////////////// |
| 123 | 123 |
| 124 GrConicEffect::~GrConicEffect() {} | 124 GrConicEffect::~GrConicEffect() {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 154 ////////////////////////////////////////////////////////////////////////////// | 154 ////////////////////////////////////////////////////////////////////////////// |
| 155 | 155 |
| 156 class GrGLQuadEffect : public GrGLVertexEffect { | 156 class GrGLQuadEffect : public GrGLVertexEffect { |
| 157 public: | 157 public: |
| 158 GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 158 GrGLQuadEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 159 | 159 |
| 160 virtual void emitCode(GrGLFullShaderBuilder* builder, | 160 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 161 const GrDrawEffect& drawEffect, | 161 const GrDrawEffect& drawEffect, |
| 162 EffectKey key, | 162 EffectKey key, |
| 163 const char* outputColor, | 163 const char* outputColor, |
| 164 const char* inputColor, | 164 const GrGLSLExpr4& inputColor, |
| 165 const TransformedCoordsArray&, | 165 const TransformedCoordsArray&, |
| 166 const TextureSamplerArray&) SK_OVERRIDE; | 166 const TextureSamplerArray&) SK_OVERRIDE; |
| 167 | 167 |
| 168 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 168 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
| 169 | 169 |
| 170 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 170 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
| 171 | 171 |
| 172 private: | 172 private: |
| 173 GrBezierEdgeType fEdgeType; | 173 GrBezierEdgeType fEdgeType; |
| 174 | 174 |
| 175 typedef GrGLVertexEffect INHERITED; | 175 typedef GrGLVertexEffect INHERITED; |
| 176 }; | 176 }; |
| 177 | 177 |
| 178 GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory, | 178 GrGLQuadEffect::GrGLQuadEffect(const GrBackendEffectFactory& factory, |
| 179 const GrDrawEffect& drawEffect) | 179 const GrDrawEffect& drawEffect) |
| 180 : INHERITED (factory) { | 180 : INHERITED (factory) { |
| 181 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 181 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
| 182 fEdgeType = ce.getEdgeType(); | 182 fEdgeType = ce.getEdgeType(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void GrGLQuadEffect::emitCode(GrGLFullShaderBuilder* builder, | 185 void GrGLQuadEffect::emitCode(GrGLFullShaderBuilder* builder, |
| 186 const GrDrawEffect& drawEffect, | 186 const GrDrawEffect& drawEffect, |
| 187 EffectKey key, | 187 EffectKey key, |
| 188 const char* outputColor, | 188 const char* outputColor, |
| 189 const char* inputColor, | 189 const GrGLSLExpr4& inputColor, |
| 190 const TransformedCoordsArray&, | 190 const TransformedCoordsArray&, |
| 191 const TextureSamplerArray& samplers) { | 191 const TextureSamplerArray& samplers) { |
| 192 const char *vsName, *fsName; | 192 const char *vsName, *fsName; |
| 193 | 193 |
| 194 const SkString* attrName = | 194 const SkString* attrName = |
| 195 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 195 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 196 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); | 196 builder->fsCodeAppendf("\t\tfloat edgeAlpha;\n"); |
| 197 | 197 |
| 198 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); | 198 builder->addVarying(kVec4f_GrSLType, "HairQuadEdge", &vsName, &fsName); |
| 199 | 199 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 232 } |
| 233 case kFillNoAA_GrBezierEdgeType: { | 233 case kFillNoAA_GrBezierEdgeType: { |
| 234 builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsNa
me, fsName, | 234 builder->fsCodeAppendf("\t\tedgeAlpha = (%s.x*%s.x - %s.y);\n", fsNa
me, fsName, |
| 235 fsName); | 235 fsName); |
| 236 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); | 236 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); |
| 237 break; | 237 break; |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 241 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 242 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 242 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str()); |
| 243 | 243 |
| 244 | 244 |
| 245 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); | 245 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str()); |
| 246 } | 246 } |
| 247 | 247 |
| 248 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { | 248 GrGLEffect::EffectKey GrGLQuadEffect::GenKey(const GrDrawEffect& drawEffect, con
st GrGLCaps&) { |
| 249 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); | 249 const GrQuadEffect& ce = drawEffect.castEffect<GrQuadEffect>(); |
| 250 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 250 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 251 } | 251 } |
| 252 | 252 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 ////////////////////////////////////////////////////////////////////////////// | 285 ////////////////////////////////////////////////////////////////////////////// |
| 286 | 286 |
| 287 class GrGLCubicEffect : public GrGLVertexEffect { | 287 class GrGLCubicEffect : public GrGLVertexEffect { |
| 288 public: | 288 public: |
| 289 GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 289 GrGLCubicEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 290 | 290 |
| 291 virtual void emitCode(GrGLFullShaderBuilder* builder, | 291 virtual void emitCode(GrGLFullShaderBuilder* builder, |
| 292 const GrDrawEffect& drawEffect, | 292 const GrDrawEffect& drawEffect, |
| 293 EffectKey key, | 293 EffectKey key, |
| 294 const char* outputColor, | 294 const char* outputColor, |
| 295 const char* inputColor, | 295 const GrGLSLExpr4& inputColor, |
| 296 const TransformedCoordsArray&, | 296 const TransformedCoordsArray&, |
| 297 const TextureSamplerArray&) SK_OVERRIDE; | 297 const TextureSamplerArray&) SK_OVERRIDE; |
| 298 | 298 |
| 299 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 299 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
| 300 | 300 |
| 301 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} | 301 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE {} |
| 302 | 302 |
| 303 private: | 303 private: |
| 304 GrBezierEdgeType fEdgeType; | 304 GrBezierEdgeType fEdgeType; |
| 305 | 305 |
| 306 typedef GrGLVertexEffect INHERITED; | 306 typedef GrGLVertexEffect INHERITED; |
| 307 }; | 307 }; |
| 308 | 308 |
| 309 GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory, | 309 GrGLCubicEffect::GrGLCubicEffect(const GrBackendEffectFactory& factory, |
| 310 const GrDrawEffect& drawEffect) | 310 const GrDrawEffect& drawEffect) |
| 311 : INHERITED (factory) { | 311 : INHERITED (factory) { |
| 312 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); | 312 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); |
| 313 fEdgeType = ce.getEdgeType(); | 313 fEdgeType = ce.getEdgeType(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 void GrGLCubicEffect::emitCode(GrGLFullShaderBuilder* builder, | 316 void GrGLCubicEffect::emitCode(GrGLFullShaderBuilder* builder, |
| 317 const GrDrawEffect& drawEffect, | 317 const GrDrawEffect& drawEffect, |
| 318 EffectKey key, | 318 EffectKey key, |
| 319 const char* outputColor, | 319 const char* outputColor, |
| 320 const char* inputColor, | 320 const GrGLSLExpr4& inputColor, |
| 321 const TransformedCoordsArray&, | 321 const TransformedCoordsArray&, |
| 322 const TextureSamplerArray& samplers) { | 322 const TextureSamplerArray& samplers) { |
| 323 const char *vsName, *fsName; | 323 const char *vsName, *fsName; |
| 324 | 324 |
| 325 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", | 325 builder->addVarying(kVec4f_GrSLType, "CubicCoeffs", |
| 326 &vsName, &fsName); | 326 &vsName, &fsName); |
| 327 const SkString* attr0Name = | 327 const SkString* attr0Name = |
| 328 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); | 328 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]); |
| 329 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); | 329 builder->vsCodeAppendf("\t%s = %s;\n", vsName, attr0Name->c_str()); |
| 330 | 330 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 case kFillNoAA_GrBezierEdgeType: { | 377 case kFillNoAA_GrBezierEdgeType: { |
| 378 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x*%s.x - %s.y*%s.z;\
n", | 378 builder->fsCodeAppendf("\t\tedgeAlpha = %s.x*%s.x*%s.x - %s.y*%s.z;\
n", |
| 379 fsName, fsName, fsName, fsName, fsName); | 379 fsName, fsName, fsName, fsName, fsName); |
| 380 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); | 380 builder->fsCodeAppend("\t\tedgeAlpha = float(edgeAlpha < 0.0);\n"); |
| 381 break; | 381 break; |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, | 385 builder->fsCodeAppendf("\t%s = %s;\n", outputColor, |
| 386 (GrGLSLExpr4(inputColor) * GrGLSLExpr1("edgeAlpha")).
c_str()); | 386 (inputColor * GrGLSLExpr1("edgeAlpha")).c_str()); |
| 387 } | 387 } |
| 388 | 388 |
| 389 GrGLEffect::EffectKey GrGLCubicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { | 389 GrGLEffect::EffectKey GrGLCubicEffect::GenKey(const GrDrawEffect& drawEffect, co
nst GrGLCaps&) { |
| 390 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); | 390 const GrCubicEffect& ce = drawEffect.castEffect<GrCubicEffect>(); |
| 391 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; | 391 return ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2; |
| 392 } | 392 } |
| 393 | 393 |
| 394 ////////////////////////////////////////////////////////////////////////////// | 394 ////////////////////////////////////////////////////////////////////////////// |
| 395 | 395 |
| 396 GrCubicEffect::~GrCubicEffect() {} | 396 GrCubicEffect::~GrCubicEffect() {} |
| (...skipping 16 matching lines...) Expand all Loading... |
| 413 | 413 |
| 414 GR_DEFINE_EFFECT_TEST(GrCubicEffect); | 414 GR_DEFINE_EFFECT_TEST(GrCubicEffect); |
| 415 | 415 |
| 416 GrEffectRef* GrCubicEffect::TestCreate(SkRandom* random, | 416 GrEffectRef* GrCubicEffect::TestCreate(SkRandom* random, |
| 417 GrContext*, | 417 GrContext*, |
| 418 const GrDrawTargetCaps& caps, | 418 const GrDrawTargetCaps& caps, |
| 419 GrTexture*[]) { | 419 GrTexture*[]) { |
| 420 const GrBezierEdgeType edgeType = static_cast<GrBezierEdgeType>(random->next
ULessThan(3)); | 420 const GrBezierEdgeType edgeType = static_cast<GrBezierEdgeType>(random->next
ULessThan(3)); |
| 421 return GrCubicEffect::Create(edgeType, caps); | 421 return GrCubicEffect::Create(edgeType, caps); |
| 422 } | 422 } |
| OLD | NEW |