Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Unified Diff: src/core/SkPMFloat.h

Issue 1048593002: Refactor Sk2x<T> + Sk4x<T> into SkNf<N,T> and SkNi<N,T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: This is actually faster Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkNx.h ('k') | src/core/SkRect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPMFloat.h
diff --git a/src/core/SkPMFloat.h b/src/core/SkPMFloat.h
index 66262a8916ae772ef59d78db76d4aae0c840d095..27f6f78f26028e47fca9f24ff2908f90faf40f60 100644
--- a/src/core/SkPMFloat.h
+++ b/src/core/SkPMFloat.h
@@ -11,13 +11,7 @@
#include "SkTypes.h"
#include "SkColor.h"
#include "SkColorPriv.h"
-#include "Sk4x.h"
-
-#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
- #include <immintrin.h>
-#elif defined(SK_ARM_HAS_NEON)
- #include <arm_neon.h>
-#endif
+#include "SkNx.h"
// A pre-multiplied color storing each component in the same order as SkPMColor,
// but as a float in the range [0, 255].
@@ -29,29 +23,25 @@ public:
// May be more efficient than one at a time. No special alignment assumed for SkPMColors.
static void From4PMColors(const SkPMColor[4], SkPMFloat*, SkPMFloat*, SkPMFloat*, SkPMFloat*);
- explicit SkPMFloat(SkPMColor);
- SkPMFloat(float a, float r, float g, float b) {
- // TODO: faster when specialized?
- fColor[SK_A32_SHIFT / 8] = a;
- fColor[SK_R32_SHIFT / 8] = r;
- fColor[SK_G32_SHIFT / 8] = g;
- fColor[SK_B32_SHIFT / 8] = b;
- }
-
// Uninitialized.
SkPMFloat() {}
+ explicit SkPMFloat(SkPMColor);
+ SkPMFloat(float a, float r, float g, float b)
+ #ifdef SK_PMCOLOR_IS_RGBA
+ : fColors(r,g,b,a) {}
+ #else
+ : fColors(b,g,r,a) {}
+ #endif
- SkPMFloat(const SkPMFloat& that) { *this = that; }
- SkPMFloat& operator=(const SkPMFloat& that);
- // Freely autoconvert between SkPMFloat and Sk4f. They're always byte-for-byte identical.
- /*implicit*/ SkPMFloat(const Sk4f& fs) { fs.storeAligned(fColor); }
- /*implicit*/ operator Sk4f() const { return Sk4f::LoadAligned(fColor); }
+ // Freely autoconvert between SkPMFloat and Sk4s.
+ /*implicit*/ SkPMFloat(const Sk4s& fs) { fColors = fs; }
+ /*implicit*/ operator Sk4s() const { return fColors; }
- float a() const { return fColor[SK_A32_SHIFT / 8]; }
- float r() const { return fColor[SK_R32_SHIFT / 8]; }
- float g() const { return fColor[SK_G32_SHIFT / 8]; }
- float b() const { return fColor[SK_B32_SHIFT / 8]; }
+ float a() const { return fColors[SK_A32_SHIFT / 8]; }
+ float r() const { return fColors[SK_R32_SHIFT / 8]; }
+ float g() const { return fColors[SK_G32_SHIFT / 8]; }
+ float b() const { return fColors[SK_B32_SHIFT / 8]; }
// get() and clamped() round component values to the nearest integer.
SkPMColor get() const; // May SkASSERT(this->isValid()). Some implementations may clamp.
@@ -75,24 +65,22 @@ public:
}
private:
- union {
- float fColor[4];
-#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
- __m128 fColors;
-#elif defined(SK_ARM_HAS_NEON)
- float32x4_t fColors;
-#endif
- };
+ Sk4s fColors;
};
-#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
- #include "../opts/SkPMFloat_SSSE3.h"
-#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
- #include "../opts/SkPMFloat_SSE2.h"
-#elif defined(SK_ARM_HAS_NEON)
- #include "../opts/SkPMFloat_neon.h"
-#else
+#ifdef SKNX_NO_SIMD
+ // Platform implementations of SkPMFloat assume Sk4s uses SSE or NEON. _none is generic.
#include "../opts/SkPMFloat_none.h"
+#else
+ #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
+ #include "../opts/SkPMFloat_SSSE3.h"
+ #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
+ #include "../opts/SkPMFloat_SSE2.h"
+ #elif defined(SK_ARM_HAS_NEON)
+ #include "../opts/SkPMFloat_neon.h"
+ #else
+ #include "../opts/SkPMFloat_none.h"
+ #endif
#endif
#endif//SkPM_DEFINED
« no previous file with comments | « src/core/SkNx.h ('k') | src/core/SkRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698