Guard against D3D NaN/Infinity literals bug in color burn

Bug: skia:6857
Change-Id: Ibbbdd70483502d9e21429f86d3183e55bc007dd6
Reviewed-on: https://skia-review.googlesource.com/30101
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
This commit is contained in:
Brian Osman 2017-08-02 13:00:36 -04:00 committed by Skia Commit-Bot
parent 8289306771
commit 1a39d3fb4e

View File

@ -70,6 +70,12 @@ static void color_burn_component(GrGLSLFragmentBuilder* fsBuilder,
const char* src,
const char* dst,
const char component) {
const char* divisorGuard = "";
const GrShaderCaps* shaderCaps = fsBuilder->getProgramBuilder()->shaderCaps();
if (shaderCaps->mustGuardDivisionEvenAfterExplicitZeroCheck()) {
divisorGuard = "+ 0.00000001";
}
fsBuilder->codeAppendf("if (%s.a == %s.%c) {", dst, dst, component);
fsBuilder->codeAppendf("%s.%c = %s.a * %s.a + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
final, component, src, dst, src, component, dst, dst, component,
@ -78,8 +84,8 @@ static void color_burn_component(GrGLSLFragmentBuilder* fsBuilder,
fsBuilder->codeAppendf("%s.%c = %s.%c * (1.0 - %s.a);",
final, component, dst, component, src);
fsBuilder->codeAppend("} else {");
fsBuilder->codeAppendf("float d = max(0.0, %s.a - (%s.a - %s.%c) * %s.a / %s.%c);",
dst, dst, dst, component, src, src, component);
fsBuilder->codeAppendf("float d = max(0.0, %s.a - (%s.a - %s.%c) * %s.a / (%s.%c %s));",
dst, dst, dst, component, src, src, component, divisorGuard);
fsBuilder->codeAppendf("%s.%c = %s.a * d + %s.%c * (1.0 - %s.a) + %s.%c * (1.0 - %s.a);",
final, component, src, src, component, dst, dst, component, src);
fsBuilder->codeAppend("}");