Detect explicit uniform gradient positions

When the color stop positions are uniform, the client is allowed to not
specify them (implicit positions, signaled by a null |pos| pointer).
This enables some internal optiomizations and yields improved
rasterization times.

But if the client does pass explicit uniform positions, we currently
treat them as general/non-uniform.

Detect explicit uniform color stop positions at construction time, and
drop them - to ensure optimal treatment downstream.

Change-Id: I32ee86daa652622de2936a6f47acb68b64e0b70a
Reviewed-on: https://skia-review.googlesource.com/67765
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@chromium.org>
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index 352e468..2897f99 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -179,17 +179,29 @@
     }
 
     if (desc.fPos) {
-        SkScalar pos = 0;
+        SkScalar prev = 0;
         SkScalar* origPosPtr = fOrigPos;
-        *origPosPtr++ = pos; // force the first pos to 0
+        *origPosPtr++ = prev; // force the first pos to 0
 
         int startIndex = dummyFirst ? 0 : 1;
         int count = desc.fCount + dummyLast;
+
+        bool uniformStops = true;
+        const SkScalar uniformStep = desc.fPos[startIndex] - prev;
         for (int i = startIndex; i < count; i++) {
             // Pin the last value to 1.0, and make sure pos is monotonic.
-            pos = (i == desc.fCount) ? 1 : SkScalarPin(desc.fPos[i], pos, 1);
-            *origPosPtr++ = pos;
+            auto curr = (i == desc.fCount) ? 1 : SkScalarPin(desc.fPos[i], prev, 1);
+            uniformStops &= SkScalarNearlyEqual(uniformStep, curr - prev);
+
+            *origPosPtr++ = prev = curr;
         }
+
+#ifndef SK_SUPPORT_LEGACY_UNIFORM_GRADIENTS
+        // If the stops are uniform, treat them as implicit.
+        if (uniformStops) {
+            fOrigPos = nullptr;
+        }
+#endif
     }
 }