aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/shaders
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2017-11-03 12:54:07 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-11-04 12:37:57 +0000
commit64bb78e1f1ed3eadcfd5482e7857895b999d8e01 (patch)
tree75769172c30ba725945d0cd1334d8da7b9a731fc /src/shaders
parent9d22cd9dbcaa9c7a1818fdc5fd72ec1714d06725 (diff)
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>
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/gradients/SkGradientShader.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp
index 352e468d73..2897f9916b 100644
--- a/src/shaders/gradients/SkGradientShader.cpp
+++ b/src/shaders/gradients/SkGradientShader.cpp
@@ -179,17 +179,29 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
}
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
}
}