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

Side by Side Diff: src/opts/SkColor_opts_SSE2.h

Issue 2097883002: revise row blits to keep intermediate precision so that color is preserved when blended against its… (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Fix overflow in destination scale calculation Created 4 years, 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The Android Open Source Project 2 * Copyright 2014 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkColor_opts_SSE2_DEFINED 8 #ifndef SkColor_opts_SSE2_DEFINED
9 #define SkColor_opts_SSE2_DEFINED 9 #define SkColor_opts_SSE2_DEFINED
10 10
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 __m128i rb = _mm_and_si128(mask, c); 73 __m128i rb = _mm_and_si128(mask, c);
74 rb = _mm_mulhi_epu16(rb, s); 74 rb = _mm_mulhi_epu16(rb, s);
75 75
76 __m128i ag = _mm_andnot_si128(mask, c); 76 __m128i ag = _mm_andnot_si128(mask, c);
77 ag = _mm_mulhi_epu16(ag, s); // Alpha and green values are in the higher byte of each word. 77 ag = _mm_mulhi_epu16(ag, s); // Alpha and green values are in the higher byte of each word.
78 ag = _mm_andnot_si128(mask, ag); 78 ag = _mm_andnot_si128(mask, ag);
79 79
80 return _mm_or_si128(rb, ag); 80 return _mm_or_si128(rb, ag);
81 } 81 }
82 82
83 // Portable version SkFastFourByteInterp256 is in SkColorPriv.h.
84 static inline __m128i SkFastFourByteInterp256_SSE2(const __m128i& src, const __m 128i& dst, const unsigned src_scale) {
85 // Computes dst + (((src - dst)*src_scale)>>8)
86 const __m128i mask = _mm_set1_epi32(0x00FF00FF);
87
88 // Unpack the 16x8-bit source into 2 8x16-bit splayed halves.
89 __m128i src_rb = _mm_and_si128(mask, src);
90 __m128i src_ag = _mm_srli_epi16(src, 8);
91 __m128i dst_rb = _mm_and_si128(mask, dst);
92 __m128i dst_ag = _mm_srli_epi16(dst, 8);
93
94 // Compute scaled differences.
95 __m128i diff_rb = _mm_sub_epi16(src_rb, dst_rb);
96 __m128i diff_ag = _mm_sub_epi16(src_ag, dst_ag);
97 __m128i s = _mm_set1_epi16(src_scale);
98 diff_rb = _mm_mullo_epi16(diff_rb, s);
99 diff_ag = _mm_mullo_epi16(diff_ag, s);
100
101 // Pack the differences back together.
102 diff_rb = _mm_srli_epi16(diff_rb, 8);
103 diff_ag = _mm_andnot_si128(mask, diff_ag);
104 __m128i diff = _mm_or_si128(diff_rb, diff_ag);
105
106 // Add difference to destination.
107 return _mm_add_epi8(dst, diff);
108 }
109
83 static inline __m128i SkGetPackedA32_SSE2(const __m128i& src) { 110 static inline __m128i SkGetPackedA32_SSE2(const __m128i& src) {
84 #if SK_A32_SHIFT == 24 // It's very common (universal?) that alph a is the top byte. 111 #if SK_A32_SHIFT == 24 // It's very common (universal?) that alph a is the top byte.
85 return _mm_srli_epi32(src, 24); // You'd hope the compiler would remove th e left shift then, 112 return _mm_srli_epi32(src, 24); // You'd hope the compiler would remove th e left shift then,
86 #else // but I've seen Clang just do a dumb left shift of zero. :( 113 #else // but I've seen Clang just do a dumb left shift of zero. :(
87 __m128i a = _mm_slli_epi32(src, (24 - SK_A32_SHIFT)); 114 __m128i a = _mm_slli_epi32(src, (24 - SK_A32_SHIFT));
88 return _mm_srli_epi32(a, 24); 115 return _mm_srli_epi32(a, 24);
89 #endif 116 #endif
90 } 117 }
91 118
92 static inline __m128i SkGetPackedR32_SSE2(const __m128i& src) { 119 static inline __m128i SkGetPackedR32_SSE2(const __m128i& src) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return d_pixel; 233 return d_pixel;
207 } 234 }
208 235
209 // Portable version is SkPMSrcOver in SkColorPriv.h. 236 // Portable version is SkPMSrcOver in SkColorPriv.h.
210 static inline __m128i SkPMSrcOver_SSE2(const __m128i& src, const __m128i& dst) { 237 static inline __m128i SkPMSrcOver_SSE2(const __m128i& src, const __m128i& dst) {
211 return _mm_add_epi32(src, 238 return _mm_add_epi32(src,
212 SkAlphaMulQ_SSE2(dst, _mm_sub_epi32(_mm_set1_epi32(256) , 239 SkAlphaMulQ_SSE2(dst, _mm_sub_epi32(_mm_set1_epi32(256) ,
213 SkGetPackedA32_SSE2 (src)))); 240 SkGetPackedA32_SSE2 (src))));
214 } 241 }
215 242
216 // Portable version is SkBlendARGB32 in SkColorPriv.h.
217 static inline __m128i SkBlendARGB32_SSE2(const __m128i& src, const __m128i& dst,
218 const __m128i& aa) {
219 __m128i src_scale = SkAlpha255To256_SSE2(aa);
220 // SkAlpha255To256(255 - SkAlphaMul(SkGetPackedA32(src), src_scale))
221 __m128i dst_scale = SkGetPackedA32_SSE2(src);
222 dst_scale = _mm_mullo_epi16(dst_scale, src_scale);
223 dst_scale = _mm_srli_epi16(dst_scale, 8);
224 dst_scale = _mm_sub_epi32(_mm_set1_epi32(256), dst_scale);
225
226 __m128i result = SkAlphaMulQ_SSE2(src, src_scale);
227 return _mm_add_epi8(result, SkAlphaMulQ_SSE2(dst, dst_scale));
228 }
229
230 // Fast path for SkBlendARGB32_SSE2 with a constant alpha factor. 243 // Fast path for SkBlendARGB32_SSE2 with a constant alpha factor.
231 static inline __m128i SkBlendARGB32_SSE2(const __m128i& src, const __m128i& dst, 244 static inline __m128i SkBlendARGB32_SSE2(const __m128i& src, const __m128i& dst,
232 const unsigned aa) { 245 const unsigned aa) {
233 unsigned alpha = SkAlpha255To256(aa); 246 unsigned alpha = SkAlpha255To256(aa);
234 __m128i src_scale = _mm_set1_epi32(alpha); 247 __m128i src_scale = _mm_set1_epi16(alpha);
235 // SkAlpha255To256(255 - SkAlphaMul(SkGetPackedA32(src), src_scale)) 248 // SkAlphaMulInv256(SkGetPackedA32(src), src_scale)
236 __m128i dst_scale = SkGetPackedA32_SSE2(src); 249 __m128i dst_scale = SkGetPackedA32_SSE2(src);
250 // High words in dst_scale are 0, so it's safe to multiply with 16-bit src_s cale.
237 dst_scale = _mm_mullo_epi16(dst_scale, src_scale); 251 dst_scale = _mm_mullo_epi16(dst_scale, src_scale);
238 dst_scale = _mm_srli_epi16(dst_scale, 8); 252 dst_scale = _mm_sub_epi32(_mm_set1_epi32(256<<8), dst_scale);
239 dst_scale = _mm_sub_epi32(_mm_set1_epi32(256), dst_scale); 253 dst_scale = _mm_srli_epi32(dst_scale, 8);
254 // Duplicate scales into 2x16-bit pattern per pixel.
255 dst_scale = _mm_shufflelo_epi16(dst_scale, _MM_SHUFFLE(2, 2, 0, 0));
256 dst_scale = _mm_shufflehi_epi16(dst_scale, _MM_SHUFFLE(2, 2, 0, 0));
240 257
241 __m128i result = SkAlphaMulQ_SSE2(src, alpha); 258 const __m128i mask = _mm_set1_epi32(0x00FF00FF);
242 return _mm_add_epi8(result, SkAlphaMulQ_SSE2(dst, dst_scale)); 259
260 // Unpack the 16x8-bit source/destination into 2 8x16-bit splayed halves.
261 __m128i src_rb = _mm_and_si128(mask, src);
262 __m128i src_ag = _mm_srli_epi16(src, 8);
263 __m128i dst_rb = _mm_and_si128(mask, dst);
264 __m128i dst_ag = _mm_srli_epi16(dst, 8);
265
266 // Scale them.
267 src_rb = _mm_mullo_epi16(src_rb, src_scale);
268 src_ag = _mm_mullo_epi16(src_ag, src_scale);
269 dst_rb = _mm_mullo_epi16(dst_rb, dst_scale);
270 dst_ag = _mm_mullo_epi16(dst_ag, dst_scale);
271
272 // Add the scaled source and destination.
273 dst_rb = _mm_add_epi16(src_rb, dst_rb);
274 dst_ag = _mm_add_epi16(src_ag, dst_ag);
275
276 // Unsplay the halves back together.
277 dst_rb = _mm_srli_epi16(dst_rb, 8);
278 dst_ag = _mm_andnot_si128(mask, dst_ag);
279 return _mm_or_si128(dst_rb, dst_ag);
243 } 280 }
244 281
245 #undef ASSERT_EQ 282 #undef ASSERT_EQ
246 #endif // SkColor_opts_SSE2_DEFINED 283 #endif // SkColor_opts_SSE2_DEFINED
OLDNEW
« include/core/SkColorPriv.h ('K') | « src/opts/SkBlitRow_opts_mips_dsp.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698