diff options
author | 2017-06-19 15:27:47 -0400 | |
---|---|---|
committer | 2017-06-19 19:52:02 +0000 | |
commit | ae7bb04f4c63cee7ae2a3a0e3d81362ae041226a (patch) | |
tree | 9035762b4f662556161984daebf45e7431e87bf2 /src/shaders/gradients | |
parent | 99609bb7ab206055a564d277e97afb2f3dfeb96d (diff) |
Remove non-F32 specializations of Sk4fGradient
We're only using Sk4fGradients for raster pipeline burst mode => dest is
always F32.
Change-Id: If8f0ce257fc9ef36da33602ffd61617628733cfc
Reviewed-on: https://skia-review.googlesource.com/20280
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/shaders/gradients')
-rw-r--r-- | src/shaders/gradients/Sk4fGradientBase.cpp | 47 | ||||
-rw-r--r-- | src/shaders/gradients/Sk4fGradientBase.h | 12 | ||||
-rw-r--r-- | src/shaders/gradients/Sk4fGradientPriv.h | 58 | ||||
-rw-r--r-- | src/shaders/gradients/Sk4fLinearGradient.cpp | 88 | ||||
-rw-r--r-- | src/shaders/gradients/Sk4fLinearGradient.h | 12 | ||||
-rw-r--r-- | src/shaders/gradients/SkLinearGradient.cpp | 13 |
6 files changed, 63 insertions, 167 deletions
diff --git a/src/shaders/gradients/Sk4fGradientBase.cpp b/src/shaders/gradients/Sk4fGradientBase.cpp index bf884ac476..cb0fcd0513 100644 --- a/src/shaders/gradients/Sk4fGradientBase.cpp +++ b/src/shaders/gradients/Sk4fGradientBase.cpp @@ -294,6 +294,8 @@ GradientShaderBase4fContext::GradientShaderBase4fContext(const SkGradientShaderB , fDither(rec.fPaint->isDither()) #endif { + SkASSERT(rec.fPreferredDstType == ContextRec::kPM4f_DstType); + const SkMatrix& inverse = this->getTotalInverse(); fDstToPos.setConcat(shader.fPtsToUnit, inverse); fDstToPosProc = fDstToPos.getMapXYProc(); @@ -315,57 +317,44 @@ GradientShaderBase4fContext::isValid() const { void SkGradientShaderBase:: GradientShaderBase4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count) { - if (fColorsArePremul) { - this->shadePremulSpan<DstType::L32, ApplyPremul::False>(x, y, dst, count); - } else { - this->shadePremulSpan<DstType::L32, ApplyPremul::True>(x, y, dst, count); - } + // This impl only shades to 4f. + SkASSERT(false); } void SkGradientShaderBase:: GradientShaderBase4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count) { if (fColorsArePremul) { - this->shadePremulSpan<DstType::F32, ApplyPremul::False>(x, y, dst, count); + this->shadePremulSpan<ApplyPremul::False>(x, y, dst, count); } else { - this->shadePremulSpan<DstType::F32, ApplyPremul::True>(x, y, dst, count); + this->shadePremulSpan<ApplyPremul::True>(x, y, dst, count); } } -template<DstType dstType, ApplyPremul premul> +template<ApplyPremul premul> void SkGradientShaderBase:: -GradientShaderBase4fContext::shadePremulSpan(int x, int y, - typename DstTraits<dstType, premul>::Type dst[], - int count) const { +GradientShaderBase4fContext::shadePremulSpan(int x, int y, SkPM4f dst[], int count) const { const SkGradientShaderBase& shader = static_cast<const SkGradientShaderBase&>(fShader); switch (shader.fTileMode) { case kClamp_TileMode: - this->shadeSpanInternal<dstType, - premul, - kClamp_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kClamp_TileMode>(x, y, dst, count); break; case kRepeat_TileMode: - this->shadeSpanInternal<dstType, - premul, - kRepeat_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kRepeat_TileMode>(x, y, dst, count); break; case kMirror_TileMode: - this->shadeSpanInternal<dstType, - premul, - kMirror_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kMirror_TileMode>(x, y, dst, count); break; } } -template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> +template<ApplyPremul premul, SkShader::TileMode tileMode> void SkGradientShaderBase:: -GradientShaderBase4fContext::shadeSpanInternal(int x, int y, - typename DstTraits<dstType, premul>::Type dst[], - int count) const { +GradientShaderBase4fContext::shadeSpanInternal(int x, int y, SkPM4f dst[], int count) const { static const int kBufSize = 128; SkScalar ts[kBufSize]; - TSampler<dstType, premul, tileMode> sampler(*this); + TSampler<premul, tileMode> sampler(*this); SkASSERT(count > 0); do { @@ -373,14 +362,14 @@ GradientShaderBase4fContext::shadeSpanInternal(int x, int y, this->mapTs(x, y, ts, n); for (int i = 0; i < n; ++i) { const Sk4f c = sampler.sample(ts[i]); - DstTraits<dstType, premul>::store(c, dst++); + DstTraits<premul>::store(c, dst++); } x += n; count -= n; } while (count > 0); } -template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> +template<ApplyPremul premul, SkShader::TileMode tileMode> class SkGradientShaderBase::GradientShaderBase4fContext::TSampler { public: TSampler(const GradientShaderBase4fContext& ctx) @@ -443,8 +432,8 @@ private: } void loadIntervalData(const Sk4fGradientInterval* i) { - fCb = DstTraits<dstType, premul>::load(i->fCb); - fCg = DstTraits<dstType, premul>::load(i->fCg); + fCb = DstTraits<premul>::load(i->fCb); + fCg = DstTraits<premul>::load(i->fCg); } const GradientShaderBase4fContext& fCtx; diff --git a/src/shaders/gradients/Sk4fGradientBase.h b/src/shaders/gradients/Sk4fGradientBase.h index bd0aab4203..3e83d04c49 100644 --- a/src/shaders/gradients/Sk4fGradientBase.h +++ b/src/shaders/gradients/Sk4fGradientBase.h @@ -82,16 +82,14 @@ private: void addMirrorIntervals(const SkGradientShaderBase&, const Sk4f& componentScale, bool reverse); - template<DstType, ApplyPremul, SkShader::TileMode tileMode> + template<ApplyPremul, SkShader::TileMode tileMode> class TSampler; - template <DstType dstType, ApplyPremul premul> - void shadePremulSpan(int x, int y, typename DstTraits<dstType, premul>::Type[], - int count) const; + template <ApplyPremul premul> + void shadePremulSpan(int x, int y, SkPM4f[], int count) const; - template <DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> - void shadeSpanInternal(int x, int y, typename DstTraits<dstType, premul>::Type[], - int count) const; + template <ApplyPremul premul, SkShader::TileMode tileMode> + void shadeSpanInternal(int x, int y, SkPM4f[], int count) const; }; #endif // Sk4fGradientBase_DEFINED diff --git a/src/shaders/gradients/Sk4fGradientPriv.h b/src/shaders/gradients/Sk4fGradientPriv.h index f18d6ced7b..138bd170c9 100644 --- a/src/shaders/gradients/Sk4fGradientPriv.h +++ b/src/shaders/gradients/Sk4fGradientPriv.h @@ -22,11 +22,6 @@ namespace { enum class ApplyPremul { True, False }; -enum class DstType { - L32, // Linear 32bit. - F32, // Linear float. -}; - template <ApplyPremul> struct PremulTraits; @@ -56,64 +51,19 @@ struct PremulTraits<ApplyPremul::True> { // // - store4x() Store 4 Sk4f values to dest (opportunistic optimization). // -template <DstType, ApplyPremul premul> -struct DstTraits; - -template <ApplyPremul premul> -struct DstTraits<DstType::L32, premul> { - using PM = PremulTraits<premul>; - using Type = SkPMColor; - - // For L32, prescaling by 255 saves a per-pixel multiplication when premul is not needed. - static Sk4f load(const SkPM4f& c) { - return premul == ApplyPremul::False - ? c.to4f_pmorder() * Sk4f(255) - : c.to4f_pmorder(); - } - - static void store(const Sk4f& c, Type* dst) { - if (premul == ApplyPremul::False) { - // c is prescaled by 255, just store. - SkNx_cast<uint8_t>(c).store(dst); - } else { - *dst = Sk4f_toL32(PM::apply(c)); - } - } - - static void store(const Sk4f& c, Type* dst, int n) { - Type pmc; - store(c, &pmc); - sk_memset32(dst, pmc, n); - } - - static void store4x(const Sk4f& c0, const Sk4f& c1, - const Sk4f& c2, const Sk4f& c3, - Type* dst) { - if (premul == ApplyPremul::False) { - Sk4f_ToBytes((uint8_t*)dst, c0, c1, c2, c3); - } else { - store(c0, dst + 0); - store(c1, dst + 1); - store(c2, dst + 2); - store(c3, dst + 3); - } - } -}; - template <ApplyPremul premul> -struct DstTraits<DstType::F32, premul> { +struct DstTraits { using PM = PremulTraits<premul>; - using Type = SkPM4f; static Sk4f load(const SkPM4f& c) { return c.to4f(); } - static void store(const Sk4f& c, Type* dst) { + static void store(const Sk4f& c, SkPM4f* dst) { PM::apply(c).store(dst->fVec); } - static void store(const Sk4f& c, Type* dst, int n) { + static void store(const Sk4f& c, SkPM4f* dst, int n) { const Sk4f pmc = PM::apply(c); for (int i = 0; i < n; ++i) { pmc.store(dst[i].fVec); @@ -122,7 +72,7 @@ struct DstTraits<DstType::F32, premul> { static void store4x(const Sk4f& c0, const Sk4f& c1, const Sk4f& c2, const Sk4f& c3, - Type* dst) { + SkPM4f* dst) { store(c0, dst + 0); store(c1, dst + 1); store(c2, dst + 2); diff --git a/src/shaders/gradients/Sk4fLinearGradient.cpp b/src/shaders/gradients/Sk4fLinearGradient.cpp index 202461cc22..aab1779c70 100644 --- a/src/shaders/gradients/Sk4fLinearGradient.cpp +++ b/src/shaders/gradients/Sk4fLinearGradient.cpp @@ -12,8 +12,8 @@ namespace { -template<DstType dstType, ApplyPremul premul> -void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Type dst[], int n) { +template<ApplyPremul premul> +void ramp(const Sk4f& c, const Sk4f& dc, SkPM4f dst[], int n) { SkASSERT(n > 0); const Sk4f dc2 = dc + dc; @@ -25,7 +25,7 @@ void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Ty Sk4f c3 = c1 + dc2; while (n >= 4) { - DstTraits<dstType, premul>::store4x(c0, c1, c2, c3, dst); + DstTraits<premul>::store4x(c0, c1, c2, c3, dst); dst += 4; c0 = c0 + dc4; @@ -35,12 +35,12 @@ void ramp(const Sk4f& c, const Sk4f& dc, typename DstTraits<dstType, premul>::Ty n -= 4; } if (n & 2) { - DstTraits<dstType, premul>::store(c0, dst++); - DstTraits<dstType, premul>::store(c1, dst++); + DstTraits<premul>::store(c0, dst++); + DstTraits<premul>::store(c1, dst++); c0 = c0 + dc2; } if (n & 1) { - DstTraits<dstType, premul>::store(c0, dst); + DstTraits<premul>::store(c0, dst); } } @@ -143,20 +143,8 @@ SkLinearGradient::LinearGradient4fContext::findInterval(SkScalar fx) const { void SkLinearGradient:: LinearGradient4fContext::shadeSpan(int x, int y, SkPMColor dst[], int count) { - if (!this->isFast()) { - this->INHERITED::shadeSpan(x, y, dst, count); - return; - } - - // TODO: plumb dithering - SkASSERT(count > 0); - if (fColorsArePremul) { - this->shadePremulSpan<DstType::L32, - ApplyPremul::False>(x, y, dst, count); - } else { - this->shadePremulSpan<DstType::L32, - ApplyPremul::True>(x, y, dst, count); - } + // This impl only shades to 4f. + SkASSERT(false); } void SkLinearGradient:: @@ -166,48 +154,35 @@ LinearGradient4fContext::shadeSpan4f(int x, int y, SkPM4f dst[], int count) { return; } - // TONOTDO: plumb dithering SkASSERT(count > 0); if (fColorsArePremul) { - this->shadePremulSpan<DstType::F32, - ApplyPremul::False>(x, y, dst, count); + this->shadePremulSpan<ApplyPremul::False>(x, y, dst, count); } else { - this->shadePremulSpan<DstType::F32, - ApplyPremul::True>(x, y, dst, count); + this->shadePremulSpan<ApplyPremul::True>(x, y, dst, count); } } -template<DstType dstType, ApplyPremul premul> +template<ApplyPremul premul> void SkLinearGradient:: -LinearGradient4fContext::shadePremulSpan(int x, int y, - typename DstTraits<dstType, premul>::Type dst[], - int count) const { +LinearGradient4fContext::shadePremulSpan(int x, int y, SkPM4f dst[], int count) const { const SkLinearGradient& shader = static_cast<const SkLinearGradient&>(fShader); switch (shader.fTileMode) { case kClamp_TileMode: - this->shadeSpanInternal<dstType, - premul, - kClamp_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kClamp_TileMode>(x, y, dst, count); break; case kRepeat_TileMode: - this->shadeSpanInternal<dstType, - premul, - kRepeat_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kRepeat_TileMode>(x, y, dst, count); break; case kMirror_TileMode: - this->shadeSpanInternal<dstType, - premul, - kMirror_TileMode>(x, y, dst, count); + this->shadeSpanInternal<premul, kMirror_TileMode>(x, y, dst, count); break; } } -template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> +template<ApplyPremul premul, SkShader::TileMode tileMode> void SkLinearGradient:: -LinearGradient4fContext::shadeSpanInternal(int x, int y, - typename DstTraits<dstType, premul>::Type dst[], - int count) const { +LinearGradient4fContext::shadeSpanInternal(int x, int y, SkPM4f dst[], int count) const { SkPoint pt; fDstToPosProc(fDstToPos, x + SK_ScalarHalf, @@ -215,12 +190,12 @@ LinearGradient4fContext::shadeSpanInternal(int x, int y, &pt); const SkScalar fx = pinFx<tileMode>(pt.x()); const SkScalar dx = fDstToPos.getScaleX(); - LinearIntervalProcessor<dstType, premul, tileMode> proc(fIntervals->begin(), - fIntervals->end() - 1, - this->findInterval(fx), - fx, - dx, - SkScalarNearlyZero(dx * count)); + LinearIntervalProcessor<premul, tileMode> proc(fIntervals->begin(), + fIntervals->end() - 1, + this->findInterval(fx), + fx, + dx, + SkScalarNearlyZero(dx * count)); while (count > 0) { // What we really want here is SkTPin(advance, 1, count) // but that's a significant perf hit for >> stops; investigate. @@ -235,12 +210,9 @@ LinearGradient4fContext::shadeSpanInternal(int x, int y, || (n == count && proc.currentRampIsZero())); if (proc.currentRampIsZero()) { - DstTraits<dstType, premul>::store(proc.currentColor(), - dst, n); + DstTraits<premul>::store(proc.currentColor(), dst, n); } else { - ramp<dstType, premul>(proc.currentColor(), - proc.currentColorGrad(), - dst, n); + ramp<premul>(proc.currentColor(), proc.currentColorGrad(), dst, n); } proc.advance(SkIntToScalar(n)); @@ -249,7 +221,7 @@ LinearGradient4fContext::shadeSpanInternal(int x, int y, } } -template<DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> +template<ApplyPremul premul, SkShader::TileMode tileMode> class SkLinearGradient:: LinearGradient4fContext::LinearIntervalProcessor { public: @@ -314,8 +286,8 @@ private: void compute_interval_props(SkScalar t) { SkASSERT(in_range(t, fInterval->fT0, fInterval->fT1)); - const Sk4f dc = DstTraits<dstType, premul>::load(fInterval->fCg); - fCc = DstTraits<dstType, premul>::load(fInterval->fCb) + dc * Sk4f(t); + const Sk4f dc = DstTraits<premul>::load(fInterval->fCg); + fCc = DstTraits<premul>::load(fInterval->fCb) + dc * Sk4f(t); fDcDx = dc * fDx; fZeroRamp = fIsVertical || (dc == 0).allTrue(); } @@ -334,8 +306,8 @@ private: // // Avg += C * (t1 - t0) // - const auto c = DstTraits<dstType, premul>::load(i->fCb) - + DstTraits<dstType, premul>::load(i->fCg) * (i->fT0 + i->fT1) * 0.5f; + const auto c = DstTraits<premul>::load(i->fCb) + + DstTraits<premul>::load(i->fCg) * (i->fT0 + i->fT1) * 0.5f; fCc = fCc + c * (i->fT1 - i->fT0); } } diff --git a/src/shaders/gradients/Sk4fLinearGradient.h b/src/shaders/gradients/Sk4fLinearGradient.h index f1c0bb5a30..96af4dfced 100644 --- a/src/shaders/gradients/Sk4fLinearGradient.h +++ b/src/shaders/gradients/Sk4fLinearGradient.h @@ -25,16 +25,14 @@ protected: private: using INHERITED = GradientShaderBase4fContext; - template<DstType, ApplyPremul, TileMode> + template<ApplyPremul, TileMode> class LinearIntervalProcessor; - template <DstType dstType, ApplyPremul premul> - void shadePremulSpan(int x, int y, typename DstTraits<dstType, premul>::Type[], - int count) const; + template <ApplyPremul premul> + void shadePremulSpan(int x, int y, SkPM4f[], int count) const; - template <DstType dstType, ApplyPremul premul, SkShader::TileMode tileMode> - void shadeSpanInternal(int x, int y, typename DstTraits<dstType, premul>::Type[], - int count) const; + template <ApplyPremul premul, SkShader::TileMode tileMode> + void shadeSpanInternal(int x, int y, SkPM4f[], int count) const; const Sk4fGradientInterval* findInterval(SkScalar fx) const; diff --git a/src/shaders/gradients/SkLinearGradient.cpp b/src/shaders/gradients/SkLinearGradient.cpp index 02969bdf3b..e8a68f6f9e 100644 --- a/src/shaders/gradients/SkLinearGradient.cpp +++ b/src/shaders/gradients/SkLinearGradient.cpp @@ -10,9 +10,6 @@ #include "SkLinearGradient.h" #include "SkRefCnt.h" -// define to test the 4f gradient path -// #define FORCE_4F_CONTEXT - static const float kInv255Float = 1.0f / 255; static inline int repeat_8bits(int x) { @@ -39,14 +36,6 @@ static SkMatrix pts_to_unit_matrix(const SkPoint pts[2]) { return matrix; } -static bool use_4f_context(const SkShaderBase::ContextRec& rec, uint32_t flags) { -#ifdef FORCE_4F_CONTEXT - return true; -#else - return rec.fPreferredDstType == SkShaderBase::ContextRec::kPM4f_DstType; -#endif -} - /////////////////////////////////////////////////////////////////////////////// SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc) @@ -77,7 +66,7 @@ void SkLinearGradient::flatten(SkWriteBuffer& buffer) const { SkShaderBase::Context* SkLinearGradient::onMakeContext( const ContextRec& rec, SkArenaAlloc* alloc) const { - return use_4f_context(rec, fGradFlags) + return rec.fPreferredDstType == ContextRec::kPM4f_DstType ? CheckedMakeContext<LinearGradient4fContext>(alloc, *this, rec) : CheckedMakeContext< LinearGradientContext>(alloc, *this, rec); } |