Index: src/effects/gradients/Sk4fGradientBase.cpp |
diff --git a/src/effects/gradients/Sk4fGradientBase.cpp b/src/effects/gradients/Sk4fGradientBase.cpp |
index e09ba77a04da61e333ab39023c0311ed7fce2230..a22136831d6ec1f233bd4bb0177d2df92e2957bb 100644 |
--- a/src/effects/gradients/Sk4fGradientBase.cpp |
+++ b/src/effects/gradients/Sk4fGradientBase.cpp |
@@ -11,10 +11,13 @@ |
namespace { |
-SkPMColor pack_color(SkColor c, bool premul) { |
- return premul |
- ? SkPreMultiplyColor(c) |
- : SkPackARGB32NoCheck(SkColorGetA(c), SkColorGetR(c), SkColorGetG(c), SkColorGetB(c)); |
+Sk4f pack_color(SkColor c, bool premul, const Sk4f& component_scale) { |
+ const SkColor4f c4f = SkColor4f::FromColor(c); |
+ const Sk4f pm4f = premul |
+ ? c4f.premul().to4f() |
+ : Sk4f{c4f.fR, c4f.fG, c4f.fB, c4f.fA}; |
+ |
+ return pm4f * component_scale; |
} |
template<SkShader::TileMode> |
@@ -117,20 +120,17 @@ private: |
} // anonymous namespace |
SkGradientShaderBase::GradientShaderBase4fContext:: |
-Interval::Interval(SkPMColor c0, SkScalar p0, |
- SkPMColor c1, SkScalar p1, |
- const Sk4f& componentScale) |
+Interval::Interval(const Sk4f& c0, SkScalar p0, |
+ const Sk4f& c1, SkScalar p1) |
: fP0(p0) |
, fP1(p1) |
- , fZeroRamp(c0 == c1) { |
- SkASSERT(p0 != p1); |
+ , fZeroRamp((c0 == c1).allTrue()) { |
- const Sk4f c4f0 = SkPM4f::FromPMColor(c0).to4f() * componentScale; |
- const Sk4f c4f1 = SkPM4f::FromPMColor(c1).to4f() * componentScale; |
- const Sk4f dc4f = (c4f1 - c4f0) / (p1 - p0); |
+ SkASSERT(p0 != p1); |
+ const Sk4f dc = (c1 - c0) / (p1 - p0); |
- c4f0.store(&fC0.fVec); |
- dc4f.store(&fDc.fVec); |
+ c0.store(&fC0.fVec); |
+ dc.store(&fDc.fVec); |
} |
SkGradientShaderBase:: |
@@ -216,12 +216,11 @@ GradientShaderBase4fContext::buildIntervals(const SkGradientShaderBase& shader, |
if (shader.fTileMode == SkShader::kClamp_TileMode) { |
// synthetic edge interval: -/+inf .. P0 |
- const SkPMColor clamp_color = pack_color(shader.fOrigColors[first_index], |
- fColorsArePremul); |
+ const Sk4f clamp_color = pack_color(shader.fOrigColors[first_index], |
+ fColorsArePremul, componentScale); |
const SkScalar clamp_pos = reverse ? SK_ScalarMax : SK_ScalarMin; |
fIntervals.emplace_back(clamp_color, clamp_pos, |
- clamp_color, first_pos, |
- componentScale); |
+ clamp_color, first_pos); |
} else if (shader.fTileMode == SkShader::kMirror_TileMode && reverse) { |
// synthetic mirror intervals injected before main intervals: (2 .. 1] |
addMirrorIntervals(shader, componentScale, false); |
@@ -234,21 +233,19 @@ GradientShaderBase4fContext::buildIntervals(const SkGradientShaderBase& shader, |
iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, SkScalar p1) { |
SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == p0); |
- fIntervals.emplace_back(pack_color(c0, fColorsArePremul), |
+ fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale), |
p0, |
- pack_color(c1, fColorsArePremul), |
- p1, |
- componentScale); |
+ pack_color(c1, fColorsArePremul, componentScale), |
+ p1); |
}); |
if (shader.fTileMode == SkShader::kClamp_TileMode) { |
// synthetic edge interval: Pn .. +/-inf |
- const SkPMColor clamp_color = |
- pack_color(shader.fOrigColors[last_index], fColorsArePremul); |
+ const Sk4f clamp_color = pack_color(shader.fOrigColors[last_index], |
+ fColorsArePremul, componentScale); |
const SkScalar clamp_pos = reverse ? SK_ScalarMin : SK_ScalarMax; |
fIntervals.emplace_back(clamp_color, last_pos, |
- clamp_color, clamp_pos, |
- componentScale); |
+ clamp_color, clamp_pos); |
} else if (shader.fTileMode == SkShader::kMirror_TileMode && !reverse) { |
// synthetic mirror intervals injected after main intervals: [1 .. 2) |
addMirrorIntervals(shader, componentScale, true); |
@@ -265,11 +262,10 @@ GradientShaderBase4fContext::addMirrorIntervals(const SkGradientShaderBase& shad |
iter.iterate([this, &componentScale] (SkColor c0, SkColor c1, SkScalar p0, SkScalar p1) { |
SkASSERT(fIntervals.empty() || fIntervals.back().fP1 == 2 - p0); |
- fIntervals.emplace_back(pack_color(c0, fColorsArePremul), |
+ fIntervals.emplace_back(pack_color(c0, fColorsArePremul, componentScale), |
2 - p0, |
- pack_color(c1, fColorsArePremul), |
- 2 - p1, |
- componentScale); |
+ pack_color(c1, fColorsArePremul, componentScale), |
+ 2 - p1); |
}); |
} |