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

Unified Diff: src/opts/SkXfermode_opts_SSE2.cpp

Issue 234653002: Xfermode: SSE2 implementation of darken&lighten mode (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase and fix reviewer's comment Created 6 years, 8 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 | « no previous file | 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 d5871083f70f60169c07acfaef16a3bff3bdbf9b..4e4532b7bdc6475c1ea5ae9f7b170cf5e7cb407b 100644
--- a/src/opts/SkXfermode_opts_SSE2.cpp
+++ b/src/opts/SkXfermode_opts_SSE2.cpp
@@ -283,6 +283,64 @@ static __m128i overlay_modeproc_SSE2(const __m128i& src, const __m128i& dst) {
return SkPackARGB32_SSE2(a, r, g, b);
}
+static inline __m128i darken_byte_SSE2(const __m128i& sc, const __m128i& dc,
+ const __m128i& sa, const __m128i& da) {
+ __m128i sd = _mm_mullo_epi16(sc, da);
+ __m128i ds = _mm_mullo_epi16(dc, sa);
+
+ __m128i cmp = _mm_cmplt_epi32(sd, ds);
+
+ __m128i tmp = _mm_add_epi32(sc, dc);
+ __m128i ret1 = _mm_sub_epi32(tmp, SkDiv255Round_SSE2(ds));
+ __m128i ret2 = _mm_sub_epi32(tmp, SkDiv255Round_SSE2(sd));
+ __m128i ret = _mm_or_si128(_mm_and_si128(cmp, ret1),
+ _mm_andnot_si128(cmp, ret2));
+ return ret;
+}
+
+static __m128i darken_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 = darken_byte_SSE2(SkGetPackedR32_SSE2(src),
+ SkGetPackedR32_SSE2(dst), sa, da);
+ __m128i g = darken_byte_SSE2(SkGetPackedG32_SSE2(src),
+ SkGetPackedG32_SSE2(dst), sa, da);
+ __m128i b = darken_byte_SSE2(SkGetPackedB32_SSE2(src),
+ SkGetPackedB32_SSE2(dst), sa, da);
+ return SkPackARGB32_SSE2(a, r, g, b);
+}
+
+static inline __m128i lighten_byte_SSE2(const __m128i& sc, const __m128i& dc,
+ const __m128i& sa, const __m128i& da) {
+ __m128i sd = _mm_mullo_epi16(sc, da);
+ __m128i ds = _mm_mullo_epi16(dc, sa);
+
+ __m128i cmp = _mm_cmpgt_epi32(sd, ds);
+
+ __m128i tmp = _mm_add_epi32(sc, dc);
+ __m128i ret1 = _mm_sub_epi32(tmp, SkDiv255Round_SSE2(ds));
+ __m128i ret2 = _mm_sub_epi32(tmp, SkDiv255Round_SSE2(sd));
+ __m128i ret = _mm_or_si128(_mm_and_si128(cmp, ret1),
+ _mm_andnot_si128(cmp, ret2));
+ return ret;
+}
+
+static __m128i lighten_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 = lighten_byte_SSE2(SkGetPackedR32_SSE2(src),
+ SkGetPackedR32_SSE2(dst), sa, da);
+ __m128i g = lighten_byte_SSE2(SkGetPackedG32_SSE2(src),
+ SkGetPackedG32_SSE2(dst), sa, da);
+ __m128i b = lighten_byte_SSE2(SkGetPackedB32_SSE2(src),
+ SkGetPackedB32_SSE2(dst), sa, da);
+ return SkPackARGB32_SSE2(a, r, g, b);
+}
+
static inline __m128i colordodge_byte_SSE2(const __m128i& sc, const __m128i& dc,
const __m128i& sa, const __m128i& da) {
__m128i diff = _mm_sub_epi32(sa, sc);
@@ -726,8 +784,8 @@ SkXfermodeProcSIMD gSSE2XfermodeProcs[] = {
screen_modeproc_SSE2,
overlay_modeproc_SSE2,
- NULL, // kDarken_Mode
- NULL, // kLighten_Mode
+ darken_modeproc_SSE2,
+ lighten_modeproc_SSE2,
colordodge_modeproc_SSE2,
colorburn_modeproc_SSE2,
hardlight_modeproc_SSE2,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698