| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 class GrGLArithmeticEffect : public GrGLEffect { | 239 class GrGLArithmeticEffect : public GrGLEffect { |
| 240 public: | 240 public: |
| 241 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 241 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 242 virtual ~GrGLArithmeticEffect(); | 242 virtual ~GrGLArithmeticEffect(); |
| 243 | 243 |
| 244 virtual void emitCode(GrGLShaderBuilder*, | 244 virtual void emitCode(GrGLShaderBuilder*, |
| 245 const GrDrawEffect&, | 245 const GrDrawEffect&, |
| 246 EffectKey, | 246 EffectKey, |
| 247 const char* outputColor, | 247 const char* outputColor, |
| 248 const char* inputColor, | 248 const GrGLSLExpr4& inputColor, |
| 249 const TransformedCoordsArray&, | 249 const TransformedCoordsArray&, |
| 250 const TextureSamplerArray&) SK_OVERRIDE; | 250 const TextureSamplerArray&) SK_OVERRIDE; |
| 251 | 251 |
| 252 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 252 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 253 | 253 |
| 254 private: | 254 private: |
| 255 GrGLUniformManager::UniformHandle fKUni; | 255 GrGLUniformManager::UniformHandle fKUni; |
| 256 | 256 |
| 257 typedef GrGLEffect INHERITED; | 257 typedef GrGLEffect INHERITED; |
| 258 }; | 258 }; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 : INHERITED(factory) { | 337 : INHERITED(factory) { |
| 338 } | 338 } |
| 339 | 339 |
| 340 GrGLArithmeticEffect::~GrGLArithmeticEffect() { | 340 GrGLArithmeticEffect::~GrGLArithmeticEffect() { |
| 341 } | 341 } |
| 342 | 342 |
| 343 void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder, | 343 void GrGLArithmeticEffect::emitCode(GrGLShaderBuilder* builder, |
| 344 const GrDrawEffect& drawEffect, | 344 const GrDrawEffect& drawEffect, |
| 345 EffectKey key, | 345 EffectKey key, |
| 346 const char* outputColor, | 346 const char* outputColor, |
| 347 const char* inputColor, | 347 const GrGLSLExpr4& inputColor, |
| 348 const TransformedCoordsArray& coords, | 348 const TransformedCoordsArray& coords, |
| 349 const TextureSamplerArray& samplers) { | 349 const TextureSamplerArray& samplers) { |
| 350 | 350 |
| 351 GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backg
roundTexture(); | 351 GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backg
roundTexture(); |
| 352 const char* dstColor; | 352 const char* dstColor; |
| 353 if (backgroundTex) { | 353 if (backgroundTex) { |
| 354 builder->fsCodeAppend("\t\tvec4 bgColor = "); | 354 builder->fsCodeAppend("\t\tvec4 bgColor = "); |
| 355 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); | 355 builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); |
| 356 builder->fsCodeAppendf(";\n"); | 356 builder->fsCodeAppendf(";\n"); |
| 357 dstColor = "bgColor"; | 357 dstColor = "bgColor"; |
| 358 } else { | 358 } else { |
| 359 dstColor = builder->dstColor(); | 359 dstColor = builder->dstColor(); |
| 360 } | 360 } |
| 361 | 361 |
| 362 SkASSERT(NULL != dstColor); | 362 SkASSERT(NULL != dstColor); |
| 363 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | 363 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
| 364 kVec4f_GrSLType, "k"); | 364 kVec4f_GrSLType, "k"); |
| 365 const char* kUni = builder->getUniformCStr(fKUni); | |
| 366 | 365 |
| 367 // We don't try to optimize for this case at all | 366 GrGLSLExpr4 src; |
| 368 if (NULL == inputColor) { | 367 if (gUseUnpremul) { |
| 369 builder->fsCodeAppendf("\t\tconst vec4 src = vec4(1);\n"); | 368 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor.c_str()); |
| 369 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1.0);\
n"); |
| 370 src = GrGLSLExpr4("src"); |
| 370 } else { | 371 } else { |
| 371 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); | 372 src = inputColor; |
| 372 if (gUseUnpremul) { | |
| 373 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1.
0);\n"); | |
| 374 } | |
| 375 } | 373 } |
| 376 | 374 |
| 377 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); | 375 GrGLSLExpr4 dst; |
| 378 if (gUseUnpremul) { | 376 if (gUseUnpremul) { |
| 377 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); |
| 379 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\
n"); | 378 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\
n"); |
| 379 dst = GrGLSLExpr4("dst"); |
| 380 } else { |
| 381 dst = GrGLSLExpr4(dstColor); |
| 380 } | 382 } |
| 381 | 383 |
| 382 builder->fsCodeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); | 384 GrGLSLExpr4 kExpr(builder->getUniformCStr(fKUni)); |
| 385 builder->fsCodeAppendf("\t\t%s = %s;\n", outputColor, |
| 386 (kExpr.x() * inputColor * dst + |
| 387 kExpr.y() * src + |
| 388 kExpr.z() * dst + |
| 389 kExpr.w()).c_str()); |
| 390 |
| 383 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); | 391 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); |
| 384 if (gUseUnpremul) { | 392 if (gUseUnpremul) { |
| 385 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); | 393 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); |
| 386 } else { | 394 } else { |
| 387 builder->fsCodeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); | 395 builder->fsCodeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); |
| 388 } | 396 } |
| 389 } | 397 } |
| 390 | 398 |
| 391 void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { | 399 void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { |
| 392 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); | 400 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 421 background); | 429 background); |
| 422 } | 430 } |
| 423 return true; | 431 return true; |
| 424 } | 432 } |
| 425 | 433 |
| 426 #endif | 434 #endif |
| 427 | 435 |
| 428 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) | 436 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) |
| 429 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) | 437 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) |
| 430 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 438 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |