From 0340df5b3698aff1c9540fcdbc3dafd9d5ddb0b0 Mon Sep 17 00:00:00 2001 From: mtklein Date: Tue, 31 Mar 2015 08:17:00 -0700 Subject: [PATCH] back to Sk4f for SkPMColor #floats BUG=skia: BUG=skia:3592 Review URL: https://codereview.chromium.org/1047823002 --- bench/PMFloatBench.cpp | 4 ++-- src/core/SkPMFloat.h | 10 +++++----- src/effects/SkColorMatrixFilter.cpp | 28 ++++++++++++++-------------- src/opts/SkPMFloat_SSSE3.h | 2 +- src/opts/SkPMFloat_neon.h | 2 +- tests/PMFloatTest.cpp | 6 +++--- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/bench/PMFloatBench.cpp b/bench/PMFloatBench.cpp index fd0d232d2a..09819e9962 100644 --- a/bench/PMFloatBench.cpp +++ b/bench/PMFloatBench.cpp @@ -103,7 +103,7 @@ struct PMFloatGradientBench : public Benchmark { SkPMColor fDevice[100]; void onDraw(const int loops, SkCanvas*) override { - Sk4s c0 = SkPMFloat::FromARGB(255, 255, 0, 0), + Sk4f c0 = SkPMFloat::FromARGB(255, 255, 0, 0), c1 = SkPMFloat::FromARGB(255, 0, 0, 255), dc = c1 - c0, fx(0.1f), @@ -112,7 +112,7 @@ struct PMFloatGradientBench : public Benchmark { dcdx4(dcdx+dcdx+dcdx+dcdx); for (int n = 0; n < loops; n++) { - Sk4s a = c0 + dc*fx + Sk4s(0.5f), // The +0.5f lets us call trunc() instead of get(). + Sk4f a = c0 + dc*fx + Sk4f(0.5f), // The +0.5f lets us call trunc() instead of get(). b = a + dcdx, c = b + dcdx, d = c + dcdx; diff --git a/src/core/SkPMFloat.h b/src/core/SkPMFloat.h index 27f6f78f26..3147879458 100644 --- a/src/core/SkPMFloat.h +++ b/src/core/SkPMFloat.h @@ -34,9 +34,9 @@ public: #endif - // Freely autoconvert between SkPMFloat and Sk4s. - /*implicit*/ SkPMFloat(const Sk4s& fs) { fColors = fs; } - /*implicit*/ operator Sk4s() const { return fColors; } + // Freely autoconvert between SkPMFloat and Sk4f. + /*implicit*/ SkPMFloat(const Sk4f& fs) { fColors = fs; } + /*implicit*/ operator Sk4f() const { return fColors; } float a() const { return fColors[SK_A32_SHIFT / 8]; } float r() const { return fColors[SK_R32_SHIFT / 8]; } @@ -65,11 +65,11 @@ public: } private: - Sk4s fColors; + Sk4f fColors; }; #ifdef SKNX_NO_SIMD - // Platform implementations of SkPMFloat assume Sk4s uses SSE or NEON. _none is generic. + // Platform implementations of SkPMFloat assume Sk4f uses SSE or NEON. _none is generic. #include "../opts/SkPMFloat_none.h" #else #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3 diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index c2d4e48c75..fc8aba258e 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -255,9 +255,9 @@ uint32_t SkColorMatrixFilter::getFlags() const { */ static const float gInv255 = 0.0039215683f; // (1.0f / 255) - ULP == SkBits2Float(0x3B808080) -static Sk4s premul(const Sk4s& x) { +static Sk4f premul(const Sk4f& x) { float scale = SkPMFloat(x).a() * gInv255; - Sk4s pm = x * Sk4s(scale, scale, scale, 1); + Sk4f pm = x * Sk4f(scale, scale, scale, 1); #ifdef SK_DEBUG SkPMFloat pmf(pm); @@ -267,9 +267,9 @@ static Sk4s premul(const Sk4s& x) { return pm; } -static Sk4s unpremul(const SkPMFloat& pm) { +static Sk4f unpremul(const SkPMFloat& pm) { float scale = 255 / pm.a(); // candidate for fast/approx invert? - return Sk4s(pm) * Sk4s(scale, scale, scale, 1); + return Sk4f(pm) * Sk4f(scale, scale, scale, 1); } static Sk4f clamp_0_255(const Sk4f& value) { @@ -292,11 +292,11 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor #endif if (use_floats) { - const Sk4s c0 = Sk4s::Load(fTranspose + 0); - const Sk4s c1 = Sk4s::Load(fTranspose + 4); - const Sk4s c2 = Sk4s::Load(fTranspose + 8); - const Sk4s c3 = Sk4s::Load(fTranspose + 12); - const Sk4s c4 = Sk4s::Load(fTranspose + 16); // translates + const Sk4f c0 = Sk4f::Load(fTranspose + 0); + const Sk4f c1 = Sk4f::Load(fTranspose + 4); + const Sk4f c2 = Sk4f::Load(fTranspose + 8); + const Sk4f c3 = Sk4f::Load(fTranspose + 12); + const Sk4f c4 = Sk4f::Load(fTranspose + 16); // translates // todo: we could cache this in the constructor... SkPMColor matrix_translate_pmcolor = SkPMFloat(premul(clamp_0_255(c4))).clamped(); @@ -314,13 +314,13 @@ void SkColorMatrixFilter::filterSpan(const SkPMColor src[], int count, SkPMColor srcf = unpremul(srcf); } - Sk4s r4 = Sk4s(srcf.r()); - Sk4s g4 = Sk4s(srcf.g()); - Sk4s b4 = Sk4s(srcf.b()); - Sk4s a4 = Sk4s(srcf.a()); + Sk4f r4 = Sk4f(srcf.r()); + Sk4f g4 = Sk4f(srcf.g()); + Sk4f b4 = Sk4f(srcf.b()); + Sk4f a4 = Sk4f(srcf.a()); // apply matrix - Sk4s dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4; + Sk4f dst4 = c0 * r4 + c1 * g4 + c2 * b4 + c3 * a4 + c4; // clamp, re-premul, and write dst[i] = SkPMFloat(premul(clamp_0_255(dst4))).get(); diff --git a/src/opts/SkPMFloat_SSSE3.h b/src/opts/SkPMFloat_SSSE3.h index 390c71ce3f..ccc4d4feb8 100644 --- a/src/opts/SkPMFloat_SSSE3.h +++ b/src/opts/SkPMFloat_SSSE3.h @@ -33,7 +33,7 @@ inline SkPMColor SkPMFloat::trunc() const { inline SkPMColor SkPMFloat::get() const { SkASSERT(this->isValid()); - return SkPMFloat(Sk4s(0.5f) + *this).trunc(); + return SkPMFloat(Sk4f(0.5f) + *this).trunc(); } inline SkPMColor SkPMFloat::clamped() const { diff --git a/src/opts/SkPMFloat_neon.h b/src/opts/SkPMFloat_neon.h index 41c553ebb9..1373c3ae3a 100644 --- a/src/opts/SkPMFloat_neon.h +++ b/src/opts/SkPMFloat_neon.h @@ -32,7 +32,7 @@ inline SkPMColor SkPMFloat::trunc() const { inline SkPMColor SkPMFloat::get() const { SkASSERT(this->isValid()); - return SkPMFloat(Sk4s(0.5f) + *this).trunc(); + return SkPMFloat(Sk4f(0.5f) + *this).trunc(); } inline SkPMColor SkPMFloat::clamped() const { diff --git a/tests/PMFloatTest.cpp b/tests/PMFloatTest.cpp index 435969c21f..309cd60f4a 100644 --- a/tests/PMFloatTest.cpp +++ b/tests/PMFloatTest.cpp @@ -32,9 +32,9 @@ DEF_TEST(SkPMFloat, r) { REPORTER_ASSERT(r, SkScalarNearlyEqual( 1.0f, clamped.g())); REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.0f, clamped.b())); - // Test SkPMFloat <-> Sk4s conversion. - Sk4s fs = clamped; - SkPMFloat scaled = fs * Sk4s(0.25f); + // Test SkPMFloat <-> Sk4f conversion. + Sk4f fs = clamped; + SkPMFloat scaled = fs * Sk4f(0.25f); REPORTER_ASSERT(r, SkScalarNearlyEqual(63.75f, scaled.a())); REPORTER_ASSERT(r, SkScalarNearlyEqual(38.25f, scaled.r())); REPORTER_ASSERT(r, SkScalarNearlyEqual( 0.25f, scaled.g()));