Relocate gradient negative fract() workaround to GLSLCodeGenerator

Change-Id: If5aba5b266f86f677b6e63b0f79792f1d3213336
Reviewed-on: https://skia-review.googlesource.com/32202
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/src/sksl/SkSLGLSLCodeGenerator.cpp b/src/sksl/SkSLGLSLCodeGenerator.cpp
index 69d3028..64527a0 100644
--- a/src/sksl/SkSLGLSLCodeGenerator.cpp
+++ b/src/sksl/SkSLGLSLCodeGenerator.cpp
@@ -234,6 +234,18 @@
             return;
         }
     }
+    if (!fProgram.fSettings.fCaps->canUseFractForNegativeValues() && c.fFunction.fName == "fract" &&
+        c.fFunction.fBuiltin) {
+        ASSERT(c.fArguments.size() == 1);
+
+        this->write("(0.5 - sign(");
+        this->writeExpression(*c.fArguments[0], kSequence_Precedence);
+        this->write(") * (0.5 - fract(abs(");
+        this->writeExpression(*c.fArguments[0], kSequence_Precedence);
+        this->write("))))");
+
+        return;
+    }
     if (fProgram.fSettings.fCaps->mustForceNegatedAtanParamToFloat() &&
         c.fFunction.fName == "atan" &&
         c.fFunction.fBuiltin && c.fArguments.size() == 2 &&