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 "SkArithmeticMode.h" | 8 #include "SkArithmeticMode.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 EffectKey key, | 321 EffectKey key, |
322 const char* outputColor, | 322 const char* outputColor, |
323 const char* inputColor, | 323 const char* inputColor, |
324 const TextureSamplerArray& samplers) { | 324 const TextureSamplerArray& samplers) { |
325 const char* dstColor = builder->dstColor(); | 325 const char* dstColor = builder->dstColor(); |
326 GrAssert(NULL != dstColor); | 326 GrAssert(NULL != dstColor); |
327 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 327 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
328 kVec4f_GrSLType, "k"); | 328 kVec4f_GrSLType, "k"); |
329 const char* kUni = builder->getUniformCStr(fKUni); | 329 const char* kUni = builder->getUniformCStr(fKUni); |
330 | 330 |
331 const char* srcColor = "srcColor"; | |
332 | |
333 // We don't try to optimize for this case at all | 331 // We don't try to optimize for this case at all |
334 if (NULL == inputColor) { | 332 if (NULL == inputColor) { |
335 builder->fsCodeAppendf("\t\tconst vec4 srcColor = %s;\n", GrGLSLOnesVecf
(4)); | 333 builder->fsCodeAppendf("\t\tconst vec4 src = %s;\n", GrGLSLOnesVecf(4)); |
336 } else { | 334 } else { |
337 builder->fsCodeAppendf("\t\tvec4 srcColor = %s;\n", inputColor); | 335 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); |
338 builder->fsCodeAppendf("\t\tsrcColor.rgb = clamp(srcColor.rgb / srcColor
.a, 0.0, 1.0);\n"); | 336 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1.0);\
n"); |
339 } | 337 } |
340 | 338 |
341 builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb / %s.a, 0.0, 1.0);\n", dst
Color, dstColor, dstColor); | 339 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); |
| 340 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\n"); |
342 | 341 |
343 builder->fsCodeAppendf("\t\t%s = %s.x * %s * %s + %s.y * %s + %s.z * %s + %s
.w;\n", outputColor, kUni, srcColor, dstColor, kUni, srcColor, kUni, dstColor, k
Uni); | 342 builder->fsCodeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); |
344 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); | 343 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); |
345 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor); | 344 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor); |
346 } | 345 } |
347 | 346 |
348 void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { | 347 void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { |
349 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); | 348 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); |
350 uman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 349 uman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
351 } | 350 } |
352 | 351 |
353 GrGLEffect::EffectKey GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffec
t, const GrGLCaps&) { | 352 GrGLEffect::EffectKey GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffec
t, const GrGLCaps&) { |
(...skipping 26 matching lines...) Expand all Loading... |
380 SkScalarToFloat(fK[3])); | 379 SkScalarToFloat(fK[3])); |
381 } | 380 } |
382 return true; | 381 return true; |
383 } | 382 } |
384 | 383 |
385 #endif | 384 #endif |
386 | 385 |
387 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) | 386 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) |
388 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) | 387 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) |
389 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 388 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |