Fix 4f gradient swizzle post http://crrev.com/1774523002

* store interval colors in pm4f-natural/RGBA order
* swizzle to dst order during interval advance

Also remove an unused Interval ctor.

R=reed@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1770153002

Review URL: https://codereview.chromium.org/1770153002
This commit is contained in:
fmalita 2016-03-08 10:20:49 -08:00 committed by Commit bot
parent 93bb080503
commit d8a4f77211
3 changed files with 20 additions and 20 deletions

View File

@ -28,24 +28,14 @@ Interval::Interval(SkPMColor c0, SkScalar p0,
, fZeroRamp(c0 == c1) {
SkASSERT(p0 != p1);
const Sk4f c4f0 = SkNx_cast<float>(Sk4b::Load(&c0)) * componentScale;
const Sk4f c4f1 = SkNx_cast<float>(Sk4b::Load(&c1)) * componentScale;
const Sk4f c4f0 = SkPM4f::FromPMColor(c0).to4f() * componentScale;
const Sk4f c4f1 = SkPM4f::FromPMColor(c1).to4f() * componentScale;
const Sk4f dc4f = (c4f1 - c4f0) / (p1 - p0);
c4f0.store(&fC0.fVec);
dc4f.store(&fDc.fVec);
}
SkGradientShaderBase::GradientShaderBase4fContext::
Interval::Interval(const Sk4f& c0, const Sk4f& dc,
SkScalar p0, SkScalar p1)
: fP0(p0)
, fP1(p1)
, fZeroRamp((dc == 0).allTrue()) {
c0.store(fC0.fVec);
dc.store(fDc.fVec);
}
bool SkGradientShaderBase::GradientShaderBase4fContext::
Interval::contains(SkScalar fx) const {
return in_range(fx, fP0, fP1);

View File

@ -29,8 +29,6 @@ protected:
Interval(SkPMColor c0, SkScalar p0,
SkPMColor c1, SkScalar p1,
const Sk4f& componentScale);
Interval(const Sk4f& c0, const Sk4f& dc,
SkScalar p0, SkScalar p1);
bool isZeroRamp() const { return fZeroRamp; }

View File

@ -161,6 +161,19 @@ float dst_component_scale<SkPMColor>() {
return 255;
}
template<typename DstType>
Sk4f dst_swizzle(const SkPM4f&);
template<>
Sk4f dst_swizzle<SkPM4f>(const SkPM4f& c) {
return c.to4f();
}
template<>
Sk4f dst_swizzle<SkPMColor>(const SkPM4f& c) {
return c.to4f_pmorder();
}
SkPMColor pack_color(SkColor c, bool premul) {
return premul
? SkPreMultiplyColor(c)
@ -304,11 +317,10 @@ LinearGradient4fContext::LinearGradient4fContext(const SkLinearGradient& shader,
SkASSERT(shader.fColorCount > 1);
SkASSERT(shader.fOrigColors);
const float kInv255Float = 1.0f / 255;
const float paintAlpha = rec.fPaint->getAlpha() * kInv255Float;
const float paintAlpha = rec.fPaint->getAlpha() * (1.0f / 255);
const Sk4f componentScale = fColorsArePremul
? Sk4f(paintAlpha * kInv255Float)
: Sk4f(kInv255Float, kInv255Float, kInv255Float, paintAlpha * kInv255Float);
? Sk4f(paintAlpha)
: Sk4f(1.0f, 1.0f, 1.0f, paintAlpha);
const bool dx_is_pos = fDstToPos.getScaleX() >= 0;
const int first_index = dx_is_pos ? 0 : shader.fColorCount - 1;
const int last_index = shader.fColorCount - 1 - first_index;
@ -562,8 +574,8 @@ public:
private:
void compute_interval_props(SkScalar t) {
fDc = Sk4f::Load(fInterval->fDc.fVec);
fCc = Sk4f::Load(fInterval->fC0.fVec);
fDc = dst_swizzle<DstType>(fInterval->fDc);
fCc = dst_swizzle<DstType>(fInterval->fC0);
fCc = fCc + fDc * Sk4f(t);
fCc = fCc * fDstComponentScale;
fDcDx = fDc * fDstComponentScale * Sk4f(fDx);