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

Unified Diff: src/opts/SkXfermode_opts_SSE2.cpp

Issue 1150833003: Clean up Sk4f xfermodes and covered _SSE2 xfermodes. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: dead Created 5 years, 7 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/SkXfermode.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/opts/SkXfermode_opts_SSE2.cpp
diff --git a/src/opts/SkXfermode_opts_SSE2.cpp b/src/opts/SkXfermode_opts_SSE2.cpp
index fccf66514789950d58da06f9695af0fb90d4409a..b92477094b72cbd8b6ab5b8f884355bf2f969990 100644
--- a/src/opts/SkXfermode_opts_SSE2.cpp
+++ b/src/opts/SkXfermode_opts_SSE2.cpp
@@ -25,26 +25,6 @@ static inline __m128i SkDiv255Round_SSE2(const __m128i& a) {
return prod;
}
-static inline __m128i saturated_add_SSE2(const __m128i& a, const __m128i& b) {
- __m128i sum = _mm_add_epi32(a, b);
- __m128i cmp = _mm_cmpgt_epi32(sum, _mm_set1_epi32(255));
-
- sum = _mm_or_si128(_mm_and_si128(cmp, _mm_set1_epi32(255)),
- _mm_andnot_si128(cmp, sum));
- return sum;
-}
-
-static inline __m128i clamp_signed_byte_SSE2(const __m128i& n) {
- __m128i cmp1 = _mm_cmplt_epi32(n, _mm_setzero_si128());
- __m128i cmp2 = _mm_cmpgt_epi32(n, _mm_set1_epi32(255));
- __m128i ret = _mm_and_si128(cmp2, _mm_set1_epi32(255));
-
- __m128i cmp = _mm_or_si128(cmp1, cmp2);
- ret = _mm_or_si128(_mm_and_si128(cmp, ret), _mm_andnot_si128(cmp, n));
-
- return ret;
-}
-
static inline __m128i clamp_div255round_SSE2(const __m128i& prod) {
// test if > 0
__m128i cmp1 = _mm_cmpgt_epi32(prod, _mm_setzero_si128());
@@ -65,131 +45,6 @@ static inline __m128i clamp_div255round_SSE2(const __m128i& prod) {
return ret;
}
-
-static __m128i srcover_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i isa = _mm_sub_epi32(_mm_set1_epi32(256), SkGetPackedA32_SSE2(src));
- return _mm_add_epi32(src, SkAlphaMulQ_SSE2(dst, isa));
-}
-
-static __m128i dstover_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i ida = _mm_sub_epi32(_mm_set1_epi32(256), SkGetPackedA32_SSE2(dst));
- return _mm_add_epi32(dst, SkAlphaMulQ_SSE2(src, ida));
-}
-
-static __m128i srcin_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i da = SkGetPackedA32_SSE2(dst);
- return SkAlphaMulQ_SSE2(src, SkAlpha255To256_SSE2(da));
-}
-
-static __m128i dstin_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- return SkAlphaMulQ_SSE2(dst, SkAlpha255To256_SSE2(sa));
-}
-
-static __m128i srcout_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i ida = _mm_sub_epi32(_mm_set1_epi32(256), SkGetPackedA32_SSE2(dst));
- return SkAlphaMulQ_SSE2(src, ida);
-}
-
-static __m128i dstout_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i isa = _mm_sub_epi32(_mm_set1_epi32(256), SkGetPackedA32_SSE2(src));
- return SkAlphaMulQ_SSE2(dst, isa);
-}
-
-static __m128i srcatop_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
- __m128i isa = _mm_sub_epi32(_mm_set1_epi32(255), sa);
-
- __m128i a = da;
-
- __m128i r1 = SkAlphaMulAlpha_SSE2(da, SkGetPackedR32_SSE2(src));
- __m128i r2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedR32_SSE2(dst));
- __m128i r = _mm_add_epi32(r1, r2);
-
- __m128i g1 = SkAlphaMulAlpha_SSE2(da, SkGetPackedG32_SSE2(src));
- __m128i g2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedG32_SSE2(dst));
- __m128i g = _mm_add_epi32(g1, g2);
-
- __m128i b1 = SkAlphaMulAlpha_SSE2(da, SkGetPackedB32_SSE2(src));
- __m128i b2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedB32_SSE2(dst));
- __m128i b = _mm_add_epi32(b1, b2);
-
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static __m128i dstatop_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
- __m128i ida = _mm_sub_epi32(_mm_set1_epi32(255), da);
-
- __m128i a = sa;
-
- __m128i r1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedR32_SSE2(src));
- __m128i r2 = SkAlphaMulAlpha_SSE2(sa, SkGetPackedR32_SSE2(dst));
- __m128i r = _mm_add_epi32(r1, r2);
-
- __m128i g1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedG32_SSE2(src));
- __m128i g2 = SkAlphaMulAlpha_SSE2(sa, SkGetPackedG32_SSE2(dst));
- __m128i g = _mm_add_epi32(g1, g2);
-
- __m128i b1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedB32_SSE2(src));
- __m128i b2 = SkAlphaMulAlpha_SSE2(sa, SkGetPackedB32_SSE2(dst));
- __m128i b = _mm_add_epi32(b1, b2);
-
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static __m128i xor_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
- __m128i isa = _mm_sub_epi32(_mm_set1_epi32(255), sa);
- __m128i ida = _mm_sub_epi32(_mm_set1_epi32(255), da);
-
- __m128i a1 = _mm_add_epi32(sa, da);
- __m128i a2 = SkAlphaMulAlpha_SSE2(sa, da);
- a2 = _mm_slli_epi32(a2, 1);
- __m128i a = _mm_sub_epi32(a1, a2);
-
- __m128i r1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedR32_SSE2(src));
- __m128i r2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedR32_SSE2(dst));
- __m128i r = _mm_add_epi32(r1, r2);
-
- __m128i g1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedG32_SSE2(src));
- __m128i g2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedG32_SSE2(dst));
- __m128i g = _mm_add_epi32(g1, g2);
-
- __m128i b1 = SkAlphaMulAlpha_SSE2(ida, SkGetPackedB32_SSE2(src));
- __m128i b2 = SkAlphaMulAlpha_SSE2(isa, SkGetPackedB32_SSE2(dst));
- __m128i b = _mm_add_epi32(b1, b2);
-
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static __m128i plus_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i b = saturated_add_SSE2(SkGetPackedB32_SSE2(src),
- SkGetPackedB32_SSE2(dst));
- __m128i g = saturated_add_SSE2(SkGetPackedG32_SSE2(src),
- SkGetPackedG32_SSE2(dst));
- __m128i r = saturated_add_SSE2(SkGetPackedR32_SSE2(src),
- SkGetPackedR32_SSE2(dst));
- __m128i a = saturated_add_SSE2(SkGetPackedA32_SSE2(src),
- SkGetPackedA32_SSE2(dst));
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static __m128i modulate_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i a = SkAlphaMulAlpha_SSE2(SkGetPackedA32_SSE2(src),
- SkGetPackedA32_SSE2(dst));
- __m128i r = SkAlphaMulAlpha_SSE2(SkGetPackedR32_SSE2(src),
- SkGetPackedR32_SSE2(dst));
- __m128i g = SkAlphaMulAlpha_SSE2(SkGetPackedG32_SSE2(src),
- SkGetPackedG32_SSE2(dst));
- __m128i b = SkAlphaMulAlpha_SSE2(SkGetPackedB32_SSE2(src),
- SkGetPackedB32_SSE2(dst));
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
static inline __m128i SkMin32_SSE2(const __m128i& a, const __m128i& b) {
__m128i cmp = _mm_cmplt_epi32(a, b);
return _mm_or_si128(_mm_and_si128(cmp, a), _mm_andnot_si128(cmp, b));
@@ -201,58 +56,6 @@ static inline __m128i srcover_byte_SSE2(const __m128i& a, const __m128i& b) {
}
-static inline __m128i blendfunc_multiply_byte_SSE2(const __m128i& sc, const __m128i& dc,
- const __m128i& sa, const __m128i& da) {
- // sc * (255 - da)
- __m128i ret1 = _mm_sub_epi32(_mm_set1_epi32(255), da);
- ret1 = _mm_mullo_epi16(sc, ret1);
-
- // dc * (255 - sa)
- __m128i ret2 = _mm_sub_epi32(_mm_set1_epi32(255), sa);
- ret2 = _mm_mullo_epi16(dc, ret2);
-
- // sc * dc
- __m128i ret3 = _mm_mullo_epi16(sc, dc);
-
- __m128i ret = _mm_add_epi32(ret1, ret2);
- ret = _mm_add_epi32(ret, ret3);
-
- return clamp_div255round_SSE2(ret);
-}
-
-static __m128i multiply_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
- __m128i a = srcover_byte_SSE2(sa, da);
-
- __m128i sr = SkGetPackedR32_SSE2(src);
- __m128i dr = SkGetPackedR32_SSE2(dst);
- __m128i r = blendfunc_multiply_byte_SSE2(sr, dr, sa, da);
-
- __m128i sg = SkGetPackedG32_SSE2(src);
- __m128i dg = SkGetPackedG32_SSE2(dst);
- __m128i g = blendfunc_multiply_byte_SSE2(sg, dg, sa, da);
-
-
- __m128i sb = SkGetPackedB32_SSE2(src);
- __m128i db = SkGetPackedB32_SSE2(dst);
- __m128i b = blendfunc_multiply_byte_SSE2(sb, db, sa, da);
-
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static __m128i screen_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i a = srcover_byte_SSE2(SkGetPackedA32_SSE2(src),
- SkGetPackedA32_SSE2(dst));
- __m128i r = srcover_byte_SSE2(SkGetPackedR32_SSE2(src),
- SkGetPackedR32_SSE2(dst));
- __m128i g = srcover_byte_SSE2(SkGetPackedG32_SSE2(src),
- SkGetPackedG32_SSE2(dst));
- __m128i b = srcover_byte_SSE2(SkGetPackedB32_SSE2(src),
- SkGetPackedB32_SSE2(dst));
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
// Portable version overlay_byte() is in SkXfermode.cpp.
static inline __m128i overlay_byte_SSE2(const __m128i& sc, const __m128i& dc,
const __m128i& sa, const __m128i& da) {
@@ -580,67 +383,11 @@ static __m128i softlight_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
return SkPackARGB32_SSE2(a, r, g, b);
}
-static inline __m128i difference_byte_SSE2(const __m128i& sc, const __m128i& dc,
- const __m128i& sa, const __m128i& da) {
- __m128i tmp1 = _mm_mullo_epi16(sc, da);
- __m128i tmp2 = _mm_mullo_epi16(dc, sa);
- __m128i tmp = SkMin32_SSE2(tmp1, tmp2);
-
- __m128i ret1 = _mm_add_epi32(sc, dc);
- __m128i ret2 = _mm_slli_epi32(SkDiv255Round_SSE2(tmp), 1);
- __m128i ret = _mm_sub_epi32(ret1, ret2);
-
- ret = clamp_signed_byte_SSE2(ret);
- return ret;
-}
-
-static __m128i difference_modeproc_SSE2(const __m128i& src,
- const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
-
- __m128i a = srcover_byte_SSE2(sa, da);
- __m128i r = difference_byte_SSE2(SkGetPackedR32_SSE2(src),
- SkGetPackedR32_SSE2(dst), sa, da);
- __m128i g = difference_byte_SSE2(SkGetPackedG32_SSE2(src),
- SkGetPackedG32_SSE2(dst), sa, da);
- __m128i b = difference_byte_SSE2(SkGetPackedB32_SSE2(src),
- SkGetPackedB32_SSE2(dst), sa, da);
- return SkPackARGB32_SSE2(a, r, g, b);
-}
-
-static inline __m128i exclusion_byte_SSE2(const __m128i& sc, const __m128i& dc,
- const __m128i&, __m128i&) {
- __m128i tmp1 = _mm_mullo_epi16(_mm_set1_epi32(255), sc); // 255 * sc
- __m128i tmp2 = _mm_mullo_epi16(_mm_set1_epi32(255), dc); // 255 * dc
- tmp1 = _mm_add_epi32(tmp1, tmp2);
- tmp2 = _mm_mullo_epi16(sc, dc); // sc * dc
- tmp2 = _mm_slli_epi32(tmp2, 1); // 2 * sc * dc
-
- __m128i r = _mm_sub_epi32(tmp1, tmp2);
- return clamp_div255round_SSE2(r);
-}
-
-static __m128i exclusion_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
- __m128i sa = SkGetPackedA32_SSE2(src);
- __m128i da = SkGetPackedA32_SSE2(dst);
-
- __m128i a = srcover_byte_SSE2(sa, da);
- __m128i r = exclusion_byte_SSE2(SkGetPackedR32_SSE2(src),
- SkGetPackedR32_SSE2(dst), sa, da);
- __m128i g = exclusion_byte_SSE2(SkGetPackedG32_SSE2(src),
- SkGetPackedG32_SSE2(dst), sa, da);
- __m128i b = exclusion_byte_SSE2(SkGetPackedB32_SSE2(src),
- SkGetPackedB32_SSE2(dst), sa, da);
- return SkPackARGB32_SSE2(a, r, g, b);
-}
////////////////////////////////////////////////////////////////////////////////
typedef __m128i (*SkXfermodeProcSIMD)(const __m128i& src, const __m128i& dst);
-extern SkXfermodeProcSIMD gSSE2XfermodeProcs[];
-
void SkSSE2ProcCoeffXfermode::xfer32(SkPMColor dst[], const SkPMColor src[],
int count, const SkAlpha aa[]) const {
SkASSERT(dst && src && count >= 0);
@@ -765,49 +512,19 @@ void SkSSE2ProcCoeffXfermode::toString(SkString* str) const {
}
#endif
-////////////////////////////////////////////////////////////////////////////////
-
-// 4 pixels modeprocs with SSE2
-SkXfermodeProcSIMD gSSE2XfermodeProcs[] = {
- NULL, // kClear_Mode
- NULL, // kSrc_Mode
- NULL, // kDst_Mode
- srcover_modeproc_SSE2,
- dstover_modeproc_SSE2,
- srcin_modeproc_SSE2,
- dstin_modeproc_SSE2,
- srcout_modeproc_SSE2,
- dstout_modeproc_SSE2,
- srcatop_modeproc_SSE2,
- dstatop_modeproc_SSE2,
- xor_modeproc_SSE2,
- plus_modeproc_SSE2,
- modulate_modeproc_SSE2,
- screen_modeproc_SSE2,
-
- overlay_modeproc_SSE2,
- darken_modeproc_SSE2,
- lighten_modeproc_SSE2,
- colordodge_modeproc_SSE2,
- colorburn_modeproc_SSE2,
- hardlight_modeproc_SSE2,
- softlight_modeproc_SSE2,
- difference_modeproc_SSE2,
- exclusion_modeproc_SSE2,
- multiply_modeproc_SSE2,
-
- NULL, // kHue_Mode
- NULL, // kSaturation_Mode
- NULL, // kColor_Mode
- NULL, // kLuminosity_Mode
-};
-
SkProcCoeffXfermode* SkPlatformXfermodeFactory_impl_SSE2(const ProcCoeff& rec,
SkXfermode::Mode mode) {
- void* procSIMD = reinterpret_cast<void*>(gSSE2XfermodeProcs[mode]);
-
- if (procSIMD != NULL) {
- return SkNEW_ARGS(SkSSE2ProcCoeffXfermode, (rec, mode, procSIMD));
+ SkXfermodeProcSIMD proc = nullptr;
+ // TODO(mtklein): implement these Sk4px.
+ switch (mode) {
+ case SkProcCoeffXfermode::kOverlay_Mode: proc = overlay_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kDarken_Mode: proc = darken_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kLighten_Mode: proc = lighten_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kColorDodge_Mode: proc = colordodge_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kColorBurn_Mode: proc = colorburn_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kHardLight_Mode: proc = hardlight_modeproc_SSE2; break;
+ case SkProcCoeffXfermode::kSoftLight_Mode: proc = softlight_modeproc_SSE2; break;
+ default: break;
}
- return NULL;
+ return proc ? SkNEW_ARGS(SkSSE2ProcCoeffXfermode, (rec, mode, (void*)proc)) : nullptr;
}
« no previous file with comments | « src/core/SkXfermode.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698